/* serpientejuego.com — game component styles (needs tokens.css) */

.sj-game { max-width: var(--sj-w, var(--board-max)); margin: 0 auto; position: relative; }

/* Board shape (cols / rows) as CSS numbers: <html data-sj-board> is set before paint by site.js
   (saved Tamaño) and by the game on every new game, so the placeholder, the canvas and the
   computer fit formula (site.css) all use the real board: P 10×9 · M 17×15 · G 24×21. */
:root { --sj-c: 17; --sj-r: 15; }
[data-sj-board="pequeno"] { --sj-c: 10; --sj-r: 9; }
[data-sj-board="grande"] { --sj-c: 24; --sj-r: 21; }

/* Before the game script runs, the empty box already takes the game's exact size
   (HUD bar + board), so the page below does not jump when the game appears (CLS). */
[data-sj-game]:empty { max-width: var(--sj-w, var(--board-max)); margin: 0 auto; }
[data-sj-game]:empty::before {
  content: ""; display: block; box-sizing: border-box; height: 50px;
  background: var(--hud-bg); border: 1px solid var(--sj-card-line); border-bottom: 0;
  border-radius: var(--sj-card-r) var(--sj-card-r) 0 0;
}
[data-sj-game]:empty::after {
  content: ""; display: block; box-sizing: content-box; aspect-ratio: var(--sj-c) / var(--sj-r);
  background: var(--board-a); border: 1px solid var(--sj-card-line); border-top: 0;
  border-radius: 0 0 var(--sj-card-r) var(--sj-card-r);
}
.sj-game:fullscreen { --sj-card-line: transparent; max-width: none; display: flex; flex-direction: column; justify-content: center; background: var(--bg); padding: 12px; }
.sj-game:fullscreen .sj-board { width: min(100%, calc((100vh - 80px) * 17 / 15)); margin: 0 auto; }
.sj-game:fullscreen .sj-hud { width: min(100%, calc((100vh - 80px) * 17 / 15)); margin: 0 auto; }

/* Game card (design v6, C5): HUD + board read as one card with a thin site border, 16 px corners
   and a light shadow (no thick coloured frame). Everything inside is unchanged. */
