/* ==========================================================================
   UNO — styles
   Performance notes: animated properties are transform/opacity only; no
   backdrop-filter, no animated box-shadow/filter; glows cross-fade via opacity.
   ========================================================================== */

:root {
  --red: #e53935;
  --yellow: #fdd835;
  --green: #43a047;
  --blue: #1e88e5;
  --ink: #141414;

  --bg: #1c1410;
  --panel: #241a13;
  --text: #f3e7d8;
  --muted: #b79a7d;
  --accent: #d97a35;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  /* card widths (height = 1.5 × width) */
  --cw: clamp(52px, min(17vw, 11vh), 92px);   /* piles + flying cards */
  --hw: clamp(58px, min(19vw, 13vh), 106px);  /* human hand */
  --mw: clamp(22px, 6.5vmin, 46px);    /* opponent fans (big enough to read hand size) */
  --hand-h: 160px;                     /* set by JS */
  --cur: rgba(255, 255, 255, .35);     /* active color */
}

@media (max-height: 520px) {
  :root { --cw: 50px; --hw: 58px; --mw: 22px; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.screen { position: fixed; inset: 0; }

/* ================================================================= SETUP */

#setup {
  display: grid;
  place-items: center;
  overflow-y: auto;
  background:
    radial-gradient(900px 500px at 80% -10%, #3a2213 0%, transparent 60%),
    radial-gradient(700px 500px at 0% 110%, #2a1a10 0%, transparent 60%),
    var(--bg);
  padding: calc(var(--safe-t) + 48px) 16px calc(var(--safe-b) + 24px);
}

.back-link {
  position: absolute;
  top: calc(var(--safe-t) + 14px);
  left: calc(var(--safe-l) + 16px);
  color: var(--muted);
  text-decoration: none;
  font-size: .9rem;
}
.back-link:hover { color: var(--accent); }

.setup-gear {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  right: calc(var(--safe-r) + 12px);
}

.setup-inner {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.logo-fan {
  position: relative;
  width: 100%;
  height: 150px;
  perspective: 800px;
}
.card.logo-card {
  --w: 74px;
  left: 50%;
  top: 14px;
  transform-origin: 50% 120%;
  transform: translateX(-50%) rotate(calc(var(--i) * 14deg)) translateY(calc(var(--i) * var(--i) * 3px));
  animation: fanIn .7s cubic-bezier(.2, .9, .3, 1.15) both, bob 4s ease-in-out infinite;
  animation-delay: calc((var(--i) + 2) * 80ms), calc(900ms + (var(--i) + 2) * 300ms);
}
@keyframes fanIn {
  from { transform: translateX(-50%) translateY(60px) rotate(0) rotateY(180deg); opacity: 0; }
}
@keyframes bob {
  50% { transform: translateX(-50%) rotate(calc(var(--i) * 14deg)) translateY(calc(var(--i) * var(--i) * 3px - 6px)); }
}

.logo {
  margin: -10px 0 6px;
  font: italic 900 clamp(3.2rem, 14vw, 4.6rem)/1 system-ui, sans-serif;
  letter-spacing: .02em;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--red), 6px 6px 0 #000;
  transform: rotate(-6deg);
}

.field { width: 100%; }
.label {
  font-size: .72rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 8px 4px;
}
.label { display: block; }
.name-input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 2px solid #3a2a1e;
  background: var(--panel);
  color: var(--text);
  font: 700 16px/1.2 system-ui, sans-serif; /* 16px: no iOS zoom on focus */
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.name-input:focus { border-color: var(--accent); }
.name-input::placeholder { color: #6e5a48; }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.seg button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  border-radius: 14px;
  background: var(--panel);
  border: 2px solid #3a2a1e;
  font-weight: 700;
  font-size: 1.05rem;
  transition: transform .15s, border-color .15s, background-color .15s;
}
.seg button:active { transform: scale(.96); }
.seg button { position: relative; color: var(--muted); }
.seg button.on {
  border-color: #ffd0a8;
  background: linear-gradient(180deg, #f08a3c, #c04a2b);
  color: #fff;
  transform: scale(1.04);
  box-shadow: 0 6px 18px rgba(217, 122, 53, .35);
}
.seg button.on::after {
  /* check badge on the selected option */
  content: "✓";
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  color: #c04a2b;
  font: 900 13px/22px system-ui, sans-serif;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.seg.two { grid-template-columns: repeat(2, 1fr); }
.seg .dots { font-size: .6rem; letter-spacing: 2px; color: var(--muted); }
.seg .on .dots { color: #fff; }
.seg .lvl { font-size: 1.3rem; line-height: 1; }

.btn-start {
  margin-top: 6px;
  min-width: 200px;
  padding: 15px 34px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f08a3c, #c04a2b);
  color: #fff;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: .04em;
  box-shadow: 0 6px 0 #7a2c18, 0 10px 24px rgba(0, 0, 0, .4);
  transition: transform .1s, box-shadow .1s;
}
.btn-start:active { transform: translateY(4px); box-shadow: 0 2px 0 #7a2c18, 0 4px 12px rgba(0, 0, 0, .4); }

.btn-ghost {
  padding: 13px 26px;
  border-radius: 999px;
  border: 2px solid #5a4636;
  font-weight: 700;
}

/* ================================================================= CARDS */

.card {
  --w: var(--cw);
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w);
  height: calc(var(--w) * 1.5);
  border-radius: calc(var(--w) * .11);
}
/* Only flipping (flying) cards get a 3D context. Static cards stay flat so
   Safari hit-tests overlapping hand cards by z-index, not by 3D depth. */
.card.flip3d { transform-style: preserve-3d; }
.card.size-hand { --w: var(--hw); }
.card.size-mini { --w: var(--mw); }

.face, .back {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #fbf8f2;
  padding: calc(var(--w) * .065);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 calc(var(--w) * .04) calc(var(--w) * .1) rgba(0, 0, 0, .3);
}
.flip3d .back { transform: rotateY(180deg); }

.in {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--w) * .075);
  overflow: hidden;
  background: var(--cc);
}
.c-r { --cc: var(--red); }
.c-y { --cc: var(--yellow); }
.c-g { --cc: var(--green); }
.c-b { --cc: var(--blue); }
.c-w { --cc: var(--ink); }

.oval {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 80%;
  height: 94%;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%) rotate(30deg) scaleX(.82);
}
.c-w .oval {
  background: conic-gradient(var(--red) 0 25%, var(--blue) 0 50%, var(--yellow) 0 75%, var(--green) 0);
}

.sym, .corner {
  position: absolute;
  font-style: italic;
  font-weight: 900;
  line-height: 1;
  display: grid;
  place-items: center;
}
.sym {
  inset: 0;
  color: var(--cc);
  font-size: calc(var(--w) * .5);
  text-shadow: calc(var(--w) * .025) calc(var(--w) * .025) 0 var(--ink);
  letter-spacing: -.04em;
}
.c-w .sym { color: #fff; text-shadow: calc(var(--w) * .025) calc(var(--w) * .025) 0 var(--ink), 0 0 calc(var(--w) * .04) var(--ink); }
.corner {
  color: #fff;
  font-size: calc(var(--w) * .18);
  text-shadow: 1px 1px 0 var(--ink);
}
.corner.tl { left: 7%; top: 4%; }
.corner.br { right: 7%; bottom: 4%; transform: rotate(180deg); }
.ul { text-decoration: underline; text-decoration-thickness: .08em; text-underline-offset: .08em; }

.sym svg, .corner svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.sym svg { width: 58%; stroke-width: 3.6; filter: drop-shadow(calc(var(--w) * .02) calc(var(--w) * .02) 0 var(--ink)); }
.corner svg { width: calc(var(--w) * .2); stroke-width: 3.2; }

/* back */
.back .in { background: var(--ink); }
.back .oval { background: var(--red); }
.back .logo {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: italic 900 calc(var(--w) * .3)/1 system-ui, sans-serif;
  color: var(--yellow);
  text-shadow: calc(var(--w) * .02) calc(var(--w) * .02) 0 var(--ink);
  transform: rotate(-20deg);
}
.card.size-mini .back { padding: 1.5px; box-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
.card.size-mini .logo { display: none; }

.flying { z-index: 50; will-change: transform; pointer-events: none; }

/* ================================================================= TABLE */

/* A dim room around the table. */
#game {
  background: radial-gradient(ellipse 90% 70% at 50% 40%, #2a1c14 0%, #140e0a 60%, #0b0806 100%);
  touch-action: manipulation;
}

#table {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* Wooden table rim with the felt inside; one warm lamp from above. All static
   gradients (painted once); the grain is a generated 128px tile (--felt-tex). */
.rim {
  position: absolute;
  inset: max(6px, 1.4vmin);
  border-radius: min(110px, 16vmin);
  background:
    repeating-linear-gradient(100deg, rgba(0, 0, 0, .09) 0 3px, transparent 3px 9px),
    linear-gradient(160deg, #8a5530 0%, #6b3f22 35%, #7b4a2a 60%, #4e2c16 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .65), inset 0 2px 0 rgba(255, 220, 180, .22), inset 0 -3px 6px rgba(0, 0, 0, .45);
}
.felt {
  position: absolute;
  inset: clamp(8px, 1.8vmin, 14px);
  border-radius: min(96px, 14vmin);
  background:
    radial-gradient(ellipse 65% 45% at 50% 40%, rgba(255, 214, 150, .16), transparent 70%),
    var(--felt-tex, none),
    radial-gradient(ellipse 80% 70% at 50% 44%, #1f6b4a 0%, #165238 50%, #0c3022 100%);
  background-size: auto, 128px 128px, auto;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, .6), inset 0 0 0 1px rgba(0, 0, 0, .5);
}

/* Active-color glow: one layer whose gradient color follows the active color.
   (A single static layer; four stacked full-screen layers were heavy on phone GPUs.) */
.glow {
  position: absolute;
  left: 50%;
  top: 44%;
  width: 100vmax;
  height: 100vmax;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, var(--glow, transparent) 0, transparent 45%);
  pointer-events: none;
}
#table[data-color="r"] { --glow: rgba(229, 57, 53, .32); }
#table[data-color="y"] { --glow: rgba(253, 216, 53, .26); }
#table[data-color="g"] { --glow: rgba(67, 160, 71, .32); }
#table[data-color="b"] { --glow: rgba(30, 136, 229, .34); }
#table[data-color="r"] { --cur: var(--red); }
#table[data-color="y"] { --cur: var(--yellow); }
#table[data-color="g"] { --cur: var(--green); }
#table[data-color="b"] { --cur: var(--blue); }

/* center: deck + discard + direction ring */
#center {
  position: absolute;
  z-index: 5; /* deck & discard stay above the tea layer (4) */
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  width: calc(var(--cw) * 3);
  height: calc(var(--cw) * 3);
}
@media (max-height: 520px) { #center, .glow { top: 40%; } }

.ring {
  position: absolute;
  inset: 0;
  pointer-events: none;
  perspective: 600px;
}
.ring-flip {
  position: absolute;
  inset: 0;
  transition: transform .6s cubic-bezier(.5, -0.2, .3, 1.3);
}
.ring-flip.ccw { transform: rotateY(180deg); }
.ring-spin {
  width: 100%;
  height: 100%;
  animation: spin 16s linear infinite;
  overflow: visible;
}
.ring-spin circle {
  fill: none;
  stroke: var(--cur);
  stroke-width: 1.6;
  stroke-dasharray: 5 4;
  opacity: .85;
  transition: stroke .5s;
}
.ring-spin .arr { fill: var(--cur); transition: fill .5s; }
@keyframes spin { to { transform: rotate(360deg); } }

.pointer {
  position: absolute;
  inset: 0;
  transition: transform .55s cubic-bezier(.3, 1.3, .5, 1);
  opacity: 0;
}
.pointer.on { opacity: 1; }
.pointer i {
  position: absolute;
  left: 100%;
  top: 50%;
  width: 0;
  height: 0;
  margin: -9px 0 0 -2px;
  border-left: 16px solid #fff;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6));
  animation: nudge 1s ease-in-out infinite;
}
@keyframes nudge { 50% { transform: translateX(5px); } }

.piles {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  gap: calc(var(--cw) * .4);
}
.piles > * { position: relative; }

#deck {
  position: relative;
  border-radius: calc(var(--cw) * .11);
}
#deck .back { box-shadow: none; }
#deck.empty { opacity: .25; }
#deck.clickable { cursor: pointer; }
#deck::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: calc(var(--cw) * .16);
  border: 3px solid #fff;
  opacity: 0;
  pointer-events: none;
}
#deck.hint::after { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 0; transform: scale(.96); }
  50% { opacity: .9; transform: scale(1.04); }
}

.discard {
  width: var(--cw);
  height: calc(var(--cw) * 1.5);
}
.discard .card.tinted .face {
  box-shadow: 0 0 0 calc(var(--w) * .05) var(--tint), 0 4px 12px rgba(0, 0, 0, .45);
}

.btn-pass {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--cw) * .75 + 12px);
  transform: translateX(-50%);
  padding: 9px 20px;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 4px 0 #9a9a9a, 0 6px 16px rgba(0, 0, 0, .4);
  white-space: nowrap;
  z-index: 20;
  animation: popIn .25s cubic-bezier(.2, .9, .3, 1.3);
}
@keyframes popIn { from { transform: translateX(-50%) scale(.4); opacity: 0; } }

