/* Layout: single column app, header bar, views swap in place. Cool terminal neutrals, teal accent, mood colors are semantic. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --ink: #142235;
  --muted: #5b6b7e;
  --line: #d7dee6;
  --accent: #0d6b74;
  --accent-ink: #ffffff;
  --accent-soft: #dcefef;
  --guest: #fbf3ea;
  --guest-line: #ecd9c4;
  --good: #2e8a57;
  --warn: #c98a12;
  --bad: #c2413a;
  --good-soft: #e3f3ea;
  --bad-soft: #f8e5e3;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --r: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141c; --surface: #16202b; --surface-2: #1c2834; --ink: #e6edf4; --muted: #95a5b6; --line: #2a3846;
    --accent: #4cb5bd; --accent-ink: #062226; --accent-soft: #163c40; --guest: #2a2219; --guest-line: #4a3b2b;
    --good: #5cc48a; --warn: #e6ad3c; --bad: #ef7067; --good-soft: #173527; --bad-soft: #3d1f1d; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e141c; --surface: #16202b; --surface-2: #1c2834; --ink: #e6edf4; --muted: #95a5b6; --line: #2a3846;
  --accent: #4cb5bd; --accent-ink: #062226; --accent-soft: #163c40; --guest: #2a2219; --guest-line: #4a3b2b;
  --good: #5cc48a; --warn: #e6ad3c; --bad: #ef7067; --good-soft: #173527; --bad-soft: #3d1f1d; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--body); min-height: 100vh; }
h1, h2, h3 { font-family: var(--display); line-height: 1.12; text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.9rem, 5vw, 2.7rem); font-weight: 800; }
h2 { font-size: clamp(1.4rem, 3.5vw, 1.8rem); font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .09em; font-size: .78rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }
.err { color: var(--bad); font-weight: 600; }
.spacer { flex: 1; }

/* header */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.brand b { font-family: var(--display); font-size: 1.15rem; display: block; line-height: 1; }
.brand small { color: var(--muted); font-size: .8rem; }
.mark { display: inline-flex; gap: 3px; align-items: flex-end; }
.mark i { width: 10px; height: 22px; border-radius: 5px 5px 2px 2px; background: var(--accent); display: block; }
.mark i + i { height: 18px; opacity: .55; }
.topnav { display: flex; align-items: center; gap: 10px; }
.who { font-size: .9rem; color: var(--muted); }
.demobar { background: var(--accent-soft); color: var(--ink); font-size: .9rem; padding: 8px 16px; text-align: center; }

main { max-width: 1040px; margin: 0 auto; padding: 28px 16px 48px; }
.view { display: grid; gap: 18px; }
.narrow { max-width: 620px; }

/* controls */
.primary, .ghost { border-radius: 999px; border: 1px solid transparent; padding: 11px 20px; font-weight: 700; cursor: pointer; transition: transform .08s, background .15s; }
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .5; cursor: progress; }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.ghost:hover { background: var(--surface-2); }
.sm { padding: 7px 14px; font-size: .92rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }
.form { display: grid; gap: 8px; }
.form label { font-weight: 600; font-size: .95rem; margin-top: 6px; }
.form button { margin-top: 12px; justify-self: start; }
input, select, textarea { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; }
textarea { resize: vertical; min-height: 54px; }

/* pick */
.pickhead { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 14px; }
.levels { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.levels button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; font-weight: 600; cursor: pointer; color: var(--muted); }
.levels button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.scn { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; cursor: pointer; display: grid; gap: 8px; align-content: start; transition: border-color .15s, transform .1s; }
.scn:hover { border-color: var(--accent); transform: translateY(-1px); }
.scn .arch { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.scn h3 { font-size: 1.2rem; }
.scn q { font-style: italic; color: var(--muted); font-size: .95rem; quotes: "\201C" "\201D"; }
.scn .best { font-family: var(--mono); font-size: .78rem; color: var(--accent); }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; background: var(--accent-soft); color: var(--ink); padding: 3px 9px; border-radius: 999px; justify-self: start; }

