/* ==========================================================================
   Kylar J. Matheson — Portfolio Stylesheet
   Sections: Reset, Variables, Typography, Layout, Navigation, Hero, Cards,
   Sections, Buttons, Forms, Tables, Gallery, Timeline, Athletics, Admin,
   Modals, Toasts, Responsive, Print, Accessibility
   ========================================================================== */

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 88px; }
body { margin: 0; }
img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, h4, p { margin: 0; }
input, textarea, select { font: inherit; color: inherit; }

/* ---------- Variables ---------- */
:root {
  --bg: #0a0a0b;
  --surface: #131315;
  --surface-2: #1b1b1e;
  --surface-3: #232326;
  --text: #f2f1ef;
  --muted: #9a9a9d;
  --muted-2: #6d6d70;
  --accent: #d81324;
  --accent-hover: #b80f1e;
  --accent-soft: rgba(216, 19, 36, 0.14);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --radius-s: 4px;
  --radius-m: 8px;
  --radius-l: 14px;
  --font-display: "Manrope", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --container: 1180px;
  --nav-h: 76px;
}

:root[data-theme="light"] {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f2f0ed;
  --surface-3: #e9e6e2;
  --text: #151415;
  --muted: #5b5a5c;
  --muted-2: #8a8889;
  --accent: #c8102e;
  --accent-hover: #a80d26;
  --accent-soft: rgba(200, 16, 46, 0.09);
  --border: rgba(10, 10, 10, 0.1);
  --border-strong: rgba(10, 10, 10, 0.18);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- Typography ---------- */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 800; letter-spacing: -0.01em; }
h1 { font-size: clamp(2.4rem, 5vw, 4rem); line-height: 1.04; }
h2 { font-size: clamp(1.7rem, 3vw, 2.4rem); line-height: 1.12; }
h3 { font-size: 1.3rem; line-height: 1.25; }
h4 { font-size: 1.05rem; }
p { color: var(--muted); max-width: 62ch; }
.lede { font-size: 1.1rem; color: var(--text); }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 32px; flex-wrap: wrap; }
.section-head .bib { font-family: var(--font-display); font-weight: 700; color: var(--accent); font-size: 0.85rem; letter-spacing: 0.06em; display: block; margin-bottom: 8px; }
.section-head h2 { border-bottom: 2px solid var(--accent); padding-bottom: 14px; display: inline-block; }
.section-sub { color: var(--muted); max-width: 56ch; margin-top: 10px; }

/* ---------- Layout ---------- */
.container { max-width: var(--container); margin: 0 auto; padding: 0 24px; }
.view { display: none; }
.view.active { display: block; animation: viewIn 0.4s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
section.block { padding: 88px 0; border-top: 1px solid var(--border); }
section.block:first-child { border-top: none; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.empty-state { padding: 40px 24px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius-m); color: var(--muted); background: var(--surface); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 6px; font-family: var(--font-display); }
#loader { position: fixed; inset: 0; background: var(--bg); z-index: 999; display: flex; align-items: center; justify-content: center; transition: opacity 0.4s ease; }
#loader.hidden { opacity: 0; pointer-events: none; }
.loader-mark { width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: 10px 16px; z-index: 2000; border-radius: 0 0 8px 0; }
.skip-link:focus { left: 0; }
#offline-banner { display: none; background: var(--surface-3); color: var(--muted); font-size: 0.85rem; text-align: center; padding: 8px; border-bottom: 1px solid var(--border); }
#offline-banner.show { display: block; }

/* ---------- Navigation ---------- */
#site-nav { position: sticky; top: 0; z-index: 500; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); height: var(--nav-h); }
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 100%; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 800; }
.brand .mark { width: 34px; height: 34px; border-radius: var(--radius-s); background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; letter-spacing: 0.02em; }
.brand .name { font-size: 1rem; }
.brand .name small { display: block; font-weight: 500; color: var(--muted); font-size: 0.7rem; font-family: var(--font-body); }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a { padding: 8px 12px; border-radius: var(--radius-s); font-size: 0.92rem; color: var(--muted); transition: color 0.2s, background 0.2s; white-space: nowrap; }
.nav-links a:hover, .nav-links a:focus-visible { color: var(--text); background: var(--surface-2); }
.nav-links a.active { color: var(--text); }
.nav-links a.active { position: relative; }
.nav-links a.active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 2px; height: 2px; background: var(--accent); }
.nav-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: flex; align-items: center; justify-content: center; transition: border-color 0.2s, transform 0.2s; }
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }
#hamburger { display: none; }
#mobile-nav { display: none; position: fixed; inset: var(--nav-h) 0 0 0; background: var(--bg); z-index: 490; padding: 20px 0; overflow-y: auto; }
#mobile-nav.open { display: block; }
#mobile-nav a { display: block; padding: 16px 24px; font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; border-bottom: 1px solid var(--border); }

