/* ---------- Reset & base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  overscroll-behavior: none; touch-action: manipulation;
  background: #0f0f1a; color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none;
}
#app { min-height: 100dvh; display: flex; flex-direction: column; }

:root {
  --bg: #0f0f1a;
  --panel: #1b1b2e;
  --panel-2: #25253c;
  --accent: #ffd23f;
  --good: #5cff8f;
  --bad: #ff3f6c;
  --muted: #9a9ab0;
  --team: #5cb3ff;          /* overridden per active team */
  --team-ink: #04121f;      /* readable text on team color */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Screens ---------- */
.screen {
  position: relative;
  flex: 1; display: flex; flex-direction: column;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  gap: 14px; min-height: 0;
}
.screen.center { justify-content: center; align-items: center; text-align: center; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

h1 { font-size: clamp(28px, 8vw, 56px); margin: 0; font-weight: 900; letter-spacing: -1px; }
h2 { font-size: clamp(20px, 5vw, 32px); margin: 0; font-weight: 800; }
.sub { color: var(--muted); font-size: clamp(14px, 3.6vw, 18px); }
.brand { color: var(--accent); }

/* ---------- Buttons ---------- */
button {
  font-family: inherit; font-weight: 800; border: none; border-radius: 16px;
  padding: 18px 20px; font-size: clamp(18px, 5vw, 26px); color: #fff;
  background: var(--panel-2); cursor: pointer; transition: transform .06s ease, filter .15s ease;
  touch-action: manipulation;
}
button:active { transform: scale(0.97); filter: brightness(1.1); }
button.press { transform: scale(0.95); filter: brightness(1.15); }
button:disabled { opacity: .4; }
.btn-primary { background: var(--accent); color: #1a1400; }
.btn-good { background: var(--good); color: #04220f; }
.btn-bad { background: var(--bad); color: #2a0010; }
.btn-ghost { background: transparent; border: 2px solid var(--panel-2); }
.btn-block { width: 100%; }
.btn-xl { padding: 26px; font-size: clamp(24px, 7vw, 40px); border-radius: 22px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ---------- Setup form ---------- */
.card { background: var(--panel); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
label.field { display: flex; flex-direction: column; gap: 8px; font-weight: 700; font-size: 16px; }
input[type=text], input[type=number] {
  font-family: inherit; font-size: 22px; font-weight: 700; padding: 14px;
  border-radius: 12px; border: 2px solid var(--panel-2); background: var(--bg); color: #fff;
}
input:focus { outline: none; border-color: var(--accent); }

.team-row { display: flex; align-items: center; gap: 10px; }
.team-row input[type=text] { flex: 1; min-width: 0; }

/* tappable team rows (open the editor popup) */
.team-cards { display: flex; flex-direction: column; gap: 10px; }
.team-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 14px;
  background: var(--panel-2); cursor: pointer; border-left: 6px solid var(--tcol, var(--panel-2));
  transition: transform .06s ease, filter .15s ease;
}
.team-card:active { transform: scale(0.99); filter: brightness(1.08); }
.team-color-dot.lg { width: 30px; height: 30px; }
.team-card-name { flex: 1; min-width: 0; font-weight: 900; font-size: 21px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-players-badge {
  flex: none; font-weight: 800; font-size: 16px; color: var(--muted);
  background: rgba(255,255,255,.06); padding: 6px 12px; border-radius: 999px;
}
.team-edit-ico { flex: none; font-size: 20px; color: var(--muted); }

/* big stepper used in the team-editor popup */
.big-stepper { display: flex; align-items: center; gap: 16px; }
.round-btn {
  width: 56px; height: 56px; border-radius: 50%; padding: 0; font-size: 30px; font-weight: 900;
  background: var(--panel-2); display: flex; align-items: center; justify-content: center; line-height: 1;
}
.big-count { min-width: 56px; text-align: center; font-weight: 900; font-size: 36px; font-variant-numeric: tabular-nums; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; flex: none;
}
.swatch.sel { border-color: #fff; transform: scale(1.12); }
.team-color-dot { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.icon-btn { flex: none; width: 52px; padding: 14px 0; }

/* stacked deck selectors */
.deck-list { display: flex; flex-direction: column; gap: 10px; }
.deck {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 14px;
  background: var(--panel-2); border: 2px solid transparent; cursor: pointer;
  transition: transform .06s ease, border-color .15s ease, background .15s ease;
}
.deck:active { transform: scale(0.99); }
.deck.sel { border-color: var(--accent); background: #2c2c12; }
.deck.nsfw.sel { border-color: var(--bad); background: #2c1018; }
.deck-emoji { font-size: 30px; flex: none; width: 38px; text-align: center; }
.deck-text { flex: 1; min-width: 0; }
.deck-name { font-weight: 900; font-size: 20px; }
.deck-desc { color: var(--muted); font-size: 14px; font-weight: 600; }
.deck-check {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-weight: 900; font-size: 18px; background: rgba(255,255,255,.06); color: #1a1400;
}
.deck.sel .deck-check { background: var(--accent); }
.deck.nsfw.sel .deck-check { background: var(--bad); color: #fff; }

/* top-right corner reset */
.corner-reset {
  position: absolute; top: calc(10px + var(--safe-top)); right: 12px; z-index: 5;
  width: 48px; height: 48px; padding: 0; border-radius: 50%;
  background: rgba(0,0,0,.22); color: var(--team-ink); font-size: 24px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid rgba(0,0,0,.18); backdrop-filter: blur(4px);
}

/* pretty modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(6,6,14,0); transition: background .18s ease;
}
.modal-overlay.in { background: rgba(6,6,14,.66); }
.modal-overlay.out { background: rgba(6,6,14,0); }
.modal-card {
  width: 100%; max-width: 420px; background: var(--panel); border-radius: 22px; padding: 24px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 24px 60px rgba(0,0,0,.5);
  max-height: calc(100dvh - 40px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateY(16px) scale(.96); opacity: 0; transition: transform .2s cubic-bezier(.2,.8,.2,1), opacity .2s ease;
}
.modal-overlay.in .modal-card { transform: translateY(0) scale(1); opacity: 1; }
.modal-msg { color: var(--muted); font-size: 17px; line-height: 1.45; font-weight: 600; }
.modal-actions { display: flex; gap: 12px; margin-top: 4px; }
.modal-actions button { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  padding: 12px 18px; border-radius: 999px; background: var(--panel-2); font-weight: 800;
  font-size: 17px; border: 2px solid transparent;
}
.chip.sel { background: var(--accent); color: #1a1400; }
.chip.nsfw.sel { background: var(--bad); color: #fff; }

.seg-label { font-weight: 700; font-size: 15px; color: var(--muted); margin-bottom: 8px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg .chip { flex: 1; text-align: center; min-width: 64px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- Handoff ---------- */
.handoff { background: var(--team); color: var(--team-ink); }
.handoff .sub, .handoff h1, .handoff h2 { color: var(--team-ink); }
.player-badge {
  font-weight: 900; font-size: clamp(20px, 6vw, 34px); padding: 8px 22px; border-radius: 999px;
  background: rgba(0,0,0,.22); color: var(--team-ink); margin-bottom: 4px;
}
.mini-scores { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 520px; }
.mini-score {
  display: flex; align-items: center; gap: 12px; background: rgba(0,0,0,.18);
  border-radius: 12px; padding: 10px 14px; font-weight: 800; font-size: 20px;
}
.mini-score .nm { flex: 1; text-align: left; }

/* ---------- Play screen ---------- */
.play { background: var(--team); color: var(--team-ink); padding: 0; }
.play .topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 18px 6px; font-weight: 900; font-size: 18px;
}
.timer {
  font-variant-numeric: tabular-nums; font-weight: 900; text-align: center;
  font-size: clamp(64px, 22vw, 200px); line-height: 1; letter-spacing: -3px;
}
.timer.low { color: var(--bad); animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.06); } }

.word-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 10px 20px; min-height: 0; }
.word {
  font-weight: 900; text-align: center; text-transform: uppercase;
  font-size: clamp(40px, 13vw, 130px); line-height: 1.02; letter-spacing: -1px;
  overflow-wrap: anywhere; word-break: break-word;
}
.word-count { font-weight: 800; opacity: .7; margin-top: 14px; font-size: 18px; }

.play-actions { display: flex; gap: 12px; padding: 12px 14px calc(16px + var(--safe-bottom)); }
.play-actions button { flex: 1; }
.skip-note { font-size: 14px; opacity: .8; font-weight: 800; }

/* landscape: timer left, word right */
@media (orientation: landscape) and (max-height: 560px) {
  .play .topbar { padding-top: calc(6px + var(--safe-top)); }
  .play-body { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 0; }
  .timer { flex: 0 0 38%; font-size: clamp(56px, 18vh, 160px); }
  .word-wrap { flex: 1; }
}

/* ---------- Review ---------- */
.review-list { display: flex; flex-direction: column; gap: 8px; }
.review-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--panel); font-weight: 800; font-size: 19px;
}
.review-item .w { flex: 1; text-align: left; overflow-wrap: anywhere; }
.review-item .toggle {
  padding: 8px 14px; border-radius: 999px; font-size: 15px; font-weight: 900; min-width: 92px;
}
.review-item.got .toggle { background: var(--good); color: #04220f; }
.review-item.miss .toggle { background: var(--panel-2); color: var(--muted); }
.tally { display: flex; gap: 16px; justify-content: center; font-weight: 900; font-size: 22px; }
.tally .g { color: var(--good); }
.tally .m { color: var(--muted); }

/* ---------- Scoreboard ---------- */
.board { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 560px; }
.board-row {
  display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: 16px;
  background: var(--panel); font-weight: 900; font-size: 26px;
}
.board-row .rank { width: 40px; font-size: 30px; color: var(--muted); }
.board-row .nm { flex: 1; text-align: left; }
.board-row .pts { font-variant-numeric: tabular-nums; }
.board-row.win { background: var(--accent); color: #1a1400; transform: scale(1.03); }
.board-row.win .rank { color: #1a1400; }
.crown { font-size: 30px; }

/* ---------- Flash overlay ---------- */
.flash {
  position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 50;
  background: var(--bad);
}
.flash.go { animation: flashseq 1.4s ease-out; }
@keyframes flashseq {
  0%,18%,36% { opacity: .92; }
  9%,27%,45% { opacity: 0; }
  100% { opacity: 0; }
}

/* small penalty flash on the play screen */
.penalty-pop {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%);
  font-size: clamp(28px, 9vw, 64px); font-weight: 900; color: var(--bad);
  text-shadow: 0 2px 12px rgba(0,0,0,.4); pointer-events: none;
  animation: pop 1s ease-out forwards;
}
@keyframes pop {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px) scale(.6); }
  20% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(1); }
}

/* confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.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); opacity: .9; }
}

.spacer { flex: 1; }
.footer-note { color: var(--muted); font-size: 13px; text-align: center; }
.countdown {
  font-size: clamp(120px, 40vw, 360px); font-weight: 900; line-height: 1;
  animation: cdpop .9s ease-out;
}
@keyframes cdpop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.muteline { display:flex; align-items:center; justify-content:center; gap:8px; }
