:root {
  --red: #D72600;
  --yellow: #ECD407;
  --green: #379711;
  --blue: #0956BF;
  --felt: #0f5a2e;
  --felt-dark: #073519;
  --ink: #0d1b12;
  --cw: 92px; /* hand card width */
  --tw: 110px; /* table card width */
  font-family: "Nunito", system-ui, sans-serif;
  color: #fff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 40%, #18803f 0%, var(--felt) 45%, var(--felt-dark) 100%) fixed;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; }
.hidden { display: none !important; }

/* ---------- generic ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 12px 20px; cursor: pointer;
  font-weight: 900; letter-spacing: .3px; color: #fff; background: #1f2937;
  box-shadow: 0 4px 0 rgba(0,0,0,.35); transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.red { background: var(--red); }
.btn.yellow { background: var(--yellow); color: #222; }
.btn.green { background: var(--green); }
.btn.blue { background: var(--blue); }
.btn.ghost { background: rgba(255,255,255,.12); box-shadow: none; }
.btn.small { padding: 6px 12px; border-radius: 10px; font-size: 14px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 2px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.25); color: #fff; outline: none; font-weight: 800;
}
.input:focus { border-color: var(--yellow); }
.panel {
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.12); border-radius: 20px;
  padding: 20px; backdrop-filter: blur(6px);
}
.panel h2 { margin: 0 0 12px; font-size: 18px; text-transform: uppercase; letter-spacing: 1px; opacity: .85; }
.row { display: flex; gap: 10px; align-items: center; }
.muted { opacity: .7; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: #111; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 800;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 90vw; text-align: center;
}

/* ---------- cards ---------- */
.card { width: var(--cw); aspect-ratio: 2 / 3; position: relative; flex: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,.45)); }
.card-svg { width: 100%; height: 100%; display: block; }

/* ---------- home ---------- */
.home { max-width: 1040px; margin: 0 auto; padding: 28px 18px 60px; }
.logo { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 10px 0 28px; }
.logo .fan { display: flex; }
.logo .fan .card { --cw: 64px; margin-left: -28px; }
.logo .fan .card:nth-child(1) { transform: rotate(-18deg) translateY(8px); margin-left: 0; }
.logo .fan .card:nth-child(2) { transform: rotate(-6deg); }
.logo .fan .card:nth-child(3) { transform: rotate(6deg); }
.logo .fan .card:nth-child(4) { transform: rotate(18deg) translateY(8px); }
.logo h1 {
  font-family: "Archivo Black", sans-serif; font-style: italic; font-size: 64px; margin: 0; line-height: 1;
  color: var(--yellow); -webkit-text-stroke: 3px #000; text-shadow: 4px 5px 0 #000; transform: rotate(-6deg);
}
.logo h1 small { display: block; font-size: 20px; color: #fff; -webkit-text-stroke: 0; text-shadow: 2px 2px 0 #000; letter-spacing: 6px; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .home-grid { grid-template-columns: 1fr; } .logo h1 { font-size: 46px; } }
.stack { display: flex; flex-direction: column; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; font-weight: 700; }
.check input { width: 18px; height: 18px; accent-color: var(--yellow); }
.list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; }
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: rgba(255,255,255,.07); padding: 10px 12px; border-radius: 12px; font-weight: 800;
}
.code { font-family: "Archivo Black", monospace; letter-spacing: 3px; }
.lb-rank { width: 28px; display: inline-block; opacity: .7; }

