:root {
  --felt: #12543d; --felt-d: #0c3a2b; --ink: #10201a; --paper: #fbf7ec; --amber: #f5a524;
  --us: #7fd1ff; --them: #ffb27f; --txt: #f4f1e8;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-d) 100%); color: var(--txt); font-size: 18px; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { opacity: .7; font-size: .85em; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.center { justify-content: center; align-items: center; margin: 14px 0; }

.btn { background: #fff; color: var(--ink); border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 700; text-decoration: none; display: inline-block; text-align: center; box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn:disabled { opacity: .6; }
.btn.big { font-size: 1.15em; padding: 14px 22px; }
.btn.small { padding: 7px 12px; font-size: .9em; }
.btn.tiny { padding: 3px 8px; font-size: .75em; margin-left: 6px; }
.btn.amber { background: var(--amber); }
.btn.wa { background: #25d366; color: #fff; }

/* ---------- inicio ---------- */
.home-wrap { max-width: 440px; margin: 0 auto; padding: 24px 16px 40px; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 2.2em; margin: 8px 0 0; }
.brand .tile { width: 70px; height: 35px; }
.sub { margin: 4px 0 18px; opacity: .85; }
.card { background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.12); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 1.2em; }
form label { display: block; margin-bottom: 12px; font-size: .95em; }
input, select { font: inherit; width: 100%; padding: 12px; border-radius: 10px; border: 0; margin-top: 4px; background: var(--paper); color: var(--ink); }
select { width: auto; padding: 8px 10px; }
#code, #nameInput { font-size: 1.6em; letter-spacing: .3em; text-align: center; text-transform: uppercase; }
#nameInput { letter-spacing: normal; text-transform: none; margin-bottom: 12px; }
form .btn.big { width: 100%; }
.err { color: #ffb3a8; min-height: 1.2em; margin: 8px 0 0; }

/* ---------- fichas ---------- */
.tile .face { fill: var(--paper); stroke: #2a2a2a; stroke-width: 2; }
.tile .mid { stroke: #555; stroke-width: 2; }
.tile .pips { fill: #1b1b1b; }
.tile.back rect { fill: #24343a; stroke: #0b0b0b; stroke-width: 2; }

/* ---------- juego ---------- */
body.play { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: rgba(0,0,0,.35); }
.bar .code b { letter-spacing: .15em; color: var(--amber); }
.score { flex: 1; display: flex; gap: 14px; justify-content: center; font-size: .95em; flex-wrap: wrap; }
.score .us b { color: var(--us); font-size: 1.2em; } .score .them b { color: var(--them); font-size: 1.2em; }
.score .tgt { opacity: .7; }

#lobby { padding: 14px; overflow: auto; max-width: 560px; margin: 0 auto; width: 100%; }
.invite p { margin: 0 0 8px; }
.invite .link { font-size: 1.3em; font-weight: 800; color: var(--amber); word-break: break-all; margin-bottom: 10px; }
.felt-mini { position: relative; display: grid; grid-template-areas: ". top ." "left mid right" ". me ."; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 10px 0; }
.felt-mini .mid { grid-area: mid; display: flex; align-items: center; justify-content: center; text-align: center; font-size: .75em; opacity: .7; border: 2px dashed rgba(255,255,255,.2); border-radius: 50%; aspect-ratio: 1; }
.seat { background: rgba(0,0,0,.3); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; text-align: center; border: 2px solid transparent; }
.seat.us { border-color: var(--us); } .seat.them { border-color: var(--them); }
.seat small { opacity: .7; }
.seat.s2 { grid-area: top; } .seat.s3 { grid-area: left; } .seat.s1 { grid-area: right; } .seat.s0 { grid-area: me; }
.tag { background: var(--amber); color: var(--ink); border-radius: 6px; padding: 1px 6px; font-size: .7em; font-weight: 700; }
.tag.you { background: var(--us); }
.hint { text-align: center; opacity: .85; }

#table { flex: 1; display: grid; min-height: 0; padding: 6px;
  grid-template-areas: "left top right" "left board right" "sides sides sides" "me me me" "hand hand hand" "emo emo emo";
  grid-template-columns: 64px 1fr 64px; grid-template-rows: auto 1fr auto auto auto auto; gap: 4px; }
.opp.top { grid-area: top; display: flex; justify-content: center; }
.opp.left { grid-area: left; display: flex; align-items: center; }
.opp.right { grid-area: right; display: flex; align-items: center; }
.board { grid-area: board; position: relative; min-height: 0; overflow: hidden; background: rgba(0,0,0,.12); border-radius: 14px; padding: 4px; }
.board .empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; opacity: .75; font-size: 1.1em; text-align: center; }
.snake { position: relative; margin: auto; }
.bt { position: absolute; }
.bt .tile { width: 100%; height: 100%; display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.5)); }
.bt.fresh .tile .face { fill: #fff3c4; }
.sides { grid-area: sides; text-align: center; font-size: .9em; color: var(--amber); font-weight: 700; }
.slot { position: absolute; border: 3px dashed var(--amber); border-radius: 8px; background: rgba(245,165,36,.18); display: flex; align-items: center; justify-content: center; animation: pulse 1s infinite alternate; }
.slot span { font-weight: 900; color: var(--amber); font-size: 1.1em; text-shadow: 0 1px 2px #000; }
.slot.first { border-radius: 50%; }
.slot.turn { border-style: dotted; background: rgba(245,165,36,.08); }
.slot.turn span { font-size: 1.4em; }
body.dragging .slot:not(.hot) { opacity: .55; }
.slot.hot { z-index: 2; opacity: 1 !important; }
.edge { position: absolute; border: 2px dashed rgba(255,255,255,.18); border-radius: 10px; pointer-events: none; }
.slot.first span { font-size: .8em; text-align: center; }
.slot.hot { background: rgba(245,165,36,.55); transform: scale(1.12); }
@keyframes pulse { from { opacity: .65; } to { opacity: 1; } }
.ghost { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; filter: drop-shadow(0 8px 10px rgba(0,0,0,.6)); }
.ghost .tile { width: 100%; height: 100%; display: block; }
.ghost .tile .face { fill: #fff3c4; }
body.dragging { cursor: grabbing; user-select: none; }
.me { grid-area: me; display: flex; justify-content: center; }
.hand { grid-area: hand; display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; padding: 4px 0; }
.htile { touch-action: none; user-select: none; -webkit-user-select: none; transition: transform .15s, opacity .15s; }
.htile.can { cursor: grab; }
.htile.lifted { opacity: .25; }
.htile .tile { width: min(11vw, 52px); height: min(22vw, 104px); display: block; }
.htile.can { transform: translateY(-8px); }
.htile.can .tile .face { stroke: var(--amber); stroke-width: 4; }
.htile.no { opacity: .45; }
.emojis { grid-area: emo; display: flex; justify-content: center; gap: 6px; }
.emojis button { background: rgba(0,0,0,.25); border: 0; border-radius: 10px; font-size: 1.2em; padding: 2px 8px; }

.ptag { position: relative; background: rgba(0,0,0,.35); border-radius: 12px; padding: 6px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 2px solid transparent; font-size: .85em; min-width: 60px; }
.ptag.us { border-color: rgba(127,209,255,.6); } .ptag.them { border-color: rgba(255,178,127,.6); }
.ptag.turn { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(245,165,36,.35); }
.ptag.me { flex-direction: row; gap: 10px; font-size: 1em; }
.ptag.me.turn .nm { color: var(--amber); font-weight: 800; }
.ptag .nm { font-weight: 700; text-align: center; word-break: break-word; }
.ptag .cnt { opacity: .8; font-size: .85em; }
.ptag .backs { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; max-width: 120px; }
.ptag .backs i { width: 7px; height: 13px; background: #24343a; border: 1px solid #000; border-radius: 2px; }
.opp.left .ptag, .opp.right .ptag { width: 60px; padding: 6px 2px; }
.opp.left .backs, .opp.right .backs { max-width: 40px; }
.em { position: absolute; top: -18px; right: -8px; font-size: 1.8em; opacity: 0; pointer-events: none; }
.em.pop { animation: pop 2.2s ease-out; }
@keyframes pop { 0% { opacity: 0; transform: scale(.4); } 15% { opacity: 1; transform: scale(1.2); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.overlay .card { background: var(--felt-d); max-width: 460px; width: 100%; max-height: 90dvh; overflow: auto; }
.result h2 { text-align: center; font-size: 1.5em; }
.result .pts { text-align: center; font-size: 1.3em; font-weight: 800; color: var(--amber); margin: 0; }
.result .tot { text-align: center; opacity: .85; }
.rhands { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 14px; }
.rh { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.25); border-radius: 10px; padding: 6px 8px; border-left: 4px solid var(--them); }
.rh.us { border-left-color: var(--us); }
.rh b { width: 90px; font-size: .85em; }
.rh span { flex: 1; display: flex; gap: 2px; flex-wrap: wrap; }
.rh span .tile { width: 18px; height: 36px; }
.rh em { font-style: normal; font-weight: 800; }
.result .btn { width: 100%; }
.toast { position: fixed; left: 50%; top: 60px; transform: translateX(-50%) translateY(-20px); background: #000c; padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .25s; pointer-events: none; z-index: 20; }
.toast.on { opacity: 1; transform: translateX(-50%); }
.status { position: fixed; bottom: 0; left: 0; right: 0; background: #7a1f1f; padding: 12px; text-align: center; z-index: 30; }

@media (min-width: 800px) {
  #table { grid-template-columns: 140px 1fr 140px; max-width: 1100px; margin: 0 auto; width: 100%; }
  .opp.left .ptag, .opp.right .ptag { width: 130px; }
  .opp.left .backs, .opp.right .backs { max-width: 120px; }
}

.btn.install { width: 100%; margin-bottom: 16px; background: var(--amber); font-size: 1.1em; padding: 12px; }
.bar { padding-top: max(8px, env(safe-area-inset-top)); }
body.play { padding-bottom: env(safe-area-inset-bottom); }
