:root {
  --bg: #f8f3ee;
  --surface: #ffffff;
  --surface-2: #f2eae3;
  --ink: #2b1e23;
  --muted: #7a6a70;
  --line: #e6dbd3;
  --accent: #8e2c48;
  --accent-ink: #ffffff;
  --ok: #2f7d5b;
  --ok-soft: #e3f1ea;
  --dis: #a8650a;
  --dis-soft: #fbefdc;
  --cheat: #b3263a;
  --cheat-soft: #f9e1e4;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(60, 30, 40, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1316;
    --surface: #241a1e;
    --surface-2: #2e2226;
    --ink: #f3e9ec;
    --muted: #b09ea4;
    --line: #3a2c31;
    --accent: #d9648a;
    --accent-ink: #1a1316;
    --ok: #5cc293;
    --ok-soft: #1f3329;
    --dis: #e6a54a;
    --dis-soft: #3a2c17;
    --cheat: #ef6b7e;
    --cheat-soft: #3d1e24;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.app { max-width: 600px; margin: 0 auto; padding: 24px 16px 64px; }

h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 600; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 2.2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.stack > * + * { margin-top: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* Buttons & inputs */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: 14px;
  cursor: pointer;
  width: 100%;
  transition: transform .08s, background .15s, border-color .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); width: auto; padding: 8px 10px; }
.btn-ghost:hover { color: var(--ink); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 140px; }

label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
input[type=text], textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
input[type=text]:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 110px; resize: vertical; font-size: .85rem; word-break: break-all; }

/* Start screen */
.eyebrow {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 2px 8px; font-size: .68rem; }
.hero { padding: 16px 0 4px; }
.hero p { font-size: 1.05rem; }

.legend { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.legend span.muted { display: block; font-size: .875rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; }
.dot.ok { background: var(--ok); }
.dot.dis { background: var(--dis); }
.dot.cheat { background: var(--cheat); }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.steps li { counter-increment: s; display: flex; gap: 12px; }
.steps li::before {
  content: counter(s);
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: .85rem;
}

/* Play screen */
.play-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.q-card { margin: 20px 0; min-height: 190px; display: flex; flex-direction: column; justify-content: center; }
.q-card.enter { animation: enter .25s ease; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.scenario { font-family: Fraunces, Georgia, serif; font-size: 1.45rem; line-height: 1.35; margin: 12px 0 0; }

.choices { display: grid; gap: 10px; }
.choice {
  display: flex;
  gap: 14px;
  align-items: center;
  text-align: left;
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .08s;
}
.choice:active { transform: scale(.985); }
.choice-key { flex: none; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; color: #fff; }
.choice.ok .choice-key { background: var(--ok); }
.choice.dis .choice-key { background: var(--dis); }
.choice.cheat .choice-key { background: var(--cheat); }
.choice.ok.selected { border-color: var(--ok); background: var(--ok-soft); }
.choice.dis.selected { border-color: var(--dis); background: var(--dis-soft); }
.choice.cheat.selected { border-color: var(--cheat); background: var(--cheat-soft); }
@media (hover: hover) {
  .choice.ok:not([disabled]):hover { border-color: var(--ok); background: var(--ok-soft); }
  .choice.dis:not([disabled]):hover { border-color: var(--dis); background: var(--dis-soft); }
  .choice.cheat:not([disabled]):hover { border-color: var(--cheat); background: var(--cheat-soft); }
}
.choice-desc { display: block; font-size: .85rem; color: var(--muted); }
.hint { margin-top: 18px; }

/* Share */
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; font-size: .85rem; }
.copy-row .btn { width: auto; white-space: nowrap; }
.note { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: .9rem; color: var(--muted); }
.error { background: var(--cheat-soft); color: var(--cheat); border-radius: 12px; padding: 12px 14px; font-size: .9rem; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Results */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 8px; text-align: center; }
.stat b { display: block; font-family: Fraunces, Georgia, serif; font-size: 1.7rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--muted); }
.cat-bars { display: grid; gap: 14px; }
.cat-bar .top { display: flex; justify-content: space-between; gap: 12px; font-size: .9rem; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 5px; }
.bar span { display: block; height: 100%; background: var(--accent); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tab { flex: 1; border: 0; background: transparent; font: inherit; font-size: .85rem; font-weight: 600; color: var(--muted); padding: 9px 4px; border-radius: 9px; cursor: pointer; }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.prompt { border-left: 4px solid var(--accent); background: var(--surface); padding: 14px 16px; border-radius: 0 12px 12px 0; font-family: Fraunces, Georgia, serif; font-size: 1.05rem; }
.r-list { display: grid; gap: 10px; }
.r-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.r-card.big { border-color: var(--cheat); }
.r-card p { margin: 8px 0 12px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { font-size: .85rem; padding: 5px 11px; border-radius: 99px; font-weight: 500; }
.pill b { font-weight: 700; margin-right: 4px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.dis { background: var(--dis-soft); color: var(--dis); }
.pill.cheat { background: var(--cheat-soft); color: var(--cheat); }
.gap { font-size: .68rem; padding: 2px 8px; border-radius: 99px; background: var(--dis-soft); color: var(--dis); }
.gap.big { background: var(--cheat-soft); color: var(--cheat); }
.gap.same { background: var(--ok-soft); color: var(--ok); }

.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 99px;
  font-weight: 600; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.footer { margin-top: 32px; text-align: center; font-size: .85rem; color: var(--muted); }

@media (max-width: 420px) {
  h1 { font-size: 1.85rem; }
  .scenario { font-size: 1.25rem; }
  .card { padding: 20px; }
}

/* 6-digit codes */
.code-input {
  font-size: 1.35rem !important;
  font-weight: 700;
  letter-spacing: .18em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.code-input::placeholder { color: var(--muted); opacity: .45; }
.code-display {
  font-family: Fraunces, Georgia, serif;
  font-size: 3.2rem;
  font-weight: 600;
  letter-spacing: .08em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1.1;
  padding: 8px 0;
  user-select: all;
}

/* Loading & waiting */
.loading { min-height: 60vh; display: grid; place-content: center; justify-items: center; gap: 14px; }
.loading p { margin: 0; }
.waiting-row { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.pulse {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  flex: none;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .35; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1.1); }
}
@media (prefers-reduced-motion: reduce) {
  .pulse, .q-card.enter { animation: none; }
}

/* Live game */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.player {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px; font-size: .9rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px;
  min-width: 0; overflow-wrap: anywhere;
}
.chip { font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.chip.done { background: var(--ok-soft); color: var(--ok); }
.chip.turn { background: var(--accent); color: var(--accent-ink); }
.chip.away { background: var(--dis-soft); color: var(--dis); }
.choices.locked .choice { cursor: default; }
.choices.locked .choice:not(.selected) { opacity: .4; }
.reveal { animation: enter .3s ease; }
.verdict { font-family: Fraunces, Georgia, serif; font-size: 1.5rem; font-weight: 600; text-align: center; }
.verdict.same { color: var(--ok); }
.verdict.diff { color: var(--dis); }
.verdict.big { color: var(--cheat); }
.center-pills { justify-content: center; }
.big-pill { font-size: 1rem; padding: 8px 14px; }
.conn {
  position: sticky; top: 8px; z-index: 5; margin-bottom: 12px;
  background: var(--dis-soft); color: var(--dis);
  border-radius: 12px; padding: 8px 12px; font-size: .85rem; font-weight: 600; text-align: center;
}
.conn[hidden] { display: none; }
