:root {
  --bg: #10132a;
  --panel: #1b2048;
  --panel-2: #242b5e;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f4f3ff;
  --muted: #a9acd6;
  --accent: #ffc845;
  --accent-ink: #2a1d00;
  --accent-shadow: #c48f00;
  --good: #2fd27a;
  --bad: #ff4d6d;
  --card: #fffdf7;
  --font-display: 'Fredoka', system-ui, sans-serif;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  /* Motion: strong custom curves; the built-in keywords feel limp. */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(1200px 800px at 15% -10%, #2b2f73 0%, transparent 60%),
    radial-gradient(900px 700px at 110% 110%, #3a1f5c 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
html { -webkit-text-size-adjust: 100%; }

/* Touch: no double-tap zoom, no grey tap flash, no long-press menus/selection while playing. */
button, a, input, .card, .tab, .emote-btn, .logo-card { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#screen-game, #screen-tutorial, .hero-cards {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
/* On touch screens you tap a card to call SET, so the SET! button isn't needed. */
.only-touch { display: none; }
@media (pointer: coarse) {
  #set-btn, .only-mouse { display: none; }
  .only-touch { display: inline; }
}
[hidden] { display: none !important; }
.hidden { display: none !important; }

kbd {
  font-family: var(--font);
  font-weight: 800;
  font-size: 0.85em;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

/* ---------- Buttons & inputs ---------- */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, filter 150ms ease;
}
@media (hover: hover) { .btn:hover { background: rgba(255, 255, 255, 0.14); } }
.btn:active, .icon-btn:active, .chip:active, .tab:active, .emote-btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
@media (hover: hover) { .btn.primary:hover { background: var(--accent); filter: brightness(1.06); } }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  width: 40px; height: 40px;
  border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 18px;
  display: grid; place-items: center;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}
@media (hover: hover) { .icon-btn:hover { background: rgba(255, 255, 255, 0.15); } }

input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  font-weight: 700;
  min-width: 0;
}
input::placeholder { color: rgba(255, 255, 255, 0.35); }

/* ---------- Screens ---------- */
.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; }

/* ---------- Home ---------- */
#screen-home { justify-content: center; position: relative; }
.home-corner {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 2;
}
.corner-install { background: rgba(255, 200, 69, 0.14); color: var(--accent); border: 1px solid rgba(255, 200, 69, 0.35); }
@media (hover: hover) { .corner-install:hover { background: rgba(255, 200, 69, 0.24); } }
@media (max-width: 640px) {
  .home-corner { top: 10px; right: 10px; }
  #screen-home .home { padding-top: 60px; gap: 22px; }
  .daily-card { padding: 18px; }
  .daily-card > .btn { flex: 1 1 100%; }
  .daily-info h2 { font-size: 24px; }
  .tagline { font-size: 16px; }
}
.home {
  width: min(1100px, 100%);
  padding: 32px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.hero { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* The logo: one letter per card. */
.logo-cards, .hero-cards { display: flex; justify-content: center; gap: clamp(10px, 2vw, 18px); }
.logo-card {
  --card-w: clamp(84px, 15vw, 128px);
  width: var(--card-w);
  aspect-ratio: 2 / 3;
  background: var(--card);
  border-radius: calc(var(--card-w) * 0.08);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15), 0 14px 34px rgba(0, 0, 0, 0.35);
  display: flex;
}
.logo-card svg { width: 100%; height: 100%; display: block; }
.logo-card:nth-child(1) { transform: rotate(-8deg); }
.logo-card:nth-child(2) { transform: translateY(-6px); }
.logo-card:nth-child(3) { transform: rotate(8deg); }
.hero-cards { margin: 8px 0 22px; }
.hero-cards .logo-card { animation: float 4s ease-in-out infinite; }
.hero-cards .logo-card:nth-child(1) { animation-delay: -1s; }
.hero-cards .logo-card:nth-child(3) { animation-delay: -2s; }
@keyframes float { 50% { translate: 0 -8px; } }

.tagline { color: var(--muted); font-size: 18px; line-height: 1.6; margin: 8px 0 0; }
.tagline em { color: var(--text); font-style: normal; font-weight: 800; }

.name-row { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.name-row label { color: var(--muted); font-weight: 700; }
.name-row input { width: 200px; }

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.mode {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-top: 4px solid var(--mode-color);
  border-radius: 20px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mode p { margin: 0; color: var(--muted); line-height: 1.5; flex-grow: 0; }
.mode > p:first-of-type { flex-grow: 1; }
.mode-chill { --mode-color: #3ddc97; }
.mode-bot { --mode-color: #ff8a3d; }
.mode-online { --mode-color: #8f6bff; }
.mode-head { display: flex; flex-direction: column; gap: 4px; }
.mode-head h2 { margin: 0; font-family: var(--font-display); font-size: 30px; font-weight: 600; }
.mode-tag { color: var(--mode-color); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; }
.mode-meta { font-size: 14px; }
.mode-meta strong { color: var(--text); }
.goal-picker { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.goal-label { color: var(--muted); font-size: 13px; font-weight: 800; margin-right: 2px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
.chip.active { background: rgba(255, 138, 61, 0.2); border-color: rgba(255, 138, 61, 0.6); color: var(--text); }
.level-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.level-picker .btn { padding: 12px 4px; min-width: 0; }
.level[data-level='easy'] { background: rgba(47, 210, 122, 0.18); }
.level[data-level='medium'] { background: rgba(255, 200, 69, 0.2); }
.level[data-level='hard'] { background: rgba(255, 77, 109, 0.22); }
@media (hover: hover) { .level:hover { filter: brightness(1.3); } }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.35em; text-align: center; }

.rules {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 20px;
}
.rules summary { cursor: pointer; font-weight: 800; }
.rules-body { color: var(--muted); line-height: 1.6; }
.rules-body b, .rules-body i { color: var(--text); }
.rules-body h3 { color: var(--text); font-family: var(--font-display); font-weight: 600; margin: 18px 0 6px; }
.rules-body ul { padding-left: 20px; margin: 0; }

/* ---------- About / FAQ / footer (home) ---------- */
.about { color: var(--muted); line-height: 1.6; }
.about h2 { color: var(--text); font-family: var(--font-display); font-weight: 600; font-size: 24px; margin: 8px 0 8px; }
.about h3 { color: var(--text); font-family: var(--font-display); font-weight: 600; font-size: 19px; margin: 22px 0 8px; }
.about b { color: var(--text); }
.about-list { padding-left: 20px; margin: 10px 0 0; }
.about-list li { margin-bottom: 4px; }
.faq { border-top: 1px solid var(--line); padding: 10px 2px; }
.faq:last-of-type { border-bottom: 1px solid var(--line); }
.faq summary { color: var(--text); font-weight: 800; cursor: pointer; }
.faq p { margin: 8px 0 2px; }
.site-footer { color: rgba(169, 172, 214, 0.7); font-size: 12px; text-align: center; line-height: 1.5; padding-top: 4px; }
.site-footer p { margin: 0 auto; max-width: 640px; }

/* ---------- Panels / lobby ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  width: min(480px, 100%);
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
}
.row { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.row .btn { flex: 1; }
#screen-lobby { align-items: center; justify-content: center; padding: 16px; }
.eyebrow { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: 0.15em; font-size: 12px; font-weight: 800; }
.room-code { font-family: var(--font-display); font-weight: 700; font-size: 72px; letter-spacing: 0.2em; color: var(--accent); margin: 4px 0 10px; }
.lobby h3 { text-align: left; font-family: var(--font-display); font-weight: 600; margin: 24px 0 10px; }
.lobby-players { list-style: none; margin: 0; padding: 0; text-align: left; }
.lobby-players li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  font-weight: 700;
}
.lobby-players em { color: var(--muted); font-style: normal; font-weight: 600; }
.badge { margin-left: auto; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; background: rgba(255, 200, 69, 0.18); color: var(--accent); padding: 3px 8px; border-radius: 99px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--pc); flex: none; }
.lobby-hint { color: var(--muted); min-height: 1.5em; }

/* ---------- Game ---------- */
#screen-game.active { flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 6px;
}
.mode-title { font-weight: 800; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock { font-family: var(--font-display); font-weight: 600; font-size: 30px; font-variant-numeric: tabular-nums; }
.clock.low { color: var(--bad); animation: pulse 1s ease-in-out infinite; }
.topbar-right { display: flex; gap: 12px; align-items: center; justify-content: flex-end; }
.deck-info { color: var(--muted); font-weight: 700; font-size: 14px; white-space: nowrap; }

.scoreboard { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 4px 16px 6px; }
.player {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.player.you { background: rgba(255, 255, 255, 0.1); }
.player.calling { border-color: var(--pc); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc) 30%, transparent); }
.pname { font-weight: 800; max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pscore { font-family: var(--font-display); font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.psets { color: var(--muted); font-size: 13px; font-weight: 700; }

.board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  --cc: var(--accent);
}
.board {
  --card-w: 160px;
  --gap: 14px;
  display: grid;
  gap: var(--gap);
  grid-auto-flow: column;
  grid-template-rows: repeat(var(--rows, 3), auto);
  grid-auto-columns: var(--card-w);
  padding: 12px;
  border-radius: 24px;
  transition: box-shadow 0.2s;
}
.board.rowflow { grid-auto-flow: row; grid-template-rows: none; grid-template-columns: repeat(var(--cols, 3), var(--card-w)); }
.board-wrap.calling .board {
  box-shadow: 0 0 0 3px var(--cc), 0 0 50px color-mix(in srgb, var(--cc) 35%, transparent);
}

.card {
  --sel: transparent;
  position: relative;
  width: var(--card-w);
  aspect-ratio: 3 / 2;
  background: var(--card);
  border-radius: calc(var(--card-w) * 0.08);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15), 0 8px 20px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.card svg { width: 100%; height: 100%; display: block; }
body[data-cards='horizontal'] .card { aspect-ratio: 2 / 3; }
/* Phones: game cards a bit less elongated so they can be bigger (same query as phoneQuery in main.js). */
@media (pointer: coarse), (max-width: 640px), (max-height: 500px) {
  body[data-cards='horizontal'] .board .card { aspect-ratio: 82 / 109; }
  body[data-cards='vertical'] .board .card { aspect-ratio: 110 / 82; }
}
@media (hover: hover) and (pointer: fine) { .board .card:hover { transform: translateY(-2px); } }
/* Press feedback: the card gives a little under the finger/cursor. */
.board .card:not(.selected):active, .tut-board .tut-card:not(.selected):active { transform: scale(0.97); }
.card .key {
  position: absolute;
  top: 6%; left: 5%;
  font: 800 max(10px, calc(var(--card-w) * 0.075)) / 1 var(--font);
  color: #8f8cab;
  background: #f0eee6;
  border-radius: 5px;
  padding: 3px 5px;
}
.board:not(.keyed) .key { display: none; }
@media (pointer: coarse) { .card .key { display: none; } }

.card.selected {
  transform: translateY(-6px) scale(1.04);
  box-shadow: 0 0 0 max(3px, calc(var(--card-w) * 0.03)) var(--sel), 0 14px 30px rgba(0, 0, 0, 0.35);
}
@media (hover: hover) and (pointer: fine) { .board .card.selected:hover { transform: translateY(-6px) scale(1.04); } }
.card.hinted { animation: hintPulse 1.2s ease-in-out infinite; }
.card.good { animation: good 0.6s var(--ease-out) forwards; box-shadow: 0 0 0 5px var(--good), 0 0 40px rgba(47, 210, 122, 0.7); }
/* The whole wrong pick shakes; only the card(s) that break it turn red (.odd, below). */
.card.bad { animation: shake 0.45s ease; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.55); }
/* Dealt many times a game, so short and calm: a small drop-in, no overshoot. (DEAL_MS in main.js.) */
.card.deal { animation: deal 320ms var(--ease-out) both; }

@keyframes deal { from { opacity: 0; transform: translateY(-14px) scale(0.92) rotate(-3deg); } }
@keyframes good {
  0% { transform: scale(1.04); }
  40% { transform: scale(1.12); }
  100% { transform: scale(0.6) translateY(-30px); opacity: 0; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px) rotate(-2deg); }
  40% { transform: translateX(9px) rotate(2deg); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}
@keyframes hintPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent), 0 0 10px rgba(255, 200, 69, 0.4); }
  50% { box-shadow: 0 0 0 5px var(--accent), 0 0 34px rgba(255, 200, 69, 0.8); }
}
@keyframes pulse { 50% { opacity: 0.55; } }

.burst {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(32px, 6vw, 60px);
  white-space: nowrap;
  opacity: 0;
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
}
.burst.show { animation: burst 1.1s ease forwards; }
.burst.good { color: var(--good); }
.burst.bad { color: var(--bad); }
.burst.other { color: var(--text); }
@keyframes burst {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  35% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

.action-bar { padding: 6px 16px calc(14px + env(safe-area-inset-bottom)); }
.call-timer { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin-bottom: 10px; }
.call-bar { height: 100%; width: 100%; transform-origin: left; transform: scaleX(0); background: var(--accent); }
.action-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.side-left { display: flex; gap: 12px; align-items: center; }
.side-right { justify-self: end; }
.sets-info { color: var(--muted); font-weight: 700; font-size: 14px; }
.prompt { font-family: var(--font-display); font-weight: 600; font-size: 22px; text-align: center; white-space: nowrap; }
.prompt.mine { color: var(--accent); animation: pulse 0.7s ease-in-out infinite; }
.prompt.other { color: var(--cc, var(--text)); }
.prompt.locked { color: var(--bad); }

.set-btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.06em;
  padding: 12px 30px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 0 var(--accent-shadow);
}
@media (hover: hover) { .set-btn:hover { background: var(--accent); filter: brightness(1.06); } }
.set-btn { transition: transform 100ms var(--ease-out), box-shadow 100ms var(--ease-out), filter 150ms ease; }
.set-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-shadow); }
.set-btn:disabled { box-shadow: 0 6px 0 var(--accent-shadow); }

.countdown {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(100px, 22vw, 200px);
  color: var(--accent);
  background: rgba(10, 12, 30, 0.45);
  pointer-events: none;
  z-index: 20;
  text-shadow: 0 10px 60px rgba(0, 0, 0, 0.6);
}
.countdown.pop { animation: pop 0.5s ease; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } }

/* Countdown mode, last seconds: red pulse around the screen edge (faster when critical). */
/* Drawn behind the game content (cards stay white) and sized relative to the screen, so it looks
   the same on a phone as on a big monitor. A gradient is also cheaper to animate on phones than a
   big blurred box-shadow. */
#screen-game > * { position: relative; z-index: 1; }
#screen-game > .countdown, #screen-game > .splash, #screen-game > .flash, #screen-game > .overlay { position: fixed; }
#screen-game > .countdown { z-index: 20; }
#screen-game > .splash { z-index: 21; }
#screen-game > .flash { z-index: 5; }
#screen-game > .overlay { z-index: 40; }
#screen-game::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  background: radial-gradient(ellipse 75% 70% at 50% 50%, transparent 55%, rgba(255, 50, 80, 0.35) 80%, rgba(255, 40, 70, 0.7) 100%);
}
#screen-game.danger::after { animation: dangerPulse 1s ease-out infinite; }
#screen-game.critical::after { animation-duration: 0.5s; }
@keyframes dangerPulse { 0% { opacity: 0.9; } 100% { opacity: 0.15; } }

