/* Production design tokens + shared components (Dark-first + Warm Paper Light). */
:root {
  --bg: #0B0D10;
  --surface: #13161C;
  --surface-2: #1A1E26;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --glow: rgba(212, 163, 115, 0.40);
  --ink: #EAE6DF;
  --ink-2: #9EA3AF;
  --ink-3: #6E7380;
  --brass: #D4A373;
  --brass-ink: #0B0D10;
  --teal: #14B8A6;
  --danger: #F87171;
  --nav-bg: rgba(11, 13, 16, 0.78);
  --hud-bg: rgba(19, 22, 28, 0.86);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  --skeleton: rgba(255, 255, 255, 0.045);
  --skeleton-hi: rgba(255, 255, 255, 0.10);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --serif: 'Instrument Serif', Georgia, serif;
  --sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #F3EFE7;
  --surface: #EAE5DB;
  --surface-2: #E1DBCF;
  --border: rgba(24, 24, 27, 0.11);
  --border-strong: rgba(24, 24, 27, 0.20);
  --glow: rgba(180, 83, 9, 0.40);
  --ink: #18181B;
  --ink-2: #52525B;
  --ink-3: #6B6B73;
  --brass: #A4500A;
  --brass-ink: #FBF8F2;
  --teal: #0F766E;
  --danger: #B91C1C;
  --nav-bg: rgba(243, 239, 231, 0.86);
  --hud-bg: rgba(243, 239, 231, 0.92);
  --shadow: 0 24px 50px rgba(60, 40, 20, 0.16);
  --skeleton: rgba(24, 24, 27, 0.06);
  --skeleton-hi: rgba(24, 24, 27, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: 6px; }

.skip-link {
  position: fixed; left: 16px; top: -64px; z-index: 100;
  background: var(--brass); color: var(--brass-ink);
  padding: 10px 14px; border-radius: 8px; font-weight: 600; text-decoration: none;
  transition: top 0.2s ease;
}
.skip-link:focus { top: 12px; }

kbd {
  font-family: var(--mono); font-size: 11px; line-height: 1.5;
  color: var(--ink-3); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 10px;
  font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid transparent; white-space: nowrap;
  transition: transform 0.2s var(--ease), box-shadow 0.25s ease, background-color 0.2s ease, border-color 0.2s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn-primary { background: var(--brass); color: var(--brass-ink); }
.btn-primary:hover { box-shadow: 0 10px 26px color-mix(in srgb, var(--brass) 30%, transparent); }
.btn-ghost { background: var(--surface); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; }
.btn .arrow { transition: transform 0.25s var(--ease); }
.btn:hover .arrow { transform: translateX(3px); }

/* Theme toggle */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.15s ease;
}
.theme-toggle:hover { border-color: var(--glow); background: var(--surface-2); transform: translateY(-1px); }
.theme-toggle:active { transform: scale(0.97); }
.tt-icon { display: inline-block; transition: transform 0.5s var(--ease); }
.theme-toggle:hover .tt-icon { transform: rotate(28deg); }

/* Loading shimmer */
.skeleton {
  background: linear-gradient(100deg, var(--skeleton) 30%, var(--skeleton-hi) 50%, var(--skeleton) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* Book cover (supports real cover image or typographic fallback) */
.cover {
  --c1: #22324A; --c2: #0E1626;
  position: relative; aspect-ratio: 2 / 3; overflow: hidden;
  border-radius: 3px 8px 8px 3px;
  background:
    radial-gradient(120% 60% at 80% 0%, rgba(255, 255, 255, 0.08), transparent 60%),
    linear-gradient(160deg, var(--c1), var(--c2));
  padding: 13% 10% 11% 17%;
  display: flex; flex-direction: column; justify-content: space-between;
  color: #F3EFE8;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 16px 30px rgba(0, 0, 0, 0.38);
  container-type: inline-size;
}
.cover.has-img { padding: 0; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 7%; z-index: 1;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.45), rgba(255, 255, 255, 0.07) 70%, transparent);
}
.cover::after {
  content: ''; position: absolute; inset: -20%; z-index: 1;
  background: linear-gradient(115deg, transparent 42%, rgba(255, 255, 255, 0.10) 50%, transparent 58%);
  transform: translateX(-70%); transition: transform 0.9s var(--ease); pointer-events: none;
}
.cv-cat { font-family: var(--mono); font-size: max(6px, 6.2cqi); letter-spacing: 0.08em; text-transform: uppercase; color: #D9AC7E; }
.cv-title { font-family: var(--serif); font-size: max(8px, 11.5cqi); line-height: 1.08; }
.cv-rule { display: block; width: 28%; height: 1px; background: rgba(217, 172, 126, 0.55); margin-top: 8cqi; }
.cv-author { font-family: var(--mono); font-size: max(5.5px, 5.4cqi); text-transform: uppercase; letter-spacing: 0.06em; color: rgba(243, 239, 232, 0.62); }

/* Progress bar */
.bar { height: 4px; border-radius: 99px; background: var(--border); overflow: hidden; }
.bar > span {
  display: block; height: 100%; border-radius: inherit; background: var(--brass);
  transform-origin: left; animation: grow 1.1s var(--ease) both;
}
.bar.is-done > span { background: var(--teal); }
@keyframes grow { from { transform: scaleX(0); } }

/* Toast */
.toast {
  position: fixed; left: 50%; top: 18px; z-index: 95;
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 9px 16px; font-size: 13px; box-shadow: var(--shadow);
  transition: opacity 0.2s ease, transform 0.25s var(--ease);
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* Command palette */
.palette { position: fixed; inset: 0; z-index: 90; display: grid; place-items: start center; padding-top: 14vh; }
.palette[hidden] { display: none; }
.palette-backdrop { position: absolute; inset: 0; background: rgba(5, 6, 8, 0.55); backdrop-filter: blur(4px); opacity: 0; transition: opacity 0.18s ease; }
.palette-panel {
  position: relative; width: min(600px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px;
  box-shadow: var(--shadow); overflow: hidden;
  opacity: 0; transform: translateY(-8px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.22s var(--ease);
}
.palette.is-open .palette-backdrop { opacity: 1; }
.palette.is-open .palette-panel { opacity: 1; transform: none; }
.palette-search { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--ink-3); }
.palette-search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--ink); font-size: 15px; }
.palette-list { list-style: none; max-height: min(52vh, 420px); overflow-y: auto; padding: 6px; }
.palette-group { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); padding: 10px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px; border-radius: 9px; cursor: pointer; color: var(--ink-2); font-size: 14px; }
.palette-item.is-active { background: var(--surface-2); color: var(--ink); }
.pi-icon { width: 22px; text-align: center; color: var(--brass); }
.pi-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pi-hint { font-family: var(--mono); font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.palette-empty { padding: 22px 12px; color: var(--ink-3); font-size: 14px; text-align: center; }
.palette-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--ink-3); }
.palette-foot kbd { margin-right: 3px; }

/* Passcode Lock Screen */
.lock-screen {
  min-height: calc(100vh - 68px);
  display: grid; place-items: center; padding: 32px 18px;
}
.lock-screen[hidden] { display: none; }
.lock-card {
  width: min(420px, 100%);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 20px;
  padding: 32px 28px; box-shadow: var(--shadow);
}
.lock-card h1 { font-family: var(--serif); font-weight: 400; font-size: 36px; line-height: 1.08; margin-bottom: 8px; }
.lock-card p { font-size: 14px; color: var(--ink-2); margin-bottom: 22px; }
.lock-field {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border-strong); color: var(--ink);
  font-size: 15px; outline: none; margin-bottom: 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.lock-field:focus { border-color: var(--glow); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brass) 15%, transparent); }
.lock-error { font-size: 13px; color: var(--danger); margin-bottom: 12px; min-height: 18px; }

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