/* ==========================================================================
   Shared design tokens + base chrome for index.html and quiz.html
   Direction: Editorial Field Guide. Warm Paper is the default light theme,
   Charcoal Ink is the dark theme. Theme is stored in localStorage
   ("blueprint-theme": "paper" | "dark") and shared by both pages.
   Raw hex colors live ONLY in the token blocks below.
   ========================================================================== */

:root,
:root[data-theme="paper"] {
  color-scheme: light;

  /* surfaces */
  --bg: #f6f1e7;
  --surface: #fffdf9;
  --subtle: #ede6d6;
  --rule: #d9cfb8;
  --rule-strong: #b9ac8e;

  /* text */
  --ink: #1f1d1a;
  --ink-2: #4a443b;
  --muted: #625644;

  /* accent + semantic */
  --accent: #b84a27;
  --accent-ink: #ffffff;
  --accent-text: #a23f1f;
  --accent-tint: rgba(184, 74, 39, 0.1);
  --sage: #4d6134;
  --sage-tint: rgba(77, 97, 52, 0.12);
  --danger: #a8241c;
  --danger-tint: rgba(168, 36, 28, 0.08);
  --warn: #7a5200;
  --warn-tint: rgba(122, 82, 0, 0.1);
  --info: #2a5a87;

  /* simulators */
  --stage-bg: #f1ead9;
  --sim-1: #b84a27;
  --sim-2: #4d6134;
  --sim-3: #2a5a87;
  --sim-4: #8a6414;
  --sim-5: #7a3f6b;
  --sim-6: #1f6b66;
  --sim-7: #5f4f8f;
  --sim-8: #3f3a33;

  --shadow-color: rgba(60, 45, 20, 0.16);
  --scrim: rgba(31, 29, 26, 0.45);
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #131517;
  --surface: #1b1e22;
  --subtle: #23272d;
  --rule: #31363d;
  --rule-strong: #4a5059;

  --ink: #e7e5e0;
  --ink-2: #b5bcc4;
  --muted: #9ba3ad;

  --accent: #e07a52;
  --accent-ink: #131517;
  --accent-text: #e88a64;
  --accent-tint: rgba(224, 122, 82, 0.14);
  --sage: #7fa660;
  --sage-tint: rgba(127, 166, 96, 0.14);
  --danger: #f07167;
  --danger-tint: rgba(240, 113, 103, 0.12);
  --warn: #e0a64a;
  --warn-tint: rgba(224, 166, 74, 0.13);
  --info: #6fa3d6;

  --stage-bg: #14161a;
  --sim-1: #e07a52;
  --sim-2: #7fa660;
  --sim-3: #6fa3d6;
  --sim-4: #d4a443;
  --sim-5: #c486b5;
  --sim-6: #55b3ab;
  --sim-7: #a592d6;
  --sim-8: #c9c3b8;

  --shadow-color: rgba(0, 0, 0, 0.5);
  --scrim: rgba(0, 0, 0, 0.6);
}

:root {
  --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 6px;
  --radius-lg: 10px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --page-max: 1320px;
  --page-pad: 1.5rem;
  --topbar-h: 56px;
}

/* ==========================================================================
   Base
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--accent);
  accent-color: var(--accent);
  scrollbar-color: var(--rule-strong) var(--bg);
}

h1, h2, h3 {
  text-wrap: balance;
}

p, li {
  text-wrap: pretty;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

a {
  color: var(--accent-text);
  text-underline-offset: 0.2em;
}

button {
  font-family: inherit;
}

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

.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;
}

[hidden] {
  display: none !important;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  box-shadow: 0 1px 0 var(--rule-strong);
  background: var(--surface);
  color: var(--ink-2);
}

/* ==========================================================================
   Top bar: brand, cross-navigation and theme switch (both pages)
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}

.topbar-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--page-pad);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.topnav {
  display: flex;
  gap: 0.25rem;
  margin-right: auto;
}

.topnav > a,
.topnav > span {
  min-height: 44px;
  padding: 0 0.8rem;
  display: inline-flex;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.nav-arrow {
  margin-left: 0.35rem;
}

.topnav > a:hover {
  color: var(--ink);
}

.topnav [aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.theme-switch {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface);
  flex-shrink: 0;
}

.theme-switch button {
  min-height: 36px;
  padding: 0 0.8rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.theme-switch button:hover {
  color: var(--ink);
}

.theme-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

/* ==========================================================================
   Buttons (shared)
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-text);
  border-color: var(--accent-text);
  color: var(--accent-ink);
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
  font-weight: 600;
}

.btn.danger:hover:not(:disabled) {
  filter: brightness(0.92);
  color: var(--surface);
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn[aria-pressed="true"],
.btn[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

/* ==========================================================================
   Mobile chrome
   ========================================================================== */

@media (max-width: 768px) {
  :root {
    --page-pad: 1rem;
  }

  .topbar-inner {
    gap: 0.5rem;
  }

  .brand {
    display: none;
  }

  .topnav > a,
  .topnav > span {
    padding: 0 0.55rem;
    font-size: 0.85rem;
  }

  .theme-switch button {
    min-height: 36px;
    padding: 0 0.65rem;
  }

  .btn {
    min-height: 44px;
  }
}

@media (min-width: 561px) {
  .only-xs {
    display: none;
  }
}

@media (max-width: 560px) {
  .hide-xs {
    display: none;
  }
}

/* ==========================================================================
   Reduced motion: keep state changes, drop the movement
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
