/* ====== Jueguitos — "noche de juegos en un scrapbook" ======
   Papel crema con grano, stickers con contorno grueso y sombra dura, colores dopamina.
   Ver DESIGN.md para las reglas. */
:root {
  --paper: #fff4df;
  --paper-2: #ffe9c2;
  --sheet: #fffdf7;
  --ink: #1f1a17;
  --ink-soft: #6b5d52;
  --tomato: #ff5a3c;
  --sun: #ffc93c;
  --mint: #3ddc97;
  --cobalt: #3b6cff;
  --bubble: #ff8fc7;
  --grape: #8b5cf6;

  --stroke: 3px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --shadow-lg: 7px 7px 0 var(--ink);
  --r: 18px;
  --r-sm: 12px;
  --ease-pop: cubic-bezier(.34, 1.56, .64, 1);

  --display: 'Bagel Fat One', 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'Bricolage Grotesque', system-ui, sans-serif;
  --pixel: 'Pixelify Sans', monospace;

  /* alias viejos para los juegos */
  --card: var(--sheet); --muted: var(--ink-soft); --accent: var(--tomato); --accent2: var(--mint); --line: var(--ink); --err: var(--tomato);

  font-family: var(--body);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { background: var(--paper); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); font-size: 17px; line-height: 1.45;
  background:
    radial-gradient(circle at 1px 1px, #1f1a1716 1.2px, transparent 0) 0 0 / 22px 22px,
    radial-gradient(ellipse at 10% -10%, #ffd9a0 0, transparent 55%),
    radial-gradient(ellipse at 110% 110%, #ffc2dd 0, transparent 50%),
    var(--paper);
  background-attachment: fixed;
}
/* grano de papel */
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: .35; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .3 0 0 0 0 .2 0 0 0 .18 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#app { max-width: 1240px; margin: 0 auto; padding: 28px 16px 48px; }

h1, h2, .display { font-family: var(--display); font-weight: 400; letter-spacing: .01em; line-height: 1.05; }
h1 { font-size: clamp(2.8rem, 8vw, 5.2rem); margin: 0; }
h2 { font-size: 2rem; margin: 0 0 12px; }
h3 { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-soft); margin: 26px 0 10px; }
.muted { color: var(--ink-soft); }
.err { color: var(--tomato); font-weight: 700; margin: 12px 0 0; }
.err:empty { display: none; }
a { color: var(--ink); text-decoration-thickness: 2px; text-underline-offset: 3px; }
code { font-family: var(--pixel); font-size: 1.05em; background: var(--sun); border: 2px solid var(--ink); border-radius: 8px; padding: 0 8px; }

/* ---- sticker card ---- */
.card {
  position: relative; background: var(--sheet); border: var(--stroke); border-radius: var(--r);
  box-shadow: var(--shadow-lg); padding: 30px; max-width: 560px; margin: 6vh auto;
}
.card.tape::before { /* cinta de papel */
  content: ''; position: absolute; top: -16px; left: 50%; width: 120px; height: 30px; transform: translateX(-50%) rotate(-3deg);
  background: #ffe28acc; border-left: 2px dashed #0002; border-right: 2px dashed #0002;
}
.center { text-align: center; }
#lang { position: fixed; top: 14px; right: 16px; z-index: 60; }
/* en partida (solo el host tiene "← Sala"): pill arriba a la izquierda, dentro del flujo de scroll, con su propio espacio → nunca tapa barras de acción del juego */
#lang.ingame { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); right: auto; bottom: auto; }
#lang.ingame:not(:empty) ~ #app { padding-top: 58px; }

/* ---- botones que se hunden ---- */
button, .btn {
  font: inherit; font-weight: 800; color: var(--ink); background: var(--sun);
  border: var(--stroke); border-radius: var(--r-sm); box-shadow: var(--shadow);
  padding: 11px 20px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s var(--ease-pop), box-shadow .12s, background .15s;
}
@media (hover: hover) {
  button:hover:not(:disabled), .btn:hover { transform: translate(-1px, -2px); box-shadow: 5px 6px 0 var(--ink); }
}
/* táctil: sin zoom por doble toque, sin flash gris, sin menú/selección al mantener apretado */
button, .btn, [role="button"], a, label, input, select, textarea, summary { touch-action: manipulation; }
button, .btn, [role="button"] { -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button:active:not(:disabled), .btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); transition-duration: .05s; }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: 2px 2px 0 var(--ink); }
button.primary { background: var(--tomato); color: #fff; }
button.ghost, .btn.ghost { background: var(--sheet); }
button.mint { background: var(--mint); }
button:focus-visible, input:focus-visible, .btn:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 3px; }