/* "Find the SET!" splash after the 3-2-1 countdown */
.splash {
  position: fixed;
  inset: 0;
  z-index: 21;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, rgba(40, 44, 110, 0.7), rgba(10, 12, 30, 0.75));
}
.splash .logo-card { --card-w: clamp(96px, 16vw, 170px); }
.splash.in .logo-card:nth-child(1) { animation: flyLeft 0.6s cubic-bezier(0.2, 1.25, 0.35, 1) both; }
.splash.in .logo-card:nth-child(2) { animation: flyUp 0.6s 0.09s cubic-bezier(0.2, 1.25, 0.35, 1) both; }
.splash.in .logo-card:nth-child(3) { animation: flyRight 0.6s 0.18s cubic-bezier(0.2, 1.25, 0.35, 1) both; }
.splash-text {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(30px, 5vw, 52px);
  color: var(--text);
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.5);
}
.splash.in .splash-text { animation: rise 0.45s 0.35s ease-out both; }
.splash.out { animation: splashOut 0.3s var(--ease-out) forwards; }
@keyframes flyLeft { from { opacity: 0; transform: translateX(-70vw) rotate(-50deg); } to { transform: rotate(-8deg); } }
@keyframes flyUp { from { opacity: 0; transform: translateY(60vh) scale(0.6); } to { transform: translateY(-6px); } }
@keyframes flyRight { from { opacity: 0; transform: translateX(70vw) rotate(50deg); } to { transform: rotate(8deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(0.9); } }
@keyframes splashOut { to { opacity: 0; transform: scale(1.08); } }

.flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 5; }
.flash.good { background: radial-gradient(circle at 50% 50%, transparent 40%, rgba(47, 210, 122, 0.35)); animation: flash 0.6s ease; }
.flash.bad { background: radial-gradient(circle at 50% 50%, transparent 40%, rgba(255, 77, 109, 0.35)); animation: flash 0.6s ease; }
@keyframes flash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }

