:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --fg: #141414;
  --fg-2: #5f5f5a;
  --line: #e4e2dc;
  --accent: #141414;
  --accent-fg: #ffffff;
  --t0: #e5484d;
  --t1: #3e63dd;
  --t2: #f5a524;
  --t3: #30a46c;
  --ok: #30a46c;
  --bad: #e5484d;
  --radius: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121212;
  --card: #1c1c1c;
  --fg: #f0efe9;
  --fg-2: #a3a29c;
  --line: #2c2c2c;
  --accent: #f0efe9;
  --accent-fg: #121212;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--t1); outline-offset: 2px; }
a { color: inherit; }

.wrap { max-width: 560px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top, 0px)) 16px calc(28px + env(safe-area-inset-bottom, 0px)); }
.screen { display: flex; flex-direction: column; gap: 16px; }
.center { text-align: center; }
.muted { color: var(--fg-2); margin: 0; }
h1, h2 { margin: 0; letter-spacing: -.02em; }

/* ---------- home ---------- */
.hero { text-align: center; padding: 18px 0 6px; }
.hero h1 { font-size: clamp(34px, 9vw, 46px); line-height: 1.05; font-weight: 800; margin-top: 14px; }
.hero p { margin: 10px auto 0; max-width: 400px; color: var(--fg-2); }
.logo { display: inline-grid; grid-template-columns: 22px 22px; gap: 5px; }
.logo i { width: 22px; height: 22px; border-radius: 6px; }
.t0 { background: var(--t0); } .t1 { background: var(--t1); } .t2 { background: var(--t2); } .t3 { background: var(--t3); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--fg-2); flex: 1; }
input, select {
  width: 100%; height: 52px; padding: 0 16px; border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--fg); font-size: 17px;
}
input:focus, select:focus { outline: none; border-color: var(--fg-2); }
.row { display: flex; gap: 10px; }

.btn {
  height: 48px; padding: 0 20px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--card); font-weight: 650; white-space: nowrap;
}
.btn:hover { border-color: var(--fg-2); }
.btn:active { transform: scale(.98); }
.btn.big { height: 58px; font-size: 18px; width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.join { display: flex; gap: 10px; }
.join input { text-align: center; letter-spacing: .3em; font-weight: 700; }
.join input::placeholder { letter-spacing: normal; font-weight: 400; }
.setup { display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: var(--radius); background: var(--card); border: 1.5px solid var(--line); }
.error { min-height: 1.4em; margin: 0; color: var(--bad); text-align: center; }
.error:empty { min-height: 0; }

.top { margin-top: 10px; }
.top h2 { font-size: 18px; margin-bottom: 8px; }
.top ol, .board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.top li, .board li {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 12px; background: var(--card); border: 1.5px solid var(--line);
}
.top li b, .board li b { margin-left: auto; font-variant-numeric: tabular-nums; }
.place { width: 22px; font-weight: 800; color: var(--fg-2); flex: none; }
.board li.me { border-color: var(--fg); }
.foot { text-align: center; color: var(--fg-2); font-size: 13px; margin: 8px 0 0; }

/* ---------- lobby ---------- */
.code { text-align: center; font-size: clamp(56px, 18vw, 84px); font-weight: 800; letter-spacing: .08em; line-height: 1; font-variant-numeric: tabular-nums; }
.share { display: flex; gap: 10px; }
.share input { font-size: 14px; height: 48px; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chips li { padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1.5px solid var(--line); font-weight: 600; animation: pop .25s ease; }
.chips li.host::after { content: " ★"; color: var(--t2); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

/* ---------- game ---------- */
.game-top { display: flex; align-items: center; gap: 12px; font-weight: 650; }
.game-top .score { margin-left: auto; font-variant-numeric: tabular-nums; }
.timer { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: var(--fg); transform-origin: left; }
.timer i.low { background: var(--bad); }
.question { font-size: clamp(22px, 6vw, 30px); line-height: 1.25; text-align: center; padding: 8px 0; min-height: 3.2em; display: flex; align-items: center; justify-content: center; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.options.tf { grid-template-columns: 1fr 1fr; }
.opt {
  position: relative; min-height: 96px; padding: 14px 14px 14px 46px; border: 0; border-radius: var(--radius);
  color: #fff; font-size: 17px; font-weight: 700; text-align: left; line-height: 1.25;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18); transition: transform .08s, opacity .2s, filter .2s;
}
.opt::before { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 18px; opacity: .9; }
.opt.c0 { background: var(--t0); } .opt.c0::before { content: "▲"; }
.opt.c1 { background: var(--t1); } .opt.c1::before { content: "◆"; }
.opt.c2 { background: var(--t2); color: #2a1a00; } .opt.c2::before { content: "●"; }
.opt.c3 { background: var(--t3); } .opt.c3::before { content: "■"; }
.opt:active:not(:disabled) { transform: scale(.97); }
.opt:disabled { cursor: default; }
.opt.dim { opacity: .35; filter: saturate(.4); }
.opt.picked { outline: 4px solid var(--fg); outline-offset: 2px; }
.opt.right { opacity: 1; filter: none; outline: 4px solid var(--ok); outline-offset: 2px; }
.opt .count { position: absolute; right: 12px; bottom: 8px; font-size: 13px; opacity: .9; }
.status { text-align: center; font-weight: 700; min-height: 1.6em; font-size: 18px; }
.status .plus { color: var(--ok); }
.status .minus { color: var(--bad); }

/* ---------- final ---------- */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: end; margin-top: 8px; }
.step { text-align: center; }
.step .bar { margin-top: 6px; border-radius: 12px 12px 4px 4px; display: grid; place-items: center; font-size: 26px; font-weight: 800; color: #fff; }
.step.p1 .bar { height: 120px; background: var(--t2); color: #2a1a00; }
.step.p2 .bar { height: 88px; background: var(--t1); }
.step.p3 .bar { height: 64px; background: var(--t0); }
.step .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step .pts { font-size: 13px; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.you-result { font-size: 18px; font-weight: 650; margin: 4px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 14px; background: var(--accent); color: var(--accent-fg);
  font-weight: 600; z-index: 10;
}

@media (max-width: 380px) {
  .opt { min-height: 84px; font-size: 15px; padding-left: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
