:root {
  --bg: #16112b;
  --bg2: #221a40;
  --card: #2a2150;
  --card2: #342a62;
  --line: #463a7a;
  --text: #f6f3ff;
  --muted: #a9a0cf;
  --accent: #ff5d8f;
  --accent2: #ffc24b;
  --good: #3ddc97;
  --bad: #ff6b6b;
  --radius: 16px;
  color-scheme: dark;
}

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

html, body { margin: 0; }
body {
  font-family: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #3b1f6b 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 10%, #5a1f4f 0%, transparent 55%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.4;
}

#app { max-width: 540px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }

h2, h3 { margin: 0.6em 0 0.4em; }
h3 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0.5em 0; }
.muted { color: var(--muted); }
.tiny { font-size: 0.82rem; }
.center { text-align: center; }
.big { font-size: 1.6rem; font-weight: 800; }

/* ---------- buttons & inputs */
.btn {
  display: block; width: 100%;
  font: inherit; font-weight: 700; font-size: 1.05rem;
  padding: 14px 18px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card2); color: var(--text); cursor: pointer;
  transition: transform 0.08s, background 0.2s, opacity 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff8a5c); border-color: transparent; color: #fff; box-shadow: 0 6px 20px -6px #ff5d8f99; }
.btn.ghost { background: transparent; }
.btn.small { display: inline-block; width: auto; padding: 8px 14px; font-size: 0.9rem; margin-top: 8px; }
.btn.big { font-size: 1.2rem; padding: 18px; }
.btn.danger { color: var(--bad); border-color: #ff6b6b55; }

.chip-btn {
  font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); cursor: pointer;
}
.chip-btn.accent { background: var(--accent); border-color: transparent; }

input, textarea {
  width: 100%; font: inherit; font-size: 1.1rem; /* >=16px stops iOS zoom */
  padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg); color: var(--text); outline: none; resize: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-weight: 700; font-size: 0.9rem; color: var(--muted); }
