/* ============================================================
   UNO — visual system
   Palette: official-UNO primaries on a casino-felt table.
   Display type: Baloo 2 (chunky, rounded) for the wordmark and
   the card numerals — the single most recognizable UNO trait.
   ============================================================ */

:root {
  --uno-red: #E4322B;
  --uno-yellow: #F7C600;
  --uno-green: #17A34A;
  --uno-blue: #1666C6;
  --card-black: #17171C;

  --felt-hi: #14624B;
  --felt-lo: #062219;
  --gold: #F2C14E;
  --paper: #FBFBF7;
  --ink: #131316;
  --txt: #F3F6F4;
  --muted: #D5E6DE; /* lightened for AA contrast on the felt background */

  --font-display: 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --card-w: 76px;
  --card-h: 114px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--txt);
  background:
    radial-gradient(ellipse 120% 90% at 50% 32%, var(--felt-hi), var(--felt-lo) 78%);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh; /* account for dynamic browser bars on mobile */
}

/* overflow-x: clip absorbs transient horizontal spill (speech bubbles at edge
   seats, the active-player scale-up) without creating a scroll container, so
   the page never gains a sideways "margin". Fixed-position layers (toast,
   flying cards) are unaffected. */
#app { min-height: 100vh; min-height: 100dvh; overflow-x: clip; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen[hidden] { display: none; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  padding: 0.7rem 1.6rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.btn--primary {
  background: var(--uno-red);
  color: #fff;
  box-shadow: 0 6px 0 #9e211c, 0 10px 20px rgba(0,0,0,0.35);
}
.btn--primary:hover { background: #ef3b34; }
.btn--primary:active { box-shadow: 0 3px 0 #9e211c, 0 6px 12px rgba(0,0,0,0.35); }

.btn--ghost {
  background: rgba(255,255,255,0.1);
  color: var(--txt);
  border: 2px solid rgba(255,255,255,0.35);
  padding: 0.5rem 1.2rem;
  font-size: 0.95rem;
}
.btn--ghost:hover { background: rgba(255,255,255,0.2); }

/* ============================================================
   START SCREEN
   ============================================================ */
#start-screen { align-items: center; justify-content: center; padding: 2rem; }

.start {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  max-width: 420px;
  width: 100%;
  animation: fade-up 0.5s ease both;
}

/* The UNO logo — the iconic tilted red oval wordmark */
.logo {
  position: relative;
  display: grid;
  place-items: center;
  width: 260px;
  height: 150px;
  margin-bottom: 0.3rem;
}
.logo::before {
  content: "";
  position: absolute;
  inset: 8% 0;
  background: var(--uno-red);
  border-radius: 50%;
  transform: rotate(-11deg);
  box-shadow: 0 14px 34px rgba(0,0,0,0.4), inset 0 0 0 6px #fff;
}
.logo__word {
  position: relative;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 5.2rem;
  color: #fff;
  transform: rotate(-11deg);
  letter-spacing: 0.02em;
  text-shadow: 3px 4px 0 rgba(0,0,0,0.28);
}

.start__tag {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  text-align: center;
}

.start__form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  width: 100%;
  align-items: stretch;
  margin-top: 0.6rem;
}
.start__label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  text-align: center;
}
.start__input {
  font-family: var(--font-body);
  font-size: 1.1rem;
  text-align: center;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.95);
  color: var(--ink);
}
.start__input:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.start__form .btn { align-self: center; margin-top: 0.3rem; }

/* ============================================================
   GAME SCREEN
   ============================================================ */