.sj-game, [data-sj-game] { --sj-card-line: var(--site-line, #E2E7DF); --sj-card-r: 16px; }

/* ---------- HUD (v5.3): stats · Modo chip · Terminar · sound / fullscreen / settings ---------- */
.sj-hud {
  box-sizing: border-box; height: 50px;
  display: flex; align-items: center; gap: 12px;
  color: var(--hud-text); background: var(--hud-bg);
  padding: 0 6px 0 12px;
  border: 1px solid var(--sj-card-line); border-bottom: 0;
  border-radius: var(--sj-card-r) var(--sj-card-r) 0 0;
  font: var(--fw-bold) var(--fs-sm)/1 var(--font-display);
}
.sj-stat { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; flex: none; }
.sj-stat svg { width: 18px; height: 18px; flex: none; }
[data-theme="nokia"] .sj-hud .i-fill { fill: var(--hud-text); }
[data-theme="nokia"] .sj-hud .i-stroke { stroke: var(--hud-text); }

/* Modo chip: white pill; the ::after stretches the tap area to 44 px high */
.sj-chip {
  position: relative; display: inline-flex; align-items: center; gap: 4px; min-width: 0; flex: 0 1 auto;
  height: 32px; padding: 0 12px; border: 0; border-radius: var(--radius-pill); cursor: pointer;
  background: #fff; color: #25602b; font: 800 13px/1 var(--font-display);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
}
.sj-chip::after { content: ""; position: absolute; inset: -6px 0; }
.sj-chip [data-mode] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sj-chev { font-size: 10px; flex: none; }
[data-theme="nokia"] .sj-chip { background: var(--hud-text); color: var(--hud-bg); border-radius: 2px; box-shadow: none; }
/* reto: the fixed setup as plain text (not a button) */
.sj-mode { min-width: 0; flex: 0 1 auto; font-weight: 600; opacity: .92; font-size: var(--fs-xs);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sj-end {
  position: relative; flex: none; border: 0; cursor: pointer; height: 32px; padding: 0 12px;
  border-radius: var(--radius-pill); background: var(--hud-text); color: var(--hud-bg);
  font: var(--fw-bold) var(--fs-xs)/1 var(--font-display);
}
.sj-end::after { content: ""; position: absolute; inset: -6px 0; }
.sj-end[hidden] { display: none; }

/* v5.4 (B1): each icon button IS the 44 × 44 tap box (side by side, no overlap);
   the 30 px tile you see is its ::before */
.sj-hud-icons { margin-left: auto; display: flex; gap: 0; flex: none; margin-right: -4px; }
.sj-hicon {
  position: relative; width: 44px; height: 44px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 10px; cursor: pointer; background: none; color: var(--hud-text);
  -webkit-tap-highlight-color: transparent;
}
.sj-hicon::before {
  content: ""; position: absolute; left: 7px; top: 7px; width: 30px; height: 30px; border-radius: 9px;
  background: rgba(255, 255, 255, .16);
}
.sj-hicon[hidden] { display: none; }
.sj-hicon svg { position: relative; width: 20px; height: 20px; }
.sj-hicon:hover::before { background: rgba(255, 255, 255, .26); }

/* ---------- Board ---------- */
.sj-board {
  position: relative; background: var(--board-a);
  border: 1px solid var(--sj-card-line); border-top: 0;
  border-radius: 0 0 var(--sj-card-r) var(--sj-card-r);
  box-shadow: 0 6px 16px -6px rgba(31, 42, 34, .22);
}
.sj-board canvas {
  display: block; width: 100%; aspect-ratio: var(--sj-c) / var(--sj-r);
  touch-action: none;                 /* only the board blocks page scroll */
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  border-radius: 0 0 calc(var(--sj-card-r) - 1px) calc(var(--sj-card-r) - 1px);
}

.sj-hint {
  position: absolute; left: 50%; top: 70%; transform: translateX(-50%);
  background: rgba(0, 0, 0, .62); color: #fff; padding: 10px 16px; border-radius: var(--radius-pill);
  font: 600 var(--fs-sm)/1.2 var(--font-ui); white-space: nowrap; pointer-events: none;
}
.sj-hint[hidden] { display: none; }
[data-theme="nokia"] .sj-hint { background: var(--hud-bg); color: var(--hud-text); font-family: var(--font-mono); }

/* ---------- Pause / Fin popups (still inside the board) ---------- */
.sj-panel {
  position: absolute; inset: 0; display: grid; place-items: center; padding: var(--space-3);
  background: rgba(0, 0, 0, .35); border-radius: 0 0 calc(var(--sj-card-r) - 1px) calc(var(--sj-card-r) - 1px);
  z-index: 2;
}
.sj-panel[hidden] { display: none; }
.sj-card {
  background: var(--surface); color: var(--text); border-radius: var(--radius-lg); box-shadow: var(--shadow-2);
  padding: var(--space-5); width: min(100%, 340px); text-align: center;
  display: flex; flex-direction: column; gap: var(--space-2);
  max-height: 100%; overflow: auto;
}
.sj-title { font: var(--fw-black) var(--fs-xl)/var(--lh-tight) var(--font-display); margin: 0 0 var(--space-2); }
.sj-badge {
  align-self: center; margin: 0 0 4px; padding: 4px 12px; border-radius: var(--radius-pill);
  background: #fff1c2; color: #7a5300; box-shadow: inset 0 0 0 1px #f3d27a;
  font: var(--fw-bold) var(--fs-sm)/1.3 var(--font-display);
}
.sj-badge[hidden] { display: none; }
.sj-row2 { display: flex; gap: var(--space-2); }
.sj-row2 > * { flex: 1; }
.sj-small { margin: var(--space-1) 0 0; font-size: var(--fs-xs); color: var(--text-muted); }

.sj-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap);
  padding: 0 var(--space-4); border-radius: var(--radius-pill); border: 0; cursor: pointer; text-decoration: none;
  background: var(--primary); color: var(--primary-contrast); font: var(--fw-bold) var(--fs-md)/1 var(--font-display);
}
.sj-btn.ghost { background: transparent; color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }

.sj-note { display: block; font-size: var(--fs-xs); color: var(--text-muted); margin-top: 4px; }
.sj-link {
  background: none; border: 0; cursor: pointer; padding: 6px; color: var(--primary); text-decoration: underline;
  text-underline-offset: 3px; font: 600 var(--fs-sm)/1.3 var(--font-ui); text-align: center;
}
.sj-link[hidden] { display: none; }
.sj-link.danger { color: var(--accent); font-size: var(--fs-xs); margin-top: var(--space-1); }
.sj-reto-line[hidden] { display: none; }
.sj-dice { width: 16px; height: 16px; flex: none; }

/* ---------- Ajustes (v5.3): bottom sheet on phones, centred box on computers ---------- */
html.sj-sheet-open, html.sj-sheet-open body { overflow: hidden; }
.sj-sheet-wrap { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-end; justify-content: center; }
.sj-sheet-wrap[hidden] { display: none; }
.sj-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sj-sheet {
  position: relative; display: flex; flex-direction: column; width: 100%; max-width: 560px;
  height: min(86vh, 640px); height: min(86dvh, 640px);
  background: var(--surface); color: var(--text); text-align: left;
  border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  font: var(--fw-regular) var(--fs-md)/1.3 var(--font-ui);
  transition: transform .15s ease-out;
}
.sj-grip { flex: none; width: 40px; height: 5px; margin: 6px auto 0; border-radius: 3px; background: var(--border); touch-action: none; }
.sj-sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 12px 2px 18px; touch-action: none; }
.sj-sheet-title { margin: 0; font: var(--fw-black) 1.25rem/1.2 var(--font-display); }
.sj-x {
  width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--surface-2); color: var(--text);
}
.sj-x svg { width: 20px; height: 20px; }