/* ================================================================= SEATS */

.seat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  z-index: 5;
  pointer-events: none;
}
.pos-top       { top: calc(var(--safe-t) + 10px); left: 50%; transform: translateX(-50%); }
.pos-left      { left: calc(var(--safe-l) + 8px); top: 44%; transform: translateY(-60%); }
.pos-right     { right: calc(var(--safe-r) + 8px); top: 44%; transform: translateY(-60%); }
.pos-left-top  { top: calc(var(--safe-t) + 12px); left: max(60px, 16%); }
.pos-right-top { top: calc(var(--safe-t) + 12px); right: max(60px, 16%); }
.pos-bottom    { left: 50%; bottom: calc(var(--hand-h) + var(--safe-b) + 6px); transform: translateX(-50%); flex-direction: row; gap: 8px; }
@media (max-height: 520px) {
  .pos-left, .pos-right { top: 40%; }
  .pos-bottom { left: calc(var(--safe-l) + 10px); bottom: calc(var(--safe-b) + 10px); transform: none; flex-direction: column; }
}

.avatar {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .35);
  border: 2px solid rgba(255, 255, 255, .25);
  font-size: 26px;
  line-height: 1;
}
.seat.me .avatar { width: 44px; height: 44px; font-size: 24px; }
.avatar::before {
  /* active-turn ring (pulsing via opacity/transform only) */
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 3px solid var(--cur);
  opacity: 0;
  transition: opacity .25s;
}
.seat.active .avatar { border-color: #fff; }
.seat.active .avatar::before { opacity: 1; animation: ringPulse 1.2s ease-in-out infinite; }
@keyframes ringPulse { 50% { transform: scale(1.12); } }
.seat.skipped .avatar { opacity: .45; }

.count {
  position: absolute;
  right: -8px;
  bottom: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  font: 800 12px/22px system-ui, sans-serif;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .5);
}
.seat.last-card .count { background: var(--red); color: #fff; }

.name {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, .85);
  text-shadow: 0 1px 2px #000;
}
.seat.active .name { color: #fff; }

.fan {
  position: relative;
  width: calc(var(--mw) * 3.4);
  height: calc(var(--mw) * 1.75);
  margin-top: 2px;
}
.fan .card {
  /* --step (deg) is set from JS so the fan opens wider the more cards there are */
  left: calc(50% - var(--mw) / 2);
  transform-origin: 50% 110%;
  transform: rotate(calc((var(--i) - (var(--n) - 1) / 2) * var(--step, 9deg)));
}

/* ================================================================= HAND */

.hand {
  position: absolute;
  left: calc(var(--safe-l) + 0px);
  right: calc(var(--safe-r) + 0px);
  bottom: calc(var(--safe-b) + 4px);
  height: var(--hand-h);
  z-index: 10;
}
@media (max-height: 520px) {
  .hand { left: calc(var(--safe-l) + 64px); right: calc(var(--safe-r) + 64px); }
}
.hand::before {
  /* "your turn" floor glow */
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -30px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, .22), transparent);
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
.hand.my-turn::before { opacity: 1; }

