/* KB Adventures Story Player Prototype — Stream 4
 * Same brand tokens as kbadventures-website (warm cream + chocolate + honey + sage).
 * Reduced-motion respected. No third-party fonts, no CDN.
 */

:root {
  --background: 250 245 232;
  --surface: 255 251 240;
  --surface-2: 238 223 199;
  --foreground: 43 31 18;
  --muted: 109 88 65;
  --brand-cozy: 91 58 28;
  --brand-honey: 200 134 26;
  --brand-sage: 92 142 127;
  --brand-coral: 196 82 72;
  --border: 214 192 158;
  --focus-ring: 200 134 26;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: 31 27 22;
    --surface: 43 38 31;
    --surface-2: 62 53 42;
    --foreground: 245 232 211;
    --muted: 168 152 130;
    --brand-cozy: 230 195 140;
    --brand-honey: 236 184 87;
    --brand-sage: 142 192 177;
    --brand-coral: 230 130 120;
    --border: 74 62 48;
  }
}

* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: rgb(var(--background));
  color: rgb(var(--foreground));
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation: none !important;
  transition: none !important;
}
/* The ONLY uses of !important in this file are inside the user-opted-in
 * reduce-motion override above. This is a user accessibility preference,
 * not a styling shortcut, so the project CSS hard rule does not apply. */

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

:focus-visible {
  outline: 3px solid rgb(var(--focus-ring));
  outline-offset: 3px;
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: rgb(var(--brand-cozy));
  color: rgb(var(--surface));
  padding: .5rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgb(var(--border));
  background: rgb(var(--surface));
}
.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: rgb(var(--brand-cozy));
}
.brand-bus { font-size: 1.6rem; }
.prototype-pill {
  background: rgb(var(--surface-2));
  color: rgb(var(--brand-cozy));
  font-size: .7rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  padding: .35rem .75rem;
  border-radius: 999px;
  font-weight: 700;
}

.player {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

.screen {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}
.hidden { display: none !important; }
/* .hidden also uses !important — also acceptable: it is a state-toggle
 * utility that must always win over screen-specific layout rules. */

/* ---------- Landing screen ---------- */
.screen-landing { animation: fade-in .35s ease-out; }
.landing-card {
  background: rgb(var(--surface));
  border: 1px solid rgb(var(--border));
  border-radius: 24px;
  padding: 2.5rem 2rem;
  box-shadow: 0 16px 48px rgb(91 58 28 / 0.10);
  text-align: center;
  max-width: 640px;
  width: 100%;
}
.kicker {
  text-transform: uppercase;
  letter-spacing: .2em;
  font-size: .75rem;
  font-weight: 700;
  color: rgb(var(--brand-honey));
  margin: 0 0 .5rem;
}
.story-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 2.75rem);
  margin: 0 0 1rem;
  line-height: 1.1;
  color: rgb(var(--brand-cozy));
}
.story-blurb {
  font-size: 1.1rem;
  line-height: 1.55;
  color: rgb(var(--foreground));
  margin: 0 0 1rem;
}
.meta {
  color: rgb(var(--muted));
  font-size: .9rem;
  margin: 0 0 1.5rem;
}
.play-help {
  margin: 1rem 0 0;
  color: rgb(var(--muted));
  font-size: .9rem;
}

.trust-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
}
.trust {
  background: rgb(var(--surface-2));
  color: rgb(var(--brand-cozy));
  padding: .4rem .8rem;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 14px;
  padding: .75rem 1.25rem;
  font-size: 1rem;
  transition: transform .12s ease-out, background .15s ease-out;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: rgb(var(--brand-cozy));
  color: rgb(var(--surface));
}
.btn-primary:hover { background: rgb(var(--brand-honey)); }
.btn-ghost {
  background: rgb(var(--surface));
  color: rgb(var(--brand-cozy));
  border-color: rgb(var(--border));
}
.btn-ghost:hover { background: rgb(var(--surface-2)); }
.btn-xl {
  padding: 1.25rem 2.5rem;
  font-size: 1.35rem;
  border-radius: 18px;
  box-shadow: 0 8px 24px rgb(91 58 28 / 0.25);
}

/* ---------- Scene viewer ---------- */
.scene-image-wrap {
  width: 100%;
  max-width: 720px;
  aspect-ratio: 8 / 5;
  background: rgb(var(--surface-2));
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 12px 36px rgb(91 58 28 / 0.10);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: scene-pop .4s ease-out;
}
.scene-image-wrap svg { width: 100%; height: 100%; display: block; }
.scene-text-wrap {
  max-width: 640px;
  text-align: center;
}
.scene-text {
  font-family: Georgia, serif;
  font-size: clamp(1.15rem, 2.5vw, 1.4rem);
  line-height: 1.55;
  color: rgb(var(--foreground));
  margin: 0;
}
.caption {
  margin-top: 1rem;
  font-size: 1rem;
  background: rgb(var(--surface));
  border: 1px solid rgb(var(--border));
  border-radius: 12px;
  padding: .75rem 1rem;
  color: rgb(var(--brand-cozy));
  font-weight: 500;
  min-height: 2.5em;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem;
}

