:root {
  --ink: #1B1740;
  --ink-2: #26215A;
  --ink-3: #332C73;
  --line: #463E8C;
  --text: #F3F0FF;
  --muted: #ADA6DB;
  --signal: #FFC83D;
  --signal-ink: #2A1F00;
  --alarm: #FF4F5E;
  --safe: #52D6A8;
  --font: "Bricolage Grotesque", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r-sm: 10px;
  --r-lg: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

#app { max-width: 520px; margin: 0 auto; padding: 20px 18px 190px; }

h1, h2, h3 { margin: 0; line-height: 1.1; font-weight: 800; }
h1 { font-size: clamp(56px, 18vw, 88px); letter-spacing: -0.04em; }
h2 { font-size: 30px; letter-spacing: -0.02em; }
h3 { font-size: 20px; }
p { margin: 0; }
.muted { color: var(--muted); }
.stack > * + * { margin-top: 14px; }
.stack-lg > * + * { margin-top: 26px; }

/* ---------- Top bar ---------- */
#bar {
  position: sticky; top: 0; z-index: 5;
  background: var(--ink);
  border-bottom: 1px solid var(--line);
}
#bar .inner {
  max-width: 520px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; gap: 12px; font-size: 15px;
}
#bar .code { font-weight: 800; letter-spacing: 0.12em; background: var(--ink-3); padding: 3px 9px; border-radius: 8px; }
#bar .lead { color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#bar .lead b { color: var(--text); font-weight: 600; }
#bar .score { font-weight: 800; font-variant-numeric: tabular-nums; }
#bar .score span { color: var(--muted); font-weight: 400; }

/* ---------- Controls ---------- */
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }

