/* =====================================================================
   base.css: design tokens, reset, and shared building blocks.

   Both themes use the SAME variable names. Switching themes only changes
   one attribute on <html> (data-theme="academic" | "obsidian"), and every
   component re-colors itself because it only ever uses these variables.
   ===================================================================== */

:root {
  --font-serif: 'Merriweather', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: 'Space Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --wrap: 1120px;
}

/* Academic: PrepPros-inspired blue and white, with Crest gold as the accent */
:root,
:root[data-theme="academic"] {
  --bg: #FFFFFF;
  --bg-alt: #F4F6FA;
  --surface: #FFFFFF;
  --text: #17223F;
  --text-soft: #4B5674;
  --rule: #D6DCE8;
  --primary: #2A4AA6;
  --primary-hover: #1F3A88;
  --primary-ink: #FFFFFF;
  --primary-tint: #EAEFFA;
  --band: #18295C;
  --band-text: #FFFFFF;
  --band-soft: #C9D2EC;
  --band-grid: rgba(255, 255, 255, 0.07);
  --crest-fill: #18295C;
  --gold: #C9A227;
  --gold-text: #876708;
  --gold-tint: #FBF4DD;
  --good: #1F7A4A;
  --good-tint: #E4F3EA;
  --bad: #B23A2C;
  --bad-tint: #FBE9E6;
  --sheet: #FFFFFF;
  --sheet-edge: #CBD3E3;
  color-scheme: light;
}

/* Obsidian: the original CrestPrep black and gold */
:root[data-theme="obsidian"] {
  --bg: #0A0E1A;
  --bg-alt: #0E1322;
  --surface: #131A2F;
  --text: #E8EBF4;
  --text-soft: #AEB7D1;
  --rule: #27314F;
  --primary: #C9A227;
  --primary-hover: #E8C765;
  --primary-ink: #0A0E1A;
  --primary-tint: #2A2510;
  --band: #0D1220;
  --band-text: #F4F2EA;
  --band-soft: #AEB7D1;
  --band-grid: rgba(201, 162, 39, 0.09);
  --crest-fill: #1E2846;
  --gold: #E8C765;
  --gold-text: #E8C765;
  --gold-tint: #2A2510;
  --good: #63C48F;
  --good-tint: #11291C;
  --bad: #F2907F;
  --bad-tint: #35181A;
  --sheet: #131A2F;
  --sheet-edge: #2E3A5C;
  color-scheme: dark;
}

/* ---------- Reset and type ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
img, svg, iframe, video { max-width: 100%; display: block; }
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 0.5em;
  color: var(--text);
}
h1 { font-size: clamp(1.9rem, 3.4vw, 2.6rem); }
h2 { font-size: clamp(1.45rem, 2.4vw, 1.85rem); }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 1em; }
ul, ol { margin: 0 0 1em; padding-left: 1.25em; }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
#view:focus { outline: none; }

.wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }
.wrap-narrow { width: min(100% - 2rem, 880px); margin-inline: auto; }
.muted { color: var(--text-soft); }
.small { font-size: 0.875rem; }
.mono { font-family: var(--font-mono); }
.center { text-align: center; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -999px; top: 0; z-index: 200; background: var(--primary); color: var(--primary-ink); padding: 0.5rem 1rem; }
.skip-link:focus { left: 1rem; top: 0.5rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 40px; padding: 0.5rem 1.1rem;
  border: 1px solid transparent; border-radius: var(--radius);
  font-weight: 600; font-size: 0.95rem; line-height: 1.2;
  text-decoration: none; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); color: var(--primary-ink); }
.btn-outline { background: var(--surface); border-color: var(--rule); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--primary); padding-inline: 0.6rem; }
.btn-ghost:hover { background: var(--primary-tint); color: var(--primary); }
.btn-gold { background: var(--gold); color: #1B1606; }
.btn-gold:hover { filter: brightness(1.06); color: #1B1606; }
.btn-sm { min-height: 32px; padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 0.3rem; font-size: 0.875rem; font-weight: 600; }
.input {
  min-height: 40px; width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface); font-weight: 400;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.form-error { color: var(--bad); font-size: 0.875rem; font-weight: 600; margin: 0.5rem 0 0; }
.form-error:empty { display: none; }

/* ---------- Panels, chips, bars ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--primary-tint); color: var(--primary);
  font-size: 0.8rem; font-weight: 600;
}
.bar { height: 8px; background: var(--primary-tint); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: inherit; transition: width 0.4s ease; }
.bar-gold > span { background: var(--gold); }

/* Segmented control: a row of radio-style buttons */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.seg button {
  border: 0; border-right: 1px solid var(--rule);
  background: var(--surface); padding: 0.4rem 0.8rem;
  font-size: 0.85rem; font-weight: 500;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }

/* The gold "100% free" seal */
.seal {
  display: inline-flex; align-items: center;
  padding: 0.2rem 0.65rem;
  border: 1.5px solid var(--gold); border-radius: var(--radius-sm);
  color: var(--gold); font-weight: 700; font-size: 0.85rem;
  transform: rotate(-2deg);
}

/* ---------- Toasts ---------- */
#toast-root {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  display: grid; gap: 0.5rem; justify-items: center;
  z-index: 300; pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 0.55rem 1rem; border-radius: var(--radius);
  font-weight: 600; font-size: 0.9rem;
  animation: toast-in 0.2s ease-out;
}
.toast-good { background: var(--good); color: #FFFFFF; }
.toast-gold { background: var(--gold); color: #1B1606; }
.toast.is-leaving { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

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