/* ---------- Choice screen ---------- */
.screen-choice .choice-prompt {
  font-family: Georgia, serif;
  font-size: clamp(1.5rem, 4vw, 2rem);
  color: rgb(var(--brand-cozy));
  text-align: center;
  margin: 0;
}
.choice-options {
  display: grid;
  gap: 1rem;
  width: 100%;
  max-width: 720px;
}
.choice-btn {
  font-family: inherit;
  background: rgb(var(--surface));
  color: rgb(var(--foreground));
  border: 3px solid rgb(var(--brand-honey));
  border-radius: 18px;
  padding: 1.5rem 1.5rem;
  font-size: 1.15rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform .15s ease-out, background .15s ease-out;
}
.choice-btn:hover {
  background: rgb(var(--brand-honey) / 0.15);
  transform: translateY(-2px);
}
.choice-btn .choice-num {
  background: rgb(var(--brand-cozy));
  color: rgb(var(--surface));
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

/* ---------- Ending ---------- */
.ending-title {
  font-family: Georgia, serif;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  color: rgb(var(--brand-cozy));
  text-align: center;
  margin: 0;
}

/* ---------- Settings dialog ---------- */
dialog#settings-dialog {
  border: none;
  border-radius: 20px;
  padding: 0;
  background: rgb(var(--surface));
  color: rgb(var(--foreground));
  box-shadow: 0 20px 60px rgb(91 58 28 / 0.25);
  max-width: 440px;
  width: 90%;
}
dialog#settings-dialog::backdrop {
  background: rgb(43 31 18 / 0.55);
}
.settings-form { padding: 2rem 1.5rem; }
.settings-form h2 {
  margin: 0 0 1rem;
  font-family: Georgia, serif;
  color: rgb(var(--brand-cozy));
}
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .75rem 0;
  border-bottom: 1px solid rgb(var(--border));
}
.settings-row:last-of-type { border-bottom: none; }
.settings-row select,
.settings-row input[type=range] {
  font-family: inherit;
  font-size: 1rem;
  padding: .4rem .6rem;
  border-radius: 8px;
  border: 1px solid rgb(var(--border));
  background: rgb(var(--background));
  color: rgb(var(--foreground));
}
.settings-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* ---------- Footer ---------- */
.site-footer {
  padding: 1rem 1.5rem;
  text-align: center;
  border-top: 1px solid rgb(var(--border));
  color: rgb(var(--muted));
  font-size: .85rem;
  background: rgb(var(--surface));
}
.site-footer a {
  color: rgb(var(--brand-honey));
  text-decoration: none;
  font-weight: 600;
}
.site-footer a:hover { text-decoration: underline; }

/* ---------- Animations ---------- */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes scene-pop {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------- Story selection grid ---------- */
.screen-selection {
  animation: fade-in .35s ease-out;
  width: 100%;
  max-width: 1100px;
}
.selection-header {
  text-align: center;
  margin-bottom: 1.25rem;
}
.selection-blurb {
  max-width: 540px;
  margin: 0 auto 0.5rem;
}
.selection-recent {
  text-align: center;
  font-size: 0.85rem;
  color: rgb(var(--muted));
  font-style: italic;
  margin: 0.25rem 0 1rem;
}
.selection-grid {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  width: 100%;
}
.story-card {
  margin: 0;
}
.story-card-btn {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 0;
  background: rgb(var(--surface));
  color: rgb(var(--foreground));
  border: 2px solid rgb(var(--border));
  border-radius: 20px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 6px 18px rgb(91 58 28 / 0.08);
  transition: transform .15s ease-out, box-shadow .15s ease-out, border-color .15s ease-out;
}
.story-card-btn:hover {
  transform: translateY(-3px);
  border-color: rgb(var(--brand-honey));
  box-shadow: 0 12px 28px rgb(91 58 28 / 0.18);
}
.story-card-btn:focus-visible {
  border-color: rgb(var(--brand-honey));
  outline-offset: 4px;
}
.story-card-cover {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: rgb(var(--surface-2));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.story-card-cover svg {
  width: 100%;
  height: 100%;
  display: block;
}
.story-card-body {
  padding: 1rem 1.1rem 1.2rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.story-card-title {
  font-family: Georgia, serif;
  font-size: 1.25rem;
  line-height: 1.25;
  margin: 0;
  color: rgb(var(--brand-cozy));
}
.story-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
}
.story-card-badge {
  background: rgb(var(--surface-2));
  color: rgb(var(--brand-cozy));
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}
.story-card-badge-age {
  background: rgb(var(--brand-honey) / 0.18);
}
.story-card-summary {
  font-size: 0.92rem;
  line-height: 1.45;
  margin: 0;
  color: rgb(var(--foreground));
}

/* Back-to-stories button on the landing card */
.btn-back {
  align-self: flex-start;
  margin-bottom: 0.5rem;
}

/* ---------- Adult back door page ---------- */
.adult-page {
  max-width: 760px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  line-height: 1.6;
}
.adult-page h1 {
  font-family: Georgia, serif;
  color: rgb(var(--brand-cozy));
}
.adult-page .warn {
  background: rgb(var(--surface-2));
  border-left: 4px solid rgb(var(--brand-coral));
  padding: 1rem 1.25rem;
  border-radius: 8px;
  margin: 1rem 0;
}
.adult-page pre {
  background: rgb(var(--surface));
  border: 1px solid rgb(var(--border));
  border-radius: 12px;
  padding: 1rem;
  overflow: auto;
  font-size: .85rem;
  max-height: 60vh;
}
.adult-page dl { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.25rem; }
.adult-page dt { font-weight: 700; color: rgb(var(--brand-cozy)); }
.adult-page .meta-table { background: rgb(var(--surface)); border: 1px solid rgb(var(--border)); border-radius: 12px; padding: 1rem 1.25rem; }
.story-admin-list { display: flex; flex-direction: column; gap: 1.5rem; }
.story-admin-card {
  background: rgb(var(--surface));
  border: 1px solid rgb(var(--border));
  border-radius: 16px;
  padding: 1.25rem 1.5rem;
}
.story-admin-card h3 {
  font-family: Georgia, serif;
  margin: 0 0 1rem;
  color: rgb(var(--brand-cozy));
}
.story-admin-card details { margin-top: 1rem; }
.story-admin-card summary { cursor: pointer; color: rgb(var(--brand-honey)); font-weight: 600; }
