* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --red: #e03131; --green: #2f9e44; --yellow: #f5b301; --blue: #1971c2;
  --bg: #171a38; --panel: #212549; --panel2: #2a2f5e;
  --ink: #eef0ff; --muted: rgba(238,240,255,.6);
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #232860, var(--bg) 70%);
  font-family: -apple-system, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; overflow-y: auto; padding: max(16px, env(safe-area-inset-top)) 0 max(16px, env(safe-area-inset-bottom)); }
.panel { text-align: center; padding: 30px 26px; width: min(400px, 92vw); margin: auto; animation: pin .3s ease; }
#game.screen { padding: 0; display: block; }
@keyframes pin { from { transform: translateY(16px) scale(.97); opacity: 0; } }

.logoCard {
  display: inline-block;
  background: var(--red);
  color: #fff; font-weight: 900; font-size: 30px; font-style: italic;
  padding: 22px 16px; border-radius: 16px;
  transform: rotate(-8deg);
  box-shadow: 0 10px 30px rgba(224,49,49,.4);
  margin-bottom: 12px;
  letter-spacing: 1px;
}
h1 { font-size: 46px; font-weight: 900; letter-spacing: 3px; margin-bottom: 8px; }
h1 span {
  background: linear-gradient(135deg, #ffe07a, #f5b301);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
h2 { font-size: 26px; font-weight: 900; letter-spacing: 3px; margin-bottom: 16px; }

input {
  width: 100%; padding: 13px 16px; margin: 14px 0 6px;
  border-radius: 14px; border: 2px solid var(--panel2);
  background: var(--panel); color: var(--ink);
  font-size: 16px; font-weight: 700; text-align: center; outline: none;
}
input:focus { border-color: var(--yellow); }

button { font-family: inherit; cursor: pointer; }
button.big {
  display: block; width: 100%; margin: 10px 0; padding: 15px 0;
  font-size: 17px; font-weight: 900; letter-spacing: 1.5px;
  color: #08331a; background: linear-gradient(135deg, #6dedb0, #22c76a);
  border: none; border-radius: 16px;
  box-shadow: 0 5px 0 #169148, 0 10px 24px rgba(0,0,0,.35);
  transition: transform .08s;
}
button.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #169148; }
button.big.alt { color: #0b2d4a; background: linear-gradient(135deg, #74c0fc, #339af0); box-shadow: 0 5px 0 #1c7ed6, 0 10px 24px rgba(0,0,0,.35); }
button.big:disabled { filter: grayscale(.8); opacity: .5; }
.ghost { display: inline-block; background: none; border: none; color: var(--muted); font-size: 14px; font-weight: 700; margin-top: 14px; text-decoration: none; padding: 8px; }
.mini { background: var(--panel2); color: var(--ink); border: none; padding: 9px 14px; border-radius: 12px; font-size: 13px; font-weight: 800; }
.err { color: #ff8787; font-weight: 700; font-size: 14px; min-height: 20px; margin-top: 8px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 600; }
.orSep { color: var(--muted); font-size: 13px; font-weight: 700; margin: 14px 0 6px; }
.joinRow { display: flex; gap: 8px; }
.joinRow input { flex: 1; margin: 0; text-transform: uppercase; letter-spacing: 4px; }
.joinRow button { padding: 0 22px; border: none; border-radius: 14px; font-weight: 900; background: var(--yellow); color: #4a2c00; font-size: 15px; }
.roomCode { font-size: 44px; font-weight: 900; letter-spacing: 10px; color: var(--yellow); margin: 4px 0 10px; text-shadow: 0 4px 18px rgba(245,179,1,.35); }
.lobbyPlayers { margin: 16px 0 8px; display: flex; flex-direction: column; gap: 8px; }
.lobbySeat { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 14px; padding: 10px 14px; font-weight: 800; font-size: 15px; }
.lobbySeat .dot { width: 18px; height: 18px; border-radius: 50%; flex: none; }
.lobbySeat .tag { margin-left: auto; font-size: 11px; font-weight: 800; color: var(--muted); letter-spacing: 1px; }
.lobbySeat.empty { opacity: .35; font-weight: 600; }
.lobbyBtns { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.countRow { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; }
.countBtn { width: 58px; height: 58px; border-radius: 16px; border: 2px solid var(--panel2); background: var(--panel); color: var(--ink); font-size: 22px; font-weight: 900; }
.countBtn.sel { border-color: var(--yellow); background: var(--panel2); box-shadow: 0 0 18px rgba(245,179,1,.25); }

/* ================= game ================= */
#tableWrap {
  position: relative; width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom));
}

/* opponents seated around the table */
#opps { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.opp {
  position: absolute; width: 92px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-weight: 800; opacity: .72; transition: opacity .25s;
}
.opp.seatL { left: 6px; top: 50%; transform: translateY(-50%); }
.opp.seatR { right: 6px; top: 50%; transform: translateY(-50%); }
.opp.seatT { left: 50%; top: 4px; transform: translateX(-50%); }
.opp.active { opacity: 1; }
.opp .avWrap {
  position: relative; width: 54px; height: 54px; border-radius: 50%;
  background: var(--panel); border: 3px solid var(--sc, #3a3f6e);
  display: flex; align-items: center; justify-content: center;
  font-size: 27px; line-height: 1;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  transition: box-shadow .25s;
}
.opp.active .avWrap {
  box-shadow: 0 0 0 3px #fff, 0 0 24px var(--sc, #fff);
  animation: seatPulse 1s ease-in-out infinite;
}
@keyframes seatPulse { 50% { transform: scale(1.08); } }
.opp .ct {
  position: absolute; bottom: -7px; right: -10px;
  background: #10132b; border: 2px solid var(--sc, #3a3f6e);
  border-radius: 12px; padding: 1px 7px;
  font-size: 12px; font-weight: 900; font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.opp.uno .ct { background: var(--red); border-color: #fff; animation: unoPulse .8s ease infinite; }
@keyframes unoPulse { 50% { transform: scale(1.25); } }
.opp .nm {
  font-size: 11px; max-width: 92px; margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
}
.opp .stars { display: block; font-size: 10px; }
.opp .timebar { height: 3px; width: 0%; max-width: 54px; background: var(--yellow); border-radius: 2px; }

/* card fly animation */
.ucard.flyCard {
  position: fixed; left: 0; top: 0; margin: 0;
  z-index: 45; pointer-events: none;
  transition: transform .38s cubic-bezier(.45,.05,.3,1);
  will-change: transform;
}
.ucard.preFly { visibility: hidden; }

#table {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 26px;
  position: relative; width: 100%;
}
#table::before {
  content: ''; position: absolute;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(340px, 84vw); height: min(340px, 46vh);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 38%, rgba(255,255,255,.09), rgba(255,255,255,.02) 68%);
  border: 2px solid rgba(255,255,255,.07);
  box-shadow: 0 30px 80px rgba(0,0,0,.35), inset 0 2px 30px rgba(255,255,255,.04);
  pointer-events: none;
}
#dirArrow {
  position: absolute; font-size: 140px; opacity: .09; pointer-events: none;
  transition: transform .4s;
}
#dirArrow.ccw { transform: scaleX(-1); }

#drawPile { position: relative; background: none; border: none; }
#drawPile .ucard.back { box-shadow: 3px 3px 0 #10132b, 6px 6px 0 #0c0e22, 0 12px 26px rgba(0,0,0,.5); }
#drawPile:active .ucard.back { transform: translateY(2px); }
#drawPile.canDraw .ucard.back { animation: drawGlow 1s ease-in-out infinite; }
@keyframes drawGlow { 50% { box-shadow: 3px 3px 0 #10132b, 6px 6px 0 #0c0e22, 0 0 26px rgba(245,179,1,.8); } }
#drawCt {
  position: absolute; bottom: -24px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.5); font-size: 11px; font-weight: 800;
  padding: 2px 10px; border-radius: 10px; z-index: 2;
}

#discard { position: relative; }
#discard .ucard { box-shadow: 0 12px 30px rgba(0,0,0,.5); }
#discard .ucard.drop { animation: drop .3s ease; }
@keyframes drop { from { transform: scale(1.5) rotate(-14deg); opacity: .3; } }

#colorRing {
  position: absolute; width: 26px; height: 26px; border-radius: 50%;
  left: calc(50% + 68px); top: calc(50% - 68px);
  border: 3px solid rgba(255,255,255,.85);
  box-shadow: 0 0 18px currentColor;
  transition: background .3s;
  z-index: 2;
}

