:root {
  --ink: #f9f5e7;
  --muted: #b4c8bf;
  --felt: #0c352b;
  --felt-deep: #071d18;
  --panel: rgba(5, 25, 21, 0.76);
  --gold: #f1c35d;
  --orange: #e68038;
  --red: #d94a45;
  --card-w: clamp(54px, 17vw, 76px);
  --card-h: calc(var(--card-w) * 1.42);
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--felt-deep);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; overscroll-behavior: none; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% 25%, rgba(40, 111, 83, .48), transparent 42%),
    linear-gradient(155deg, #123d31 0%, var(--felt-deep) 85%);
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.shell {
  width: min(100%, 620px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}

.home { display: grid; align-content: center; gap: 24px; }
.brand-lockup { text-align: center; animation: rise .6s ease both; }
.brand-mark { width: 92px; height: 92px; filter: drop-shadow(0 18px 22px rgba(0,0,0,.28)); }
.brand-lockup h1 { font-size: clamp(44px, 14vw, 68px); line-height: .95; margin: 13px 0 9px; letter-spacing: -.06em; }
.brand-lockup p { max-width: 340px; color: var(--muted); margin: 0 auto; line-height: 1.45; }

.glass-card {
  background: linear-gradient(145deg, rgba(255,255,255,.1), rgba(255,255,255,.045));
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 24px;
  box-shadow: 0 22px 65px rgba(0,0,0,.25);
  backdrop-filter: blur(18px);
}

.home-actions { padding: 20px; display: grid; gap: 13px; animation: rise .6s .08s ease both; }
.field { display: grid; gap: 7px; }
.field label { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.field input {
  width: 100%; border: 1px solid rgba(255,255,255,.13); color: var(--ink); background: rgba(2,18,14,.55);
  border-radius: 14px; padding: 14px 15px; outline: none; font-size: 16px;
}
.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(241,195,93,.13); }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.room-input { text-transform: uppercase; letter-spacing: .14em; font-weight: 800; }
.or { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; color: #7f9d90; font-size: 12px; }
.or::before, .or::after { content: ""; height: 1px; background: rgba(255,255,255,.1); }

.btn {
  border: 0; border-radius: 14px; padding: 13px 17px; min-height: 48px; cursor: pointer; color: #11271f;
  background: linear-gradient(135deg, var(--gold), #e79c3e); font-weight: 850; box-shadow: 0 8px 20px rgba(231,156,62,.2);
  transition: transform .15s ease, filter .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn.secondary { color: var(--ink); background: rgba(255,255,255,.1); box-shadow: none; border: 1px solid rgba(255,255,255,.12); }
.btn.danger { color: white; background: linear-gradient(135deg, #e95e4f, #bd3838); }
.btn.small { min-height: 38px; padding: 8px 12px; font-size: 13px; border-radius: 11px; }
.btn.icon { width: 42px; min-height: 42px; padding: 0; display: grid; place-items: center; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.eyebrow { color: var(--gold); font-size: 11px; text-transform: uppercase; font-weight: 900; letter-spacing: .13em; }
.topbar h1 { margin: 2px 0 0; font-size: 26px; letter-spacing: -.04em; }
.connection { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.connection-dot { width: 9px; height: 9px; background: #57cf8a; border-radius: 50%; box-shadow: 0 0 0 4px rgba(87,207,138,.14); }
.connection.offline .connection-dot { background: #e77f4d; box-shadow: 0 0 0 4px rgba(231,127,77,.14); }

.lobby { display: grid; align-content: start; gap: 16px; }
.invite { padding: 20px; text-align: center; }
.invite p { margin: 0; color: var(--muted); }
.room-code { margin: 8px 0 14px; font-size: clamp(34px, 11vw, 52px); letter-spacing: .15em; font-weight: 950; color: var(--gold); }
.lobby-list { padding: 8px; display: grid; gap: 6px; }
.lobby-player { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 11px; padding: 10px; border-radius: 15px; }
.lobby-player + .lobby-player { border-top: 1px solid rgba(255,255,255,.07); }
.avatar { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: linear-gradient(135deg, #2d7159, #184737); font-weight: 900; }
.player-meta strong { display: block; }
.player-meta span { color: var(--muted); font-size: 12px; }
.host-actions { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; }
.hint { color: var(--muted); text-align: center; font-size: 12px; line-height: 1.4; }

.peek-screen { min-height: calc(100dvh - 40px); display: grid; align-content: center; justify-items: center; gap: 22px; text-align: center; }
.peek-screen h1 { margin: 0 0 7px; font-size: 32px; }
.peek-screen p { margin: 0; color: var(--muted); max-width: 340px; }
.peek-cards { display: flex; gap: 15px; }

.playing-shell { padding-left: 10px; padding-right: 10px; display: flex; flex-direction: column; }
.game-header { display: flex; justify-content: space-between; align-items: center; padding: 0 6px 8px; }
.game-header .room-mini { font-weight: 900; letter-spacing: .12em; }
.game-header .round-info { color: var(--muted); font-size: 12px; }
.status-pill {
  min-height: 42px; display: grid; place-items: center; text-align: center; margin: 0 4px 10px; padding: 8px 14px;
  border-radius: 15px; color: #183025; background: linear-gradient(135deg, #f7d777, #eaa64a); font-weight: 850; font-size: 14px;
  box-shadow: 0 8px 25px rgba(231,156,62,.18);
}
.status-pill.reaction { background: linear-gradient(135deg, #ff755c, #e3aa4f); color: white; animation: reactionGlow 1s ease infinite alternate; }

.table { flex: 1; min-height: calc(100dvh - 125px); display: grid; grid-template-rows: minmax(155px, 1fr) auto minmax(215px, 1.12fr); gap: 8px; }
.opponents { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; align-content: start; }
.opponents.count-1 { grid-template-columns: minmax(0, 230px); justify-content: center; }
.player-zone { position: relative; border-radius: 18px; padding: 8px; border: 1px solid transparent; transition: background .25s, border .25s, transform .25s; }
.player-zone.active { background: rgba(241,195,93,.09); border-color: rgba(241,195,93,.45); }
.player-zone.event-pulse { animation: zonePulse .65s ease; }
.player-label { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 6px; font-size: 12px; font-weight: 800; white-space: nowrap; overflow: hidden; }
.player-label .cards-left { color: var(--muted); font-weight: 600; }
.mini-grid { display: grid; grid-template-columns: repeat(2, var(--mini-w, 36px)); grid-template-rows: repeat(2, calc(var(--mini-w, 36px) * 1.42)); gap: 4px; justify-content: center; }
.opponents.count-1 .mini-grid { --mini-w: 42px; }

.center-table { display: flex; justify-content: center; align-items: center; gap: 16px; min-height: 118px; }
.pile-wrap { display: grid; justify-items: center; gap: 5px; position: relative; }
.pile-label { color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.deck-stack::before, .deck-stack::after { content: ""; position: absolute; inset: 0; border-radius: 8px; background: #ebdebf; border: 1px solid rgba(0,0,0,.2); }
.deck-stack::before { transform: translate(4px, -4px); z-index: -2; }
.deck-stack::after { transform: translate(2px, -2px); z-index: -1; }
.deck-stack { position: relative; }
.deck-stack.deck-bump { animation: deckBump .55s ease; }
.deck-count { position: absolute; right: -8px; bottom: -8px; min-width: 24px; height: 24px; display: grid; place-items: center; border-radius: 12px; background: var(--gold); color: #173126; font-size: 11px; font-weight: 900; z-index: 3; }
.discard-slot { width: var(--card-w); height: var(--card-h); border: 2px dashed rgba(255,255,255,.15); border-radius: 10px; }

.self-zone { align-self: end; display: grid; justify-items: center; gap: 9px; padding: 8px 5px 0; }
.self-zone .player-label { font-size: 14px; }
.self-grid { display: grid; grid-template-columns: repeat(2, var(--card-w)); grid-template-rows: repeat(2, var(--card-h)); gap: 7px; }
.self-grid .slot.empty { width: var(--card-w); height: var(--card-h); }
.self-actions { min-height: 50px; display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; }
.self-zone.decision-zone { grid-template-columns: auto auto; column-gap: 13px; align-items: center; justify-content: center; }
.self-zone.decision-zone .player-label { grid-column: 1 / -1; }
.self-zone.decision-zone .self-actions { align-self: center; }
.self-zone.decision-zone .drawn-tray { flex-direction: column; gap: 6px; }
.self-zone.decision-zone .drawn-tray > div:last-child { display: grid; justify-items: center; gap: 3px; }
.self-zone.decision-zone .drawn-tray p { margin: 0; }
.drawn-tray { display: flex; align-items: center; gap: 10px; }
.drawn-card { animation: drawIn .55s cubic-bezier(.2,.85,.25,1.15) both; }
.gringo-button { letter-spacing: .06em; }

.slot { position: relative; border: 0; background: transparent; padding: 0; border-radius: 10px; }
.slot.selectable { cursor: pointer; animation: selectGlow 1s ease infinite alternate; }
.slot.selectable:active { transform: scale(.94); }
.slot.empty { border: 2px dashed rgba(255,255,255,.16); }
.slot.empty.selectable::after { content: "+"; position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,.3); font-size: 30px; }

.card {
  width: var(--card-w); height: var(--card-h); border-radius: 10px; position: relative; overflow: hidden; user-select: none;
  box-shadow: 0 7px 13px rgba(0,0,0,.28); transform-style: preserve-3d;
}
.mini-grid .card { width: var(--mini-w, 36px); height: calc(var(--mini-w, 36px) * 1.42); border-radius: 6px; box-shadow: 0 4px 7px rgba(0,0,0,.23); }
.card.face { background: linear-gradient(145deg, #fffdf4, #eadfc7); color: #16251f; border: 1px solid rgba(0,0,0,.17); }
.card.face.red { color: #c63737; }
.card.back {
  border: 3px solid #eee2c4;
  background-color: #c96c2e;
  background-image:
    linear-gradient(30deg, rgba(255,255,255,.12) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,.12) 87.5%),
    linear-gradient(150deg, rgba(255,255,255,.12) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,.12) 87.5%),
    linear-gradient(30deg, rgba(255,255,255,.12) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,.12) 87.5%),
    linear-gradient(150deg, rgba(255,255,255,.12) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,.12) 87.5%),
    linear-gradient(60deg, rgba(6,48,38,.38) 25%, transparent 25.5%, transparent 75%, rgba(6,48,38,.38) 75%);
  background-size: 20px 35px;
  background-position: 0 0, 0 0, 10px 17px, 10px 17px, 0 0;
}
.card.back::after { content: "G"; position: absolute; inset: 8%; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.35); border-radius: 50%; color: rgba(255,255,255,.78); font-size: calc(var(--card-w) * .4); font-weight: 950; }
.corner { position: absolute; top: 6px; left: 7px; display: grid; line-height: .9; justify-items: center; font-size: calc(var(--card-w) * .21); font-weight: 950; }
.corner.bottom { inset: auto 7px 6px auto; transform: rotate(180deg); }
.suit-big { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--card-w) * .54); }
.joker-word { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--card-w) * .15); font-weight: 950; letter-spacing: .08em; transform: rotate(-55deg); color: #d06e2d; }
.card.reveal-pop { animation: flipIn .48s cubic-bezier(.2,.8,.2,1.1) both; }

.power-panel { padding: 11px 13px; display: grid; gap: 8px; text-align: center; min-width: min(92vw, 360px); }
.power-panel strong { color: var(--gold); }
.power-buttons { display: flex; justify-content: center; gap: 8px; }
.reaction-meter { width: min(280px, 78vw); height: 5px; border-radius: 5px; overflow: hidden; background: rgba(255,255,255,.12); }
.reaction-meter span { display: block; height: 100%; background: #ff765d; transform-origin: left; animation: drain var(--reaction-time, 3.5s) linear forwards; }

.modal-backdrop { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 18px; background: rgba(1,12,9,.76); backdrop-filter: blur(9px); }
.modal { width: min(100%, 440px); max-height: 90dvh; overflow: auto; padding: 22px; text-align: center; animation: modalIn .4s cubic-bezier(.2,.8,.2,1.1); }
.modal h1 { margin: 4px 0 6px; font-size: 34px; }
.modal > p { color: var(--muted); margin: 0 0 17px; }
.results { display: grid; gap: 8px; margin: 15px 0; }
.result-row { padding: 11px; border-radius: 15px; background: rgba(255,255,255,.055); }
.result-row.winner { outline: 2px solid var(--gold); background: rgba(241,195,93,.1); }
.result-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.result-grid { display: flex; justify-content: center; gap: 4px; --card-w: 38px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

.flying-card { position: fixed; z-index: 50; pointer-events: none; margin: 0; transform-origin: center; }
#toast-region { position: fixed; z-index: 100; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(calc(100% - 28px), 420px); display: grid; gap: 8px; pointer-events: none; }
.toast { padding: 12px 14px; border-radius: 14px; background: rgba(5,25,21,.94); border: 1px solid rgba(255,255,255,.15); box-shadow: 0 12px 35px rgba(0,0,0,.3); animation: toastIn .3s ease, toastOut .3s 2.7s ease forwards; }
.toast.error { border-color: rgba(239,90,77,.65); }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes flipIn { from { opacity: 0; transform: perspective(500px) rotateY(85deg) scale(.9); } }
@keyframes drawIn { from { opacity: 0; transform: translateY(-48px) rotate(-7deg) scale(.82); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(20px) scale(.96); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }
@keyframes reactionGlow { to { box-shadow: 0 0 28px rgba(255,117,92,.42); } }
@keyframes selectGlow { from { box-shadow: 0 0 0 2px rgba(241,195,93,.4); } to { box-shadow: 0 0 0 5px rgba(241,195,93,.11); } }
@keyframes zonePulse { 40% { transform: scale(1.025); background: rgba(241,195,93,.15); } }
@keyframes deckBump { 40% { transform: translateY(-7px) rotate(-2deg); } }
@keyframes drain { to { transform: scaleX(0); } }

@media (min-width: 500px) {
  :root { --card-w: 72px; }
  .opponents { grid-template-columns: repeat(3, 1fr); }
  .table { grid-template-rows: minmax(130px, 1fr) auto minmax(230px, 1.1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
