:root {
  --ink: #f4efe2;
  --muted: #c3d6c9;
  --gold: #e8c25a;
  --t0: #e0574c;
  --t1: #4f8fe0;
  /* Tipografía de la baraja española (la misma que la portada) */
  --sc: "Alegreya SC", Georgia, "Times New Roman", serif;
  --serif: "Alegreya", Georgia, "Times New Roman", serif;
  --felt:
    repeating-linear-gradient(45deg, rgba(255,255,255,.018) 0 2px, transparent 2px 5px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.03) 0 2px, transparent 2px 5px),
    radial-gradient(ellipse at center, #22874f 0%, #176a3d 55%, #0c4527 100%);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: #0c4527;
  background-image: var(--felt);
  color: var(--ink);
  font-family: var(--serif);
  font-variant-numeric: lining-nums;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; background: none; }
button:disabled { cursor: default; }

/* ---------- Pantallas de menú ---------- */
.screen { height: 100dvh; overflow-y: auto; }
.center { display: grid; place-items: center; color: var(--muted); }
.page {
  display: flex; flex-direction: column;
  max-width: 460px; margin: 0 auto; padding: 0 16px max(20px, env(safe-area-inset-bottom));
}
.page > .content { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: 8px 0 12px; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 0 10px; min-height: 64px;
}
.topbar h2 { font-size: 1.3rem; }
.topbar.sticky { position: sticky; top: 0; z-index: 2; background: linear-gradient(#0f4d2c 75%, transparent); }
.brand { font-family: var(--sc); font-weight: 900; color: var(--gold); font-size: 1.35rem; text-decoration: none; }
.actions { margin-left: auto; display: flex; gap: 8px; }
.iconbtn { width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.3); font-size: 1.3rem; flex: none; }
.pill {
  position: relative; display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 14px 0 10px; border-radius: 22px;
  background: rgba(0,0,0,.3); font-weight: 600; font-size: .92rem;
}
.pill:active, .iconbtn:active { background: rgba(0,0,0,.5); }
.avatar-sm { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-weight: 800; font-size: .85rem; }
.avatar-sm.on { background: var(--gold); color: #2a2208; }
.dot { position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: #ff7a6b; }

.hero { text-align: center; }
.hero h1 { font-size: 2.2rem; line-height: 1.1; text-shadow: 0 2px 6px rgba(0,0,0,.45); }
.hero p { color: var(--muted); margin-top: 6px; }
.hero-logo { width: min(300px, 78%); height: auto; margin: 0 auto; filter: drop-shadow(0 8px 14px rgba(0,0,0,.35)); }
.hero p { font-style: italic; font-size: 1.08rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* Títulos, botones y marcadores con versalitas de naipe */
h1, h2, h3, .primary, .secondary, .pick, .pill, .tabs button, .label .name, .label .pts, .grid .card .info b,
.grid .card button, #winner h2, .stats b, .avatar, .avatar-sm, .resume b { font-family: var(--sc); }

.box {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px; border-radius: 20px; background: rgba(0,0,0,.25);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.box h2 { font-size: 1.1rem; }
.resume { display: flex; flex-direction: column; gap: 2px; border: 2px solid rgba(232,194,90,.6); text-align: center; }
.resume b { color: var(--gold); font-size: 1.1rem; }
.resume small { color: var(--muted); font-weight: 400; }

.lead { text-align: center; color: var(--muted); line-height: 1.5; }
.lead b { color: var(--ink); word-break: break-all; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: .9rem; color: var(--muted); }
.chips-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pick {
  padding: 12px 0; border-radius: 12px; background: rgba(0,0,0,.25);
  font-size: 1.25rem; font-weight: 700; border: 2px solid transparent;
}
.pick.on { border-color: var(--gold); color: var(--gold); }
.chips-pick input { padding: 10px 6px; text-align: center; font-weight: 700; font-size: 1.1rem; }
.chips-pick input:not(:placeholder-shown) { border-color: var(--gold); color: var(--gold); }
input {
  font: inherit; font-size: 1.1rem; padding: 12px 14px; border-radius: 12px;
  border: 2px solid rgba(0,0,0,.2); background: rgba(0,0,0,.3); color: var(--ink); width: 100%; min-width: 0;
  user-select: text; -webkit-user-select: text;
}
input::placeholder { color: rgba(244,239,226,.5); }
input:focus { outline: none; border-color: var(--gold); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.names label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; color: var(--muted); }
.names label:first-child input { border-left: 6px solid var(--t0); }
.names label:last-child input { border-left: 6px solid var(--t1); }
.primary {
  padding: 16px; border-radius: 14px; background: var(--gold); color: #2a2208;
  font-size: 1.2rem; font-weight: 800; box-shadow: 0 3px 0 #9c7a22;
}
.primary:disabled { opacity: .6; }
.secondary { padding: 14px; border-radius: 14px; background: rgba(0,0,0,.3); font-weight: 600; }
.link { color: var(--muted); text-decoration: underline; padding: 6px; font-size: .9rem; }
.links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; }
.msg { min-height: 1.3em; text-align: center; color: #ffb4ad; font-size: .92rem; }
.msg.ok { color: #b8f0c4; }
.note { background: rgba(0,0,0,.3); border-radius: 12px; padding: 10px 12px; font-size: .85rem; color: var(--muted); line-height: 1.45; }
.note code { color: var(--gold); }
.center-text { text-align: center; }

.google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px; border-radius: 14px; background: #fff; color: #1f1f1f; font-weight: 600;
}
.sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: rgba(255,255,255,.2); }

/* Perfil */
.who { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.who b { font-size: 1.2rem; margin-top: 6px; }
.who small { color: var(--muted); word-break: break-all; }
.avatar {
  display: grid; place-items: center; width: 84px; height: 84px; border-radius: 50%;
  background: var(--gold); color: #2a2208; font-size: 2.2rem; font-weight: 900;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats div { display: flex; flex-direction: column; align-items: center; padding: 14px; border-radius: 16px; background: rgba(0,0,0,.25); }
.stats b { font-size: 1.5rem; color: var(--gold); }
.stats small { color: var(--muted); }

/* ---------- Tienda ---------- */
.shop { padding: 0 16px 24px; max-width: 720px; margin: 0 auto; }
.shop-note { margin-bottom: 12px; text-align: center; }
.shop-note .link { color: var(--gold); font-weight: 700; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 14px; background: rgba(0,0,0,.3); margin-bottom: 14px; }
.tabs button { padding: 10px; border-radius: 10px; font-weight: 700; color: var(--muted); }
.tabs button.on { background: var(--gold); color: #2a2208; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.grid .card {
  display: flex; flex-direction: column; border-radius: 16px; overflow: hidden;
  background: rgba(0,0,0,.3); box-shadow: 0 4px 10px rgba(0,0,0,.25);
}
.preview { position: relative; aspect-ratio: 4 / 5; overflow: hidden; }
.preview { background: #1a120b; }
.preview .mini {
  position: absolute; aspect-ratio: 1; transform: translate(-50%, -50%);
  filter: drop-shadow(0 2px 1.5px rgba(0,0,0,.5));
}

.grid .card .info { padding: 10px 12px 6px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.grid .card .info b { font-size: .98rem; }
.grid .card .info small { font-size: .78rem; color: var(--muted); line-height: 1.35; }
.grid .card button { margin: 6px 12px 12px; padding: 10px; border-radius: 10px; font-weight: 800; }
.grid .card .buy { background: var(--gold); color: #2a2208; }
.grid .card .use { background: rgba(255,255,255,.15); }
.grid .card .using { border: 2px solid var(--gold); color: var(--gold); padding: 8px; }

/* ---------- Tapete en 4 zonas ---------- */
#board { position: fixed; inset: 0; overflow: hidden; touch-action: none; background: #1a120b; }
/* Tapete: imagen con marco (border-image) que llena la pantalla */
.mat { position: absolute; inset: 0; box-sizing: border-box; pointer-events: none; }
#frame { box-shadow: inset 0 0 60px rgba(0,0,0,.35); }
#decor, #frame { position: absolute; inset: 0; pointer-events: none; }
#lines { position: absolute; inset: 0; width: 100%; height: 100%; }
#lines line { stroke: rgba(255,255,255,.22); stroke-width: 2; stroke-dasharray: 8 6; vector-effect: non-scaling-stroke; }
#lines .z0 { fill: rgba(224,87,76,.08); }
#lines .z1 { fill: rgba(79,143,224,.08); }
.bank {
  position: absolute; left: 30%; right: 30%; top: 38.5%; bottom: 38.5%;
  border-radius: 24px; border: 2px dashed rgba(255,255,255,.25);
  background: rgba(0,0,0,.14);
  box-shadow: inset 0 0 30px rgba(0,0,0,.3);
}

.label {
  position: absolute; width: 220px; text-align: center; /* debajo de las pitas */
  pointer-events: none; text-shadow: 0 1px 3px rgba(0,0,0,.6);
  padding: 4px 8px; border-radius: 14px;
}
.label .kind { white-space: nowrap; font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.label .name { font-weight: 700; font-size: 1rem; }
.label[data-team="0"] .name { color: #ffb4ad; }
.label[data-team="1"] .name { color: #b2d0ff; }
.label .pts { font-size: 1.7rem; font-weight: 800; font-variant-numeric: lining-nums tabular-nums; line-height: 1.1; }
.label .pts small { font-size: .85rem; font-weight: 500; opacity: .8; }
.label .sub { font-size: .75rem; color: var(--muted); }
.label.top    { left: 50%; top: 56px; transform: translate(-50%, -50%) rotate(180deg); }
.label.bottom { left: 50%; top: calc(100% - 56px); transform: translate(-50%, -50%); }
.label.left   { left: 56px; top: 50%; transform: translate(-50%, -50%) rotate(90deg); }
.label.right  { left: calc(100% - 56px); top: 50%; transform: translate(-50%, -50%) rotate(-90deg); }

.tools {
  position: absolute; z-index: 3; right: 10px; bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; gap: 8px;
}
.tools button {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(0,0,0,.4); font-size: 1.2rem;
}
.tools button:active { background: rgba(0,0,0,.6); }
.tools button:disabled { opacity: .35; }

/* ---------- Pitas ---------- */
#chips { position: absolute; inset: 0; z-index: 1; }
.chip {
  position: absolute; left: 0; top: 0;
  width: var(--s, 46px); height: var(--s, 46px);
  margin: calc(var(--s, 46px) / -2) 0 0 calc(var(--s, 46px) / -2);
  transform: translate(var(--x), var(--y));
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), filter .15s ease-out;
  filter: drop-shadow(0 2px 1.5px rgba(0,0,0,.5));
  cursor: grab; touch-action: none;
}
.chip .body { width: 100%; height: 100%; transition: scale .15s ease-out, translate .15s ease-out; }
.chip img { display: block; pointer-events: none; -webkit-user-drag: none; }
/* Al cogerla se levanta: más grande, más arriba y con la sombra más lejos y difusa */
.chip.lifted {
  transition: filter .15s ease-out;
  filter: drop-shadow(0 18px 10px rgba(0,0,0,.38));
  cursor: grabbing;
}
.chip.lifted .body { scale: 1.28; translate: 0 -8px; }
.chip.drop .body { animation: thud .3s ease-out; }
@keyframes thud {
  0%   { scale: 1.28; translate: 0 -8px; }
  60%  { scale: .92;  translate: 0 0; }
  100% { scale: 1;    translate: 0 0; }
}

/* ---------- Ganador y avisos ---------- */
#winner {
  position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#winner .card {
  background: #14603a; border: 3px solid var(--gold); border-radius: 20px;
  padding: 28px 20px; text-align: center; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px;
}
#winner h2 { font-size: 1.9rem; color: var(--gold); }
#winner p { color: var(--muted); }
#toast {
  position: fixed; z-index: 20; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: #1b1b1b; color: var(--ink); padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,.4); font-size: .95rem; text-align: center;
}

.legal-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem .7rem; padding: 1rem 0; font-size: .85rem; }
.legal-nav a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
