/* ===== Amazing Digital Circus UNO — theme ===== */
:root {
  --red: #ff3b5c;
  --yellow: #ffd23f;
  --green: #2bd96b;
  --blue: #2d9bff;
  --wild: #b06bff;
  --ink: #1a0f2e;
  --panel: rgba(28, 14, 48, 0.82);
  --panel-edge: #ff52d9;
  --glow: #00e5ff;
  --cream: #fdf0ff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The hidden attribute must always win, even over class rules that set display
   (e.g. .chooser { display: grid }). Without this, overlays render on load. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--cream);
  background: #0c0420;
  overflow: hidden;
}

/* Surreal circus-tent backdrop: warped checkerboard + radial spotlights */
.tent-bg {
  position: fixed;
  inset: -10%;
  z-index: -2;
  background:
    radial-gradient(circle at 20% 15%, rgba(0, 229, 255, 0.25), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(255, 82, 217, 0.28), transparent 45%),
    conic-gradient(from 0deg at 50% 50%,
      #2a0f4a 0deg, #1a0833 18deg, #2a0f4a 36deg, #1a0833 54deg) ;
  background-blend-mode: screen;
  animation: spin 90s linear infinite;
}
.tent-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,0.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.03) 75%),
    linear-gradient(45deg, rgba(255,255,255,0.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.03) 75%);
  background-size: 64px 64px;
  background-position: 0 0, 32px 32px;
  opacity: 0.6;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Screens ===== */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  padding: 20px;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
}
.screen.active { display: flex; }

/* ===== Home / marquee ===== */
.marquee { text-align: center; margin: 6vh 0 18px; }
.logo {
  font-family: 'Rubik Mono One', sans-serif;
  font-size: clamp(34px, 9vw, 76px);
  margin: 0;
  letter-spacing: 2px;
  color: var(--cream);
  text-shadow:
    0 0 8px var(--glow),
    3px 3px 0 var(--red),
    -3px -3px 0 var(--blue);
  animation: wobble 5s ease-in-out infinite;
}
@keyframes wobble {
  0%,100% { transform: rotate(-1.5deg); }
  50% { transform: rotate(1.5deg); }
}
.logo-sub {
  font-family: 'Rubik Mono One', sans-serif;
  font-size: clamp(28px, 7vw, 56px);
  letter-spacing: 14px;
  color: var(--yellow);
  text-shadow: 0 0 14px var(--yellow), 2px 2px 0 var(--ink);
  margin-top: 4px;
}

.panel {
  width: min(440px, 94vw);
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 0 26px rgba(255, 82, 217, 0.35), inset 0 0 22px rgba(0,229,255,0.08);
  backdrop-filter: blur(6px);
}

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; opacity: 0.85; margin-bottom: 6px; letter-spacing: 1px; }
input {
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 18px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.35);
  color: var(--cream);
  outline: none;
}
input:focus { border-color: var(--glow); box-shadow: 0 0 12px rgba(0,229,255,0.5); }

.avatar-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 6px 0 16px;
}
.av {
  width: 56px; height: 56px;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.3);
  font-size: 28px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  position: relative;
}
.av:hover { transform: translateY(-3px) scale(1.05); }
.av.selected { border-color: var(--yellow); box-shadow: 0 0 14px var(--yellow); }
.av.taken { opacity: 0.3; pointer-events: none; }
.av .av-name {
  position: absolute; bottom: -16px; left: 50%; transform: translateX(-50%);
  font-size: 9px; letter-spacing: 0.5px; white-space: nowrap; opacity: 0.7;
}

.home-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.or { text-align: center; opacity: 0.6; font-size: 13px; letter-spacing: 3px; }
.join-row { display: flex; gap: 8px; }
.code-input {
  text-transform: uppercase;
  letter-spacing: 8px;
  text-align: center;
  font-family: 'Rubik Mono One', sans-serif;
  flex: 1;
}

/* ===== Buttons ===== */
.btn {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 17px;
  padding: 13px 20px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--red), var(--wild));
  box-shadow: 0 5px 0 #8a1230, 0 8px 18px rgba(0,0,0,0.4);
  transition: transform 0.08s, box-shadow 0.08s;
  letter-spacing: 0.5px;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #8a1230, 0 3px 10px rgba(0,0,0,0.4); }
.btn.big { font-size: 20px; padding: 15px; }
.btn.ghost { background: rgba(255,255,255,0.08); box-shadow: 0 4px 0 rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.2); }
.btn.small { font-size: 14px; padding: 9px 14px; }
.btn:disabled { filter: grayscale(0.7) brightness(0.7); cursor: not-allowed; }