.sj-tabs { flex: none; display: flex; gap: 3px; margin: 0 14px; padding: 3px; border-radius: 12px; background: var(--surface-2); }
.sj-tab {
  flex: 1; min-height: 44px; border: 0; border-radius: 9px; cursor: pointer; background: transparent;
  color: var(--text-muted); font: 600 15px/1 var(--font-ui);
}
.sj-tab[aria-selected="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-1); font-weight: 800; }

.sj-sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 2px 14px 8px; }
.sj-sheet-body:focus { outline: none; }
.sj-sheet-foot { flex: none; padding: 8px 14px 10px; border-top: 1px solid var(--border); }
.sj-play { width: 100%; min-height: 48px; border-radius: 14px; font-size: 17px; }

.sj-lbl { display: block; margin: 8px 0 5px; font: 700 13px/1.2 var(--font-ui); color: var(--text-muted); }
.sj-sec-head { display: flex; align-items: center; justify-content: space-between; height: 24px; margin: 4px 0 2px; }
.sj-sec-head .sj-lbl { margin: 0; }
.sj-rand {                     /* small link look, but a 44 px high tap area that does not push the layout */
  display: inline-flex; align-items: center; gap: 5px; min-height: 44px; margin: -9px -8px; padding: 0 8px;
  border: 0; background: none; cursor: pointer; color: var(--primary); font: 700 13px/1 var(--font-ui);
}

.sj-modes, .sj-speeds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.sj-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 48px; padding: 4px 3px; border: 1.5px solid var(--border); border-radius: 12px; cursor: pointer;
  background: var(--surface); color: var(--text); font: 600 12.5px/1.15 var(--font-ui); text-align: center;
}
.sj-tile svg { width: 20px; height: 20px; flex: none; }
.sj-tile-row { flex-direction: row; min-height: 44px; gap: 6px; }
.sj-tile[aria-pressed="true"], .sj-pill[aria-pressed="true"] {
  border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}
.sj-desc {
  margin: 5px 0 0; padding: 5px 10px; min-height: 2.6em; display: flex; align-items: center;
  border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 13px; line-height: 1.3;
}
.sj-two { display: flex; gap: 8px; }
.sj-pills { display: flex; gap: 4px; flex: 1; }
.sj-pill {
  flex: 1; min-width: 44px; min-height: 44px; border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer;
  background: var(--surface); color: var(--text); font: 700 14px/1 var(--font-ui);
}
.sj-reto-note { margin: 12px 0 0; padding: 14px; border-radius: 12px; background: var(--surface-2); color: var(--text); font-size: 15px; line-height: 1.4; }