/* ---------- lobby ---------- */
.lobby { max-width: 860px; margin: 0 auto; padding: 24px 16px 60px; }
.room-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.room-head h1 { margin: 0; font-family: "Archivo Black"; font-style: italic; font-size: 30px; text-shadow: 2px 3px 0 #000; }
.code-box {
  display: flex; align-items: center; gap: 10px; background: #000; padding: 8px 8px 8px 16px; border-radius: 14px;
}
.code-box .code { font-size: 28px; color: var(--yellow); }
.players-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.player-chip {
  display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.08); padding: 10px; border-radius: 14px; font-weight: 800;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-family: "Archivo Black"; font-size: 18px; border: 3px solid #fff; box-shadow: 0 2px 0 #000;
}
.player-chip .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: rgba(255,255,255,.15); font-weight: 900; text-transform: uppercase; }
.tag.host { background: var(--yellow); color: #000; }
.tag.off { background: #555; }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 12px; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-weight: 800; font-size: 14px; }
.settings select { padding: 8px; border-radius: 10px; background: rgba(0,0,0,.3); color: #fff; border: 2px solid rgba(255,255,255,.2); }
.settings select option { color: #000; }

/* ---------- game table ---------- */
.game { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: 1fr auto; overflow: hidden; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: rgba(0,0,0,.3); }
.topbar .title { font-weight: 900; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) { .topbar .title { font-size: 13px; } .seat { min-width: 96px; padding: 6px 8px 4px; } .mini-fan { height: 36px; } .mini-fan .card { --cw: 24px; margin-left: -15px; } }
.table { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 10px; min-height: 0; }
.opponents { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 14px; width: 100%; }
.seat {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 10px 6px;
  border-radius: 16px; background: rgba(0,0,0,.25); min-width: 108px; transition: box-shadow .2s, transform .2s;
  border: 2px solid transparent;
}
.seat.turn { border-color: var(--yellow); box-shadow: 0 0 0 4px rgba(236,212,7,.25), 0 0 24px rgba(236,212,7,.5); transform: translateY(2px) scale(1.04); }
.seat.offline { opacity: .55; }
.seat .sname { font-weight: 900; font-size: 14px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .count { font-family: "Archivo Black"; font-size: 13px; opacity: .85; }
.mini-fan { display: flex; height: 44px; align-items: flex-end; padding-left: 16px; }
.mini-fan .card { --cw: 30px; margin-left: -18px; }
.uno-badge {
  position: absolute; top: -10px; right: -8px; background: var(--red); color: var(--yellow); font-family: "Archivo Black";
  font-style: italic; padding: 2px 8px; border-radius: 999px; border: 2px solid #000; font-size: 13px; transform: rotate(8deg);
  -webkit-text-stroke: .5px #000; animation: pop .4s ease;
}
.catch-btn { position: absolute; bottom: -14px; z-index: 2; animation: throb 0.8s infinite; }
.timer-bar { position: absolute; left: 8px; right: 8px; bottom: 2px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.2); overflow: hidden; }
.timer-bar i { display: block; height: 100%; background: var(--yellow); transform-origin: left; }

.center { display: flex; align-items: center; justify-content: center; gap: clamp(20px, 6vw, 60px); position: relative; padding: 10px 0; }
.pile { position: relative; width: var(--tw); aspect-ratio: 2/3; }
.pile .card { --cw: var(--tw); position: absolute; inset: 0; }
.draw-pile { cursor: default; }
.draw-pile.can { cursor: pointer; }
.draw-pile.can .card:last-child { animation: nudge 1.4s ease-in-out infinite; }
.draw-pile .card:nth-child(1) { transform: translate(-4px, 4px); }
.draw-pile .card:nth-child(2) { transform: translate(-2px, 2px); }
.pile-label { position: absolute; bottom: -24px; left: 0; right: 0; text-align: center; font-weight: 900; font-size: 13px; opacity: .8; }
.discard .card { transition: transform .25s; }
.discard .card.fresh { animation: land .35s cubic-bezier(.2,1.4,.4,1); }
.color-ring {
  position: absolute; inset: -14px; border-radius: 22px; border: 6px solid var(--ring, #fff);
  box-shadow: 0 0 24px var(--ring, #fff), inset 0 0 18px var(--ring, #fff); opacity: .9; transition: border-color .3s, box-shadow .3s;
}
.direction {
  position: absolute; width: calc(var(--tw) * 3.4); aspect-ratio: 1; border-radius: 50%; pointer-events: none;
  border: 3px dashed rgba(255,255,255,.18); animation: spin 14s linear infinite;
}
.direction.ccw { animation-direction: reverse; }
.direction::before, .direction::after {
  content: "➤"; position: absolute; font-size: 22px; color: rgba(255,255,255,.35);
}
.direction::before { top: -14px; left: 50%; transform: translateX(-50%); }
.direction::after { bottom: -14px; left: 50%; transform: translateX(-50%) rotate(180deg); }
.direction.ccw::before { transform: translateX(-50%) rotate(180deg); }
.direction.ccw::after { transform: translateX(-50%); }
.stack-badge {
  position: absolute; top: -18px; right: -18px; background: var(--red); border: 3px solid #fff; color: #fff; border-radius: 50%;
  width: 46px; height: 46px; display: grid; place-items: center; font-family: "Archivo Black"; z-index: 3;
}

.status { font-weight: 900; font-size: 18px; text-align: center; text-shadow: 0 2px 0 #000; min-height: 26px; }
.status.me { color: var(--yellow); animation: pulse-text 1.2s infinite; }

.me-area { grid-column: 1 / 2; padding: 6px 10px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.me-bar { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; min-height: 48px; }
.hand { display: flex; justify-content: center; padding: 26px 20px 4px; max-width: 100%; overflow-x: auto; overflow-y: visible; scrollbar-width: thin; }
.hand .card { margin-left: calc(var(--overlap, -30px)); transition: transform .15s, filter .15s; cursor: default; }
.hand .card:first-child { margin-left: 0; }
.hand.myturn .card.playable { cursor: pointer; transform: translateY(-14px); filter: drop-shadow(0 0 8px rgba(255,255,255,.8)) drop-shadow(0 3px 4px rgba(0,0,0,.45)); }
.hand.myturn .card.playable:hover { transform: translateY(-26px) scale(1.05); z-index: 5; }
.hand.myturn .card:not(.playable) { filter: brightness(.55) drop-shadow(0 3px 4px rgba(0,0,0,.45)); }
.hand .card.drawn { outline: 4px solid var(--yellow); border-radius: 10px; }
.hand .card.new { animation: deal .35s ease-out; }

.uno-btn {
  font-family: "Archivo Black"; font-style: italic; font-size: 26px; color: var(--yellow); background: var(--red);
  border: 4px solid #fff; border-radius: 50% / 40%; padding: 6px 26px; cursor: pointer; transform: rotate(-8deg);
  box-shadow: 0 5px 0 #000; -webkit-text-stroke: 1.5px #000; text-shadow: 2px 2px 0 #000; animation: pulse .9s infinite;
}
.uno-btn:active { transform: rotate(-8deg) translateY(4px); box-shadow: 0 1px 0 #000; }

/* ---------- side panel (log + chat) ---------- */
.side { grid-row: 2 / 4; grid-column: 2; width: 300px; display: flex; flex-direction: column; background: rgba(0,0,0,.35); min-height: 0; }
.side .tabs { display: flex; }
.side .tabs button { flex: 1; padding: 10px; background: none; border: 0; color: #fff; font-weight: 900; cursor: pointer; opacity: .6; border-bottom: 3px solid transparent; }
.side .tabs button.on { opacity: 1; border-color: var(--yellow); }
.feed { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.feed .line { background: rgba(255,255,255,.06); padding: 6px 9px; border-radius: 10px; line-height: 1.3; }
.feed .line b { color: var(--yellow); }
.feed .line.bot b { color: #7dd3fc; }
.chat-form { display: flex; gap: 6px; padding: 8px; }
.chat-form .input { padding: 8px 10px; }
@media (max-width: 900px) {
  .game { grid-template-columns: 1fr; }
  .side { position: fixed; right: 0; top: 48px; bottom: 0; z-index: 40; transform: translateX(100%); transition: transform .25s; width: min(320px, 88vw); background: rgba(5,30,15,.97); }
  .side.open { transform: none; }
  :root { --cw: 70px; --tw: 84px; }
}
@media (max-height: 700px) { :root { --cw: 66px; --tw: 78px; } }

/* ---------- modals ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 60; animation: fade .2s; padding: 16px; }
.modal { background: #0b2f18; border: 2px solid rgba(255,255,255,.2); border-radius: 22px; padding: 22px; max-width: 560px; width: 100%; max-height: 90dvh; overflow: auto; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal h2 { margin: 0 0 14px; font-family: "Archivo Black"; font-style: italic; font-size: 28px; }
.color-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 280px; margin: 0 auto; }
.color-pick button { aspect-ratio: 1.3; border-radius: 18px; border: 4px solid #fff; cursor: pointer; box-shadow: 0 5px 0 #000; transition: transform .1s; }
.color-pick button:hover { transform: scale(1.06); }
.results { display: flex; flex-direction: column; gap: 8px; text-align: left; margin: 14px 0; }
.results .rrow { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.07); padding: 8px 10px; border-radius: 12px; }
.results .rrow .cards { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; }
.results .rrow .cards .card { --cw: 26px; }
.results .rrow .pts { font-family: "Archivo Black"; min-width: 60px; text-align: right; }
.winner-big { font-size: 22px; font-weight: 900; color: var(--yellow); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall linear forwards; }

/* ---------- animations ---------- */
@keyframes pop { from { transform: scale(0) rotate(8deg); } 70% { transform: scale(1.3) rotate(8deg); } }
@keyframes pulse { 50% { transform: scale(1.07) rotate(-8deg); } }
@keyframes throb { 50% { transform: scale(1.08); } }
@keyframes pulse-text { 50% { opacity: .6; } }
@keyframes nudge { 50% { transform: translateY(-6px); } }
@keyframes land { from { transform: translateY(-120px) scale(1.3) rotate(-25deg); opacity: 0; } }
@keyframes deal { from { transform: translateY(-80px) scale(.6); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- moderation ---------- */
.seat { cursor: pointer; }
.seat-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.seat-tags .tag { font-size: 10px; padding: 1px 6px; }
.vote-bar {
  position: fixed; bottom: calc(var(--cw) * 1.5 + 120px); left: 50%; transform: translateX(-50%); z-index: 55; width: min(640px, 94vw);
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: #1b1030; border: 2px solid var(--yellow); border-radius: 16px; padding: 10px 14px; font-weight: 800;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: fade .2s;
}
.btn.on { outline: 3px solid #fff; }
.modal.menu { max-width: 420px; }
.modal.menu h3 { margin: 10px 0 0; text-align: left; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; opacity: .75; }
.modal.menu .btn { width: 100%; }
.modal.menu .btn .muted { font-size: 12px; font-weight: 700; }
.player-row { display: flex; align-items: center; gap: 10px; text-align: left; padding: 8px 12px; }
.player-row span:nth-child(2) { flex: 1; }
.player-row .avatar { width: 30px; height: 30px; font-size: 14px; border-width: 2px; }
.menu-select { display: flex; flex-direction: column; gap: 6px; text-align: left; font-weight: 800; font-size: 14px; }
.menu-select select { padding: 8px; border-radius: 10px; background: rgba(0,0,0,.3); color: #fff; border: 2px solid rgba(255,255,255,.2); }
.menu-select select option { color: #000; }
