:root {
  --bg1: #1a0b2e;
  --bg2: #2d1457;
  --panel: rgba(255, 255, 255, 0.07);
  --panel-b: rgba(255, 255, 255, 0.12);
  --txt: #f4efff;
  --muted: #b9a9d9;
  --primary: #8b3dff;
  --primary2: #e0318f;
  --ok: #19c37d;
  --bad: #ff3d5a;
  --pass: #ffb020;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--txt);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2) 0%, var(--bg1) 70%) fixed;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .35; cursor: default; }
h1, h2, h3 { margin: 0; }

#app { position: fixed; inset: 0; max-width: 560px; margin: 0 auto; }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  animation: fadeIn .25s ease;
}
.screen.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.scroll { flex: 1; overflow-y: auto; padding: 8px 16px 24px; -webkit-overflow-scrolling: touch; }

.topbar {
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  padding: 10px 12px; min-height: 60px;
}
.topbar h2 { text-align: center; font-size: 1.15rem; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; font-size: 1.3rem;
  background: var(--panel); border: 1px solid var(--panel-b);
}
.icon-btn:active { transform: scale(.94); }

.bottom-bar { padding: 12px 16px 16px; }
.bottom-bar.col { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 20px; border-radius: 16px; font-weight: 700; font-size: 1rem;
  transition: transform .1s ease, filter .2s;
}
.btn:active { transform: scale(.97); }
.btn-lg { padding: 18px 22px; font-size: 1.15rem; }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  box-shadow: 0 8px 24px rgba(139, 61, 255, .35);
}
.btn-go {
  background: linear-gradient(135deg, #19c37d, #0ea5a4);
  box-shadow: 0 8px 24px rgba(25, 195, 125, .35);
  font-size: 1.4rem;
}
.btn-ghost { background: var(--panel); border: 1px solid var(--panel-b); }
.btn-danger { background: rgba(255, 61, 90, .15); border: 1px solid rgba(255, 61, 90, .4); color: #ff8fa0; margin-top: 8px; }
.chip-btn {
  padding: 6px 12px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  background: var(--panel); border: 1px solid var(--panel-b);
}

/* ---------- Home ---------- */
.home-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px; gap: 28px; overflow-y: auto; }
.logo { text-align: center; }
.logo-card {
  display: inline-block; padding: 22px 38px; border-radius: 24px;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  transform: rotate(-4deg);
  box-shadow: 0 18px 50px rgba(224, 49, 143, .4), inset 0 0 0 4px rgba(255,255,255,.25);
  animation: bob 3s ease-in-out infinite;
}
.logo-card span { font-size: 3.6rem; font-weight: 900; letter-spacing: 6px; text-shadow: 0 4px 0 rgba(0,0,0,.2); }
@keyframes bob { 0%,100% { transform: rotate(-4deg) translateY(0); } 50% { transform: rotate(-2deg) translateY(-6px); } }
.tagline { margin: 18px 0 4px; color: var(--muted); font-size: 1.05rem; }
.word-count { margin: 0; font-size: .85rem; color: #d7c6ff; opacity: .8; }
.menu { display: flex; flex-direction: column; gap: 10px; }
.install-btn {
  margin: 0 auto; padding: 10px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  background: rgba(25,195,125,.15); border: 1px solid rgba(25,195,125,.5); color: #7ff0bd;
}

/* ---------- Panels ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--panel-b);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.panel h3 { font-size: 1rem; margin-bottom: 10px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel-title h3 { margin: 0; }
.hint { font-size: .82rem; color: var(--muted); margin: 8px 0 0; }
.hint.center { text-align: center; margin: 4px 0 12px; }
.sub { margin: 10px 0 4px; color: var(--muted); }

/* team list */
.team-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.team-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.inp {
  width: 100%; padding: 13px 14px; border-radius: 12px; font: inherit; font-size: 1rem;
  background: rgba(0,0,0,.25); border: 1px solid var(--panel-b); color: var(--txt); outline: none;
  margin-bottom: 8px;
}
.inp:focus { border-color: var(--primary); }
.team-row .inp { margin: 0; }
.inp-main { font-weight: 700; border-color: rgba(139, 61, 255, .6); }
.del-btn { width: 40px; height: 40px; border-radius: 10px; flex: none; background: rgba(255,61,90,.15); color: #ff8fa0; font-size: 1.1rem; }

/* range */
input[type=range] { width: 100%; accent-color: var(--primary2); height: 32px; }

/* segmented */
.seg { display: flex; background: rgba(0,0,0,.25); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 10px 6px; border-radius: 9px; font-weight: 600; font-size: .92rem; color: var(--muted); }
.seg button.on { background: linear-gradient(135deg, var(--primary), var(--primary2)); color: #fff; }

/* categories */
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cat {
  display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 10px; border-radius: 12px; background: rgba(0,0,0,.25);
  border: 2px solid transparent; transition: all .15s;
}
.cat .ci { font-size: 1.4rem; }
.cat .cn { font-size: .82rem; font-weight: 600; line-height: 1.15; }
.cat .cc { display: block; font-size: .72rem; color: var(--muted); font-weight: 500; }
.cat.on { border-color: var(--primary2); background: rgba(224, 49, 143, .15); }

/* ---------- Turn screen ---------- */
.turn-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px 20px; text-align: center; overflow-y: auto; }
.turn-sub { color: var(--muted); margin: 0; text-transform: uppercase; letter-spacing: 3px; font-size: .85rem; }
.turn-team { font-size: 2.6rem; font-weight: 900; margin: 6px 0 10px; word-break: break-word; }
.turn-info { color: var(--muted); max-width: 320px; margin: 0 0 24px; line-height: 1.4; }
.turn-goal { color: var(--muted); font-size: .9rem; margin-top: 14px; }
.scoreboard { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.sb-row {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--panel-b);
}
.sb-row.current { border-color: var(--primary2); background: rgba(224,49,143,.14); }
.sb-row .sb-name { flex: 1; text-align: left; font-weight: 600; }
.sb-row .sb-pts { font-weight: 900; font-size: 1.3rem; }
.sb-row .sb-rank { width: 24px; color: var(--muted); font-weight: 700; }
.scoreboard.big .sb-row { padding: 14px 16px; }
.scoreboard.big .sb-row:first-child { background: linear-gradient(135deg, rgba(255,200,0,.25), rgba(255,140,0,.15)); border-color: #ffc93c; }

/* ---------- Play screen ---------- */
.play-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 4px; }
.timer { position: relative; width: 78px; height: 78px; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 8; }
.t-bg { stroke: rgba(255,255,255,.1); }
.t-fg { stroke: var(--ok); stroke-linecap: round; stroke-dasharray: 276.46; stroke-dashoffset: 0; transition: stroke .3s; }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.6rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.timer.warn .t-fg { stroke: var(--pass); }
.timer.danger .t-fg { stroke: var(--bad); }
.timer.danger span { animation: pulse 1s infinite; color: #ff8fa0; }
@keyframes pulse { 50% { transform: scale(1.15); } }
.play-score { text-align: right; min-width: 90px; }
.ps-team { display: block; font-size: .8rem; color: var(--muted); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-pts { font-size: 2rem; font-weight: 900; }

.card-area { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; padding: 8px 18px; min-height: 0; }
.tcard {
  width: 100%; max-width: 380px; max-height: 100%;
  background: #fff; color: #2a1846; border-radius: 26px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
  display: flex; flex-direction: column;
  touch-action: pan-y;
  will-change: transform;
}
.tcard.enter { animation: cardIn .28s cubic-bezier(.2,.9,.3,1.2); }
@keyframes cardIn { from { opacity: 0; transform: scale(.85) translateY(20px); } to { opacity: 1; transform: none; } }
.tcard.out-right { transition: transform .22s ease-in, opacity .22s; transform: translateX(120%) rotate(18deg); opacity: 0; }
.tcard.out-left { transition: transform .22s ease-in, opacity .22s; transform: translateX(-120%) rotate(-18deg); opacity: 0; }
.tcard.out-down { transition: transform .22s ease-in, opacity .22s; transform: translateY(60%) scale(.8); opacity: 0; }
.tcard-head {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff; padding: 18px 16px 22px; text-align: center; position: relative;
}
.tcard-cat { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: 1px; opacity: .9; background: rgba(0,0,0,.18); padding: 4px 10px; border-radius: 999px; margin-bottom: 10px; }
.tcard-head h1 { font-size: clamp(1.6rem, 8vw, 2.4rem); font-weight: 900; letter-spacing: 1px; line-height: 1.1; word-break: break-word; }
.tcard-list { list-style: none; margin: 0; padding: 8px 18px 14px; }
.tcard-list li {
  text-align: center; font-size: clamp(1.1rem, 5.4vw, 1.45rem); font-weight: 700; padding: 11px 6px;
  border-bottom: 2px dashed #eadff9; color: #3b2463;
}
.tcard-list li:last-child { border-bottom: 0; }
.flash { position: absolute; inset: 0; pointer-events: none; display: grid; place-items: center; font-size: 5rem; opacity: 0; }
.flash.show { animation: flash .5s ease; }
@keyframes flash { 0% { opacity: 0; transform: scale(.6); } 30% { opacity: 1; transform: scale(1.1); } 100% { opacity: 0; transform: scale(1.3); } }

.play-stats { display: flex; justify-content: center; align-items: center; gap: 16px; padding: 6px 12px; font-size: .95rem; color: var(--muted); }
.play-stats b { color: var(--txt); }
.play-stats small { opacity: .7; margin-left: 2px; }
.undo-btn { padding: 6px 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--panel-b); font-size: .8rem; font-weight: 600; }

.play-actions { display: grid; grid-template-columns: 1fr 1fr 1.25fr; gap: 10px; padding: 8px 14px 16px; }
.act {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 16px 6px; border-radius: 20px; font-weight: 900; font-size: 1.05rem; letter-spacing: .5px;
  min-height: 86px; transition: transform .08s;
}
.act span { font-size: 1.6rem; }
.act:active:not(:disabled) { transform: scale(.94); }
.act-taboo { background: linear-gradient(160deg, #ff5a72, #d61f45); box-shadow: 0 8px 20px rgba(255,61,90,.35); }
.act-pass { background: linear-gradient(160deg, #ffc94a, #f08c00); box-shadow: 0 8px 20px rgba(255,176,32,.3); color: #3a2200; }
.act-ok { background: linear-gradient(160deg, #2fe39a, #0e9e66); box-shadow: 0 8px 20px rgba(25,195,125,.35); }

/* ---------- Summary ---------- */
.sum-head { text-align: center; padding: 6px 0 14px; }
.sum-head p { margin: 0; color: var(--muted); font-weight: 600; }
.sum-head h1 { font-size: 3.4rem; font-weight: 900; margin: 4px 0 10px; }
.sum-pills { display: flex; justify-content: center; gap: 8px; }
.pill { padding: 6px 12px; border-radius: 999px; font-size: .9rem; background: var(--panel); }
.pill.ok { background: rgba(25,195,125,.18); }
.pill.bad { background: rgba(255,61,90,.18); }
.pill.pass { background: rgba(255,176,32,.18); }
.sum-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.sum-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-radius: 12px; background: var(--panel); border-left: 5px solid transparent;
  font-weight: 600; cursor: pointer;
}
.sum-list li.correct { border-left-color: var(--ok); }
.sum-list li.taboo { border-left-color: var(--bad); }
.sum-list li.pass { border-left-color: var(--pass); }
.sum-list li .tag { font-size: .8rem; font-weight: 700; padding: 4px 8px; border-radius: 8px; white-space: nowrap; }
.sum-list li.correct .tag { background: rgba(25,195,125,.2); color: #7ff0bd; }
.sum-list li.taboo .tag { background: rgba(255,61,90,.2); color: #ff98a8; }
.sum-list li.pass .tag { background: rgba(255,176,32,.2); color: #ffd48a; }

/* ---------- Game over ---------- */
.over-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; text-align: center; overflow-y: auto; position: relative; z-index: 1; }
.trophy { font-size: 5rem; animation: bob 2.5s ease-in-out infinite; }
.over-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; margin-top: 14px; }
.over-stats div { background: var(--panel); border-radius: 12px; padding: 10px 4px; font-size: .78rem; color: var(--muted); }
.over-stats b { display: block; font-size: 1.3rem; color: var(--txt); }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- Custom cards ---------- */
.custom-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.custom-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(0,0,0,.25); }
.custom-list .cw { flex: 1; min-width: 0; }
.custom-list .cw b { display: block; }
.custom-list .cw small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--panel-b); border-radius: 16px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 1.8rem; font-weight: 900; }
.stat span { color: var(--muted); font-size: .82rem; }
.progress { height: 12px; background: rgba(0,0,0,.3); border-radius: 999px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--primary2)); transition: width .4s; }

/* ---------- Settings toggles ---------- */
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--panel-b); cursor: pointer; }
.toggle:last-child { border-bottom: 0; }
.toggle input { display: none; }
.toggle i { width: 50px; height: 28px; border-radius: 999px; background: rgba(255,255,255,.15); position: relative; transition: background .2s; flex: none; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + i { background: var(--ok); }
.toggle input:checked + i::after { transform: translateX(22px); }

/* ---------- Prose ---------- */
.prose p, .prose li { color: #e3d9f7; line-height: 1.5; font-size: .95rem; }
.prose p { margin: 0 0 6px; }
.prose ul { margin: 0; padding-left: 20px; }
.c-ok { color: var(--ok); } .c-bad { color: var(--bad); } .c-pass { color: var(--pass); }

/* ---------- Modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(10, 4, 20, .75); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 24px; }
.modal[hidden] { display: none; }
.modal-box { width: 100%; max-width: 360px; background: #2a1650; border: 1px solid var(--panel-b); border-radius: 22px; padding: 22px; text-align: center; animation: fadeIn .2s; }
.modal-box h2 { font-size: 1.4rem; margin-bottom: 8px; }
.modal-box p { color: var(--muted); margin: 0 0 18px; line-height: 1.4; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%) translateY(120px);
  background: #fff; color: #2a1846; padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: .92rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: transform .3s ease; z-index: 60; max-width: 90%; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-height: 640px) {
  .tcard-head { padding: 12px 14px 14px; }
  .tcard-list li { padding: 7px 6px; }
  .act { min-height: 70px; padding: 10px 6px; }
  .timer { width: 64px; height: 64px; }
}