.sj-themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.sj-theme {
  position: relative; min-height: 44px; padding: 4px 2px 4px; border: 2px solid transparent; border-radius: 10px; cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14); font: 700 11.5px/1.1 var(--font-ui); text-align: center;
}
.sj-theme i { position: absolute; left: 7px; width: 40%; top: 5px; height: 5px; border-radius: 3px; }
.sj-theme span { line-height: 1.05; }
.sj-theme[aria-pressed="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 2px var(--surface); }

.sj-colors { display: grid; grid-template-columns: repeat(5, 44px); justify-content: space-between; row-gap: 4px; }
.sj-dot {
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 3px solid var(--surface); box-shadow: 0 0 0 1px rgba(0, 0, 0, .22);
  display: grid; place-items: center; color: #fff; font: 800 13px/1 var(--font-ui);
}
.sj-dot b { text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.sj-dot.rainbow { background: conic-gradient(#e8452f, #f2a024, #f5d33a, #4cb04f, #3c6fd6, #8a4fd1, #e8452f); }
.sj-dot[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--primary); }
.sj-dot[disabled] { opacity: .55; cursor: not-allowed; }

.sj-fruits { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.sj-fruit { min-height: 44px; }
.sj-fruit svg { width: 26px; height: 26px; }

.sj-switches { margin-top: 4px; }
.sj-switch {
  display: flex; width: 100%; min-height: 54px; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 4px; border: 0; border-bottom: 1px solid var(--border); background: none; cursor: pointer;
  color: var(--text); font: 500 16px/1.2 var(--font-ui); text-align: left;
}
.sj-switch i { position: relative; flex: none; width: 46px; height: 28px; border-radius: 14px; background: #c3c9c0; transition: background .15s; }
.sj-switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s;
}
.sj-switch[aria-checked="true"] i { background: var(--primary); }
.sj-switch[aria-checked="true"] i::after { transform: translateX(18px); }
.sj-sheet .sj-link.danger { display: block; min-height: 44px; margin: 14px auto 0; }


/* ---------- Fin de la partida (v5.4): same sheet, sized to its content ---------- */
.sj-sheet.sj-fin { height: auto; max-height: min(86vh, 640px); max-height: min(86dvh, 640px); text-align: center; }
.sj-fin-x { position: absolute; top: 6px; right: 8px; z-index: 1; }
.sj-fin-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 6px 16px 12px;
}
.sj-fin-title { margin: 2px 0 0; font: 700 15px/1.25 var(--font-ui); color: var(--text-muted); }
.sj-big { margin: 0; display: flex; flex-direction: column; align-items: center; color: var(--primary); }
.sj-big b { font: 900 64px/0.95 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.sj-big span { margin-top: 2px; font: 700 14px/1.2 var(--font-ui); color: var(--text-muted); }
.sj-fpills { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.sj-fpill {
  display: inline-flex; align-items: center; gap: 5px; min-height: 30px; padding: 0 12px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text); font: 700 13.5px/1 var(--font-ui); font-variant-numeric: tabular-nums;
}
.sj-fpill[hidden] { display: none; }
.sj-fpill svg { width: 16px; height: 16px; flex: none; }
.sj-fpill-mode { background: color-mix(in srgb, var(--primary) 12%, var(--surface)); color: var(--primary); }
.sj-reto-line {
  margin: 0; padding: 9px 12px; border-radius: 12px; background: #fff1c2; color: #5c4300;
  font: 700 14px/1.3 var(--font-ui);
}
.sj-again { min-height: 50px; border-radius: 14px; font-size: 18px; margin-top: 4px; }
.sj-again svg { width: 20px; height: 20px; flex: none; }
.sj-fin .sj-row2 > * { min-height: 46px; border-radius: 14px; font-size: 15px; padding: 0 8px; }
.sj-fin .sj-btn.sj-wa { color: #128c4a; box-shadow: inset 0 0 0 2px #25c45a; }
.sj-fin .sj-btn.sj-plain { color: var(--text); box-shadow: inset 0 0 0 2px var(--border); }
.sj-fin .sj-link { min-height: 44px; padding: 0 6px; font-weight: 700; }
.sj-fin .sj-small { margin: 0; }

@media (min-width: 761px) {
  .sj-sheet-wrap { align-items: center; }
  .sj-sheet { width: min(440px, 92vw); height: auto; max-height: 86vh; border-radius: 22px; box-shadow: var(--shadow-2); }
  .sj-grip { display: none; }
  .sj-sheet-head { padding-top: 14px; }
}

/* ---------- Confetti layer + toast ---------- */
.sj-fx { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.sj-toast {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 4; max-width: 90%;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-2); border-radius: var(--radius-pill);
  padding: 8px 16px; font: 600 var(--fs-sm)/1.3 var(--font-ui); text-align: center; pointer-events: none;
}
.sj-toast[hidden] { display: none; }

/* ---------- D-pad (optional, set in Ajustes) ---------- */
.sj-dpad {
  display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(2, 56px);
  gap: 6px; justify-content: center; margin: var(--space-3) auto 0; touch-action: none; user-select: none;
}
.sj-dpad[hidden] { display: none; }
.sj-dpad button {
  border: 0; border-radius: var(--radius-md); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-1); font-size: 22px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.sj-dpad button:active { background: var(--surface-2); }
.sj-dpad [data-dir="up"] { grid-column: 2; }
.sj-dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.sj-dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.sj-dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }

@media (max-width: 760px) {
  [data-sj-game]:empty::before { height: 48px; }
  .sj-hud { height: 48px; gap: 4px 5px; padding: 0 4px 0 8px; }
  /* phones: everything must fit on one line, "Fruta voladora ▾" included */
  .sj-hud { font-size: 13px; }
  .sj-stat { gap: 2px; }
  .sj-stat svg { width: 16px; height: 16px; }
  .sj-stat-time svg { display: none; }
  .sj-chip { padding: 0 9px; font-size: 12.5px; }
  .sj-hud-icons { margin-right: -3px; }
  .sj-hicon svg { width: 19px; height: 19px; }
  .sj-end { padding: 0 7px; }
  /* Paz while playing: «Terminar» needs the room — the chip drops its ▾ (still a button) */
  .sj-hud:has(.sj-end:not([hidden])) .sj-chev { display: none; }
  .sj-hud:has(.sj-end:not([hidden])) .sj-chip { padding: 0 7px; }
  .sj-card { padding: var(--space-4); }
}

/* phones up to 440 px (v5.4): three 44 px icon buttons leave no room for the timer — it hides
   (the Fin sheet still shows the time). Paz while playing: the live time matters more than the
   best time, so there the 🏆 hides instead. */
@media (max-width: 440px) {
  .sj-stat-time { display: none; }
  .sj-hud:has(.sj-end:not([hidden])) .sj-stat-time { display: inline-flex; }
  .sj-hud:has(.sj-end:not([hidden])) .sj-stat-rec { display: none; }
}

/* small phones (320–389 px, e.g. Galaxy S9+, 360 px Androids, iPhone mini): no timer, smaller icons —
   the HUD stays on one line and no mode name is cut (doc said < 360; widened so 360–389 px fit too) */
@media (max-width: 389px) {
  .sj-hud { gap: 3px; padding-left: 6px; padding-right: 3px; }
  .sj-stat svg { width: 15px; height: 15px; }
  .sj-hicon svg { width: 18px; height: 18px; }
  .sj-chip { padding: 0 5px; font-size: 12px; gap: 2px; }
  .sj-hud:has(.sj-end:not([hidden])) .sj-chip { padding: 0 6px; }
  .sj-hud-icons { margin-right: -4px; }
  .sj-end { padding: 0 6px; font-size: 12px; }
}

@media (max-height: 700px) and (max-width: 760px) {
  .sj-big b { font-size: 54px; }
  .sj-fin-body { gap: 6px; }
}

/* very small phones (< 360 px, e.g. 320 px wide): only 🍎 + chip (no ▾) + icons; the 🏆 lives in the
   Fin sheet. Paz while playing: ⏱ + «Paz» + «Terminar» (apples hide, time is what Paz counts). */
@media (max-width: 359px) {
  .sj-stat-rec, .sj-chev { display: none; }
  .sj-hud:has(.sj-end:not([hidden])) .sj-stat:first-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sj-sheet, .sj-switch i, .sj-switch i::after { transition: none; }
}