.card.size-hand {
  --lift: 0px;
  cursor: pointer;
  transform: translate3d(var(--x, 0), calc(var(--y, 0px) - var(--lift)), 0) rotate(var(--r, 0deg))
    perspective(700px) rotateX(var(--tx, 0deg)) rotateY(var(--ty, 0deg));
  transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
.card.size-hand.ok { --lift: calc(var(--w) * .14); }
@media (hover: hover) {
  .card.size-hand.ok:hover { --lift: calc(var(--w) * .26); }
}
.card.size-hand::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(0, 0, 0, .5);
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.card.size-hand.dim::after { opacity: 1; }
.card.size-hand.ok .face { box-shadow: 0 0 0 2px #fff, 0 6px 14px rgba(0, 0, 0, .45); }

/* ================================================================= BUTTONS */

.btn-uno {
  position: absolute;
  right: calc(var(--safe-r) + 14px);
  bottom: calc(var(--hand-h) + var(--safe-b) + 10px);
  z-index: 30;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--red);
  border: 4px solid var(--yellow);
  color: #fff;
  font: italic 900 18px/1 system-ui, sans-serif;
  text-shadow: 2px 2px 0 #000;
  box-shadow: 0 5px 0 #8a1c19, 0 8px 18px rgba(0, 0, 0, .5);
  transform: rotate(-8deg);
}
.btn-uno[data-state="ready"] { animation: wiggle 1.4s ease-in-out infinite; }
/* "press me": a yellow ring keeps rippling out while UNO can be called */
.btn-uno::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3px solid var(--yellow);
  opacity: 0;
  pointer-events: none;
}
.btn-uno[data-state="ready"]::after { animation: unoRing 1.1s ease-out infinite; }
@keyframes unoRing {
  from { transform: scale(.95); opacity: .9; }
  to { transform: scale(1.45); opacity: 0; }
}
.btn-uno[data-state="urgent"] { animation: urgent .45s ease-in-out infinite; }
.btn-uno[data-state="armed"] { background: #ffb300; border-color: #fff; transform: rotate(-8deg) scale(.92); box-shadow: 0 2px 0 #8a5a00; }
@keyframes wiggle {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50% { transform: rotate(6deg) scale(1.08); }
}
@keyframes urgent {
  0%, 100% { transform: rotate(-8deg) scale(1.05); }
  50% { transform: rotate(8deg) scale(1.25); }
}
@media (max-height: 520px) {
  .btn-uno { width: 60px; height: 60px; font-size: 15px; bottom: calc(var(--safe-b) + 12px); }
}

.btn-catch {
  position: fixed;
  z-index: 60;
  transform: translate(-50%, -50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  border: 3px solid #fff;
  font: italic 900 15px/1 system-ui, sans-serif;
  box-shadow: 0 5px 0 #a08200, 0 8px 18px rgba(0, 0, 0, .5);
  animation: catchPulse .5s ease-in-out infinite;
}
@keyframes catchPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.15) rotate(-4deg); }
}

