/* Shared styles: tokens, base, top bar, and the participant (phone) screens.
   Presenter-only styles live in host.css. Design rule: the question is the only loud thing. */

/* ---------- tokens ---------- */
:root {
  --bg: #f8f6f7;
  --surface: #ffffff;
  --bubble: #eeebed;
  --bubble-2: #e5e1e4;
  --ink: #1b1b1c;
  --ink-2: #5b585c;
  --ink-3: #9b979c;
  --line: #e7e3e6;
  --accent: #e8a030;
  --accent-soft: #fbefd9;
  --ok: #1d7f47;
  --ok-soft: #e2f3e8;
  --ok-line: #9fd3b2;
  --bad: #c9362b;
  --bad-soft: #fbe7e4;
  --bad-line: #efb1aa;
  --sel: #1b1b1c;
  --sel-ink: #ffffff;
  --shadow: 0 10px 40px -12px rgba(40, 30, 40, 0.16), 0 2px 6px rgba(40, 30, 40, 0.05);
  --font: "Google Sans", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131214; --surface: #1d1c1f; --bubble: #262428; --bubble-2: #302e33;
    --ink: #eceaee; --ink-2: #b3afb6; --ink-3: #7d7982; --line: #2e2c31;
    --accent-soft: #3a2e1a; --ok: #6fd39a; --ok-soft: #173424; --ok-line: #2f6a47;
    --bad: #ff8a80; --bad-soft: #3a1d1b; --bad-line: #7a3a35; --sel: #eceaee; --sel-ink: #131214;
    --shadow: 0 10px 40px -12px rgba(0, 0, 0, 0.6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131214; --surface: #1d1c1f; --bubble: #262428; --bubble-2: #302e33;
  --ink: #eceaee; --ink-2: #b3afb6; --ink-3: #7d7982; --line: #2e2c31;
  --accent-soft: #3a2e1a; --ok: #6fd39a; --ok-soft: #173424; --ok-line: #2f6a47;
  --bad: #ff8a80; --bad-soft: #3a1d1b; --bad-line: #7a3a35; --sel: #eceaee; --sel-ink: #131214;
  --shadow: 0 10px 40px -12px rgba(0, 0, 0, 0.6); color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes ring { from { transform: scale(1); opacity: 0.7; } to { transform: scale(1.6); opacity: 0; } }
@keyframes bump { 40% { transform: scale(1.18); } }
@keyframes slide { from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.round {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  color: var(--ink-3);
}
button.round:hover { background: var(--bubble); }
.round img { width: 24px; height: 24px; image-rendering: pixelated; }
.round svg { width: 20px; height: 20px; }
.brand { min-width: 0; flex: 1; line-height: 1.25; }
.brand b { display: block; font-size: 15px; font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand span { color: var(--ink-3); font-size: 13px; }
.brand span:empty { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 15px; white-space: nowrap; max-width: 44vw;
}
.pill .t { overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: var(--ink-3); }

/* name + score in the participant top bar */
.me-pill { height: 36px; padding: 0 4px 0 10px; gap: 8px; max-width: 58vw; background: transparent; border: 0; }
.me-pill .t { font-size: 14px; color: var(--ink-2); }
.me-pill .dot { width: 6px; height: 6px; }
.me-pill .sc {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 28px; padding: 0 10px; border-radius: 999px;
  background: var(--bubble); color: var(--ink);
  font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.me-pill .sc svg { flex: none; width: 14px; height: 14px; opacity: 0.45; }
.me-pill .sc.neg { color: var(--bad); }
.me-pill .sc.masked { letter-spacing: 0.1em; color: var(--ink-3); }
.me-pill .sc.bump { animation: bump 0.5s ease; }

/* ---------- question ---------- */
.wrap { max-width: 640px; margin: 0 auto; padding: 8px 16px 140px; }
.slide-in { animation: slide 0.36s cubic-bezier(.2, .8, .2, 1); }

.kicker { display: flex; align-items: center; gap: 12px; margin: 12px 2px 0; color: var(--ink-3); font-size: 13px; letter-spacing: 0.04em; }
.kicker .bar { flex: 1; height: 3px; border-radius: 4px; background: var(--bubble); overflow: hidden; }
.kicker .bar i { display: block; height: 100%; border-radius: 4px; background: var(--ink-3); transition: width 0.4s; }

.qtext {
  margin: 22px 2px 30px;
  font-size: clamp(24px, 6.6vw, 30px); font-weight: 500; line-height: 1.42; letter-spacing: -0.005em;
  white-space: pre-line; text-wrap: pretty;
}

.choices { display: grid; gap: 10px; }
.choice {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 58px; padding: 14px 18px 14px 14px;
  text-align: left; line-height: 1.45; font-size: 17px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  transition: border-color .15s, box-shadow .15s, transform .12s;
}
.choice:active:not(:disabled) { transform: scale(0.985); }
.choice:disabled { cursor: default; }
.choice .L {
  position: relative; z-index: 1; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 500; color: var(--ink-3);
  box-shadow: inset 0 0 0 1px var(--line);
}
.choice .x { position: relative; z-index: 1; flex: 1; }
.choice.sel { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.choice.sel .L { background: var(--ink); color: var(--bg); box-shadow: none; }

/* ---------- bottom bars ---------- */
.composer, .actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 24px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.composer form, .actionbar .inner { max-width: 640px; margin: 0 auto; }
.composer form {
  display: flex; align-items: center; gap: 8px;
  min-height: 60px; padding: 6px 6px 6px 22px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.composer input { flex: 1; min-width: 0; padding: 10px 0; border: 0; outline: 0; background: none; font-size: 18px; }
.composer input::placeholder { color: var(--ink-3); }

.send {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--sel); color: var(--sel-ink); transition: transform 0.12s;
}
.send:active { transform: scale(0.94); }
.send:disabled { background: var(--bubble); color: var(--ink-3); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 56px; border-radius: 999px;
  font-size: 17px; font-weight: 500;
  background: var(--sel); color: var(--sel-ink);
  transition: transform 0.12s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { background: var(--bubble); color: var(--ink-3); }
.btn.ghost { background: var(--bubble); color: var(--ink); }
.row2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

/* ---------- confirm sheet ---------- */
.sheet-bg { position: fixed; inset: 0; z-index: 40; display: grid; align-items: end; background: rgba(0, 0, 0, 0.3); }
.sheet { padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); background: var(--bg); border-radius: 28px 28px 0 0; animation: up 0.25s ease-out; }
.sheet .inner { max-width: 640px; margin: 0 auto; }
.sheet h3 { margin: 0 8px 14px; font-size: 20px; font-weight: 500; }
.sheet .note { margin: -6px 8px 16px; color: var(--ink-3); font-size: 14px; }
.confirm-choice {
  display: flex; align-items: center; gap: 14px;
  margin: 0 0 18px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; font-size: 17px;
}
.confirm-choice .L { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--sel); color: var(--sel-ink); font-size: 14px; font-weight: 500; }

/* ---------- welcome / waiting / results ---------- */
.hello { padding: 14vh 4px 24px; }
.hello h1 { margin: 0 0 10px; font-size: clamp(28px, 7.5vw, 36px); font-weight: 500; line-height: 1.15; letter-spacing: -0.01em; }
.hello h1 .soft { color: var(--ink-3); font-weight: 400; }
.hello p { margin: 0; color: var(--ink-3); font-size: 16px; line-height: 1.7; }

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

.wait { padding: 14vh 16px 0; text-align: center; }
.wait h2 { margin: 22px 0 6px; font-size: 28px; font-weight: 400; }
.wait p { margin: 0; color: var(--ink-2); }
.pulse { position: relative; width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); }
.pulse img { width: 44px; height: 44px; image-rendering: pixelated; }
.pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent); animation: ring 1.8s infinite; }

.score { padding: 28px 20px; text-align: center; }
.score .big { font-size: 52px; font-weight: 500; line-height: 1; letter-spacing: -0.02em; }
.score .big small { font-size: 20px; font-weight: 400; color: var(--ink-3); }
.score .rank { margin-top: 10px; color: var(--ink-3); font-size: 15px; }

.section-title { margin: 28px 4px 10px; color: var(--ink-3); font-size: 13px; font-weight: 500; letter-spacing: .04em; }

.board { list-style: none; margin: 0; padding: 0; }
.board li { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); }
.board li:last-child { border-bottom: 0; }
.board li.me { background: var(--bubble); border-radius: 14px; }
.board .r { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--bubble); font-size: 14px; font-weight: 500; }
.board li:nth-child(1) .r { background: #f6d77a; color: #5a4200; }
.board li:nth-child(2) .r { background: #dcdde2; color: #3b3d45; }
.board li:nth-child(3) .r { background: #eec29b; color: #5a3212; }
.board .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .s { font-weight: 500; font-variant-numeric: tabular-nums; }

.review { display: grid; gap: 10px; }
.review .item { padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; font-size: 15px; }
.review .item b { font-weight: 500; }
.review .item .a { margin-top: 6px; color: var(--ink-2); }
.review .ok { color: var(--ok); }
.review .bad { color: var(--bad); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: 76px; z-index: 50; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px;
  background: var(--sel); color: var(--sel-ink); font-size: 14px;
  box-shadow: var(--shadow); transition: opacity 0.3s; pointer-events: none;
}