/* ---------- Hero ---------- */
.hero { position: relative; min-height: 86vh; display: flex; align-items: flex-end; overflow: hidden; }
.hero-media { position: absolute; inset: 0; z-index: 0; }
.hero-media img { width: 100%; height: 100%; object-fit: cover; object-position: center 42%; }
.hero-media::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(6,6,7,0.92) 4%, rgba(6,6,7,0.55) 42%, rgba(6,6,7,0.15) 70%); }
.hero-content { position: relative; z-index: 1; padding: 60px 0 72px; width: 100%; }
.hero-eyebrow { color: var(--accent); font-family: var(--font-display); font-weight: 700; font-size: 0.9rem; letter-spacing: 0.03em; margin-bottom: 14px; }
.hero h1 { color: #fff; }
.hero-meta { color: #d8d7d5; font-size: 1.05rem; margin-top: 10px; }
.hero-copy { color: #cfcecb; margin-top: 20px; font-size: 1.08rem; max-width: 64ch; }
.hero-ctas { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 22px; border-radius: var(--radius-s); font-weight: 700; font-family: var(--font-display); font-size: 0.92rem; border: 1px solid transparent; transition: transform 0.15s ease, background 0.2s, border-color 0.2s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; color: #fff; border-color: rgba(255,255,255,0.5); }
.btn-outline:hover { border-color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--border-strong); }
.btn-sm { padding: 8px 14px; font-size: 0.82rem; }
.btn-danger { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-danger:hover { background: var(--accent-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 24px; transition: border-color 0.2s; }
.card:hover { border-color: var(--border-strong); }
.card-title { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; }
.card-meta { font-size: 0.85rem; color: var(--muted-2); margin-bottom: 10px; }
.badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 100px; font-size: 0.72rem; font-weight: 700; border: 1px solid var(--border-strong); color: var(--muted); }
.badge.accent { border-color: var(--accent); color: var(--accent); }
.badge.featured { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 20px; }
.stat-card .num { font-family: var(--font-display); font-size: 1.8rem; font-weight: 800; }
.stat-card .label { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }

/* ---------- Athlete profile ---------- */
.athlete-card { display: grid; grid-template-columns: 220px 1fr; gap: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); padding: 32px; align-items: start; }
.athlete-photo { width: 100%; aspect-ratio: 1; border-radius: var(--radius-m); overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-size: 2rem; font-weight: 800; color: var(--muted); border: 1px solid var(--border); }
.athlete-photo img { width: 100%; height: 100%; object-fit: cover; }
.event-pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.event-pill { border: 1px solid var(--border-strong); border-radius: var(--radius-s); padding: 6px 12px; font-family: var(--font-display); font-weight: 700; font-size: 0.85rem; }
.event-pill.planned { border-style: dashed; color: var(--muted); }
.lane-rule { height: 1px; background: repeating-linear-gradient(90deg, var(--border-strong) 0 18px, transparent 18px 30px); margin: 24px 0; }

/* ---------- PR table ---------- */
.pr-table { width: 100%; border-collapse: collapse; }
.pr-table th { text-align: left; font-family: var(--font-display); font-size: 0.75rem; text-transform: none; color: var(--muted-2); padding: 10px 14px; border-bottom: 1px solid var(--border-strong); }
.pr-table td { padding: 14px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.pr-table tr:last-child td { border-bottom: none; }
.pr-event { font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-m); }

/* ---------- Timeline ---------- */
.timeline-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 28px; }
.filter-chip { padding: 7px 14px; border-radius: 100px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 0.82rem; color: var(--muted); }
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.timeline-track { position: relative; padding-left: 28px; }
.timeline-track::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border-strong); }
.timeline-item { position: relative; padding-bottom: 28px; }
.timeline-item::before { content: ""; position: absolute; left: -28px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.timeline-item .date { font-family: var(--font-display); font-weight: 700; color: var(--accent); font-size: 0.8rem; }

/* ---------- Gallery ---------- */
.gallery-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.gallery-item { position: relative; border-radius: var(--radius-m); overflow: hidden; aspect-ratio: 4/3; background: var(--surface-2); border: 1px solid var(--border); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; }
.gallery-item:hover img { transform: scale(1.05); }
.gallery-item .caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 12px; background: linear-gradient(0deg, rgba(0,0,0,0.75), transparent); color: #fff; font-size: 0.82rem; }
.gallery-item.video::after { content: "▶"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.6rem; background: rgba(0,0,0,0.25); }
.lightbox { position: fixed; inset: 0; background: rgba(4,4,5,0.94); z-index: 800; display: none; align-items: center; justify-content: center; padding: 40px; }
.lightbox.open { display: flex; }
.lightbox-content { max-width: 900px; width: 100%; }
.lightbox img, .lightbox iframe { width: 100%; border-radius: var(--radius-m); max-height: 72vh; object-fit: contain; background: #000; }
.lightbox iframe { aspect-ratio: 16/9; height: auto; }
.lightbox-caption { color: #fff; margin-top: 14px; }
.lightbox-close { position: absolute; top: 24px; right: 24px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .field select { background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-s); padding: 10px 12px; color: var(--text); width: 100%; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.field textarea { min-height: 100px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Search ---------- */
.search-box { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-s); padding: 10px 14px; }
.search-box input { background: transparent; border: none; width: 100%; }
.search-box input:focus { outline: none; }
#search-results { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.search-result { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-m); background: var(--surface); }
.search-result .path { font-size: 0.75rem; color: var(--accent); font-weight: 700; }

/* ---------- Footer ---------- */
footer { border-top: 1px solid var(--border); padding: 48px 0 32px; }
.footer-grid { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 24px; }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { color: var(--muted); font-size: 0.88rem; }
.footer-links a:hover { color: var(--text); }
.footer-bottom { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; font-size: 0.8rem; color: var(--muted-2); }
.admin-link-discreet { color: var(--muted-2); font-size: 0.78rem; }

/* ---------- Admin ---------- */
.admin-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 70vh; gap: 0; }
.admin-sidebar { border-right: 1px solid var(--border); padding: 24px 16px; }
.admin-sidebar a { display: block; padding: 10px 12px; border-radius: var(--radius-s); color: var(--muted); font-size: 0.9rem; margin-bottom: 2px; }
.admin-sidebar a.active, .admin-sidebar a:hover { background: var(--surface-2); color: var(--text); }
.admin-main { padding: 32px; }
.admin-topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; flex-wrap: wrap; gap: 12px; }
.admin-breadcrumb { font-size: 0.8rem; color: var(--muted-2); margin-bottom: 6px; }
.admin-entry-list { display: flex; flex-direction: column; gap: 10px; }
.admin-entry { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); }
.admin-entry-title { font-weight: 700; font-family: var(--font-display); }
.admin-entry-meta { font-size: 0.8rem; color: var(--muted-2); }
.admin-entry-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.overview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 32px; }
.auth-panel { max-width: 420px; margin: 80px auto; text-align: center; padding: 40px 32px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); }
.auth-panel .g-mark { width: 52px; height: 52px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; }