.topbar {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  left: calc(var(--safe-l) + 10px);
  right: calc(var(--safe-r) + 10px);
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 40;
}
.icon-btn {
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(255, 255, 255, .15);
  font-size: 17px;
  line-height: 1;
}

/* ================================================================= FX */

.fx { position: fixed; inset: 0; pointer-events: none; z-index: 45; overflow: hidden; }
.probes { position: fixed; left: -999px; top: 0; visibility: hidden; }

.stamp {
  position: absolute;
  z-index: 55;
  display: grid;
  place-items: center;
  font: italic 900 30px/1 system-ui, sans-serif;
  color: #fff;
  text-shadow: 2px 2px 0 #000, 0 0 12px rgba(0, 0, 0, .5);
  white-space: nowrap;
  will-change: transform, opacity;
}
.stamp.penalty {
  min-width: 62px;
  height: 62px;
  padding: 0 10px;
  border-radius: 31px;
  background: var(--red);
  border: 3px solid #fff;
  font-size: 28px;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .5);
}
.stamp.uno {
  padding: 10px 16px;
  border-radius: 50% 50% 50% 8px / 60% 60% 40% 8px;
  background: var(--yellow);
  color: var(--red);
  border: 3px solid var(--ink);
  font-size: 26px;
  text-shadow: 1px 1px 0 var(--ink);
}
.stamp.caught {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--yellow);
  border: 3px solid var(--red);
  font-size: 22px;
}
.stamp.icon {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  border: 3px solid #fff;
}
.stamp.icon svg { width: 62%; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.stamp.skip { border-color: var(--red); }
.stamp.skip svg { stroke: #ff6b66; }
.stamp.rev.ccw svg { transform: scaleX(-1); }
.stamp.swatch {
  width: calc(var(--cw) * 1.1);
  height: calc(var(--cw) * 1.1);
  border-radius: 50%;
  background: var(--cc);
  border: 4px solid #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}

.burst {
  position: absolute;
  border-radius: 50%;
  border: 6px solid #fff;
  pointer-events: none;
  will-change: transform, opacity;
}

.bubble {
  --tail: 50%;
  position: absolute;
  z-index: 58;
  padding: 6px 10px;
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .45);
  will-change: transform, opacity;
}
.bubble.text {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(210px, 62vw);
  padding: 7px 11px 7px 8px;
  border-radius: 14px;
  font: 700 13px/1.25 system-ui, sans-serif;
  white-space: normal;
}
.bubble.text .e { font-size: 20px; flex: none; }
.bubble::after {
  /* speech-bubble tail pointing at the avatar */
  content: "";
  position: absolute;
  left: var(--tail);
  bottom: -7px;
  margin-left: -7px;
  border: 7px solid transparent;
  border-bottom: 0;
  border-top-color: #fff;
}
.bubble.below::after { top: -7px; bottom: auto; border: 7px solid transparent; border-top: 0; border-bottom-color: #fff; }

.confetti {
  position: absolute;
  top: 0;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  will-change: transform;
}

/* ================================================================= OVERLAYS */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(5, 12, 9, .62);
  padding: 16px;
}

.wheel {
  position: relative;
  width: min(260px, 70vmin);
  height: min(260px, 70vmin);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.wheel .q {
  background: var(--cc);
  border: 4px solid #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .5);
  transition: transform .12s;
}
.wheel .q:active { transform: scale(.93); }
@media (hover: hover) { .wheel .q:hover { transform: scale(1.05); } }
.wheel .q:nth-child(1) { border-radius: 100% 0 0 0; }
.wheel .q:nth-child(2) { border-radius: 0 100% 0 0; }
.wheel .q:nth-child(3) { border-radius: 0 0 0 100%; }
.wheel .q:nth-child(4) { border-radius: 0 0 100% 0; }
.wheel .hub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--ink);
  border: 4px solid #fff;
  pointer-events: none;
}

.box {
  width: min(360px, 100%);
  padding: 24px 20px 20px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid #3a2a1e;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
}
.box h2 { margin: 6px 0 14px; font-size: 1.5rem; }
.box.small h2 { margin-top: 0; }
.box .big { font-size: 60px; line-height: 1; }
#result.won .box { border-color: var(--yellow); }
#result.won h2 { color: var(--yellow); }
.box .row { display: flex; gap: 10px; justify-content: center; }
.box .row .btn-start { min-width: 0; margin: 0; padding: 13px 28px; font-size: 1.05rem; }

.ranks {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 6px;
}
.ranks li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .05);
}
.ranks li.win { background: rgba(253, 216, 53, .14); }
.ranks .rk { width: 18px; font-weight: 800; color: var(--muted); }
.ranks .emoji { font-size: 22px; }
.ranks .nm { flex: 1; text-align: left; font-weight: 700; }
.ranks .left { color: var(--muted); font-size: .9rem; }