#turnLabel { font-size: 14px; font-weight: 800; letter-spacing: 1px; min-height: 20px; }

#actionRow { display: flex; gap: 10px; min-height: 46px; align-items: center; padding: 4px; }
.actBtn {
  border: none; border-radius: 14px; padding: 10px 26px;
  font-size: 15px; font-weight: 900; letter-spacing: 1px;
  color: #08331a; background: linear-gradient(135deg, #6dedb0, #22c76a);
  box-shadow: 0 4px 0 #169148;
}
.actBtn.keep { color: var(--ink); background: var(--panel2); box-shadow: 0 4px 0 #1a1e42; }

#handWrap { width: 100%; overflow-x: auto; overflow-y: visible; padding: 18px 14px 6px; }
#hand { display: flex; justify-content: safe center; min-width: max-content; margin: 0 auto; padding: 0 8px; }
#hand .ucard { margin-left: -26px; transition: transform .15s; flex: none; }
#hand .ucard:first-child { margin-left: 0; }
#hand .ucard.playable { cursor: pointer; transform: translateY(-14px); box-shadow: 0 0 0 3px #fff, 0 14px 24px rgba(0,0,0,.45); z-index: 2; }
#hand .ucard.playable:active { transform: translateY(-20px) scale(1.05); }
#hand .ucard.justDrawn { animation: drawIn .35s ease; outline: 3px dashed rgba(255,255,255,.7); outline-offset: 2px; }
@keyframes drawIn { from { transform: translateY(40px) scale(.6); opacity: 0; } }

/* ------- card faces ------- */
.ucard {
  width: 68px; height: 100px; border-radius: 10px;
  position: relative; background: #777;
  border: 4px solid #fff;
  color: #fff; font-weight: 900;
  overflow: hidden;
  box-shadow: 0 4px 10px rgba(0,0,0,.35);
}
.ucard.red { background: var(--red); } .ucard.green { background: var(--green); }
.ucard.yellow { background: var(--yellow); } .ucard.blue { background: var(--blue); }
.ucard.wild { background: #1b1b28; }
.ucard .oval {
  position: absolute; inset: 8% 14%;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  transform: rotate(28deg);
}
.ucard .mid {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-style: italic;
  text-shadow: 2px 2px 0 rgba(0,0,0,.35);
}
.ucard .mid.small { font-size: 22px; font-style: normal; }
.ucard .tl, .ucard .br { position: absolute; font-size: 13px; font-style: italic; }
.ucard .tl { top: 4px; left: 7px; }
.ucard .br { bottom: 4px; right: 7px; transform: rotate(180deg); }
.ucard .quad {
  position: absolute; inset: 18%;
  border-radius: 50%; transform: rotate(28deg);
  background: conic-gradient(var(--red) 0 25%, var(--blue) 0 50%, var(--yellow) 0 75%, var(--green) 0);
  border: 3px solid #fff;
}
.ucard.back {
  background: #1b1b28;
}
.ucard.back::after {
  content: 'UNO';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-style: italic; font-weight: 900;
  color: var(--red);
  background: radial-gradient(ellipse at center, rgba(224,49,49,.25), transparent 70%);
  transform: rotate(-20deg);
}

#colorGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 6px 20px 10px; }
.colorBtn { height: 86px; border-radius: 18px; border: 4px solid #fff; box-shadow: 0 8px 20px rgba(0,0,0,.4); transition: transform .1s; }
.colorBtn:active { transform: scale(.94); }
.colorBtn[data-color="red"] { background: var(--red); }
.colorBtn[data-color="green"] { background: var(--green); }
.colorBtn[data-color="yellow"] { background: var(--yellow); }
.colorBtn[data-color="blue"] { background: var(--blue); }

.quit { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px; width: 44px; height: 44px; border-radius: 12px; border: none; background: rgba(255,255,255,.1); color: var(--ink); font-size: 22px; font-weight: 800; z-index: 5; }
.quit:active, .mini:active { transform: scale(.94); }

#toast {
  position: absolute; top: 20%; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.65); color: #fff; font-weight: 800; font-size: 14px;
  padding: 8px 18px; border-radius: 18px; opacity: 0; transition: opacity .25s;
  pointer-events: none; white-space: nowrap; z-index: 30;
}
#toast.show { opacity: 1; }

#unoFlash {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-8deg);
  font-size: 74px; font-weight: 900; font-style: italic;
  color: var(--yellow); text-shadow: 4px 4px 0 var(--red), 0 10px 40px rgba(0,0,0,.6);
  animation: unoIn .9s ease; pointer-events: none; z-index: 20;
}
@keyframes unoIn { 0% { transform: translate(-50%,-50%) scale(.2) rotate(-30deg); opacity: 0; } 30% { transform: translate(-50%,-50%) scale(1.2) rotate(-8deg); opacity: 1; } }