/* ---------- Modals ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(4,4,5,0.7); z-index: 700; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-l); max-width: 560px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 28px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.4rem; line-height: 1; }

/* ---------- Toasts ---------- */
#toast-stack { position: fixed; bottom: 24px; right: 24px; z-index: 900; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface-3); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent); border-radius: var(--radius-s); padding: 12px 16px; min-width: 240px; max-width: 340px; font-size: 0.88rem; box-shadow: var(--shadow); animation: toastIn 0.25s ease; }
.toast.success { border-left-color: #2ea043; }
.toast.error { border-left-color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .nav-links { display: none; }
  #hamburger { display: flex; }
  .athlete-card { grid-template-columns: 1fr; }
  .athlete-photo { width: 160px; }
  .admin-shell { grid-template-columns: 1fr; }
  .admin-sidebar { display: flex; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 12px; }
  .admin-sidebar a { white-space: nowrap; }
}
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  section.block { padding: 56px 0; }
  .hero { min-height: 78vh; }
}
@media (max-width: 480px) {
  .container { padding: 0 16px; }
  .hero-ctas { flex-direction: column; align-items: stretch; }
}

/* ---------- Accessibility ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Print ---------- */
@media print {
  #site-nav, footer, .hero-ctas, #toast-stack, .modal-overlay, #back-to-top, .icon-btn, #offline-banner, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .view { display: none !important; }
  #view-resume { display: block !important; }
  .card, section.block { border: none; padding: 0; }
  a[href]::after { content: "" !important; }
}

/* Back to top */
#back-to-top { position: fixed; bottom: 24px; left: 24px; z-index: 400; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#back-to-top.show { opacity: 1; pointer-events: auto; }
