:root {
  /*
    ChoiceBook theme variables.
    Authors can customize the book by editing these values.

    --bg: browser/page background
    --paper: main book page
    --ink: primary text
    --muted: secondary text
    --line: borders/dividers
    --accent: buttons/headings
    --accent-ink: text on accent backgrounds
    --shadow: book shadow
  */
  --bg: #171411;
  --paper: #f4ead8;
  --ink: #241b15;
  --muted: #6d5d50;
  --line: #d4c2a8;
  --accent: #7b1f24;
  --accent-ink: #fff8ef;
  --shadow: rgba(0, 0, 0, 0.35);

  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="dark"] {
  --bg: #090807;
  --paper: #191411;
  --ink: #f2e4cf;
  --muted: #b8a895;
  --line: #3a2e26;
  --accent: #d77a83;
  --accent-ink: #1b0d10;
  --shadow: rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.06), transparent 30rem),
    var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.6;
  padding: 1rem;
}

.book-shell {
  position: relative;
  width: min(760px, 100%);
  margin: 2rem auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 80px var(--shadow);
  padding: clamp(1.25rem, 4vw, 3rem);
}

.theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper), white 10%);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
}

.book-title {
  margin: 1.25rem 0 0.25rem;
  font-size: clamp(2rem, 8vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.05em;
  text-align: center;
}

.book-meta {
  margin: 0 0 2rem;
  text-align: center;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.9rem;
}

.passage-title {
  margin: 0 0 1.5rem;
  text-align: center;
  color: var(--accent);
  font-size: 1.1rem;
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.story-text {
  font-size: clamp(1.1rem, 2vw, 1.3rem);
  max-width: 62ch;
  margin: 0 auto 2rem;
}

.story-text h1,
.story-text h2,
.story-text h3 {
  line-height: 1.1;
}

.story-text p {
  margin: 0 0 1em;
}

.story-text strong {
  color: var(--accent);
}

.choices {
  display: grid;
  gap: 0.85rem;
  margin: 2rem auto;
  max-width: 62ch;
  border-top: 1px solid var(--line);
  padding-top: 1.5rem;
}

.choice-button,
.primary-button,
.secondary-button {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  padding: 0.85rem 1.1rem;
  transition: transform 120ms ease, background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.choice-button {
  text-align: left;
  border-radius: 14px;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.12);
}

.choice-button:hover,
.choice-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent);
  color: var(--accent-ink);
  transform: translateY(-1px);
}

.primary-button {
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary-button {
  border-color: var(--line);
  color: var(--muted);
}

.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.status {
  display: grid;
  gap: 1rem;
  margin: 2rem auto 0;
  max-width: 62ch;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--muted);
}

.status h3 {
  margin: 0 0 0.35rem;
  color: var(--ink);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.status-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  background: rgba(255,255,255,0.10);
}

.toolbar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 2rem;
}

.character-form {
  display: grid;
  gap: 1rem;
  max-width: 28rem;
  margin: 2rem auto;
}

.field {
  display: grid;
  gap: 0.35rem;
  font-family: var(--sans);
}

.field label {
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  font: inherit;
  background: rgba(255,255,255,0.20);
  color: var(--ink);
}

.validator {
  max-width: 62ch;
  margin: 0 auto 2rem;
  padding: 1rem;
  border: 1px dashed var(--accent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent), transparent 90%);
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

.validator strong {
  font-family: var(--sans);
}

.error-screen {
  max-width: 62ch;
  margin: 0 auto;
  font-family: var(--sans);
}

@media (max-width: 520px) {
  body {
    padding: 0;
  }

  .book-shell {
    min-height: 100vh;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .theme-toggle {
    position: static;
    display: block;
    margin-left: auto;
    margin-bottom: 1rem;
  }

  .choice-button {
    text-align: center;
  }
}