@media (prefers-reduced-motion: reduce) {
  .ring-spin, .pointer i, .logo-card, .btn-uno, .btn-catch, .seat.active .avatar::before { animation: none !important; }
}

/* ================================================================= SETTINGS */

#settings { z-index: 80; }
.settings-box { display: flex; flex-direction: column; gap: 16px; text-align: left; }
.settings-box h2 { margin: 0; text-align: center; }
.settings-box .seg button { padding: 10px 6px; font-size: .95rem; }
.settings-box .btn-start { align-self: center; min-width: 160px; margin-top: 4px; }
.gear { font-size: 18px; }

/* ================================================================= AVATARS */

.avatar .pic {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  line-height: 1;
}
.avatar .pic svg, .avatar .pic img { width: 100%; height: 100%; display: block; object-fit: cover; }

.name-row { display: flex; gap: 10px; align-items: center; }
.avatar-btn {
  flex: none;
  width: 52px;
  height: 52px;
  font-size: 28px;
  cursor: pointer;
  border-color: var(--accent);
}
.avatar-btn .edit {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font: 700 11px/20px system-ui, sans-serif;
  font-style: normal;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  justify-items: center;
  margin-bottom: 16px;
}
.avatar-grid .avatar {
  width: 56px;
  height: 56px;
  font-size: 30px;
  cursor: pointer;
  transition: transform .12s;
}
.avatar-grid .avatar:active { transform: scale(.9); }
.upload-btn { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.avatar-error { color: #ff8a80; margin: 10px 0 0; font-size: .9rem; }

.box .big .avatar.lg { display: inline-block; width: 76px; height: 76px; font-size: 44px; }
.ranks .avatar.sm { flex: none; width: 30px; height: 30px; font-size: 17px; border-width: 1px; }

/* ================================================================= POLISH */

/* bot table props sit beside the avatar, on the table side */
.seat .prop {
  position: absolute;
  top: 14px;
  width: 30px;
  height: 30px;
  transform-origin: 50% 90%;
}
.seat .prop svg { width: 100%; height: 100%; display: block; }
.pos-top .prop, .pos-left .prop, .pos-left-top .prop { left: calc(50% + 28px); }
.pos-right .prop, .pos-right-top .prop { right: calc(50% + 28px); }

/* big "UNO!" splash in the middle of the table */
.stamp.banner {
  font: italic 900 clamp(48px, 16vmin, 96px)/1 system-ui, sans-serif;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--red), 6px 6px 0 #000;
  letter-spacing: .02em;
}

/* menu background: a few cards drifting upward */
.menu-float { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.card.float-card {
  --w: 64px;
  left: var(--x);
  top: 100%;
  opacity: .14;
  animation: drift var(--d) linear infinite;
  animation-delay: var(--delay);
}
@keyframes drift {
  from { transform: translateY(0) rotate(0); }
  to { transform: translateY(calc(-100vh - 140px)) rotate(var(--rot)); }
}
.setup-inner { position: relative; z-index: 1; }
.back-link, .setup-gear { z-index: 1; }

/* tab hidden: freeze every CSS animation (battery) */
body.paused *, body.paused *::before, body.paused *::after { animation-play-state: paused !important; }

@media (prefers-reduced-motion: reduce) {
  .card.float-card { animation: none; display: none; }
}

/* volume sliders */
.vol-row { display: flex; align-items: center; gap: 10px; }
.vol-icon { width: 26px; font-size: 20px; text-align: center; flex: none; }
.vol-val { width: 44px; text-align: right; font: 700 14px/1 system-ui, sans-serif; color: var(--muted); flex: none; }
.vol {
  --fill: 50%;
  flex: 1;
  height: 32px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  touch-action: pan-y;
}
.vol::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--fill), #3a2a1e var(--fill));
}
.vol::-moz-range-track { height: 8px; border-radius: 4px; background: #3a2a1e; }
.vol::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--accent); }
.vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -8px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.vol::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
}