.btn {
  display: block; width: 100%;
  border: 0; border-radius: var(--r-sm);
  padding: 16px 18px; font-size: 19px; font-weight: 800;
  background: var(--signal); color: var(--signal-ink);
  transition: transform .08s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.ghost { background: transparent; color: var(--text); border: 2px solid var(--line); font-weight: 600; }
.btn.small { padding: 10px 14px; font-size: 16px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px 0; font-size: 15px; }

label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=password], textarea {
  width: 100%; padding: 14px 16px; font-size: 19px;
  background: var(--ink-2); border: 2px solid var(--line); border-radius: var(--r-sm);
}
input:focus, textarea:focus { border-color: var(--signal); outline: none; }
textarea { resize: none; min-height: 110px; }
input.code-in { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 800; text-align: center; font-size: 26px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.seg { display: flex; background: var(--ink-2); border-radius: var(--r-sm); padding: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 12px; border-radius: 7px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed=true] { background: var(--ink-3); color: var(--text); }

.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button { width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--line); background: none; font-size: 24px; font-weight: 800; }
.stepper output { font-size: 32px; font-weight: 800; min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 15px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Home ---------- */
.home-title { margin: 24px 0 4px; }
.home-title h1 { transform: rotate(-3deg); transform-origin: left; }
.home-title h1 .eye { color: var(--alarm); }

/* ---------- Lobby ---------- */
.joinbox { display: flex; gap: 16px; align-items: center; }
.bigcode { font-size: 64px; font-weight: 800; letter-spacing: 0.08em; line-height: 1; }
.qr { width: 108px; height: 108px; background: #fff; border-radius: var(--r-sm); padding: 6px; flex: none; }
.qr img { width: 100%; height: 100%; display: block; }

/* ---------- Players / scores ---------- */
.plist { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.plist li { display: flex; align-items: center; gap: 10px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.plist .nm { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .pts { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 20px; }
.plist .off { opacity: .45; }
.tag { font-size: 13px; padding: 2px 8px; border-radius: 99px; background: var(--ink-3); color: var(--muted); font-weight: 600; white-space: nowrap; }
.tag.lead { background: var(--signal); color: var(--signal-ink); }
.tag.done { background: transparent; color: var(--safe); border: 1px solid var(--safe); }
.plist button.more { background: none; border: 0; color: var(--muted); font-size: 22px; padding: 0 6px; line-height: 1; }
.pmenu { display: flex; gap: 8px; padding: 0 0 12px; border-bottom: 1px solid var(--line); }
.pmenu .btn { flex: 1; }

/* ---------- The card (hold to reveal) ---------- */
.card {
  position: relative;
  aspect-ratio: 3 / 4; max-height: 56vh; width: 100%;
  margin: 0 auto;
  border-radius: var(--r-lg);
  background: var(--ink-2);
  border: 2px dashed var(--line);
  display: grid; place-items: center; text-align: center;
  padding: 24px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none;
  cursor: pointer;
}
.card .face { display: none; }
.card .back { display: grid; gap: 10px; justify-items: center; color: var(--muted); }
.card .back .fp { font-size: 64px; line-height: 1; filter: grayscale(.3); }
.card.open { border-style: solid; }
.card.open .back { display: none; }
.card.open .face { display: grid; gap: 12px; justify-items: center; }
.card.open.word { background: var(--text); color: var(--ink); border-color: var(--text); }
.card.open.imp { background: var(--alarm); color: #fff; border-color: var(--alarm); }
.card .cat { font-size: 16px; font-weight: 600; opacity: .7; }
.card .word { font-size: clamp(38px, 12vw, 60px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; overflow-wrap: anywhere; }
.card .stamp {
  font-size: clamp(40px, 13vw, 64px); font-weight: 800; letter-spacing: -0.02em;
  border: 5px solid currentColor; border-radius: 10px; padding: 2px 14px;
  transform: rotate(-8deg);
}

.question {
  background: var(--text); color: var(--ink);
  border-radius: var(--r-lg); padding: 22px 20px;
  font-size: 23px; font-weight: 800; line-height: 1.25; letter-spacing: -0.01em;
}

/* ---------- Voting ---------- */
.votes { display: grid; gap: 10px; }
.vote {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-radius: var(--r-sm);
  border: 2px solid var(--line); background: var(--ink-2);
  font-size: 20px; font-weight: 600; text-align: left;
}
.vote[aria-pressed=true] { border-color: var(--alarm); background: var(--alarm); color: #fff; }

.progress { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- Results ---------- */
.verdict { padding: 22px 20px; border-radius: var(--r-lg); }
.verdict.caught { background: var(--safe); color: #062B1E; }
.verdict.escaped { background: var(--alarm); color: #fff; }
.verdict h2 { font-size: 34px; }
.verdict p { margin-top: 6px; font-weight: 600; }

.qpair { display: grid; gap: 10px; }
.qpair > div { border-radius: var(--r-sm); padding: 14px 16px; background: var(--ink-2); }
.qpair .fake { background: var(--alarm); color: #fff; }
.qpair small { display: block; font-weight: 600; opacity: .75; margin-bottom: 2px; }
.qpair b { font-size: 19px; }

.answers { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.answers li { background: var(--ink-2); border-radius: var(--r-sm); padding: 12px 16px; }
.answers li.imp { outline: 2px solid var(--alarm); }
.answers .who { font-size: 15px; color: var(--muted); font-weight: 600; }
.answers .what { font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }

.small-list { list-style: none; padding: 0; margin: 0; font-size: 16px; }
.small-list li { padding: 4px 0; }
.good { color: var(--safe); }
.bad { color: var(--alarm); }

.crown { font-size: 72px; line-height: 1; }

/* ---------- Sticky leader actions ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  background: linear-gradient(to top, var(--ink) 70%, transparent);
  padding: 22px 18px calc(16px + env(safe-area-inset-bottom, 0));
}
.dock .inner { max-width: 520px; margin: 0 auto; display: grid; gap: 10px; }
.dock .note { text-align: center; font-size: 14px; color: var(--muted); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; top: 14px; transform: translate(-50%, -140%);
  background: var(--alarm); color: #fff; font-weight: 600;
  padding: 12px 18px; border-radius: var(--r-sm); z-index: 10;
  max-width: calc(100% - 28px); transition: transform .2s ease, opacity .2s ease;
  opacity: 0; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.ok { background: var(--safe); color: #062B1E; }

/* ---------- Admin ---------- */
.admin-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); font-size: 16px; }
.admin-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.admin-list li > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.admin-list .x { background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); padding: 4px 10px; font-size: 14px; }
.admin-list .x:hover { color: var(--alarm); border-color: var(--alarm); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