.float-points {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  transform: translate(-50%, -50%);
  animation: floatUp 1.2s ease-out forwards;
}
.float-points.plus { color: var(--good); }
.float-points.minus { color: var(--bad); }
@keyframes floatUp { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -260%); } }

.overlay {
  position: fixed; inset: 0;
  z-index: 40;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(8, 10, 25, 0.72);
  backdrop-filter: blur(6px);
}
.overlay:not(.hidden) { animation: fadeIn 200ms ease-out; }
.results { animation: modalIn 240ms var(--ease-out); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.96) translateY(8px); } }
.results h2 { font-family: var(--font-display); font-weight: 700; font-size: 40px; margin: 0; }
.results-sub { color: var(--muted); margin: 8px 0 18px; }
.results-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.results-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 800; padding: 6px; }
.results-table td { padding: 10px 6px; border-top: 1px solid var(--line); font-weight: 700; }
.results-table td:nth-child(2) { text-align: left; }
.results-table .you td { color: var(--accent); }
.results-table .big { font-family: var(--font-display); font-size: 22px; }

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translate(-50%, 20px);
  background: #fff;
  color: #14162b;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 260ms var(--ease-out);
  z-index: 60;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Daily challenge ---------- */
.tutorial-btn { margin: 14px 0 4px; }
.daily-card {
  --mode-color: #ffc845;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: 22px 24px;
  border-radius: 20px;
  border: 1px solid rgba(255, 200, 69, 0.35);
  background:
    radial-gradient(600px 200px at 0% 0%, rgba(255, 200, 69, 0.18), transparent 70%),
    linear-gradient(180deg, var(--panel-2), var(--panel));
}
.daily-info { display: flex; flex-direction: column; gap: 6px; flex: 1 1 320px; }
.daily-info h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 28px; }
.daily-info p { margin: 0; color: var(--muted); line-height: 1.5; }
.daily-card > .btn { padding: 14px 22px; font-size: 17px; }
.lb-caption { margin: -4px 0 10px; color: var(--muted); font-size: 13px; font-weight: 700; }