/* Side/bottom padding respects notch safe areas (viewport-fit=cover). */
#game-screen {
  padding: 0.75rem
    max(clamp(0.5rem, 3vw, 2rem), env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(clamp(0.5rem, 3vw, 2rem), env(safe-area-inset-left));
  gap: 0.5rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; /* narrow screens: buttons drop to a second row, never overflow */
  row-gap: 0.3rem;
  padding: 0.35rem 0.25rem 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.brand__mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  color: #fff;
  background: var(--uno-red);
  padding: 0.12rem 0.7rem;
  border-radius: 8px;
  transform: rotate(-4deg);
  display: inline-block;
  box-shadow: inset 0 0 0 3px #fff, 0 4px 10px rgba(0,0,0,0.3);
}
.score {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.score__side { display: inline-flex; align-items: baseline; gap: 0.35rem; }
.score__side b { font-size: 1.3rem; color: var(--gold); }
.score__dash { color: var(--muted); }
.score__name { color: var(--txt); }

/* ---------- Zones (hands) ---------- */
.zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.zone--cpu { padding-top: 0.4rem; }
.zone--player { margin-top: auto; padding-top: 0.4rem; }

.zone__label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.zone--player .zone__label { color: var(--gold); }

.count-badge {
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--txt);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.85rem;
  min-width: 1.5rem;
  text-align: center;
}

.fan {
  display: flex;
  justify-content: center;
  padding: 22px 0 6px;
  min-height: calc(var(--card-h) + 28px);
  flex-wrap: nowrap;
}
.fan .card { flex: 0 0 auto; }
.fan .card:not(:first-child) { margin-left: calc(var(--card-w) * -0.42); }

/* Player hand: overlap is set dynamically (JS) so large hands never overflow
   the viewport. Falls back to a scrollable strip for extreme card counts. */
/* Full-width so the hand box tracks the viewport instead of shrink-wrapping to
   its cards — that keeps fitHand's width measurement honest and lets the scroll
   fallback actually scroll rather than push the page wider. */
.fan--player { --overlap: -0.42; padding-top: 32px; padding-bottom: 12px; width: 100%; max-width: 100%; }
.fan--player .card:not(:first-child) { margin-left: calc(var(--card-w) * var(--overlap)); }
.fan--scroll {
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  /* extra vertical padding: this box clips (overflow-y hidden), so fanned
     tilt/drop and the focus ring must fit inside it */
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 16px;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}
.fan--scroll .card { scroll-snap-align: center; }

/* ---------- Table (draw / discard / status) ---------- */
.table {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 5vw, 3rem);
  padding: 0.5rem 0;
  flex-wrap: wrap;
}
.pile { background: none; border: none; padding: 0; cursor: default; }
.pile--draw {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.pile--draw .card { transition: transform 0.15s ease; }
.pile--draw:hover .card { transform: translateY(-6px); }
.pile--draw:disabled { opacity: 0.4; cursor: not-allowed; }
.pile--draw:disabled:hover .card { transform: none; }
.pile--draw:disabled:hover .pile__caption { color: var(--muted); }
.pile--draw:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; border-radius: 14px; }
.pile__caption {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.pile--draw:hover .pile__caption { color: var(--gold); }

.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  min-width: 150px;
}

.banner {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  text-align: center;
  background: rgba(255,255,255,0.08);
  border: 2px solid transparent;
  transition: background 0.2s, border-color 0.2s;
}
.banner--you {
  background: rgba(242,193,78,0.16);
  border-color: var(--gold);
  color: #fff;
}
.banner--cpu { color: var(--muted); }
.banner__dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.18);
}
.chip[hidden] { display: none; }
.chip__dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.6); }

/* ============================================================
   CARDS — the signature element
   Colored rounded rect + white rim, a tilted white oval clipped
   into the classic lens, the value in the card's own color, and
   two opposing corner indices.
   ============================================================ */
.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  border: 4px solid #fff;
  overflow: hidden;
  background: #888;
  box-shadow: 0 6px 12px rgba(0,0,0,0.35);
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.card--red { background: var(--uno-red); }
.card--blue { background: var(--uno-blue); }
.card--green { background: var(--uno-green); }
.card--yellow { background: var(--uno-yellow); }
.card--wild { background: var(--card-black); }

