/* Brand tokens sourced from docs/design.md — the reader is meant to share
   the author dashboard's deep-purple theme (§2.2: "so that switching
   between authoring and play-testing feels seamless"), not its own palette. */
:root {
  --bg: #14101e;
  --surface: #1e1730;
  --surface-2: #2a1f40;
  --border: #2e2540;
  --text: #e8e3f5;
  --text-dim: #9e93b5;
  --accent: #b08cff;
  --accent-dim: #8a6ad4;
  --danger: #ff6b8a;
  --success: #6bd99a;
  /* Stat-family colors (choice semantics) stay distinct from the brand
     accent per design-system convention — separate signal, not decoration. */
  --stat-red: #ff6b8a;
  --stat-blue: #6fa8ff;
  --stat-green: #6bd99a;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.6;
}

a {
  color: var(--accent);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--text);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 96px;
}

.btn-primary,
.btn-ghost {
  font: inherit;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn-primary {
  background: var(--accent);
  color: #1a1226;
  border: none;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-dim);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--accent);
  color: var(--text);
}

/* Auth */
.auth-shell {
  max-width: 380px;
  margin: 48px auto;
  animation: fadeInUp 400ms ease-out both;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 20px 0;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--text-dim);
}

.auth-form input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  transition: border-color 150ms ease;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.google-btn {
  display: block;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 150ms ease, background-color 150ms ease;
}

.google-btn:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.03);
}

.auth-switch {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 16px;
}

.form-error {
  background: rgba(255, 107, 138, 0.12);
  border: 1px solid rgba(255, 107, 138, 0.35);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}

/* Library */
.library-shell section {
  margin-bottom: 36px;
}

.card-grid {
  display: grid;
  /* Narrower than the coverless layout was: a 2:3 cover at 220px is 330px
     tall, which made a two-row shelf taller than the viewport. */
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.story-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  /* No padding — the cover runs to the card edge and `.card-body` pads the
     rest. `overflow: hidden` is what clips the cover to the rounded corners. */
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text);
  transition: border-color 150ms ease, transform 150ms ease;
  animation: fadeInUp 400ms ease-out both;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 16px;
  /* Fill the rest of the card so the CTA below can be pushed to the floor. */
  flex: 1;
}

/* Descriptions differ in length, so without this the call to action sits at a
   different height in every card and the row of buttons reads as ragged. */
.card-body .btn-primary {
  margin-top: auto;
}

.story-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.story-card h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Cover art — see StoryCover.tsx. */
.story-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Hue is derived from the story id so a book with no cover still reads as a
     distinct object. Saturation and lightness are fixed and low, so the shelf
     stays one family rather than turning into a paint chart. */
  background: linear-gradient(
    155deg,
    hsl(var(--cover-hue, 265) 30% 27%),
    hsl(calc(var(--cover-hue, 265) + 22) 36% 13%)
  );
}

.story-cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Covers are authored at 2:3 but nothing enforces it, so crop rather than
     letterbox or stretch. */
  object-fit: cover;
}

.story-cover-monogram {
  font-size: 46px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  color: rgba(232, 227, 245, 0.5);
  user-select: none;
}

.scene-tag,
.story-desc {
  color: var(--text-dim);
  font-size: 13.5px;
  margin: 0;
}

.genre-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  background: var(--surface-2);
  border-radius: 9999px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.lock-badge {
  font-size: 11px;
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 9999px;
  padding: 2px 8px;
}

.empty-state {
  color: var(--text-dim);
}

/* Reader */
.reader-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.scene-block {
  margin-bottom: 28px;
  animation: fadeInUp 450ms ease-out both;
}

.scene-block p {
  margin: 0 0 16px;
  line-height: 1.75;
}

.choice-made {
  margin: 14px 0;
  padding-left: 14px;
  border-left: 2px solid var(--accent);
  color: var(--text-dim);
  font-style: italic;
}

.action-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
  animation: fadeInUp 350ms ease-out both;
}