#rankList { margin: 6px 0 14px; display: flex; flex-direction: column; gap: 8px; }
.rankRow { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 14px; padding: 10px 14px; font-weight: 800; font-size: 15px; }
.rankRow .medal { font-size: 20px; }
.rankRow .sc { margin-left: auto; color: var(--muted); font-size: 12px; }

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

/* ---------- house rules ---------- */
.rulesBox { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; text-align: left; }
.ruleTgl {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border-radius: 12px; padding: 10px 12px;
  font-weight: 800; font-size: 13px; cursor: pointer;
}
.ruleTgl input { width: 18px; height: 18px; accent-color: var(--yellow); flex: none; }
.ruleTgl i { display: block; font-style: normal; font-weight: 600; font-size: 11px; color: var(--muted); }
.ruleTgl.locked { opacity: .55; pointer-events: none; }

#btnUno {
  position: absolute; right: 14px; bottom: 138px;
  width: 74px; height: 74px; border-radius: 50%;
  border: 4px solid #fff;
  background: radial-gradient(circle at 35% 30%, #ff8a8a, var(--red) 60%);
  color: #fff; font-weight: 900; font-style: italic; font-size: 19px;
  box-shadow: 0 6px 20px rgba(224,49,49,.6);
  animation: unoBtn .8s ease-in-out infinite;
  z-index: 6;
}
@keyframes unoBtn { 50% { transform: scale(1.12); box-shadow: 0 6px 30px rgba(224,49,49,.9); } }
#btnUno.armed { background: radial-gradient(circle at 35% 30%, #8affb0, var(--green) 60%); animation: none; box-shadow: 0 0 22px rgba(47,158,68,.8); }