label input { margin-top: 6px; }
.code-input { text-transform: uppercase; letter-spacing: 0.4em; font-weight: 800; text-align: center; font-size: 1.5rem; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card.locked { border-color: var(--good); }

/* ---------- home */
.home { padding-top: 8vh; }
.logo { font-size: 3rem; text-align: center; margin: 0; letter-spacing: -0.03em; font-weight: 900; }
.logo span { background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { text-align: center; color: var(--muted); margin-bottom: 24px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---------- top bar & menu */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar .title { font-weight: 800; font-size: 0.95rem; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-pill, .me {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.me { max-width: 34%; overflow: hidden; text-overflow: ellipsis; }
.code-pill b { letter-spacing: 0.12em; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-left: 4px; vertical-align: middle; }
.dot.on { background: var(--good); }
.banner { position: sticky; top: 0; z-index: 10; background: var(--accent2); color: #222; text-align: center; font-weight: 700; padding: 6px; margin: 0 -16px; }

.sheet-backdrop { position: fixed; inset: 0; background: #0009; z-index: 20; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 21;
  width: min(540px, 100%); background: var(--bg2); border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px;
  animation: up 0.2s ease-out;
}
@keyframes up { from { transform: translate(-50%, 100%); } }

/* ---------- lobby */
.invite { display: flex; gap: 16px; align-items: center; }
.invite .qr { width: 118px; height: 118px; border-radius: 12px; background: #fff; padding: 6px; flex-shrink: 0; }
.invite-text { min-width: 0; }
.big-code { font-size: 2.6rem; font-weight: 900; letter-spacing: 0.12em; line-height: 1.1; color: var(--accent2); }
.url { font-weight: 700; font-size: 0.9rem; overflow-wrap: anywhere; }

.players { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.player { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.player.you { border-color: var(--accent); }
.player.away { opacity: 0.5; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; background: hsl(var(--h) 70% 60%); color: #1a1030; flex-shrink: 0; }
.pname { flex: 1; font-weight: 700; }
.p-tools { display: flex; gap: 6px; }

.games { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.game-card {
  font: inherit; color: var(--text); text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px;
  transition: transform 0.1s, border-color 0.2s;
}
.game-card:active { transform: scale(0.97); }
.game-card.selected { border-color: var(--accent); background: linear-gradient(160deg, #47285f, var(--card)); }
.game-card.unfit { opacity: 0.5; }
.g-emoji { font-size: 2rem; }
.g-name { font-weight: 800; font-size: 1.05rem; }
.g-players { font-size: 0.8rem; color: var(--accent2); font-weight: 700; }
.g-tag { font-size: 0.82rem; color: var(--muted); }
.howto { background: var(--bg2); border-radius: 12px; padding: 10px 14px; margin-top: 12px; }
.howto summary { font-weight: 700; cursor: pointer; }
.howto p { color: var(--muted); }
.start-bar { position: sticky; bottom: 0; padding: 16px 0 calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 35%); margin-top: 8px; }

/* ---------- shared game bits */
.round-tag { text-align: center; color: var(--muted); font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 8px; }
.prompt { text-align: center; font-size: 1.8rem; line-height: 1.2; margin: 12px 0 18px; }
.prompt.small { font-size: 1.4rem; }
.prompt .pre { display: block; font-size: 1rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }

.progress { position: relative; height: 26px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin: 16px 0 4px; }
.progress .bar { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #5b3fd1, var(--accent)); transition: width 0.3s; }
.progress span { position: relative; display: block; text-align: center; font-size: 0.85rem; font-weight: 700; line-height: 26px; }
.waiting { text-align: center; color: var(--muted); font-size: 0.85rem; }

.host-bar { margin-top: 20px; padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius); display: flex; flex-direction: column; gap: 8px; }
.host-label { font-size: 0.75rem; color: var(--accent2); font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choices.grid { display: grid; grid-template-columns: 1fr 1fr; }
.choice {
  font: inherit; font-size: 1.1rem; font-weight: 700; color: var(--text); text-align: left;
  background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; cursor: pointer;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.choice:active:not(:disabled) { transform: scale(0.98); }
.choice.picked { border-color: var(--accent); background: #4a2552; }
.choice.picked::after { content: ' ✓'; color: var(--accent); }
.choice:disabled { opacity: 0.5; }
.choice.def { font-weight: 600; font-size: 1rem; }
.tag { display: inline-block; font-size: 0.75rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--bg2); color: var(--muted); }
.tag.real { background: var(--good); color: #0b2a1d; }

.points-badge { margin: 10px auto; width: fit-content; font-size: 2rem; font-weight: 900; color: var(--good); animation: pop 0.4s ease-out; }
.points-badge.zero { color: var(--muted); font-size: 1.4rem; }
@keyframes pop { 0% { transform: scale(0.3); opacity: 0; } 70% { transform: scale(1.15); } }

.scoreboard { margin-top: 20px; }
.scoreboard ol { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.scoreboard li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--card); border-radius: 10px; }
.scoreboard li.you { outline: 2px solid var(--accent); }
.scoreboard .rank { width: 1.4em; color: var(--muted); font-weight: 800; }
.scoreboard .name { flex: 1; font-weight: 700; }
.scoreboard .delta { color: var(--good); font-weight: 800; font-size: 0.85rem; }
.scoreboard .score { font-weight: 900; min-width: 2ch; text-align: right; }

.final { text-align: center; }
.trophy { font-size: 4rem; text-align: center; margin-top: 12px; animation: pop 0.5s ease-out; }
.final .scoreboard, .final .awards { text-align: left; }

details.reminder { background: var(--bg2); border-radius: 12px; padding: 10px 14px; margin: 14px 0; }
details.reminder summary { cursor: pointer; font-weight: 700; color: var(--muted); }
ul.plain { padding-left: 1.2em; }

.spinner { width: 36px; height: 36px; margin: 16px auto; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- hivemind */
.answer-groups { display: flex; flex-direction: column; gap: 8px; }
.answer-group { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.answer-group.mine { border-color: var(--accent); }
.answer-group.solo { opacity: 0.7; }
.ag-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ag-label { font-size: 1.25rem; font-weight: 800; }
.ag-size { font-weight: 900; color: var(--accent2); font-size: 1.2rem; }
.ag-names { color: var(--muted); font-size: 0.9rem; }
.ag-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.ag-pts { font-size: 0.85rem; font-weight: 700; color: var(--good); }
.solo .ag-pts { color: var(--muted); }

/* ---------- most likely */
.verdict { text-align: center; font-size: 1.8rem; font-weight: 900; color: var(--accent2); margin: 8px 0 16px; animation: pop 0.5s ease-out; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 30%) 1fr 2ch; gap: 10px; align-items: center; }
.bar-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 22px; background: var(--bg2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: #6b5bd6; border-radius: 999px; animation: grow 0.6s ease-out; transform-origin: left; }
.winner .bar-fill { background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.bar-count { font-weight: 900; text-align: right; }
@keyframes grow { from { transform: scaleX(0); } }
.awards { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.award { background: var(--card); border-radius: 12px; padding: 12px 14px; }
.award.you { outline: 2px solid var(--accent); }
.award-name { font-weight: 800; }
.award ul { margin: 6px 0 0; padding-left: 1.2em; color: var(--muted); font-size: 0.92rem; }

/* ---------- imposter */
.secret-card {
  font: inherit; color: var(--text); width: 100%; min-height: 200px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  border-radius: 20px; border: 2px dashed var(--line); background: var(--card); padding: 20px; margin: 12px 0;
}
.secret-card .peek { font-size: 3rem; }
.secret-card.shown { border-style: solid; border-color: var(--good); background: linear-gradient(160deg, #1f4a3c, var(--card)); }
.secret-card.is-imposter { border-color: var(--bad); background: linear-gradient(160deg, #5a1f2c, var(--card)); }
.secret-word { font-size: 2.4rem; font-weight: 900; color: var(--accent2); line-height: 1.1; }
.role.imposter { font-size: 1.2rem; }
.role.imposter b { font-size: 2.2rem; color: var(--bad); letter-spacing: 0.06em; }
.cat { color: var(--muted); }
.result-head { text-align: center; font-size: 1.3rem; margin: 14px 0; }

/* ---------- bluff */
.word-card { text-align: center; margin: 12px 0 16px; }
.weird-word { font-size: 2.2rem; font-weight: 900; color: var(--accent2); word-break: break-word; font-family: Georgia, 'Times New Roman', serif; font-style: italic; }
.quote { font-size: 1.1rem; font-style: italic; margin: 6px 0; }
.defs { display: flex; flex-direction: column; gap: 8px; }
.def-result { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.def-result.real { border-color: var(--good); }
.def-result.mine { outline: 2px dashed var(--accent); }
.def-text { font-weight: 600; }
.def-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; font-size: 0.85rem; }

/* ---------- toast */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: #fff; color: #1a1030; font-weight: 700; padding: 12px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: 0.25s; z-index: 50; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- lobby options */
.option-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.option-label { font-weight: 700; }
.segmented { display: flex; background: var(--bg2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg { font: inherit; font-weight: 700; color: var(--muted); background: transparent; border: 0; border-radius: 9px; padding: 8px 16px; cursor: pointer; }
.seg.on { background: var(--accent); color: #fff; }
.seg:disabled { cursor: default; }

/* ---------- pot luck */
.pot { text-align: center; margin: 4px 0 6px; }
.pot-amount { font-size: 4.2rem; font-weight: 900; line-height: 1; color: var(--accent2); font-variant-numeric: tabular-nums; }
.pot.danger .pot-amount { color: #ffd76b; text-shadow: 0 0 24px #ff5d8f88; }
.zone { text-align: center; font-size: 0.85rem; font-weight: 700; padding: 6px 12px; border-radius: 999px; width: fit-content; margin: 0 auto; }
.zone.safe { background: #1f4a3c; color: var(--good); }
.zone.danger { background: #5a1f2c; color: #ffb3b3; animation: throb 1.4s ease-in-out infinite; }
@keyframes throb { 50% { transform: scale(1.04); } }

.dice { display: flex; justify-content: center; gap: 18px; margin: 18px 0 8px; }
.die {
  width: 78px; height: 78px; border-radius: 16px; background: #fbf8ff; padding: 10px;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); place-items: center;
  box-shadow: 0 6px 0 #c9c0e6, 0 10px 24px -6px #000a;
}
.die span { width: 14px; height: 14px; border-radius: 50%; }
.die .pip { background: #1a1030; }
.dice.idle .die { opacity: 0.35; }
.dice.rolling .die { animation: tumble 0.35s linear infinite; }
.dice.rolling .die:nth-child(2) { animation-duration: 0.29s; animation-direction: reverse; }
@keyframes tumble { 0% { transform: rotate(0) translateY(0); } 25% { transform: rotate(90deg) translateY(-8px); } 50% { transform: rotate(180deg); } 75% { transform: rotate(270deg) translateY(-8px); } 100% { transform: rotate(360deg); } }
.dice.add .die, .dice.seventy .die, .dice.double .die, .dice.bust .die { animation: land 0.3s ease-out; }
.dice.double .die { background: #fff4d6; box-shadow: 0 6px 0 #e9c46a, 0 0 28px #ffc24b99; }
.dice.seventy .die { background: #e6fff3; box-shadow: 0 6px 0 #7bd6ad, 0 0 28px #3ddc9799; }
.dice.bust .die { background: #ffe1e1; box-shadow: 0 6px 0 #e08a8a, 0 0 28px #ff6b6b99; }
@keyframes land { 0% { transform: scale(1.3) rotate(-12deg); } 100% { transform: none; } }

.effect { text-align: center; min-height: 1.6em; margin-bottom: 10px; font-size: 1.1rem; }
.effect b { font-size: 1.3rem; margin-right: 6px; }
.effect.seventy b { color: var(--good); }
.effect.double b { color: var(--accent2); }
.effect.bust b { color: var(--bad); }

.roll-btn { background: linear-gradient(135deg, #5b3fd1, #8a5cff); border-color: transparent; font-size: 1.3rem; padding: 18px; box-shadow: 0 6px 20px -6px #8a5cff99; }

.pl-list { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; gap: 4px; }
.pl-list li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--card); border-radius: 10px; }
.pl-list li.you { outline: 2px solid var(--accent); }
.pl-list li.away { opacity: 0.5; }
.pl-list .name { flex: 1; font-weight: 700; }
.pl-list .score { font-weight: 900; min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
.pl-banked { font-size: 0.8rem; font-weight: 800; color: var(--good); }
.pl-bust { font-size: 0.8rem; font-weight: 800; color: var(--bad); }
.pl-turn { font-size: 0.8rem; font-weight: 800; color: var(--accent2); }
.pl-in { font-size: 0.8rem; color: var(--muted); }

.bank-bar { position: sticky; bottom: 0; padding: 14px 0 calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); margin-top: 8px; }
.bank-btn { background: linear-gradient(135deg, #1fbf7a, #3ddc97); border-color: transparent; color: #08261a; font-size: 1.5rem; font-weight: 900; padding: 20px; letter-spacing: 0.04em; box-shadow: 0 8px 24px -8px #3ddc97aa; }
.bank-btn span { font-variant-numeric: tabular-nums; margin-left: 6px; }
.bank-btn.urgent { animation: throb 1s ease-in-out infinite; }
.bank-done { text-align: center; padding: 16px; border-radius: 14px; background: #1f4a3c; color: var(--good); font-weight: 700; }

.round-over { text-align: center; margin-top: 4px; }
.round-over h2 { font-size: 2rem; margin: 0; }
.round-over.bust h2 { color: var(--bad); }
.round-over.safe h2 { color: var(--good); }
.big-emoji { font-size: 3.4rem; animation: pop 0.4s ease-out; }