.card__oval {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 122%;
  height: 132%;
  transform: translate(-50%, -50%) rotate(-20deg);
  background: var(--paper);
  border-radius: 50%;
}
.card--wild .card__oval {
  background: conic-gradient(from 45deg,
    var(--uno-red) 0 25%, var(--uno-blue) 25% 50%,
    var(--uno-yellow) 50% 75%, var(--uno-green) 75% 100%);
}

.card__value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.5rem;
  line-height: 1;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.12);
}
.card--red .card__value { color: var(--uno-red); }
.card--blue .card__value { color: var(--uno-blue); }
.card--green .card__value { color: var(--uno-green); }
.card--yellow .card__value { color: #C99A00; }
.card--wild .card__value { color: #fff; text-shadow: 0 2px 5px rgba(0,0,0,0.6); }

.card__corner {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.9rem;
  line-height: 1;
  color: var(--card-black);
}
/* Corner indices sit on the white oval, so they take the card's own colour
   (like the central numeral) — never white-on-white. */
.card--red .card__corner { color: var(--uno-red); }
.card--blue .card__corner { color: var(--uno-blue); }
.card--green .card__corner { color: var(--uno-green); }
.card--yellow .card__corner { color: #C99A00; }
.card--wild .card__corner { color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.7); }
.card__corner--tl { top: 5px; left: 7px; }
.card__corner--br { bottom: 5px; right: 7px; transform: rotate(180deg); }

/* Card back — black with a red tilted oval + UNO wordmark */
.card--back { background: var(--card-black); cursor: pointer; }
.card--back::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 118%;
  height: 128%;
  transform: translate(-50%, -50%) rotate(-20deg);
  background: var(--uno-red);
  border-radius: 50%;
}
.card__logo {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  color: #fff;
  transform: rotate(-20deg);
  text-shadow: 1px 2px 0 rgba(0,0,0,0.3);
}

/* ---------- Hand fan (natural, not a rigid grid) ---------- */
.fan--player .card {
  cursor: pointer;
  transform: rotate(var(--rot, 0deg)) translateY(var(--ty, 0px));
  transform-origin: bottom center;
}
.fan--player .card:hover {
  transform: translateY(-24px) scale(1.05);
  z-index: 30;
  box-shadow: 0 20px 28px rgba(0,0,0,0.5);
}
.fan--player .card:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 3px;
  transform: translateY(-24px) scale(1.05);
  z-index: 31;
}
.fan--cpu .card {
  transform: rotate(var(--rot, 0deg)) translateY(var(--ty, 0px));
  transform-origin: top center;
}