#drawPile .pendingBadge {
  position: absolute; top: -10px; right: -10px;
  background: var(--red); color: #fff;
  font-weight: 900; font-size: 15px;
  padding: 4px 10px; border-radius: 14px;
  border: 2px solid #fff;
  animation: unoBtn .7s ease-in-out infinite;
}

#swapList { display: flex; flex-direction: column; gap: 10px; }
#swapList button {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 2px solid var(--panel2); border-radius: 14px;
  color: var(--ink); padding: 12px 16px; font-weight: 800; font-size: 15px;
}
#swapList button:active { border-color: var(--yellow); }
#swapList .dot { width: 14px; height: 14px; border-radius: 50%; }
#swapList .ct { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ---------- best-of-3 match ---------- */
.modeBtn {
  flex: 1; max-width: 150px; height: 48px; border-radius: 14px;
  border: 2px solid var(--panel2); background: var(--panel); color: var(--ink);
  font-size: 13px; font-weight: 900; letter-spacing: 1px;
}
.modeBtn.sel { border-color: var(--yellow); background: var(--panel2); box-shadow: 0 0 18px rgba(245,179,1,.25); }

#matchChip {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px;
  background: rgba(0,0,0,.4); border: 1px solid rgba(255,255,255,.15);
  border-radius: 12px; padding: 6px 10px;
  font-size: 11px; font-weight: 800; letter-spacing: .5px;
  color: var(--ink); z-index: 5; pointer-events: none;
}
#matchChip .stars, .opp .stars { color: var(--yellow); }