/* special cards fly with a halo in their color */
.flying.glowing .face { box-shadow: 0 0 0 2px #fff, 0 0 18px 6px var(--glow); }

/* ================================================================= ONLINE LOBBY */

#lobby {
  display: grid;
  place-items: center;
  overflow-y: auto;
  background:
    radial-gradient(900px 500px at 80% -10%, #3a2213 0%, transparent 60%),
    var(--bg);
  padding: calc(var(--safe-t) + 56px) 16px calc(var(--safe-b) + 24px);
}
#lobby .back-link { background: none; border: 0; font: inherit; cursor: pointer; }
.logo.small { font-size: clamp(2.4rem, 11vw, 3.2rem); margin: 0 0 10px; }
.lobby-pane { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px; }
#lobby.busy .lobby-inner { opacity: .6; pointer-events: none; }
.btn-online { margin-top: 2px; }
.or { color: var(--muted); font-size: .85rem; letter-spacing: .1em; text-transform: uppercase; }
.code-input { text-align: center; letter-spacing: .4em; font-size: 22px; }
.room-code { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted); font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; }
.room-code b { font: 900 46px/1 system-ui, sans-serif; letter-spacing: .18em; color: var(--yellow); text-shadow: 3px 3px 0 var(--red); }
.room-players { width: 100%; margin: 0; }
.room-players li.empty { opacity: .5; }
.room-players .avatar.sm { display: grid; place-items: center; }
.room-wait { color: var(--muted); margin: 0; animation: pulse-text 1.6s ease-in-out infinite; }
@keyframes pulse-text { 50% { opacity: .45; } }
.lobby-msg { min-height: 1.3em; margin: 0; color: #ffb38a; text-align: center; font-size: .92rem; }

/* ================================================================= CHAT */

.topbar-right { display: flex; gap: 8px; }
.chat-bar {
  position: absolute;
  top: calc(var(--safe-t) + 58px);
  left: 50%;
  z-index: 65;
  width: min(420px, calc(100% - 24px));
  transform: translateX(-50%);
  padding: 8px;
  border-radius: 16px;
  background: rgba(20, 14, 10, .92);
  border: 1px solid #4a3626;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.chat-quick { display: flex; justify-content: space-between; gap: 4px; margin-bottom: 8px; }
.chat-quick button {
  flex: 1;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .07);
  font-size: 20px;
  font-weight: 800;
}
.chat-quick button:active { transform: scale(.9); }
.chat-row { display: flex; gap: 8px; }
.chat-row input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid #4a3626;
  background: #241a13;
  color: var(--text);
  font: 600 16px system-ui, sans-serif; /* 16px: no iOS zoom */
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.chat-send { width: 44px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 18px; }
.chat-send:disabled { opacity: .4; }

/* ================================================================= TEA BREAK */

.tea-tray { position: absolute; left: 0; top: 0; width: 80px; height: 40px; z-index: 52; will-change: transform; }
.tea-layer { position: absolute; inset: 0; z-index: 4; pointer-events: none; } /* under seats (5) and hand (10) */
.tea-glass { position: absolute; left: 0; top: 0; will-change: transform; }
.tea-tray svg, .tea-glass svg { width: 100%; height: 100%; display: block; }
.stamp.tea-call {
  z-index: 60; /* above bot speech bubbles */
  padding: 10px 16px;
  border-radius: 18px;
  background: #fff;
  color: #a8321c;
  border: 3px solid #a8321c;
  font: italic 900 24px/1 system-ui, sans-serif;
  text-shadow: none;
}