/* ---------- Tutorial ---------- */
#screen-tutorial.active { justify-content: center; align-items: flex-start; padding: 24px 16px; }
.tutorial {
  width: min(860px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 20px 26px 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
}
.tut-top { display: flex; align-items: center; gap: 14px; }
.tut-progress { display: flex; gap: 6px; flex: 1; }
.tut-progress span { flex: 1; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); transition: background 0.3s; }
.tut-progress span.done { background: var(--accent); }
.tutorial h2 { font-family: var(--font-display); font-weight: 600; font-size: 32px; margin: 18px 0 6px; }
.tut-text { color: var(--muted); font-size: 17px; line-height: 1.6; margin: 0 0 18px; }
.tut-text b { color: var(--text); }
.tut-stage { min-height: 220px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.tut-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.tut-card { --card-w: 96px; cursor: default; }
body[data-cards='vertical'] .tut-card { --card-w: 130px; }
.tut-board { --sel: var(--accent); display: grid; grid-template-columns: repeat(3, auto); gap: 12px; padding: 12px; border-radius: 20px; transition: box-shadow 0.2s; }
.tut-board .tut-card { --card-w: 84px; --sel: var(--accent); cursor: pointer; }
body[data-cards='vertical'] .tut-board .tut-card { --card-w: 120px; }
.tut-stage.calling .tut-board { box-shadow: 0 0 0 3px var(--accent), 0 0 40px rgba(255, 200, 69, 0.35); }
.tut-features { display: grid; grid-template-columns: auto repeat(3, auto); gap: 10px 18px; align-items: center; }
.tut-feature-label { font-weight: 800; text-align: right; }
.tut-features figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tut-features .tut-card { --card-w: 56px; }
body[data-cards='vertical'] .tut-features .tut-card { --card-w: 84px; }
.tut-features figcaption { color: var(--muted); font-size: 13px; font-weight: 700; }
.tut-table { border-collapse: collapse; width: 100%; max-width: 620px; font-size: 15px; }
.tut-table th, .tut-table td { padding: 8px 10px; text-align: left; border-top: 1px solid var(--line); }
.tut-table thead th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; border-top: 0; }
.tut-table tr.broken td, .tut-table tr.broken th { background: rgba(255, 77, 109, 0.12); }
.tut-table .ok { color: var(--good); font-weight: 800; }
.tut-table .ko { color: var(--bad); font-weight: 800; }
.tut-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.tut-feedback { min-height: 1.6em; margin: 16px 0 0; text-align: center; font-weight: 800; }
.tut-feedback.good { color: var(--good); }
.tut-feedback.bad { color: var(--bad); }
.tut-feedback.info { color: var(--accent); }
.tut-list { margin: 0; padding-left: 22px; line-height: 2; font-size: 17px; align-self: stretch; }
.tut-final { display: grid; gap: 10px; width: min(380px, 100%); }
@media (max-width: 640px) {
  .tutorial { padding: 16px; }
  .tutorial h2 { font-size: 26px; }
  .emote-row { gap: 4px; }
  .emote-btn { width: 32px; height: 32px; font-size: 18px; border-radius: 10px; }
  .panel { padding: 22px 16px; }
  .results h2 { font-size: 30px; }
  #screen-tutorial.active { padding: 10px 8px; }
  .tut-text { font-size: 15px; margin-bottom: 12px; }
  .tut-row { gap: 10px; flex-wrap: nowrap; }
  .tut-card, body[data-cards='vertical'] .tut-card { --card-w: 78px; }
  body[data-cards='vertical'] .tut-card { --card-w: 96px; }
  .tut-board { gap: 8px; padding: 8px; }
  .tut-board .tut-card { --card-w: 70px; }
  body[data-cards='vertical'] .tut-board .tut-card { --card-w: 92px; }
  .tut-features { gap: 8px 10px; }
  .tut-features .tut-card { --card-w: 44px; }
  body[data-cards='vertical'] .tut-features .tut-card { --card-w: 62px; }
  .tut-feature-label { font-size: 13px; }
  .tut-table { font-size: 13px; }
  .tut-table th, .tut-table td { padding: 6px 4px; }
  .tut-table thead th { white-space: nowrap; letter-spacing: 0; font-size: 11px; }
  .tut-list { font-size: 15px; line-height: 1.8; }
}