input {
  font: inherit; font-weight: 600; padding: 11px 14px; border-radius: var(--r-sm); border: var(--stroke);
  background: #fff; color: var(--ink); min-width: 0; box-shadow: inset 3px 3px 0 #1f1a170f;
}
input::placeholder { color: #a39385; }
form, .row { display: flex; gap: 10px; }
form input, .row input { flex: 1; }
.center .row { justify-content: center; }
.lang { padding: 6px 12px; font-size: .85rem; box-shadow: 2px 2px 0 var(--ink); background: var(--sheet); }

/* ---- home ---- */
.home { display: grid; place-items: center; min-height: calc(100vh - 130px); position: relative; }
.logo { display: flex; justify-content: center; flex-wrap: wrap; margin-bottom: 6px; }
.logo span {
  display: inline-block; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 4px 5px 0 var(--ink);
  animation: drop .7s var(--ease-pop) both; animation-delay: calc(var(--i) * 55ms);
}
.logo span:nth-child(5n+1) { color: var(--tomato); transform: rotate(-6deg); }
.logo span:nth-child(5n+2) { color: var(--sun); transform: rotate(4deg) translateY(-6px); }
.logo span:nth-child(5n+3) { color: var(--mint); transform: rotate(-2deg); }
.logo span:nth-child(5n+4) { color: var(--cobalt); transform: rotate(7deg) translateY(4px); }
.logo span:nth-child(5n)   { color: var(--bubble); transform: rotate(-4deg); }
@keyframes drop { from { opacity: 0; translate: 0 -40px; scale: .6; } }
.tagline { font-weight: 700; color: var(--ink-soft); margin: 10px 0 22px; }
.home .card { margin: 0 auto; padding: 26px; width: min(100%, 470px); animation: rise .6s .35s var(--ease-pop) both; }
@keyframes rise { from { opacity: 0; translate: 0 30px; rotate: -3deg; } }
.floaties { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.floaties svg { position: absolute; width: clamp(64px, 9vw, 120px); filter: drop-shadow(4px 4px 0 var(--ink)); animation: bob 5s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
.floaties span { --d: 0s; } .floaties span svg { animation-delay: inherit; }
@keyframes bob { to { translate: 0 -14px; rotate: 6deg; } }
.home > :not(.floaties) { position: relative; z-index: 1; }

/* ---- lobby ---- */
.lobby { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 28px; align-items: start; }
.lobby .card { margin: 0; max-width: none; }
.room-code { font-family: var(--pixel); font-size: 2.4rem; letter-spacing: .12em; background: var(--sun); border: var(--stroke); border-radius: var(--r-sm); padding: 2px 14px; display: inline-block; box-shadow: var(--shadow); transform: rotate(-2deg); }
.players { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.players li { display: flex; align-items: center; gap: 12px; font-weight: 700; animation: rise .4s var(--ease-pop) both; }
.avatar { width: 44px; height: 44px; border-radius: 50%; border: var(--stroke); box-shadow: 2px 2px 0 var(--ink); display: grid; place-items: center; font-family: var(--display); font-size: 1.2rem; flex: none; }
.players li.waiting { color: var(--ink-soft); font-weight: 600; }
.players li.waiting .avatar { background: transparent; border-style: dashed; box-shadow: none; animation: spin 6s linear infinite; }
@keyframes spin { to { rotate: 1turn; } }
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 20px; margin-bottom: 8px; }
.lobby > section:first-child { position: sticky; top: 20px; }
.game .art { aspect-ratio: 16 / 9; }
.game .meta b { font-size: 1.15rem; }
.game {
  display: flex; flex-direction: column; align-items: stretch; padding: 0; overflow: hidden; text-align: left; background: var(--sheet);
  box-shadow: var(--shadow-lg); transform: rotate(var(--tilt, 0deg));
}
.game:nth-child(odd) { --tilt: -1.2deg; } .game:nth-child(even) { --tilt: 1deg; }
@media (hover: hover) {
  .game:hover:not(:disabled) { transform: rotate(0) translateY(-4px); box-shadow: 9px 10px 0 var(--ink); }
  .game:hover .art svg { transform: scale(1.08) rotate(-4deg); }
}
.game .art { display: grid; place-items: center; border-bottom: var(--stroke); }
.game .art svg { width: 62%; height: 80%; transition: transform .35s var(--ease-pop); }
.game .meta { padding: 12px 16px 14px; }
.game .meta b { font-family: var(--display); font-weight: 400; font-size: 1.35rem; display: block; line-height: 1.1; }
.game .meta small { color: var(--ink-soft); font-weight: 600; }
.game.sel { outline: 4px solid var(--ink); outline-offset: 5px; }
.game.sel::after { content: '✓'; position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%; background: var(--mint); border: var(--stroke); display: grid; place-items: center; font-weight: 900; }
.game { position: relative; }
.big { width: 100%; margin-top: 24px; position: sticky; bottom: 16px; z-index: 5; padding: 16px; font-size: 1.25rem; font-family: var(--display); font-weight: 400; letter-spacing: .02em; }
.big:not(:disabled) { animation: nudge 2.4s ease-in-out infinite; }
.lobby .big:disabled { opacity: 1; background: var(--paper-2); color: var(--ink-soft); } /* sticky sobre las cartas: que no se transparente */
@keyframes nudge { 0%, 85%, 100% { rotate: 0deg; } 90% { rotate: -2deg; } 95% { rotate: 2deg; } }

/* ---- firma ---- */
#love { text-align: center; font-size: .82rem; font-weight: 600; color: var(--ink-soft); padding: 4px 16px 22px; letter-spacing: .02em; }
#love .beat { display: inline-block; color: var(--tomato); animation: beat 1.4s ease-in-out infinite; }
@keyframes beat { 0%, 60%, 100% { transform: scale(1); } 20% { transform: scale(1.35); } 40% { transform: scale(.95); } }
.tagline-gap { height: 22px; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 50; transform: translate(-50%, 140px) rotate(-2deg);
  background: var(--mint); color: var(--ink); border: var(--stroke); box-shadow: var(--shadow); padding: 10px 20px; border-radius: var(--r-sm); font-weight: 800;
  transition: transform .35s var(--ease-pop);
}
#toast.show { transform: translate(-50%, 0) rotate(-2deg); }

/* ---- overlay de fin de partida (compartido) ---- */
.over { position: fixed; inset: 0; background: #1f1a1799; backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; z-index: 40; overflow-y: auto; overscroll-behavior: contain; }
.over > .card { margin: auto; } /* si no entra (tablet apaisada), se scrollea sin cortar el título */
.over[hidden] { display: none; }
.over .card { animation: rise .5s var(--ease-pop) both; min-width: min(420px, 100%); }
.over ol { text-align: left; display: inline-block; font-size: 1.15rem; font-weight: 700; }

/* ---- pintar (lo restyla su propio CSS; esto es la base) ---- */
.pintar .bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--sheet); border: var(--stroke); box-shadow: var(--shadow); border-radius: var(--r); padding: 10px 18px; margin-bottom: 14px; min-height: 56px; }
.word { font-family: var(--pixel); font-size: 1.5rem; letter-spacing: .3em; white-space: pre; }
.word b { letter-spacing: .05em; color: var(--tomato); }
.clock { font-family: var(--pixel); font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.clock.hurry { color: var(--tomato); animation: nudge .5s infinite; }
.board { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }
.pintar .stage { max-width: calc((100vh - 200px) * 4 / 3); width: 100%; justify-self: center; }
.pintar canvas { width: 100%; aspect-ratio: 4 / 3; background: #fff; border: var(--stroke); box-shadow: var(--shadow-lg); border-radius: var(--r); display: block; touch-action: none; }
.drawing canvas { cursor: crosshair; }
.tools { display: none; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
.drawing .tools { display: flex; }
.swatch { width: 34px; height: 34px; padding: 0; border-radius: 50%; box-shadow: 2px 2px 0 var(--ink); }
.swatch.sel { transform: scale(1.2) rotate(-8deg); box-shadow: 3px 3px 0 var(--ink); }
.size { background: var(--sheet); width: 44px; height: 44px; padding: 0; }
.size i { background: var(--ink); border-radius: 50%; display: block; }
.size.sel { background: var(--sun); }
aside { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.scores, .log { list-style: none; margin: 0; padding: 14px; background: var(--sheet); border: var(--stroke); box-shadow: var(--shadow); border-radius: var(--r); }
.scores li { display: flex; justify-content: space-between; padding: 4px 0; font-weight: 700; }
.scores li.artist { color: var(--tomato); }
.log { flex: 1; overflow-y: auto; max-height: 50vh; min-height: 200px; font-size: .95rem; }
.log li { padding: 3px 0; overflow-wrap: anywhere; }
.log .sys { color: var(--ink-soft); font-style: italic; }
.log .ok { color: #13945c; font-weight: 800; }

@media (max-width: 860px) {
  .lobby, .board { grid-template-columns: 1fr; }
}

/* ---- tablet (Andrea juega en la tablet): 768–1180px, vertical y apaisada ---- */
.room-a, .room-b { min-width: 0; }
@media (max-width: 1180px), (pointer: coarse) {
  /* los botones fijos (idioma / ← Sala) se van con el scroll y tienen su lugar arriba: nunca tapan el juego */
  #lang { position: absolute; }
  .lang { min-height: 40px; padding: 6px 14px; }
  .lobby { grid-template-columns: minmax(270px, 330px) 1fr; gap: 22px; }
  .games { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 16px; }
  .game .meta { padding: 10px 14px 12px; }
  .game .meta b { font-size: 1.2rem; }
}
@media (max-width: 860px) {
  #lang:not(.ingame) ~ #app { padding-top: 66px; }
  .lobby { grid-template-columns: 1fr; }
  .lobby > section:first-child { position: static; }
  .lobby .room { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 0 26px; padding: 20px 22px 22px; }
  .room h3:first-child { margin-top: 4px; }
  .room-code { font-size: 2rem; }
  .games { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .home { min-height: calc(100svh - 160px); }
}
@media (max-width: 600px) {
  .lobby .room { grid-template-columns: 1fr; }
  .games { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
