:root {
  --bg: #14112a;
  --panel: #1f1b3d;
  --panel-2: #2a2552;
  --line: #3a3470;
  --text: #f4f2ff;
  --muted: #a9a3d6;
  --accent: #ffcf3f;
  --accent-ink: #1b1600;
  --good: #3ddc84;
  --bad: #ff6b6b;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { background-color: var(--bg); }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(120% 80% at 50% 0%, #2b2165 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px calc(40px + env(safe-area-inset-bottom));
}

h1 { font-size: 40px; line-height: 1.05; margin: 28px 0 6px; letter-spacing: -0.02em; }
h2 { font-size: 24px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 22px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.big-emoji { font-size: 64px; line-height: 1; margin-top: 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
}

label { display: block; font-size: 14px; color: var(--muted); margin: 0 0 6px; }

input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 20px;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }
input.code { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center; }

button {
  font: inherit;
  font-weight: 650;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  touch-action: manipulation;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.good { background: var(--good); color: #062612; border-color: transparent; }
button.ghost { background: transparent; }
button.danger { color: var(--bad); }
button.block { display: block; width: 100%; }
button.huge { font-size: 22px; padding: 20px; border-radius: 18px; }
button.mini { padding: 6px 10px; font-size: 14px; border-radius: 9px; white-space: nowrap; }

.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.divider { text-align: center; color: var(--muted); margin: 18px 0; font-size: 14px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; color: var(--muted);
}
.topbar .code-pill {
  font-weight: 800; letter-spacing: 0.2em; color: var(--text);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px;
}

.room-code {
  font-size: 64px; font-weight: 900; letter-spacing: 0.15em; text-align: center;
  color: var(--accent); line-height: 1; margin: 8px 0 4px;
}
.qr { background: #fff; border-radius: 14px; padding: 10px; width: 200px; margin: 12px auto 0; }
.qr svg { display: block; width: 100%; height: auto; }

.players { list-style: none; padding: 0; margin: 0; }
.players li {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.players li:last-child { border-bottom: 0; }
.players .name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); flex: none; }
.dot.off { background: #6b6593; }
.tag { font-size: 12px; font-weight: 700; color: var(--muted); }
.score { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--accent); }

.target-name { color: var(--accent); }

.others { list-style: none; padding: 0; margin: 0; }
.others li { padding: 14px 0; border-bottom: 1px solid var(--line); }
.others li:last-child { border-bottom: 0; }
.others .who { font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.others .char { font-size: 26px; font-weight: 800; line-height: 1.15; margin: 3px 0 8px; word-break: break-word; }
.others li.done .char { color: var(--good); }
.others li.gave .char { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 2px; }

.reveal {
  text-align: center; padding: 22px 16px;
  background: linear-gradient(135deg, #2f7d4f, #1f5a3a);
  border-radius: var(--radius); margin: 14px 0;
}
.reveal .char { font-size: 34px; font-weight: 900; line-height: 1.1; margin-top: 4px; word-break: break-word; }
.reveal.gave { background: linear-gradient(135deg, #7d2f3f, #5a1f2b); }

.banner {
  background: var(--accent); color: var(--accent-ink); font-weight: 800;
  text-align: center; padding: 12px; border-radius: 12px; margin: 14px 0;
}

.host-bar { border-color: var(--accent); }
.host-bar h3 { margin-top: 0; color: var(--accent); }

/* ---------- forehead screen ---------- */
#forehead {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: hsl(var(--hue, 45), 95%, 55%);
  color: #111;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
  touch-action: none;
}
#forehead[hidden] { display: none; }
#forehead.counting { background: #111; color: #fff; }
#forehead.solved { background: var(--good); }
.fh-box { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.fh-text {
  width: 100%; text-align: center; font-weight: 900; line-height: 1.02;
  letter-spacing: -0.02em; overflow-wrap: normal; word-break: normal;
}
.fh-tag {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; font-weight: 800; font-size: 18px; opacity: 0.75; pointer-events: none;
}
.fh-close {
  position: absolute; z-index: 2;
  top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right));
  background: rgba(0,0,0,0.18); color: inherit; border: 0;
  width: 44px; height: 44px; border-radius: 50%; padding: 0; font-size: 18px;
}

/* ---------- modal + toast ---------- */
#modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(8, 6, 20, 0.8);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#modal[hidden] { display: none; }
#modal .card { max-width: 420px; width: 100%; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 70; background: #000; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 15px; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
#toast[hidden] { display: none; }

ol.howto { padding-left: 20px; margin: 0; color: var(--muted); font-size: 15px; }
ol.howto li + li { margin-top: 6px; }
ol.howto b { color: var(--text); }