/* ---------- Countdown mode ---------- */
.mode-countdown { --mode-color: #ff5a76; }

/* ---------- Leaderboard ---------- */
.leaderboard {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 20px;
}
.lb-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.lb-head h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 24px; }
.tabs { display: flex; gap: 4px; background: rgba(255, 255, 255, 0.06); padding: 4px; border-radius: 12px; }
.tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font-weight: 800; cursor: pointer; color: var(--muted); transition: transform 160ms var(--ease-out), background-color 150ms ease, color 150ms ease; }
.tab.active { background: var(--panel-2); color: var(--text); }
.lb-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.lb-list li {
  display: grid;
  grid-template-columns: 2.4em 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.lb-list li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.lb-list li.mine { background: rgba(255, 200, 69, 0.14); outline: 1px solid rgba(255, 200, 69, 0.4); }
.lb-list .rank { color: var(--muted); font-weight: 800; text-align: right; }
.lb-list li:nth-child(1) .rank { color: #ffd34d; }
.lb-list li:nth-child(2) .rank { color: #d6dcef; }
.lb-list li:nth-child(3) .rank { color: #e0a170; }
.lb-list .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .meta { color: var(--muted); font-size: 13px; font-weight: 700; }
.lb-list .score { font-family: var(--font-display); font-weight: 600; font-size: 20px; min-width: 3.5ch; text-align: right; }
.lb-list .empty { display: block; color: var(--muted); text-align: center; padding: 16px; background: none; }
.lb-list.compact { max-height: 210px; text-align: left; }
.lb-list.compact li { padding: 5px 8px; }
.lb-list.compact .score { font-size: 17px; }
.lb-result { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.lb-status { margin: 0 0 10px; font-weight: 800; }
/* ---------- Wrong set: the card that breaks it lights up red ---------- */
.card.odd { box-shadow: 0 0 0 5px var(--bad), 0 0 40px rgba(255, 77, 109, 0.85); }
.card.missed { animation: oddGlow 0.8s ease-in-out infinite; }
.card.missed::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 77, 109, 0.12);
  pointer-events: none;
}
@keyframes oddGlow {
  0%, 100% { box-shadow: 0 0 0 4px var(--bad), 0 0 16px rgba(255, 77, 109, 0.45); }
  50% { box-shadow: 0 0 0 6px var(--bad), 0 0 42px rgba(255, 77, 109, 0.9); }
}

/* ---------- Emotes ---------- */
.emote-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.emote-row:empty { display: none; }
.emote-btn {
  border: 0;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 22px;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}
@media (hover: hover) and (pointer: fine) { .emote-btn:hover { background: rgba(255, 255, 255, 0.16); transform: scale(1.12); } }
.emote-picker { position: relative; }
.emote-row.pop {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  margin: 0;
  flex-wrap: nowrap;
  padding: 6px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 10;
  /* Grows out of the 😀 button below it. */
  transform-origin: bottom left;
  transition: opacity 150ms ease-out, transform 180ms var(--ease-out);
  @starting-style { opacity: 0; transform: translateY(4px) scale(0.95); }
}
.emote-bubble {
  position: fixed;
  z-index: 70;
  font-size: 40px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: emoteUp 1.8s ease-out forwards;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
}
.emote-bubble.down { animation-name: emoteDown; }
@keyframes emoteDown {
  0% { opacity: 0; transform: translate(-50%, -60%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%, 10%) scale(1.25); }
  30% { transform: translate(-50%, 20%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, 110%) scale(1); }
}
@keyframes emoteUp {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%, -90%) scale(1.25); }
  30% { transform: translate(-50%, -110%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -230%) scale(1); }
}

@media (max-width: 640px) {
  .lb-list .meta { display: none; }
  .lb-list li { grid-template-columns: 2.2em 1fr auto; }
  .topbar { grid-template-columns: auto 1fr auto; }
  .mode-title { display: none; }
  .clock { font-size: 24px; justify-self: center; }
  .action-row { grid-template-columns: 1fr auto; }
  .prompt { grid-column: 1 / -1; order: -1; }
  .pscore { font-size: 19px; }
  .player { padding: 4px 10px; gap: 7px; }
  .psets { display: none; }
  .pname { max-width: 9ch; font-size: 14px; }
  .scoreboard { gap: 6px; flex-wrap: nowrap; padding: 0 8px 2px; }
  .room-code { font-size: 56px; }

  /* Game on a phone held upright: slim bars so the cards get as much height as possible. */
  .topbar { padding: 6px 8px 2px; gap: 8px; }
  #screen-game .icon-btn { width: 34px; height: 34px; font-size: 16px; }
  .clock { font-size: 22px; }
  .deck-info { font-size: 12px; }
  .board-wrap { padding: 2px 4px; }
  .board { padding: 4px; }
  .action-bar { padding: 2px 10px calc(6px + env(safe-area-inset-bottom)); }
  .call-timer { height: 5px; margin-bottom: 4px; }
  .prompt { font-size: 15px; }
}

/* Phone held sideways: very little height, so slim header/footer and give the cards the room. */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { padding: 4px 12px 0; gap: 8px; grid-template-columns: auto 1fr auto; }
  .mode-title, .deck-info { display: none; }
  .clock { font-size: 22px; justify-self: center; }
  .icon-btn { width: 34px; height: 34px; }
  .scoreboard { padding: 0 12px 2px; gap: 6px; flex-wrap: nowrap; }
  .player { padding: 2px 10px; gap: 6px; }
  .psets { display: none; }
  .pscore { font-size: 17px; }
  .pname { font-size: 13px; }
  .board-wrap { padding: 2px 8px; }
  .board { padding: 6px; }
  .action-bar { padding: 2px 12px calc(6px + env(safe-area-inset-bottom)); }
  .call-timer { height: 5px; margin-bottom: 4px; }
  .action-row { grid-template-columns: 1fr auto 1fr; }
  .prompt { font-size: 16px; grid-column: auto; order: 0; }
  .set-btn { font-size: 16px; padding: 6px 18px; }
  .countdown { font-size: 90px; }
  .splash .logo-card { --card-w: clamp(64px, 10vw, 110px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  /* Reduced motion is not no motion: keep the fades that explain what happened, drop the movement. */
  .card.deal { animation: fadeIn 200ms ease-out both !important; }
  .card.good { animation: fadeOut 400ms ease forwards !important; }
  .overlay:not(.hidden), .results { animation: fadeIn 200ms ease-out !important; }
  .flash.good, .flash.bad { animation-duration: 0.6s !important; }
}
@keyframes fadeOut { to { opacity: 0; } }