#matchBanner {
  font-size: 14px; font-weight: 800; color: var(--muted); margin: -6px 0 10px;
}

.rankRow .wins { color: var(--yellow); font-size: 13px; letter-spacing: 2px; }

.shareBtn {
  display: block; width: 100%; margin: 2px 0 4px; padding: 12px 0;
  font-size: 14px; font-weight: 900; letter-spacing: 1px;
  color: #08331a; background: linear-gradient(135deg, #63e6be, #20c997);
  border: none; border-radius: 14px; box-shadow: 0 4px 0 #099268;
}
.shareBtn:active { transform: translateY(2px); box-shadow: 0 2px 0 #099268; }

/* ---------- emotes ---------- */
#btnEmote {
  position: absolute; left: 14px; bottom: 138px;
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25); background: var(--panel);
  font-size: 22px; z-index: 6;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
#btnEmote:active { transform: scale(.92); }
#emoteTray {
  position: absolute; left: 12px; bottom: 192px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  background: var(--panel); border: 2px solid var(--panel2);
  border-radius: 16px; padding: 8px; z-index: 7;
  box-shadow: 0 10px 26px rgba(0,0,0,.5);
  animation: pin .18s ease;
}
#emoteTray button {
  border: none; background: var(--panel2); border-radius: 12px;
  padding: 8px 6px; color: var(--ink);
  font-size: 20px; line-height: 1.1;
}
#emoteTray button small { display: block; font-size: 9px; font-weight: 800; color: var(--muted); }
#emoteTray button:active { background: #3a4080; }

.emoteBub {
  position: fixed; z-index: 25;
  background: #fff; color: #1b1b28;
  font-size: 13px; font-weight: 800;
  padding: 6px 11px; border-radius: 14px;
  white-space: nowrap; pointer-events: none;
  box-shadow: 0 6px 16px rgba(0,0,0,.4);
  transform: translateX(-50%);
  animation: bubIn .2s ease;
}
@keyframes bubIn { from { transform: translateX(-50%) scale(.5); opacity: 0; } }
.emoteBub.unoCall {
  background: var(--yellow); color: #4a2c00;
  font-style: italic; font-weight: 900; font-size: 16px;
  border: 2px solid #fff;
  box-shadow: 0 6px 20px rgba(245,179,1,.55);
}
#myEmoteBub {
  position: absolute; left: 16px; bottom: 196px; transform: none;
  animation: bubInMy .2s ease;
}
@keyframes bubInMy { from { transform: scale(.5); opacity: 0; } }

/* ---------- coins / economy ---------- */
.coinChip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.28); border-radius: 16px; padding: 5px 14px;
  color: #ffd75e; font-weight: 800; font-size: 15px;
  font-variant-numeric: tabular-nums;
}
#coinChipHome { margin-bottom: 4px; }
.coinIcon {
  display: inline-block;
  width: 15px; height: 15px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a0, #f5b820 65%, #c78a00);
  box-shadow: inset 0 0 0 2px rgba(160,110,0,.5);
}
#coinWin {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0 auto 12px; padding: 8px 18px; border-radius: 16px;
  background: rgba(245,184,32,.14); border: 1px solid rgba(245,184,32,.4);
  color: #ffd75e; font-weight: 900; font-size: 20px;
  font-variant-numeric: tabular-nums;
  animation: coinPop .5s cubic-bezier(.2,1.4,.4,1);
}
#coinWin .coinIcon { width: 18px; height: 18px; }
@keyframes coinPop { from { transform: scale(.4); opacity: 0; } }