/* discard emphasis + fly-in from whoever played the card */
.pile--discard { position: relative; }
.pile--discard .card { box-shadow: 0 10px 22px rgba(0,0,0,0.45); }
.pile--discard > .card:not(.card--under) { position: relative; z-index: 2; }
.pile--discard .card--under {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform: rotate(var(--under-rot, 0deg));
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.card--fly-player { animation: fly-player 0.36s cubic-bezier(0.2, 0.8, 0.2, 1); }
.card--fly-cpu { animation: fly-cpu 0.36s cubic-bezier(0.2, 0.8, 0.2, 1); }

/* A played card physically travels from its owner to the centre pile. */
.flying-card {
  position: fixed;
  width: var(--card-w);
  height: var(--card-h);
  margin: 0;
  transform: translate(-50%, -50%) scale(0.72) rotate(-10deg);
  transition: left 0.44s cubic-bezier(0.2, 0.7, 0.2, 1),
              top 0.44s cubic-bezier(0.2, 0.7, 0.2, 1),
              transform 0.44s ease;
  z-index: 60;
  pointer-events: none;
}
.flying-card--landed { transform: translate(-50%, -50%) scale(1) rotate(0deg); }

/* ============================================================
   OVERLAYS (color picker + game over)
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 18, 13, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  animation: fade-in 0.2s ease both;
}
.overlay[hidden] { display: none; }

.overlay__panel {
  background: #101812;
  border: 1px solid rgba(255,255,255,0.12);
  padding: 2rem 2.2rem;
  border-radius: 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  max-width: 90vw;
}
.overlay__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.9rem;
}
.overlay__sub { margin: 0; color: var(--muted); font-size: 1.05rem; }

.color-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.9rem;
}
.color-btn {
  width: 74px;
  height: 74px;
  border-radius: 16px;
  border: 4px solid #fff;
  cursor: pointer;
  transition: transform 0.12s ease;
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
}
.color-btn:hover { transform: scale(1.06); }
.color-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.color-btn--red { background: var(--uno-red); }
.color-btn--blue { background: var(--uno-blue); }
.color-btn--green { background: var(--uno-green); }
.color-btn--yellow { background: var(--uno-yellow); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fly-player {
  from { transform: translateY(190px) rotate(-14deg) scale(0.8); opacity: 0.2; }
  to { transform: none; opacity: 1; }
}
@keyframes fly-cpu {
  from { transform: translateY(-190px) rotate(14deg) scale(0.8); opacity: 0.2; }
  to { transform: none; opacity: 1; }
}
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } 100% { content: ""; }
}

/* ---------- Points chip + action toast ---------- */
.points {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 999px;
  padding: 0.05rem 0.6rem;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}
.points b { color: var(--gold); font-size: 0.95rem; }

.toast {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%) translateY(-14px);
  background: rgba(9, 22, 16, 0.96);
  border: 2px solid rgba(255,255,255,0.16);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  padding: 0.65rem 1.3rem;
  border-radius: 999px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.5);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  max-width: 92vw;
  text-align: center;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast[hidden] { display: none; }
