/* Play and admin pages: mobile first, one column, sheets for everything that isn't the story. */
/* The di-fi palette (2026-10-17): warm ink and stone, purple for actions, gold only for dice.
   Text colours pass 4.5:1 on --bg, --surface and --chip in both themes (docs/design-plan.md item 1): --subtle is for
   small secondary text; --faint is for icons and borders only (3:1). */
:root {
  --bg: #faf7f2; --surface: #fdfcfb; --raised: #f5f1ea; --ink: #18150f; --muted: #6d6a64; --subtle: #6d6a64; --faint: #898680; --line: #e3ddd4;
  --accent: #873bc4; --accent-ink: #fdfcfb; --accent-soft: #eadcf7; --ok: #24772f; --bad: #b73f3f; --warn: #8b612b;
  --chip: #f0ebe4; --gold: #dea44e; --gold-text: #8b612b; --ph: #d9d1c4; --scrim: rgba(24, 21, 15, .38); --shadow: 0 10px 30px rgba(24, 21, 15, .12);
  --fs: 16px; --story-font: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display-font: "Bricolage Grotesque", var(--ui-font);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18150f; --surface: #1f1c16; --raised: #26231d; --ink: #faf7f2; --muted: #c2beb9; --subtle: #938f89; --faint: #898680; --line: #34312b;
    --accent: #af76e1; --accent-ink: #18150f; --accent-soft: #3b1959; --ok: #63c36d; --bad: #e37373; --warn: #e3b66b;
    --chip: #2a2721; --gold: #dea44e; --gold-text: #dea44e; --ph: #36322b; --scrim: rgba(0, 0, 0, .55); --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #18150f; --surface: #1f1c16; --raised: #26231d; --ink: #faf7f2; --muted: #c2beb9; --subtle: #938f89; --faint: #898680; --line: #34312b;
  --accent: #af76e1; --accent-ink: #18150f; --accent-soft: #3b1959; --ok: #63c36d; --bad: #e37373; --warn: #e3b66b;
  --chip: #2a2721; --gold: #dea44e; --gold-text: #dea44e; --ph: #36322b; --scrim: rgba(0, 0, 0, .55); --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--ui-font); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; }

/* ---- buttons and fields ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 10px;
       border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent-fill, var(--accent)); border-color: var(--accent-fill, var(--accent)); color: var(--accent-ink); font-weight: 600; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--chip); color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; border: 0; background: transparent; color: var(--ink); cursor: pointer; flex: 0 0 auto; }
.icon-btn:hover { background: var(--chip); }
.icon-btn svg, .btn svg { width: 20px; height: 20px; }
.field { display: block; margin: 12px 0 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field small { display: block; font-size: 12px; color: var(--subtle); margin-top: 4px; }
select, input[type=text], input[type=password], input[type=number], textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--raised); }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); flex: 0 0 auto; }
.switch b { font-weight: 500; display: block; } .switch small { color: var(--subtle); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---- app shell ---- */
.app { height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 4px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; background: var(--surface);
          border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.topbar .title { flex: 1; min-width: 0; padding: 0 4px; }
.topbar .title b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.story { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.story-inner { max-width: 720px; margin: 0 auto; padding: 16px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

.you { align-self: flex-end; max-width: 85%; background: var(--accent-soft); padding: 9px 13px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.narration { font-family: var(--story-font); font-size: var(--fs); line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.narration.streaming::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
.narration.error { font-family: var(--ui-font); font-size: 14px; color: var(--bad); }
.narration.thinking { font-family: var(--ui-font); color: var(--muted); font-size: 14px; }
.command-card { position: relative; font-family: var(--ui-font); font-size: 14px; line-height: 1.55; white-space: pre-wrap;
                overflow-wrap: anywhere; background: var(--raised); border: 1px solid var(--line); border-left: 3px solid var(--accent);
                border-radius: 10px; padding: 10px 34px 10px 12px; color: var(--ink); }
.command-card.error { color: var(--bad); }
.command-card:has(.window) { background: none; border: 0; padding: 0 34px 0 0; white-space: normal; }  /* (answers are windows) */
.command-card .window { margin: 0 0 .6em; max-width: 480px; }
.command-close { position: absolute; top: 4px; right: 4px; border: 0; background: none; color: var(--faint); font-size: 18px;
                 line-height: 1; padding: 4px 8px; cursor: pointer; }
.dots span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); margin-right: 4px; animation: pulse 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; } .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: -6px; font-size: 12px; color: var(--subtle); }
.chip { font-size: 12px; background: var(--chip); border-radius: 999px; padding: 2px 9px; color: var(--muted); }
.turn-actions { display: flex; gap: 2px; margin-left: auto; }

.composer { flex: 0 0 auto; background: var(--surface); border-top: 1px solid var(--line); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 720px; margin: 0 auto; }
.status { font-size: 12px; color: var(--muted); min-height: 0; padding: 0 4px 6px; display: flex; gap: 8px; align-items: center; }
.status:empty { display: none; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
/* The "/" menu: the text box's width and rounded shape, one command per row (command over its description). */
.compose-row { position: relative; }
.command-menu { position: absolute; left: 0; right: 52px; bottom: calc(100% + 8px); z-index: 20; max-height: min(296px, 45vh);
  overflow-y: auto; overscroll-behavior: contain; padding: 6px; background: var(--raised); border: 1px solid var(--line);
  border-radius: 22px; box-shadow: var(--shadow); font-family: var(--ui-font); scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.command-option { padding: 9px 14px 10px; border-radius: 16px; cursor: pointer; border: 1px solid transparent; }
.command-option + .command-option { margin-top: 2px; }
.command-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.command-name { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; font-weight: 600; color: var(--ink); }
.command-name b { font-weight: 700; }
.command-desc { font-size: 13px; line-height: 1.4; color: var(--muted); margin-top: 2px; }
.command-alias { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--subtle); white-space: pre; }
.command-option[aria-selected="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.command-option[aria-selected="true"] .command-name { color: var(--accent); }
.command-option[aria-selected="true"] .command-desc { color: var(--ink); }
.command-option[aria-selected="true"] .command-alias { color: var(--muted); }
.compose-row textarea { flex: 1; resize: none; min-height: 44px; max-height: 40vh; border-radius: 22px; padding: 11px 16px; line-height: 1.4; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; flex: 0 0 auto; }
.send svg { width: 20px; height: 20px; }
.send.stop { background: var(--ink); color: var(--surface); }
.send:disabled { opacity: .4; cursor: default; }

/* ---- sheets: drawers on the side, panels from the bottom on phones ---- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 20; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; z-index: 21; background: var(--surface); display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .25s ease; }
.sheet.left { top: 0; bottom: 0; left: 0; width: min(360px, 88vw); transform: translateX(-102%); padding-top: env(safe-area-inset-top); }
.sheet.right { top: 0; bottom: 0; right: 0; width: min(420px, 100vw); transform: translateX(102%); padding-top: env(safe-area-inset-top); }
.sheet.open { transform: none; }
.sheet.right { touch-action: pan-y; }  /* (vertical scrolling stays native; a sideways swipe closes the tray) */
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet-foot { border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 8px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 6px; font-weight: 600; }
.card { background: var(--raised); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; }

.list { list-style: none; margin: 0; padding: 0; }
.story-item { display: flex; align-items: center; gap: 6px; border-radius: 10px; }
.story-item button.open { flex: 1; text-align: left; background: none; border: 0; padding: 10px 8px; border-radius: 10px; cursor: pointer; min-width: 0; }
.story-item button.open:hover { background: var(--chip); }
.story-item.current button.open { background: var(--accent-soft); }
.story-item b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.story-item span { font-size: 12px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--raised); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.stat span { font-size: 12px; color: var(--muted); display: block; } .stat b { font-size: 15px; }
.bar { height: 5px; border-radius: 3px; background: var(--chip); margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.bar.mp i { background: var(--accent); }
details.group { border-bottom: 1px solid var(--line); }
details.group > summary { list-style: none; cursor: pointer; padding: 12px 0; font-weight: 600; display: flex; justify-content: space-between; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: "+"; color: var(--muted); font-weight: 400; }
details.group[open] > summary::after { content: "−"; }
details.group ul { list-style: none; padding: 0 0 10px; margin: 0; }
details.group li { padding: 5px 0; font-size: 14px; border-top: 1px dashed var(--line); }
details.group li:first-child { border-top: 0; }

/* ---- sign-in ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form.hidden { display: none; }
.login form { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login .error { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 10px; }

                    text-decoration: underline; cursor: pointer; min-height: 32px; }

/* ---- admin ---- */
.admin { min-height: 100dvh; }
.admin main { max-width: 1280px; margin: 0 auto; padding: 12px 16px 32px; }
.cols { display: grid; gap: 12px; }
@media (min-width: 1000px) { .cols { grid-template-columns: 320px 1fr; } .cols.three { grid-template-columns: 300px 340px 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; min-width: 0; }
.panel h2 { font-size: 15px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.pill { border: 1px solid var(--line); background: var(--raised); border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; }
.pill.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.rows { display: flex; flex-direction: column; gap: 2px; max-height: 70vh; overflow-y: auto; }
.rowbtn { text-align: left; border: 0; background: none; border-radius: 10px; padding: 8px 10px; cursor: pointer; width: 100%; }
.rowbtn:hover { background: var(--chip); } .rowbtn.active { background: var(--accent-soft); }
.rowbtn b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowbtn span { font-size: 12px; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; border-radius: 6px; padding: 1px 6px; background: var(--chip); color: var(--muted); margin-left: 4px; font-weight: 500; }
.tag.bad { color: var(--bad); } .tag.ok { color: var(--ok); } .tag.warn { color: var(--warn); }
.block { background: var(--raised); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.block .label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
details.stage { border: 1px solid var(--line); border-left-width: 3px; border-radius: 8px; margin: 6px 0; padding: 6px 10px; background: var(--raised); }
details.stage summary { cursor: pointer; font-size: 13px; overflow-wrap: anywhere; }
details.stage pre, .msgbox { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; max-height: 360px; overflow: auto; margin: 8px 0 2px; }
.msgbox { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--surface); }
.msgbox b { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.st-ok { border-left-color: var(--ok); } .st-bad { border-left-color: var(--bad); } .st-warn { border-left-color: var(--warn); }
.back { display: none; }
@media (max-width: 999px) {
  .cols > .panel.mobile-hidden { display: none; }
  .back { display: inline-grid; }
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