.action-bar .choice-btn:nth-child(1) {
  animation-delay: 60ms;
}
.action-bar .choice-btn:nth-child(2) {
  animation-delay: 120ms;
}
.action-bar .choice-btn:nth-child(3) {
  animation-delay: 180ms;
}

.choice-btn:hover {
  transform: translateX(2px);
  background: var(--surface-2);
}

.choice-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.choice-red {
  border-color: rgba(255, 107, 138, 0.4);
  background: rgba(255, 107, 138, 0.06);
}
.choice-red:hover {
  background: rgba(255, 107, 138, 0.12);
}
.choice-blue {
  border-color: rgba(111, 168, 255, 0.4);
  background: rgba(111, 168, 255, 0.06);
}
.choice-blue:hover {
  background: rgba(111, 168, 255, 0.12);
}
.choice-green {
  border-color: rgba(107, 217, 154, 0.4);
  background: rgba(107, 217, 154, 0.06);
}
.choice-green:hover {
  background: rgba(107, 217, 154, 0.12);
}

.loading-scene {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  padding: 14px 0;
}

/* Shown in place of the choice buttons on the last scene of a book. */
.story-end {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 40px 0 24px;
}

.story-end-rule {
  width: 64px;
  height: 1px;
  background: var(--border);
}

.story-end-label {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Whisper toasts */
.whisper-stack {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: opacity 0.4s ease;
  z-index: 20;
  animation: toastIn 300ms ease-out both;
}

.whisper-stack-exit {
  opacity: 0;
}

.whisper-toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-dim);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

/* Character drawer */
.drawer {
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  background: var(--surface);
  color: var(--text);
  width: min(420px, 100vw);
  padding: 20px;
  position: fixed;
  inset-inline: auto;
  bottom: 0;
  right: 0;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.45);
}

.drawer[open] {
  animation: drawerIn 200ms ease-out both;
}

@keyframes drawerIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.drawer::backdrop {
  background: rgba(10, 7, 16, 0.6);
  backdrop-filter: blur(4px);
}

.drawer-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  transition: color 150ms ease;
}

.drawer-close:hover {
  color: var(--text);
}

.reader-nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Author-only. Marked so it never reads as part of the story chrome — if this
   ever looks like a normal reader control, it is in the wrong place. */
.debug-toggle {
  font-size: 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}

.debug-toggle.on {
  border-style: solid;
  border-color: var(--accent, #b08cff);
  color: var(--accent, #b08cff);
}

.drawer-section {
  margin-bottom: 20px;
}

/* Everything the reader must not see carries this, so a section added to the
   wrong branch of the drawer looks wrong on sight. */
.debug-section {
  border-left: 2px solid var(--accent, #b08cff);
  padding-left: 10px;
}

.drawer-empty {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  margin: 0;
}

.drawer-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 10px;
}

.vitals-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.vital-badge {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
}

.vital-badge.hope {
  color: var(--success);
}
.vital-badge.tension {
  color: var(--stat-red);
}
.vital-badge.friction {
  color: var(--text-dim);
}

.clock-row {
  margin-bottom: 8px;
}

.clock-label {
  font-size: 13px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}

.clock-bar {
  display: flex;
  gap: 3px;
}

.clock-tick {
  width: 16px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  transition: background-color 200ms ease;
}

.clock-tick.filled {
  background: var(--stat-red);
}

.detour-flag {
  color: var(--stat-red);
  font-size: 13px;
}

.twin-cast-result {
  font-size: 13.5px;
  color: var(--text-dim);
}

.affinity-row {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  padding: 4px 0;
}

.affinity-pos {
  color: var(--success);
}
.affinity-neg {
  color: var(--stat-red);
}

.spark-state {
  color: var(--text-dim);
  text-transform: capitalize;
}

.inventory-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13.5px;
  color: var(--text-dim);
}

/* Build stamp — the commit this worker was built from. Deliberately quiet:
   it's for answering "what's deployed?", not something readers should
   notice. pointer-events: none so it can't intercept a tap near the
   bottom edge on mobile. */
.build-stamp {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  text-align: right;
  opacity: 0.6;
  pointer-events: none;
}