.hint { text-align: center; min-height: 20px; color: var(--yellow); margin: 12px 0 0; font-size: 14px; }

/* PWA install affordances */
.install-chip {
  margin: 16px auto 0; display: block;
  background: linear-gradient(135deg, var(--glow), var(--blue));
  box-shadow: 0 4px 0 #0a5a7a, 0 0 18px rgba(0,229,255,0.45);
  color: var(--ink); font-size: 16px;
  animation: bob 1.4s ease-in-out infinite;
}
.ios-hint {
  margin: 14px auto 0; max-width: 320px; text-align: center;
  font-size: 13px; line-height: 1.5; color: var(--cream); opacity: 0.85;
  background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px; padding: 10px 14px;
}
.ios-hint b { color: var(--glow); }
.ios-hint .ios-share { font-size: 15px; }
.credits { margin-top: auto; padding-top: 24px; opacity: 0.5; font-size: 12px; letter-spacing: 1px; }

/* ===== Lobby ===== */
.lobby-head {
  width: min(560px, 96vw);
  display: flex; justify-content: space-between; align-items: center;
  margin: 3vh 0 10px;
}
.room-label { font-size: 11px; letter-spacing: 3px; opacity: 0.7; }
.room-code {
  font-family: 'Rubik Mono One', sans-serif;
  font-size: 44px; letter-spacing: 8px; color: var(--glow);
  text-shadow: 0 0 16px var(--glow);
}
.section-title { font-size: 14px; letter-spacing: 2px; opacity: 0.8; margin: 16px 0 8px; text-transform: uppercase; }
.lobby-players {
  width: min(560px, 96vw);
  display: flex; flex-wrap: wrap; gap: 10px;
}
.lobby-player {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 2px solid rgba(255,255,255,0.15);
  border-radius: 14px; padding: 8px 14px 8px 8px;
}
.lobby-player .pa { font-size: 26px; }
.lobby-player.off { opacity: 0.4; }
.crown { color: var(--yellow); font-size: 14px; }
.lobby-actions { display: flex; gap: 12px; margin-top: 22px; }

