/* PTA Study Lab — base: reset, typography, shell layout (OWNER: design lead). */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  font-size: calc(100% * var(--text-scale));
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: var(--leading);
  font-feature-settings: 'kern', 'liga', 'calt';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img, svg, video, canvas { display: block; max-width: 100%; }
svg { overflow: visible; }
.icon { flex: none; display: inline-block; vertical-align: middle; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:where(button) { background: none; border: 0; padding: 0; }
a { color: var(--primary); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
p { margin: 0 0 var(--space-3); max-width: var(--measure); }
ul, ol { margin: 0 0 var(--space-3); padding-left: 1.3em; max-width: var(--measure); }
li { margin-bottom: .3em; }
li::marker { color: var(--text-muted); }
b, strong { font-weight: 700; }
em { font-style: italic; }
kbd {
  font-family: var(--font-mono); font-size: .86em; padding: .1em .4em; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px;
}
code { font-family: var(--font-mono); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0; }
::selection { background: color-mix(in srgb, var(--primary) 28%, transparent); }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.012em;
  margin: 0 0 var(--space-3);
  text-wrap: balance;
  color: var(--text);
}
h1 { font-size: var(--step-4); font-weight: 620; }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); font-family: var(--font-body); font-weight: 700; letter-spacing: 0; }
h1:focus, h2:focus, main:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--text-muted); }
.eyebrow {
  font-family: var(--font-body);
  font-size: var(--step--1); font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-muted); margin: 0 0 var(--space-2);
}
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap-1 { gap: var(--space-1); } .gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); } .gap-4 { gap: var(--space-4); }
.stack > * + * { margin-top: var(--space-4); }
.lede { font-size: var(--step-1); color: var(--text-muted); line-height: 1.45; max-width: 58ch; }

/* ── Shell ────────────────────────────────────────────────────────────── */
.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 100;
  background: var(--primary); color: var(--primary-contrast);
  padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 700;
  transition: top var(--dur-fast) var(--ease);
}
.skip-link:focus { top: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--space-2);
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--space-2), env(safe-area-inset-right)) 0 max(var(--space-3), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.topbar-brand, .topbar-back {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--tap); min-width: 0;
  color: var(--text); text-decoration: none; font-weight: 700;
}
.topbar-brand[hidden], .topbar-back[hidden] { display: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-name { font-family: var(--font-display); font-size: 1.12rem; font-weight: 650; letter-spacing: -0.01em; }
.topbar-back { margin-left: -6px; padding-right: var(--space-2); color: var(--primary); font-weight: 650; max-width: 70vw; }
.topbar-back-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }

.main {
  display: block;
  padding: var(--space-4) max(var(--space-4), env(safe-area-inset-right)) calc(var(--tabbar-h) + var(--space-7) + env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left));
  min-height: calc(100dvh - var(--topbar-h));
}
body[data-route="section"] .main { padding-bottom: calc(var(--space-7) + env(safe-area-inset-bottom)); }
.main.is-loading > .page { opacity: .45; transition: opacity var(--dur) var(--ease); }
.page { animation: page-in var(--dur-slow) var(--ease) backwards; }
@keyframes page-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.boot { display: grid; place-items: center; min-height: 50vh; }
.boot-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); animation: boot 1s var(--ease-in-out) infinite alternate; }
@keyframes boot { from { opacity: .25; transform: scale(.7); } to { opacity: 1; transform: scale(1.1); } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);   /* any number of tabs, equal widths */
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 6px max(var(--space-2), env(safe-area-inset-right)) env(safe-area-inset-bottom) max(var(--space-2), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px;
  color: var(--text-muted); text-decoration: none; font-size: .74rem; font-weight: 650; letter-spacing: .01em;
  min-height: var(--tap); border-radius: var(--radius);
}
.tab-icon {
  position: relative; display: grid; place-items: center;
  width: 56px; height: 30px; border-radius: var(--radius-pill);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tabbar a[aria-current="page"] { color: var(--primary); }
.tabbar a[aria-current="page"] .tab-icon { background: var(--primary-soft); }
.tabbar a:active .tab-icon { transform: scale(.94); }
body[data-route="section"] .tabbar { display: none; }
.badge {
  position: absolute; top: -3px; right: 6px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-contrast);
  font-size: .68rem; font-weight: 800; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}
.badge[hidden] { display: none; }

.sidebar { display: none; }

