:root {
  --bg: #f6f1e7;
  --panel: #fffdf8;
  --ink: #2a2520;
  --muted: #6d6458;
  --line: #e2d8c6;
  --accent: #8a3b12;
  --accent-ink: #fff;
  --error: #a3261b;
  --player: #efe6d4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --panel: #211d17;
    --ink: #ece4d6;
    --muted: #a99d8a;
    --line: #3a3329;
    --accent: #e08a4f;
    --accent-ink: #1a120b;
    --error: #ff8a7a;
    --player: #2c261e;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 Georgia, 'Iowan Old Style', serif; }
button, input, textarea { font: inherit; color: inherit; }
button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 6px; padding: 0.55em 1em; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: wait; }
button.link { background: none; color: var(--accent); padding: 0.3em 0; text-decoration: underline; }
input, textarea { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 0.55em 0.7em; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.fine { color: var(--muted); font-size: 0.85em; }
.error { color: var(--error); min-height: 1.2em; margin: 0.4em 0 0; }

/* PL/EN switch: both names always visible, the current one filled. Each version keeps its own game. */
.lang-switch { display: inline-flex; flex: none; white-space: nowrap; border: 1px solid var(--accent); border-radius: 6px; overflow: hidden; font-size: 0.9em; }
.lang-switch a { padding: 0.25em 0.8em; color: var(--accent); text-decoration: none; }
.lang-switch a[aria-current] { background: var(--accent); color: var(--accent-ink); }
#start .lang-switch { float: right; }

.prose { max-width: 640px; margin: 8vh auto; padding: 0 16px; }
.prose a, .fine a, label a { color: var(--accent); }
#start { max-width: 560px; margin: 12vh auto; padding: 0 16px; }
#start h1 { font-size: 2.6em; margin: 0 0 0.2em; letter-spacing: 0.02em; }
.tagline { font-size: 1.15em; }
.start-form { display: grid; gap: 0.5em; margin: 1.5em 0 1em; }
.adventures { border: 0; padding: 0; margin: 0 0 0.6em; display: grid; gap: 0.5em; }
.adventures legend { margin-bottom: 0.4em; color: var(--muted); }
.adventure { display: grid; grid-template-columns: auto 1fr; column-gap: 0.6em; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.adventure:has(input:checked) { border: 2px solid var(--accent, currentColor); padding: 9px 11px; }
.adventure input { grid-row: span 2; align-self: start; margin-top: 0.3em; }
.adventure-title { font-size: 1.1em; }
.adventure-question { color: var(--muted); font-size: 0.92em; }
.adventure-length { grid-column: 2; color: var(--muted); font-size: 0.8em; letter-spacing: 0.03em; }

#game { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; max-width: 1100px; margin: 0 auto; padding: 16px; min-height: 100vh; }
.story { display: flex; flex-direction: column; min-width: 0; }
.bar { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 0.4em; }
.bar { gap: 0.9em; }
.bar-side { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 0.4em 0.9em; }
#counter { color: var(--muted); font-size: 0.9em; }
#new-game { font-size: 0.9em; }
.log { flex: 1; overflow-y: auto; padding: 0.5em 0; max-height: calc(100vh - 220px); }
.log p { margin: 0 0 1em; white-space: pre-wrap; }
.log .you { background: var(--player); border-radius: 6px; padding: 0.35em 0.7em; font-style: italic; }
.log .pending { color: var(--muted); }
.log .ask { background: none; border-left: 3px solid var(--accent); border-radius: 0; }
.log .gm { border-left: 3px solid var(--line); padding-left: 0.7em; }
.log .gm::before, .log .ask::before { content: attr(data-label); display: block; font-size: 0.75em; font-style: normal; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.log .epilogue { font-style: italic; }
.log .result { margin-bottom: 0.4em; font-size: 0.8em; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.log .stakes { border: 1px solid var(--accent); border-radius: 6px; padding: 0.6em 0.8em; margin: 0 0 1em; }
.log .stakes p { margin: 0 0 0.5em; }
.log .stakes button { margin: 0 0.4em 0.3em 0; }
.log .stakes .fine { margin: 0.4em 0 0; color: var(--muted); font-size: 0.85em; }
.suggestions { display: flex; flex-wrap: wrap; gap: 0.4em; margin-bottom: 0.5em; }
.suggestions button { background: var(--panel); color: var(--ink); border: 1px solid var(--line); font-size: 0.9em; }
.turn-form { display: grid; grid-template-columns: 1fr auto; gap: 0.5em; align-items: end; }
.ask-toggle { grid-column: 1 / -1; display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.4em; cursor: pointer; font-size: 0.95em; }
.ask-toggle input { width: auto; accent-color: var(--accent); }
.turn-form.asking textarea { border-color: var(--accent); }
.journal { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; align-self: start; position: sticky; top: 16px; font-size: 0.92em; }
.journal h2 { margin: 0; font-size: 1.15em; }
.journal dl { margin: 0.5em 0 0; }
.journal dt { font-weight: bold; margin-top: 0.6em; }
.journal dd { margin: 0.1em 0 0; color: var(--ink); }
.journal ul { margin: 0; padding-left: 1.1em; }

.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / 0.55); display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border-radius: 10px; max-width: 460px; width: 100%; padding: 22px; max-height: 92vh; overflow-y: auto; }
.card h2 { margin-top: 0; }
.plan { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 1em 0; }
.price { font-size: 2em; margin: 0; }
.price span { font-size: 0.45em; color: var(--muted); }
#waitlist-form { display: grid; gap: 0.5em; margin-bottom: 0.5em; }
.decline summary { cursor: pointer; color: var(--muted); }
.reasons { display: grid; gap: 0.4em; }
.check { display: flex; gap: 0.5em; align-items: flex-start; font-size: 0.9em; }
.check input { width: auto; margin-top: 0.25em; }
.secondary { width: 100%; margin-top: 0.6em; background: var(--panel); color: var(--ink); border: 1px solid var(--ink); }
.kind button[aria-pressed="true"] { border-color: var(--ink); font-weight: bold; }
.reasons button { background: var(--panel); color: var(--ink); border: 1px solid var(--line); text-align: left; }

/* Phone parts (layout.js): hidden on a computer, where the journal stays beside the story. */
.tabs, .menu-btn, .mode, .menu-only { display: none; }
.composer {
  display: flex; grid-column: 1 / -1; align-items: flex-end; gap: 6px; padding: 4px 4px 4px 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
}
.composer:focus-within, .turn-form.asking .composer { border-color: var(--accent); }
.composer textarea {
  flex: 1; min-width: 0; max-height: calc(5lh + 14px); padding: 7px 0; overflow-y: auto;
  border: 0; border-radius: 0; background: none; resize: none; outline: none;
}
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mic, #send { flex: none; min-height: 40px; }
#mic {
  display: grid; place-items: center; width: 40px; padding: 0; border-radius: 50%;
  background: transparent; color: var(--accent); border: 1px solid var(--line); touch-action: none;
}
#mic[hidden], #voice-settings[hidden] { display: none; }
#send { border-radius: 20px; padding: 0 1.1em; }
.voice-play {
  position: absolute; right: 0; bottom: 0.15em; margin: 0; padding: 0; width: 28px; height: 28px;
  border-radius: 50%; background: transparent; color: var(--muted); border: 1px solid var(--line);
}
.log p:has(.voice-play) { position: relative; padding-right: 2.2em; }
.voice-play.playing { background: #1f7a4d; color: #fff; border-color: #1f7a4d; }
.voice-play.busy { animation: voice-pulse 0.8s ease-in-out infinite; }
@keyframes voice-pulse { 50% { opacity: 0.35; } }
#voice-dialog, #talk-dialog, #how-dialog {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink);
  padding: 16px; width: min(360px, calc(100% - 32px));
}
#voice-dialog::backdrop, #talk-dialog::backdrop, #how-dialog::backdrop { background: rgb(0 0 0 / 0.35); }
#talk-dialog, #how-dialog { width: min(520px, calc(100% - 32px)); }
#how-dialog header { display: flex; justify-content: space-between; align-items: center; }
#how-dialog .link { background: none; color: var(--accent); }
.how h2 { font-size: 1.05em; margin: 0.5em 0 0.3em; }
.how ul, #how-body ul { margin: 0 0 1em; padding-left: 1.2em; display: grid; gap: 0.35em; }
#voice-dialog header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#voice-dialog header .link, #talk-dialog .link { background: none; color: var(--accent); }
#talk { width: 100%; min-height: 200px; margin: 8px 0; border-radius: 24px; font-size: 1.35rem; font-weight: 700; touch-action: none; }
#talk.live { background: var(--error); color: #fff; }
#talk.wait { opacity: 0.65; }
#talk-error { min-height: 1.2em; }
#voice-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 4px; }
.voice-row { display: flex; align-items: center; gap: 8px; }
.voice-preview, .voice-name { background: none; color: var(--ink); }
.voice-preview { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); padding: 0; color: var(--accent); }
.voice-name { flex: 1; text-align: left; border-radius: 8px; }
.voice-name[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.voice-read { display: flex; align-items: center; gap: 0.5em; }
.voice-volume { display: grid; gap: 4px; margin-top: 12px; }
.voice-volume input { accent-color: var(--accent); }
.voice-read input { width: auto; accent-color: var(--accent); }
#counter { margin-left: auto; white-space: nowrap; }

/* Phone (2026-11-29): one screen with Story | Journal tabs, the menu behind "⋯" and the input fixed at the bottom.
   The same query is PHONE in layout.js; a phone on its side is short, not narrow, so height counts too. */
@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
  /* Pinned to the visible part of the screen: layout.js sets --screen-h and --screen-top while the keyboard is open. */
  #game {
    position: fixed; left: 0; top: var(--screen-top, 0); width: 100%; height: var(--screen-h, 100dvh);
    display: flex; flex-direction: column; gap: 0; max-width: none; min-height: 0; overflow: hidden;
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  .story { flex: 1; min-height: 0; }
  .log { max-height: none; min-height: 0; overscroll-behavior: contain; }
  .journal { display: none; position: static; }
  #game.show-journal .story { flex: none; }
  #game.show-journal .story > :not(.bar, .tabs) { display: none; }
  .journal h2 { display: none; }
  #game.show-journal .journal {
    display: block; flex: 1; overflow-y: auto; overscroll-behavior: contain;
    margin: 10px 0 calc(12px + env(safe-area-inset-bottom));
  }

  .bar { position: relative; flex-wrap: wrap; align-items: center; gap: 0 0.6em; padding: 8px 0 6px; border-bottom: 0; }
  #title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #counter { order: 3; flex-basis: 100%; margin: 0; font-size: 0.8em; }
  .menu-btn {
    display: block; order: 2; min-width: 44px; min-height: 36px;
    background: none; color: var(--ink); font-size: 1.4em; line-height: 1; padding: 0 0.3em;
  }
  .bar-side {
    display: none; position: absolute; top: 100%; right: 0; z-index: 10; min-width: 210px;
    flex-direction: column; align-items: flex-start; gap: 0.7em; padding: 12px 14px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
  }
  .bar.menu-open .bar-side { display: flex; }
  .menu-only { display: block; color: var(--accent); font-size: 0.9em; }

  .tabs { display: flex; border-bottom: 1px solid var(--line); }
  .tabs button {
    flex: 1; background: none; color: var(--muted); border-radius: 0; border-bottom: 2px solid transparent; padding: 0.45em;
  }
  .tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: bold; }
  .dot {
    display: inline-block; width: 8px; height: 8px; margin-left: 0.35em;
    border-radius: 50%; background: var(--accent); vertical-align: super;
  }
  .dot[hidden] { display: none; }

  /* One row of suggestions that scrolls sideways; the right edge fades so a cut-off button reads as "more". */
  .suggestions {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 6px -12px 0; padding: 0 12px;
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }
  .suggestions::-webkit-scrollbar { display: none; }
  .suggestions button { flex: none; white-space: nowrap; border-radius: 999px; padding: 0.3em 0.85em; font-size: 0.85em; }
  .suggestions:empty { display: none; }

  /* The input: mode switch above, then one rounded field that grows with the text (layout.js) up to five lines. */
  .turn-form { display: block; padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
  .ask-toggle { display: none; }
  .mode { display: flex; align-items: center; gap: 0.6em; margin-bottom: 6px; font-size: 0.85em; }
  .mode-switch { display: inline-flex; border: 1px solid var(--accent); border-radius: 999px; overflow: hidden; }
  .mode-switch button { background: none; color: var(--accent); border-radius: 0; padding: 0.2em 0.9em; }
  .mode-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
  .mode-switch button:disabled { cursor: default; }
  .mode-note { display: none; }
  .turn-form.asking .mode-note { display: inline; }
  .error { min-height: 0; margin: 0; }
  .error:not(:empty) { margin-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .turn-form:has(+ .error:not(:empty)) { padding-bottom: 4px; }

  /* While typing the keyboard takes half the screen: the turn counter and suggestions step aside (layout.js). */
  #game.typing #counter, #game.typing .suggestions { display: none; }
}

/* A phone on its side: the bar, the tabs and the input stay one line each so the story keeps some room. */
@media (max-height: 500px) and (pointer: coarse) {
  .bar { padding: 4px 0 2px; flex-wrap: nowrap; }
  #counter { order: 2; flex-basis: auto; }
  .menu-btn { order: 3; }
  .tabs button { padding: 0.25em; }
  .turn-form { display: flex; align-items: flex-end; gap: 8px; padding-top: 6px; }
  .mode { flex: none; margin: 0 0 8px; }
  .turn-form.asking .mode-note { display: none; }
  .composer { flex: 1; }
  .composer textarea { max-height: calc(2lh + 14px); }
}
/* A described item in the journal: its look and a document's words, folded under its name (engine2 world version 14). */
#j-inventory details summary { cursor: pointer; }
#j-inventory .item-look { margin: 0.3em 0 0; color: var(--muted); font-size: 0.9em; }
#j-inventory .item-text { margin: 0.3em 0 0; font-style: italic; font-size: 0.9em; white-space: pre-wrap; }