/* practice */
.practice { gap: 12px; }
.scenebar { display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.scene-meta { display: grid; gap: 4px; min-width: 0; flex: 1 1 260px; }
.meter { flex: 0 1 300px; min-width: 220px; display: grid; gap: 6px; }
.meter-top { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; color: var(--muted); }
.meter-top b { font-family: var(--mono); font-size: 1.15rem; color: var(--ink); }
.meter-track { position: relative; height: 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.meter-fill { height: 100%; width: 70%; background: var(--warn); border-radius: 999px; transition: width .5s ease, background .5s ease; }
.meter-ticks { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), var(--line) calc(10% - 1px) 10%); opacity: .7; }
.meter-reason { font-size: .85rem; color: var(--muted); font-style: italic; min-height: 1.3em; }
.chat { display: flex; flex-direction: column; gap: 10px; min-height: 280px; max-height: 58vh; overflow-y: auto; padding: 6px 2px; }
.msg { max-width: min(78%, 600px); padding: 11px 14px; border-radius: 16px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg small { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.msg.guest { align-self: flex-start; background: var(--guest); border: 1px solid var(--guest-line); border-bottom-left-radius: 4px; }
.msg.staff { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.staff small { color: inherit; opacity: .75; }
.msg.typing { color: var(--muted); }
.hint { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; font-size: .95rem; }
.hint b { color: var(--accent); }
.resolved { background: var(--good-soft); border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.composer { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .3; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 1; } }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 1.05rem; padding: 30px 0; }

/* debrief */
.db-hero { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; }
.ring { width: 112px; height: 112px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .n { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 2.1rem; }
.db-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.rub { display: grid; gap: 12px; }
.rub-row { display: grid; grid-template-columns: 96px 1fr 28px; gap: 10px; align-items: center; }
.rub-row .lab { font-weight: 700; font-size: .95rem; }
.rub-row .bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.rub-row .bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.rub-row .sc { font-family: var(--mono); font-weight: 600; text-align: right; }
.rub-note { grid-column: 1 / -1; font-size: .9rem; color: var(--muted); margin-top: -6px; }
.moment { display: grid; gap: 8px; align-content: start; }
.moment blockquote { margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); font-style: italic; }
.moment.good h3 { color: var(--good); } .moment.miss h3 { color: var(--warn); }
.try { background: var(--good-soft); border-radius: 10px; padding: 10px 14px; }
.try b { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .07em; }
.rewrite { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rewrite > div { border-radius: 10px; padding: 10px 12px; font-size: .95rem; }
.rewrite .was { background: var(--bad-soft); } .rewrite .now { background: var(--good-soft); }
.rewrite b { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 2px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.pill.ok { background: var(--good-soft); color: var(--good); } .pill.no { background: var(--bad-soft); color: var(--bad); } .pill.mid { background: var(--accent-soft); color: var(--ink); }
.spark { width: 100%; height: 70px; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* manager */
.mgr-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mgr-actions input, .mgr-actions select { width: auto; padding: 8px 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat b { display: block; font-family: var(--display); font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .88rem; }
.section-h { margin-top: 10px; }
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--surface-2); }
.tbl tbody tr { cursor: pointer; } .tbl tbody tr:hover { background: var(--surface-2); }
.tbl tr:last-child td { border-bottom: 0; }
.score { font-family: var(--mono); font-weight: 600; }
.empty { padding: 22px; color: var(--muted); text-align: center; }
.detail { width: min(760px, calc(100vw - 32px)); max-height: 88vh; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); color: var(--ink); padding: 0; }
.detail::backdrop { background: rgb(10 18 28 / .55); }
.detail-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
#dBody { padding: 18px; display: grid; gap: 14px; }
#dBody .chat { max-height: none; }

@media (max-width: 560px) {
  .db-hero { grid-template-columns: 1fr; }
  .rewrite { grid-template-columns: 1fr; }
  .msg { max-width: 88%; }
  .composer-row .primary { flex: 1 1 100%; order: -1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.rolebar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 600; }
.rolebar select { width: auto; padding: 8px 10px; }
.others { border-top: 1px solid var(--line); padding-top: 14px; }
.others summary { cursor: pointer; font-family: var(--display); font-weight: 700; font-size: 1.1rem; padding: 4px 0 14px; }
.others summary span { font-family: var(--body); font-weight: 500; font-size: .95rem; }