/* ── Desktop: sidebar course outline ───────────────────────────────────── */
@media (min-width: 960px) {
  .app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }
  .topbar, .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: var(--space-5) var(--space-3) var(--space-3);
    scrollbar-width: thin;
  }
  .main { padding: var(--space-7) clamp(var(--space-6), 4vw, var(--space-8)) var(--space-8); min-height: 100dvh; grid-column: 2; }
  body[data-route="section"] .main { padding-bottom: var(--space-8); }
  .page { max-width: var(--content-max); margin-inline: auto; }
  html { scroll-padding-top: 24px; }
}

.side-brand { display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-2) var(--space-5); color: var(--text); text-decoration: none; }
.side-brand .brand-mark { width: 38px; height: 38px; }
.side-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.side-brand-text b { font-family: var(--font-display); font-size: 1.2rem; font-weight: 650; letter-spacing: -0.01em; }
.side-brand-text small { color: var(--text-muted); font-size: .8rem; }
.side-nav { display: grid; gap: 2px; padding-bottom: var(--space-4); border-bottom: 1px solid var(--border); margin-bottom: var(--space-4); }
.side-link {
  position: relative; display: flex; align-items: center; gap: var(--space-3);
  min-height: 42px; padding: 0 var(--space-3); border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 600; width: 100%; text-align: left;
}
.side-link .icon { color: var(--text-muted); }
.side-link:hover { background: var(--surface-2); text-decoration: none; }
.side-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary-strong); }
.side-link[aria-current="page"] .icon { color: var(--primary); }
:root[data-theme="dark"] .side-link[aria-current="page"] { color: var(--primary); }
.side-link .badge { position: static; margin-left: auto; box-shadow: none; }
.side-outline { flex: 1; }
/* Settings stays visible at the bottom of the (long, scrolling) course outline. */
.side-foot {
  position: sticky; bottom: calc(-1 * var(--space-3)); z-index: 1;
  margin: var(--space-4) calc(-1 * var(--space-3)) calc(-1 * var(--space-3));
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-top: 1px solid var(--border); background: var(--surface);
}

.outline-unit { margin-bottom: var(--space-4); }
.outline-unit-title {
  display: flex; align-items: baseline; gap: var(--space-2);
  padding: var(--space-1) var(--space-2); margin-bottom: 2px;
  font-size: .76rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); text-decoration: none; border-radius: 6px;
}
.outline-unit-title:hover { color: var(--text); }
.outline-unit.is-active .outline-unit-title { color: var(--primary); }
.outline-num { font-family: var(--font-display); font-size: .95rem; letter-spacing: 0; color: var(--accent-text); font-weight: 600; }
.outline-modules, .outline-sections { list-style: none; margin: 0; padding: 0; max-width: none; }
.outline-modules li, .outline-sections li { margin: 0; }
.outline-link {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: 38px; padding: 6px var(--space-2); border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: .92rem; line-height: 1.25;
}
.outline-link:hover { background: var(--surface-2); text-decoration: none; }
.outline-item.is-active > .outline-link { background: var(--surface-2); font-weight: 700; }
.outline-link[aria-current="page"] { box-shadow: inset 3px 0 0 var(--primary); }
.outline-ring { flex: none; display: grid; place-items: center; width: 22px; height: 22px; }
.outline-title { flex: 1; min-width: 0; }
.outline-hands { color: var(--accent); display: inline-flex; flex: none; }
.done-dot { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--success); color: #fff; }
.outline-sections { margin: 2px 0 var(--space-2) 19px; padding-left: var(--space-3); border-left: 2px solid var(--border); }
.outline-section {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 5px var(--space-2); border-radius: 6px; font-size: .86rem; line-height: 1.3;
  color: var(--text-muted); text-decoration: none;
}
.outline-section:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.outline-section[aria-current="page"] { color: var(--primary-strong); background: var(--primary-soft); font-weight: 700; }
:root[data-theme="dark"] .outline-section[aria-current="page"] { color: var(--primary); }
.os-mark { flex: none; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--border-strong); color: var(--success); }
.outline-section.is-done .os-mark { border-color: var(--success); background: var(--success-soft); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .side-link[aria-current="page"],
  :root:not([data-theme="light"]) .outline-section[aria-current="page"] { color: var(--primary); }
}

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

/* Same dark-only fixes when the theme is "Auto" and the device is in dark mode (QA: these were missing). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .side-link[aria-current="page"] { color: var(--primary); }
  :root:not([data-theme="light"]) .outline-section[aria-current="page"] { color: var(--primary); }
}