.toast--show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--bad { border-color: var(--uno-red); }
.toast--special { border-color: var(--gold); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ============================================================
   MULTIPLAYER: opponent selector + bots row
   ============================================================ */
.opp-select { display: flex; gap: 0.5rem; justify-content: center; }
.opp-option {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.opp-option:hover { border-color: var(--gold); }
.opp-option:active { transform: translateY(1px); }
.opp-option--on { background: var(--uno-red); border-color: #fff; }
.opp-option:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Arena: seats around the table. Bots take the top corners / center-top,
   the human sits at the bottom, the draw/discard pile in the middle. */
.arena {
  flex: 1;
  display: grid;
  /* minmax(0, 1fr) lets tracks shrink below their content's min-content width,
     so big bot/player hands never force the grid wider than the viewport. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "tl t tr"
    "center center center"
    "you you you";
  gap: 0.5rem;
  align-items: center;
}
.arena > * { min-width: 0; }
.cpu-player, .zone, .table, .fan { min-width: 0; }
#center-area { grid-area: center; min-width: 0; }
#player-zone { grid-area: you; margin-top: 0; min-width: 0; }

.seat--tl { grid-area: tl; justify-self: start; }
.seat--t { grid-area: t; justify-self: center; }
.seat--tr { grid-area: tr; justify-self: end; }

.cpu-player {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.55rem;
  border-radius: 14px;
  border: 2px solid transparent;
  transition: transform 0.28s ease, border-color 0.25s ease, background 0.25s ease, opacity 0.25s ease;
}
/* Spotlight the player whose turn it is; fade the rest so it's obvious. */
.arena.bot-active .cpu-player { opacity: 0.5; transform: scale(0.94); }
.cpu-player--active {
  opacity: 1 !important;
  transform: scale(1.12) !important;
  border-color: var(--gold);
  background: rgba(242,193,78,0.12);
}

.thinking {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--gold);
  letter-spacing: 0.03em;
}

.speech-bubble {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  line-height: 1.2;
  padding: 0.4rem 0.7rem;
  border-radius: 12px;
  white-space: normal;
  max-width: 170px;
  text-align: center;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  z-index: 16;
  animation: pop 0.2s ease;
}
.speech-bubble::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-bottom-color: #fff;
}
@keyframes pop { from { transform: translateX(-50%) scale(0.7); opacity: 0.3; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
.cpu-player__head { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.cpu-player__name { font-family: var(--font-display); font-weight: 700; }
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.8rem;
}
.bot-tag {
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--muted);
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
}

/* Bot hands are shown smaller so up to 3 fit comfortably */
.cpu-player .card { width: calc(var(--card-w) * 0.62); height: calc(var(--card-h) * 0.62); border-width: 3px; }
.cpu-player .fan--cpu { min-height: calc(var(--card-h) * 0.62 + 8px); padding: 6px 0 2px; }
.cpu-player .fan--cpu .card:not(:first-child) { margin-left: calc(var(--card-w) * -0.30); }
.cpu-player .card__logo { font-size: 0.85rem; }

/* ============================================================
   NEW COMPONENTS — start options, tells, history, summary, share
   ============================================================ */

/* Fieldsets used for grouping start options (no default browser chrome) */
.field-group { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.field-group legend { padding: 0; }

/* Rules preset selector */
.rules-select { display: flex; flex-direction: column; gap: 0.5rem; }
.rule-option {
  text-align: left;
  background: rgba(255,255,255,0.07);
  border: 2px solid rgba(255,255,255,0.22);
  border-radius: 12px;
  padding: 0.6rem 0.85rem;
  color: var(--txt);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.rule-option:hover { border-color: var(--gold); }
.rule-option:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.rule-option--on { border-color: #fff; background: rgba(242,193,78,0.16); }
.rule-option__name { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.rule-option--on .rule-option__name { color: var(--gold); }
.rule-option__desc { font-size: 0.82rem; color: var(--muted); line-height: 1.3; }

.start__actions { display: flex; flex-direction: column; gap: 0.5rem; align-items: center; margin-top: 0.4rem; }
.start__actions .btn { align-self: center; }

.challenge-banner {
  background: rgba(242,193,78,0.16);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  color: #fff;
  max-width: 100%;
}
.challenge-banner[hidden] { display: none; }

/* Topbar: history button + right cluster */
.topbar__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  row-gap: 0.3rem;
  min-width: 0;
}
.icon-btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.3);
  color: var(--txt);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.2); border-color: var(--gold); }
.icon-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.icon-btn--off { opacity: 0.55; text-decoration: line-through; }

/* ---------- Turn timer ---------- */
.turn-timer {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
}
.turn-timer[hidden] { display: none; }
.turn-timer--urgent { color: #fff; border-color: var(--uno-red); background: rgba(228,50,43,0.25); }

/* ---------- Rejected play: shake + ✕ over the attempted card ---------- */
.card--rejected {
  animation: reject-shake 0.4s ease;
  box-shadow: 0 0 0 3px var(--uno-red), 0 6px 12px rgba(0,0,0,0.35);
}
.card--rejected::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.2rem;
  color: #fff;
  background: rgba(228,50,43,0.55);
  border-radius: inherit;
  z-index: 3;
}
@keyframes reject-shake {
  0%, 100% { translate: 0 0; }
  20% { translate: -7px 0; }
  40% { translate: 7px 0; }
  60% { translate: -5px 0; }
  80% { translate: 5px 0; }
}

/* Tactical tells over each bot seat */
.style-tag {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.85;
}
.uno-warn {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}
.uno-warn--one { background: var(--uno-red); border-color: #fff; }

/* Legal-play affordance + unambiguous disabled state on the human hand */
.fan--player .card--playable {
  box-shadow: 0 0 0 3px var(--gold), 0 6px 12px rgba(0,0,0,0.35);
}
.fan--player .card--off {
  opacity: 0.5;
  filter: saturate(0.7);
  cursor: default;
}
.fan--player .card--off:hover { transform: rotate(var(--rot, 0deg)) translateY(var(--ty, 0px)); box-shadow: 0 6px 12px rgba(0,0,0,0.35); }

/* History dialog */
.overlay__panel--log {
  align-items: stretch;
  text-align: left;
  width: min(440px, 92vw);
  max-height: 80vh;
}
.overlay__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.history-list {
  list-style: decimal inside;
  margin: 0;
  padding: 0.5rem 0.2rem;
  overflow-y: auto;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.92rem;
  line-height: 1.35;
  color: var(--txt);
}
.history-list li { padding: 0.15rem 0; border-bottom: 1px solid rgba(255,255,255,0.08); }

/* End-of-game three-moment summary */
.summary {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  text-align: left;
  max-width: 92vw;
  width: 360px;
}
.summary__head {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
}
.summary__list { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.summary__list li { font-size: 0.92rem; line-height: 1.35; color: var(--txt); }

.game-over__actions { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center; }
.share-out {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  word-break: break-all;
  max-width: 92vw;
  text-align: center;
}
.share-out[hidden] { display: none; }

/* Landscape overlay panels stay scrollable */
@media (max-height: 520px) {
  .overlay__panel { max-height: 92vh; overflow-y: auto; padding: 1.2rem 1.4rem; }
  .summary { padding: 0.6rem 0.8rem; }
}

/* ============================================================
   RESPONSIVE — kept at the END of the stylesheet on purpose: these
   overrides share specificity with the component base rules above,
   so source order is what makes them win on small screens.
   ============================================================ */
@media (max-width: 620px) {
  :root { --card-w: 60px; --card-h: 90px; --radius: 11px; }
  .card__value { font-size: 1.9rem; }
  .logo { width: 210px; height: 124px; }
  .logo__word { font-size: 4rem; }

  /* Topbar: compact pills + smaller score so everything fits; past that the
     flex-wrap on .topbar/.topbar__right drops the buttons to a second row. */
  .brand__mark { font-size: 1.2rem; }
  .score { font-size: 0.9rem; }
  .score__side b { font-size: 1.05rem; }
  .topbar__right { gap: 0.4rem; }
  .icon-btn { font-size: 0.7rem; padding: 0.28rem 0.6rem; }

  /* Compact the three bot seats so they fit their narrow columns. Seats fill
     their track (instead of sizing to the fan) and clip, so they never collide. */
  .arena { gap: 0.25rem; }
  .seat--tl, .seat--t, .seat--tr { justify-self: stretch; }
  .cpu-player { padding: 0.2rem 0.3rem; align-items: center; max-width: 100%; gap: 0.15rem; }
  /* Clip only the fan (face-down cards), never the seat — speech bubbles live
     outside the seat box and must stay visible. */
  .cpu-player .fan--cpu { max-width: 100%; overflow: hidden; }
  .cpu-player .card { width: calc(var(--card-w) * 0.5); height: calc(var(--card-h) * 0.5); }
  .cpu-player .fan--cpu { min-height: calc(var(--card-h) * 0.5 + 6px); padding: 4px 0 0; overflow: hidden; }
  .cpu-player .fan--cpu .card:not(:first-child) { margin-left: calc(var(--card-w) * -0.34); }
  /* Keep each bot head on one compact wrapping row — stacking the avatar,
     name and count vertically made every seat ~170px tall and pushed the
     player hand below the fold on short phones. */
  .cpu-player__head { flex-wrap: wrap; justify-content: center; gap: 0.15rem 0.25rem; font-size: 0.72rem; text-align: center; }
  .avatar { width: 18px; height: 18px; font-size: 0.6rem; }
  .count-badge { font-size: 0.7rem; padding: 0.02rem 0.4rem; min-width: 1.2rem; }
  .cpu-player__name { max-width: 4.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .style-tag { font-size: 0.55rem; }
  .uno-warn { font-size: 0.55rem; }
  /* Softer spotlight scale: 1.12 spills outside the edge columns on phones. */
  .cpu-player--active { transform: scale(1.05) !important; }

  /* Speech bubbles at the edge seats pin to the seat edge instead of
     centering, so they never poke past the viewport. */
  .speech-bubble { max-width: min(170px, 46vw); }
  .seat--tl .speech-bubble { left: 0; transform: none; animation: fade-in 0.2s ease; }
  .seat--tl .speech-bubble::after { left: 20%; }
  .seat--tr .speech-bubble { left: auto; right: 0; transform: none; animation: fade-in 0.2s ease; }
  .seat--tr .speech-bubble::after { left: auto; right: 20%; transform: none; }

  /* Center table: tighter rhythm so piles + status share the vertical budget. */
  .table { gap: clamp(0.6rem, 4vw, 2rem); padding: 0.25rem 0; }
  .status { min-width: 0; gap: 0.35rem; }
  .banner { font-size: 0.92rem; padding: 0.35rem 0.85rem; }
  .pile__caption { font-size: 0.68rem; }

  /* Player zone: shave label + fan padding (hover raise is 24px, fits in 26). */
  .zone { gap: 0.25rem; }
  .zone__label { font-size: 0.85rem; }
  .fan--player { padding-top: 26px; }
}

@media (max-width: 400px) {
  .bot-tag { display: none; } /* avatar + style label already signal "bot" */
  .cpu-player__name { max-width: 4.2rem; }
}

@media (max-width: 400px) {
  :root { --card-w: 52px; --card-h: 78px; }
  .card__value { font-size: 1.6rem; }
  .fan--cpu .card:not(:first-child) { margin-left: calc(var(--card-w) * -0.42); }
  /* Squeeze the topbar so score + three buttons share one wrapped row
     (brand above) instead of spilling onto a third line. Long player names
     still wrap gracefully thanks to flex-wrap. */
  .score { font-size: 0.78rem; gap: 0.3rem; }
  .score__side b { font-size: 0.95rem; }
  .topbar__right { gap: 0.25rem; }
  /* Vertical padding keeps the tap target ~24px even with the smaller label */
  .icon-btn { font-size: 0.6rem; padding: 0.32rem 0.45rem; letter-spacing: 0.01em; }
}

/* Landscape, low height: compress the vertical rhythm so the table, the top
   card, the active colour and the main action all stay on screen. */
@media (orientation: landscape) and (max-height: 480px) {
  :root { --card-w: 46px; --card-h: 69px; }
  #game-screen {
    padding-top: 0.2rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    gap: 0.25rem;
  }
  .topbar { padding: 0.15rem 0.25rem 0.3rem; }
  .brand__mark { font-size: 1.05rem; }
  .score { font-size: 0.85rem; }
  .score__side b { font-size: 1rem; }
  .topbar__right { gap: 0.4rem; }
  .icon-btn { font-size: 0.68rem; padding: 0.22rem 0.55rem; }

  .arena { gap: 0.2rem; }
  .cpu-player { padding: 0.15rem 0.35rem; gap: 0.1rem; }
  .cpu-player__head { font-size: 0.78rem; gap: 0.3rem; }
  .avatar { width: 20px; height: 20px; font-size: 0.65rem; }
  .style-tag { font-size: 0.5rem; }
  .cpu-player .card { width: calc(var(--card-w) * 0.45); height: calc(var(--card-h) * 0.45); }
  .cpu-player .fan--cpu { min-height: calc(var(--card-h) * 0.45 + 4px); padding: 2px 0 0; }

  .table { padding: 0; gap: clamp(0.8rem, 3vw, 2rem); }
  /* Status lays out horizontally: stacking banner + timer + color chip
     vertically is what blew the height budget on short screens. */
  .status { min-width: 0; flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.3rem 0.5rem; }
  .banner { font-size: 0.9rem; padding: 0.3rem 0.8rem; }
  .chip { font-size: 0.8rem; }
  .pile__caption { font-size: 0.62rem; }

  .zone { gap: 0.2rem; }
  .zone__label { font-size: 0.8rem; }
  .fan { padding: 18px 0 2px; min-height: calc(var(--card-h) + 16px); }
  .fan--player { padding-top: 20px; padding-bottom: 6px; }
  .fan--scroll { padding-bottom: 12px; }
}