/* ===== Game table ===== */
#game { padding: 8px; justify-content: space-between; }
.opponents {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  width: 100%; padding-top: 6px;
}
.opp {
  background: var(--panel);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  padding: 6px 12px;
  display: flex; align-items: center; gap: 8px;
  min-width: 96px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.opp.turn {
  border-color: var(--yellow);
  box-shadow: 0 0 18px var(--yellow);
  transform: translateY(2px) scale(1.04);
}
.opp.off { opacity: 0.4; }
.opp .pa { font-size: 28px; }
.opp .pmeta { display: flex; flex-direction: column; line-height: 1.15; }
.opp .pname { font-size: 15px; font-weight: 600; }
.opp .pscore { font-size: 12px; color: var(--yellow); font-weight: 700; }
/* Big, unmistakable remaining-card count */
.opp .pcards {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px; padding: 3px 11px; margin-left: 2px; min-width: 46px;
}
.opp .pcards-num {
  font-family: 'Rubik Mono One', sans-serif; font-size: 24px; line-height: 1;
  color: var(--glow); text-shadow: 0 0 8px rgba(0,229,255,0.6);
}
.opp .pcards-lbl { font-size: 9px; letter-spacing: 0.5px; opacity: 0.65; margin-top: 2px; }
.opp .pcards.one { background: var(--red); border-color: #fff; }
.opp .pcards.one .pcards-num { color: #fff; text-shadow: 0 0 8px rgba(255,255,255,0.7); }
.opp .catch-btn {
  font-size: 12px; padding: 5px 10px; border-radius: 8px; border: none;
  background: var(--red); color: #fff; cursor: pointer; margin-left: 4px; font-weight: 700;
  box-shadow: 0 3px 0 #8a1230; animation: pulse 0.8s infinite;
}
.uno-flag { font-size: 11px; background: var(--yellow); color: var(--ink); border-radius: 6px; padding: 1px 5px; font-weight: 700; }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* ===== Current-color indicator (crucial after a Wild) ===== */
.color-tag {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: 'Rubik Mono One', sans-serif; font-size: 16px; letter-spacing: 2px;
  padding: 7px 20px; border-radius: 999px; border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 0 18px rgba(0,0,0,0.4), 0 4px 10px rgba(0,0,0,0.4);
  animation: colorpop 0.35s ease;
}
.color-tag::before { content: '🎨'; font-size: 14px; }
@keyframes colorpop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.table {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; position: relative; min-height: 180px;
}
.table-center { display: flex; align-items: center; gap: 26px; position: relative; }
.dir-indicator {
  position: absolute; top: -38px; left: 50%; transform: translateX(-50%);
  font-size: 26px; color: var(--glow); text-shadow: 0 0 10px var(--glow);
}
.deck-pile { position: relative; cursor: pointer; transition: transform 0.1s; }
.deck-pile:hover { transform: translateY(-4px); }
.deck-count {
  position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  background: var(--ink); border-radius: 10px; padding: 1px 8px; font-size: 12px;
  border: 1px solid rgba(255,255,255,0.2);
}
.turn-banner {
  font-size: 22px; font-weight: 700; text-align: center; min-height: 28px;
  text-shadow: 0 0 10px rgba(0,0,0,0.6);
}
.turn-banner.your-turn { color: var(--yellow); text-shadow: 0 0 14px var(--yellow); animation: bob 1s infinite; }
@keyframes bob { 50% { transform: translateY(-3px); } }

/* Play-order strip: shows the seating order, who's up, who's next, and direction. */
.turn-order {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 6px; margin-top: 6px; font-size: 13px; opacity: 0.95;
}
.turn-order .to-label { font-size: 11px; letter-spacing: 1px; opacity: 0.6; text-transform: uppercase; }
.turn-order .to-player {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,0.07);
  border: 1px solid transparent; transition: all 0.2s;
}
.turn-order .to-player.now {
  background: rgba(255,210,63,0.2); border-color: var(--yellow);
  box-shadow: 0 0 10px rgba(255,210,63,0.5); font-weight: 700;
}
.turn-order .to-player.next { border-color: var(--glow); }
.turn-order .to-player.off { opacity: 0.4; }
.turn-order .to-arrow { color: var(--glow); font-size: 14px; opacity: 0.7; }
.turn-order .to-dir {
  margin-left: 4px; font-size: 12px; letter-spacing: 1px; color: var(--glow);
  border: 1px solid var(--glow); border-radius: 999px; padding: 2px 10px;
  text-shadow: 0 0 8px var(--glow);
}

/* Big transient flash when an action card resolves (skip / reverse / +2 / +4). */
.action-flash {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 5; pointer-events: none; white-space: nowrap;
  font-family: 'Rubik Mono One', sans-serif; font-size: clamp(22px, 6vw, 40px);
  padding: 10px 26px; border-radius: 16px; text-align: center;
  background: rgba(10, 4, 24, 0.9); border: 3px solid var(--yellow); color: #fff;
  box-shadow: 0 0 30px rgba(255,210,63,0.7);
  animation: flashpop 1.6s ease forwards;
}
@keyframes flashpop {
  0% { transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.1) rotate(2deg); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.95); opacity: 0; }
}

