:root {
  --mesa: #F7E9CF; --mesa-2: #EBD7B0; --tinta: #2A2118; --suave: #6B5A44; --papel: #FFFDF7;
  --rojo: #E5484D; --rojo-os: #B8282D; --azul: #2F6BFF; --azul-os: #1B47B8; --ok: #1F9D63;
  --borde: #CDB68A;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--mesa); color: var(--tinta); font-family: Figtree, system-ui, sans-serif; }
body { overflow-x: hidden; }
.app { min-height: 100dvh; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.pant { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }
.cuerpo { flex: 1; padding: 16px 22px; display: flex; flex-direction: column; gap: 16px; }
.pie { padding: 12px 22px 22px; display: flex; flex-direction: column; gap: 10px; }
.centro { text-align: center; }
.muted { color: var(--suave); }
.chico { font-size: 14px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2 { font-family: Fraunces, Georgia, serif; font-weight: 900; margin: 0; letter-spacing: -.02em; line-height: 1.05; }
.t1 { font-size: 52px; } .t2 { font-size: 30px; }
.etiqueta { font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--suave); }

/* botones */
.btn { appearance: none; border: 0; cursor: pointer; font: 800 19px Figtree, sans-serif; min-height: 56px; border-radius: 18px; padding: 0 22px; background: var(--tinta); color: var(--mesa); box-shadow: 0 5px 0 #000; transition: transform .08s, box-shadow .08s; width: 100%; }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #000; }
.btn.s { background: transparent; color: var(--tinta); border: 2.5px solid var(--tinta); box-shadow: none; }
.btn.rojo { background: var(--rojo); color: #fff; box-shadow: 0 5px 0 var(--rojo-os); }
.btn.azul { background: var(--azul); color: #fff; box-shadow: 0 5px 0 var(--azul-os); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-texto { appearance: none; background: none; border: 0; color: var(--suave); font: 700 16px Figtree, sans-serif; text-decoration: underline; min-height: 44px; cursor: pointer; }
.btn-atras { appearance: none; background: none; border: 0; font: 800 15px Figtree, sans-serif; color: var(--suave); padding: 14px 22px 0; text-align: left; cursor: pointer; min-height: 44px; }

/* campos */
.campo-wrap { display: flex; flex-direction: column; gap: 6px; }
.campo { width: 100%; min-height: 56px; border-radius: 16px; border: 3px solid var(--tinta); background: var(--papel); padding: 0 16px; font: 700 20px Figtree, sans-serif; color: var(--tinta); }
.campo:focus { outline: 3px solid var(--azul); outline-offset: 2px; }
.codigo { display: flex; gap: 10px; justify-content: center; }
.codigo input { width: 64px; height: 76px; text-align: center; font: 900 38px Fraunces, serif; text-transform: uppercase; border-radius: 16px; border: 3px solid var(--tinta); background: var(--papel); color: var(--tinta); padding: 0; }
.codigo input:focus { outline: 3px solid var(--azul); outline-offset: 2px; }
.error { color: var(--rojo-os); font-weight: 700; margin: 0; text-align: center; }

/* inicio */
.hero { padding: 38px 22px 8px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.hero p { margin: 0; font-size: 18px; line-height: 1.4; color: var(--suave); max-width: 320px; }
.logo-vasos { display: block; }
.menu { display: flex; flex-direction: column; gap: 12px; }

/* sala */
.caja { background: var(--papel); border: 3px solid var(--tinta); border-radius: 22px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.sala-cod { font: 900 64px/1 Fraunces, serif; letter-spacing: .12em; text-indent: .12em; text-align: center; user-select: all; }
.vs { display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 800; }
.chip-j { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; border: 3px solid var(--tinta); background: var(--papel); font-weight: 800; max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pto { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.pto.A { background: var(--rojo); } .pto.B { background: var(--azul); }
.espera { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; font-weight: 700; color: var(--suave); text-align: center; }
.cab { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px 0; font-size: 13px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--suave); }

/* juego */
.marcador { display: flex; align-items: stretch; gap: 10px; padding: 14px 22px 0; }
.jug { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 16px; border: 3px solid transparent; background: var(--mesa-2); font-weight: 800; transition: background .2s, border-color .2s, transform .2s; }
.jug span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jug.turno { background: var(--papel); border-color: var(--tinta); transform: translateY(-2px); }
.jug.A.turno { border-color: var(--rojo); } .jug.B.turno { border-color: var(--azul); }
.jug.der { flex-direction: row-reverse; text-align: right; }
.aviso { text-align: center; font-weight: 800; font-size: 20px; min-height: 30px; padding: 14px 22px 0; }
.tablero-wrap { padding: 8px 14px; flex: 1; display: flex; align-items: center; }
.tablero { width: 100%; height: auto; display: block; background: var(--papel); border: 3px solid var(--tinta); border-radius: 26px; touch-action: manipulation; user-select: none; }
.trazo { stroke: var(--tinta); stroke-width: 3.2; fill: none; stroke-linecap: round; }
.lugar { fill: var(--papel); stroke: var(--tinta); stroke-width: 3; }
.meta-A { fill: rgba(229,72,77,.13); } .meta-B { fill: rgba(47,107,255,.13); }
.zona { fill: transparent; cursor: pointer; }
.destino { fill: rgba(31,157,99,.22); stroke: var(--ok); stroke-width: 3.5; animation: late 1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; pointer-events: none; }
@keyframes late { 50% { transform: scale(1.18); } }
.ficha { transition: transform .28s cubic-bezier(.3,.9,.3,1.2); pointer-events: none; }
.ficha .cuerpo-vaso { transition: transform .15s; transform-box: fill-box; transform-origin: 50% 100%; }
.ficha.sel .cuerpo-vaso { transform: translateY(-9px) scale(1.12); }
.ficha.movible .aro { opacity: 1; }
.aro { fill: none; stroke: var(--tinta); stroke-width: 2.5; stroke-dasharray: 3 5; opacity: 0; }
.acciones { padding: 6px 22px 22px; display: flex; gap: 10px; }
.acciones .btn { min-height: 52px; font-size: 17px; }

/* fin */
.fin { position: fixed; inset: 0; background: rgba(42,33,24,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 5; animation: sube .25s ease-out; }
.fin-caja { width: 100%; max-width: 520px; background: var(--mesa); border: 3px solid var(--tinta); border-bottom: 0; border-radius: 30px 30px 0 0; padding: 26px 22px calc(22px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
@keyframes sube { from { transform: translateY(40px); opacity: 0; } }
.fin-caja h2 { font-size: 40px; }
.reglas li { margin: 0 0 10px; line-height: 1.4; font-size: 17px; }
.reglas { padding-left: 22px; margin: 0; }

/* toasts */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 9; }
.toast { background: var(--tinta); color: var(--mesa); padding: 12px 18px; border-radius: 14px; font-weight: 700; max-width: 90%; text-align: center; }
.toast.error { background: var(--rojo-os); color: #fff; }
@media (prefers-reduced-motion: reduce) { .ficha, .destino, .fin { animation: none; transition: none; } }