/* UNO button is "armed" (pulsing) only when you're at 1-2 cards and it matters. */
.uno-btn.armed { animation: unopulse 0.7s infinite; }
@keyframes unopulse {
  50% { transform: scale(1.1); box-shadow: 0 4px 0 #7a4a00, 0 0 22px var(--yellow); }
}

/* ===== Cards ===== */
.card {
  width: 74px; height: 108px;
  border-radius: 11px;
  position: relative;
  display: grid; place-items: center;
  font-family: 'Rubik Mono One', sans-serif;
  user-select: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  border: 3px solid #fff;
  overflow: hidden;
}
.card .corner {
  position: absolute; font-size: 14px; line-height: 1;
}
.card .corner.tl { top: 6px; left: 7px; }
.card .corner.br { bottom: 6px; right: 7px; transform: rotate(180deg); }
.card .pip {
  font-size: 34px;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.25);
  z-index: 1;
}
/* white oval like a real UNO card */
.card::before {
  content: '';
  position: absolute; inset: 8px;
  background: rgba(255,255,255,0.16);
  border-radius: 50% / 42%;
  transform: rotate(-22deg);
}
.card.red { background: var(--red); }
.card.yellow { background: var(--yellow); }
.card.yellow .pip, .card.yellow .corner { color: #6b4a00; text-shadow: 1px 1px 0 rgba(255,255,255,0.4); }
.card.green { background: var(--green); }
.card.blue { background: var(--blue); }
.card.wild {
  background:
    conic-gradient(var(--red) 0 90deg, var(--green) 90deg 180deg, var(--blue) 180deg 270deg, var(--yellow) 270deg 360deg);
}
.card.wild .pip { font-size: 22px; }
.card .corner { font-weight: 700; }

.card.back {
  background: repeating-conic-gradient(from 0deg, var(--red) 0 22deg, var(--blue) 22deg 44deg);
  border-color: #fff;
}
.card.back::before { background: rgba(26,15,46,0.85); border-radius: 50%; inset: 14px; transform: none; }
.back-face { font-size: 30px; z-index: 1; }

.discard-pile .card { transform: rotate(-4deg); }

/* ===== Hand ===== */
.hand-area { width: 100%; }
.hand-actions { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 6px; }
.uno-btn {
  background: linear-gradient(135deg, var(--yellow), #ff8a00);
  box-shadow: 0 4px 0 #7a4a00; color: var(--ink); font-size: 16px; padding: 9px 22px;
}
.you-tag { font-size: 13px; opacity: 0.8; }
.hand {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px 14px;
  scroll-snap-type: x proximity;
  min-height: 130px; align-items: flex-end;
}
.hand .card {
  flex: 0 0 auto; scroll-snap-align: center;
  cursor: pointer; transition: transform 0.12s;
}
.hand .card.playable { box-shadow: 0 0 0 3px var(--yellow), 0 6px 14px rgba(0,0,0,0.5); }
.hand .card.playable:hover { transform: translateY(-14px) scale(1.05); }
.hand .card.dim { opacity: 0.5; }

/* ===== Log ===== */
.log {
  width: min(560px, 96vw);
  max-height: 56px; overflow-y: auto;
  font-size: 12.5px; line-height: 1.5; opacity: 0.85;
  background: rgba(0,0,0,0.25); border-radius: 10px; padding: 6px 12px;
  margin: 4px auto;
}
.log div:last-child { color: var(--yellow); }

/* ===== Chooser / overlays ===== */
.chooser {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(6,2,16,0.78); backdrop-filter: blur(4px);
}
.chooser-card {
  background: var(--panel); border: 2px solid var(--panel-edge);
  border-radius: 22px; padding: 26px 30px; text-align: center;
  box-shadow: 0 0 30px rgba(255,82,217,0.5);
}
.chooser-card h3 { margin: 0 0 16px; font-size: 22px; }
.color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.color-btn {
  width: 84px; height: 84px; border-radius: 16px; border: 3px solid #fff; cursor: pointer;
  transition: transform 0.1s;
}
.color-btn:hover { transform: scale(1.08); }
.color-btn.red { background: var(--red); }
.color-btn.yellow { background: var(--yellow); }
.color-btn.green { background: var(--green); }
.color-btn.blue { background: var(--blue); }

.win-card .win-emoji { font-size: 60px; animation: bob 0.7s infinite; }
.win-card h3 { font-size: 26px; }
.win-buttons { margin-top: 6px; }
.win-card .btn { margin: 8px 6px 0; }

/* ===== Scoreboard ===== */
.scoreboard {
  margin: 14px auto 4px;
  width: min(420px, 80vw);
  display: flex; flex-direction: column; gap: 6px;
  text-align: left;
}
.sb-head, .sb-row {
  display: grid;
  grid-template-columns: 1.6em 1fr auto auto;
  gap: 10px; align-items: center;
  padding: 7px 12px; border-radius: 10px;
}
.sb-head {
  font-size: 11px; letter-spacing: 1px; opacity: 0.6; text-transform: uppercase;
  padding: 2px 12px;
}
.sb-row { background: rgba(255,255,255,0.06); }
.sb-row.leader { background: rgba(255,210,63,0.16); border: 1px solid var(--yellow); }
.sb-row.winner-row .sb-name::after { content: ' 🎉'; }
.sb-rank { opacity: 0.6; font-size: 13px; }
.sb-av { font-size: 20px; }
.sb-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.sb-round { color: var(--green); font-size: 13px; min-width: 42px; text-align: right; }
.sb-round.zero { opacity: 0.35; color: var(--cream); }
.sb-total { font-family: 'Rubik Mono One', sans-serif; font-size: 18px; color: var(--yellow); min-width: 48px; text-align: right; }
.sb-cards { font-size: 13px; color: var(--cream); opacity: 0.8; min-width: 42px; text-align: right; }
.sb-target { font-size: 12px; opacity: 0.7; margin-top: 8px; }

/* running total badge on opponent chips */
.opp .pscore { font-size: 11px; color: var(--yellow); font-weight: 700; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--red); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-weight: 600; z-index: 30; box-shadow: 0 6px 18px rgba(0,0,0,0.5);
}

/* ===== Confetti ===== */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 14px; opacity: 0.9;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.3; }
}

@media (max-width: 420px) {
  .card { width: 58px; height: 86px; }
  .card .pip { font-size: 26px; }
  .opp { min-width: 78px; }
}
