/* Self-hosted fonts (latin subset) */
@font-face { font-family: 'Fredoka'; font-weight: 500; font-style: normal; font-display: swap; src: url('fonts/fredoka-500.woff2') format('woff2'); }
@font-face { font-family: 'Fredoka'; font-weight: 700; font-style: normal; font-display: swap; src: url('fonts/fredoka-700.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-weight: 600; font-style: normal; font-display: swap; src: url('fonts/nunito-600.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-weight: 800; font-style: normal; font-display: swap; src: url('fonts/nunito-800.woff2') format('woff2'); }

/* Design tokens */
:root {
    color-scheme: light dark; /* Native controls (caret, autofill, scrollbars) follow the theme */
    --ink: #1a1a1a;
    --cream: #fff4dc;
    --green: #22c55e;
    --green-d: #15803d;
    --yellow: #ffd23f;
    --pink: #ff7aa2;
    --sky: #bdf0ff;
    --sky-d: #4cc9f0;
    --tongue: #ff4d6d;

    /* Semantic (light) */
    --bg: var(--cream);
    --bg-dot: #f6e6c3;
    --card: #ffffff;
    --text: var(--ink);
    --line: var(--ink);
    --shadow: var(--ink);
    --cell: #f3efe6;
    --cell-visited: #d9f7e3;
    --wall: var(--ink);
    --ok: var(--green-d);
    --err: #d6304f;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17161f;
        --bg-dot: #23212f;
        --card: #26243a;
        --text: #f5efe0;
        --line: #f5efe0;
        --shadow: #8a84b8;
        --cell: #34314d;
        --cell-visited: #285f43;
        --wall: #f5efe0;
        --ok: #4ade80;
        --err: #ff8fa3;
    }
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
    font-weight: 600;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 16px;
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 520px;
    margin: 0 auto;
}

/* Header */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.logo {
    font: 700 40px/1 'Fredoka', 'Segoe UI', sans-serif;
    letter-spacing: -1px;
    color: var(--text);
}

.logo b {
    color: var(--green);
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.day-pill {
    display: inline-block;
    background: var(--yellow);
    color: var(--ink);
    border: 2.5px solid var(--line);
    border-radius: 99px;
    padding: 2px 10px;
    box-shadow: 2px 2px 0 var(--shadow);
    font: 800 13px/1.4 'Nunito', sans-serif;
    white-space: nowrap;
}

.timer {
    font: 700 17px/1 'Fredoka', 'Segoe UI', sans-serif;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.timer-label {
    margin-right: 2px;
}

.icon-btn {
    width: 44px;
    height: 44px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    line-height: 1;
    background: var(--card);
    color: var(--text);
    border: 3px solid var(--line);
    border-radius: 14px;
    box-shadow: 3px 3px 0 var(--shadow);
    cursor: pointer;
    transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.icon-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--shadow);
}

/* Game area */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.board-card {
    width: 100%;
    max-width: 498px; /* 480px canvas + padding + border */
    background: var(--card);
    border: 3px solid var(--line);
    border-radius: 20px;
    padding: 6px;
    box-shadow: 5px 5px 0 var(--shadow);
}

.board-card.shake {
    animation: board-shake 0.3s ease-in-out;
}

@keyframes board-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px) rotate(-0.6deg); }
    40% { transform: translateX(5px) rotate(0.5deg); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(2px); }
}

#gameCanvas {
    display: block;
    /* Until setupCanvas sizes it (inline style wins), keep the 400px default inside the card */
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    border-radius: 14px;
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 28 28" fill="none"><circle cx="14" cy="14" r="11" fill="%2322c55e" stroke="%231a1a1a" stroke-width="3"/><circle cx="14" cy="14" r="3" fill="%231a1a1a"/></svg>') 14 14, pointer;
    touch-action: none;
}

/* Status line under the board */
.status {
    min-height: 22px;
    text-align: center;
    font: 700 16px/1.35 'Fredoka', 'Segoe UI', sans-serif;
    color: var(--text);
}

.status.success {
    color: var(--ok);
}

.status.error {
    color: var(--err);
}

#game-status[hidden],
.solved-strip[hidden] {
    display: none;
}

/* Solved strip: replaces the status line under the board once the day is won */
.solved-strip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px 8px;
    background: var(--card);
    border: 3px solid var(--line);
    border-radius: 16px;
    box-shadow: 3px 3px 0 var(--shadow);
    animation: strip-in 0.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}

.solved-line {
    margin: 0;
    text-align: center;
    font: 700 16px/1.3 'Fredoka', 'Segoe UI', sans-serif;
    color: var(--ok);
}

.solved-actions {
    display: flex;
    gap: 10px;
    width: 100%;
}

.solved-actions .btn {
    flex: 1 1 0;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 15px;
}

.solved-note {
    margin: 0;
    font: 500 12px/1.2 'Fredoka', 'Segoe UI', sans-serif;
    color: var(--text);
    opacity: 0.65;
}

@keyframes strip-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .solved-strip {
        animation: none;
    }
}

/* Buttons */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}

/* Equal widths, but never narrower than the label: wrap instead of squeezing */
.controls .btn {
    flex: 1 1 0;
    min-width: max-content;
    padding-left: 12px;
    padding-right: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 48px;
    padding: 10px 16px;
    font: 700 17px/1.1 'Fredoka', 'Segoe UI', sans-serif;
    color: var(--ink);
    background: var(--card);
    border: 3px solid var(--line);
    border-radius: 14px;
    box-shadow: 3px 3px 0 var(--shadow);
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}

.btn:hover:not(:disabled) {
    filter: brightness(1.04);
}

.btn:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--shadow);
}

.btn:focus-visible,
.icon-btn:focus-visible {
    outline: 3px solid var(--sky-d);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: 1px 1px 0 var(--shadow);
    transform: translate(2px, 2px);
}

.btn-primary {
    background: var(--pink);
    color: var(--ink);
}

.btn-secondary {
    background: var(--card);
    color: var(--text);
}

.btn-hint {
    background: var(--yellow);
    color: var(--ink);
}

.btn-ranking {
    background: var(--sky);
    color: var(--ink);
}

/* Personal best */
.personal-best {
    font-weight: 800;
    font-size: 14px;
}

/* Countdown to the next puzzle */
.fomo-countdown {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    background: var(--sky);
    color: var(--ink);
    border: 3px solid var(--line);
    border-radius: 16px;
    box-shadow: 3px 3px 0 var(--shadow);
}

.countdown-text {
    font-weight: 800;
    font-size: 14px;
}

.countdown-time {
    font: 700 20px/1 'Fredoka', 'Segoe UI', sans-serif;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.fomo-countdown.soon {
    background: var(--yellow);
}

.fomo-countdown.urgent {
    background: var(--pink);
}

/* Desktop: a little more air */
@media (min-width: 600px) {
    body {
        padding: 32px 24px;
    }

    .game-header {
        margin-bottom: 20px;
    }

    .logo {
        font-size: 48px;
    }

    .game-area {
        gap: 16px;
    }
}

/* Narrow phones */
@media (max-width: 360px) {
    .logo {
        font-size: 34px;
    }

    .btn {
        font-size: 15px;
    }
}

/* Board bounce on the winning bite */
.board-card.bump {
    animation: board-bump 0.5s cubic-bezier(0.3, 1.6, 0.5, 1);
}

@keyframes board-bump {
    0% { transform: scale(1); }
    40% { transform: scale(1.04) rotate(-1deg); }
    100% { transform: scale(1); }
}

/* Confetti layer: covers the viewport, under the modals, never takes input */
#fx-canvas {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 900;
    pointer-events: none;
}

/* Modals: shared base (backdrop + sticker card) */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 26, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 12px;
    animation: fadeIn 0.3s ease;
}

.modal.hidden {
    display: none;
}

.modal-card {
    position: relative;
    width: 100%;
    max-width: 440px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    background: var(--card);
    color: var(--text);
    border: 3px solid var(--line);
    border-radius: 22px;
    box-shadow: 5px 5px 0 var(--shadow);
    padding: 16px;
}

/* ✕ in the top-right corner of a modal card */
.modal-x {
    position: absolute;
    top: 10px;
    right: 10px;
    font: 700 18px/1 'Fredoka', 'Segoe UI', sans-serif;
}

/* Result screen: full screen over an opaque polka-dot background, so a screenshot never shows the board */
.victory-modal {
    --rgap: clamp(4px, 1.3vh, 14px);
    --rtime: clamp(48px, 9.2vh, 76px);
    --rlogo: clamp(32px, 5.6vh, 52px);
    display: block;
    padding: 0;
    background-color: var(--bg);
    background-image: radial-gradient(var(--bg-dot) 3px, transparent 3.5px);
    background-size: 24px 24px;
}

/* The visible height without the browser bars, where supported */
@supports (height: 1dvh) {
    .victory-modal {
        --rgap: clamp(4px, 1.3dvh, 14px);
        --rtime: clamp(48px, 9.2dvh, 76px);
        --rlogo: clamp(32px, 5.6dvh, 52px);
    }
}

/* Scrolls only with «Ver detalles» open; closed, everything fits on a 375×667 phone */
.result-screen {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.result-col {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--rgap);
    max-width: 440px;
    min-height: 100%;
    margin: 0 auto;
    padding: calc(var(--rgap) + 6px) 16px var(--rgap);
    text-align: center;
    overflow: hidden; /* The sticker rising from below must not make the screen scroll */
}

.result-x {
    position: absolute;
    top: 10px;
    right: 16px;
    font: 700 18px/1 'Fredoka', 'Segoe UI', sans-serif;
}

.result-logo {
    display: block;
    width: auto;
    height: var(--rlogo);
}

/* The logo is an <img>: in dark mode its ink strokes turn light and the green stays green */
@media (prefers-color-scheme: dark) {
    .result-logo {
        filter: invert(1) hue-rotate(180deg);
    }
}

.result-day {
    font-size: 14px;
}

/* The sticker: white card, hard shadow, a little tilted */
.result-sticker {
    position: relative;
    width: min(100%, 320px);
    margin: calc(var(--rgap) * 0.8) 0 calc(var(--rgap) * 0.4);
    padding: 10px 14px 12px;
    background: var(--card);
    color: var(--text);
    border: 3px solid var(--line);
    border-radius: 22px;
    box-shadow: 5px 5px 0 var(--shadow);
    transform: rotate(-3deg);
}

.result-screen.enter .result-sticker {
    animation: card-in 0.7s cubic-bezier(0.25, 1.5, 0.5, 1) both;
}

@keyframes card-in {
    from { transform: translateY(60vh) rotate(6deg); }
    to { transform: translateY(0) rotate(-3deg); }
}

/* The snake lying on the sticker's top edge, head out past the corner */
.result-snake {
    position: absolute;
    top: -27px;
    right: -14px;
    width: 92px;
    transform: rotate(4deg);
    overflow: visible;
}

.result-nam {
    font: 700 clamp(24px, 4.2vh, 32px)/1 'Fredoka', 'Segoe UI', sans-serif;
    color: var(--green);
    -webkit-text-stroke: 1.5px var(--ink);
    paint-order: stroke fill;
    letter-spacing: 0.5px;
}

.result-time {
    margin: 2px 0 6px;
    font: 700 var(--rtime)/1 'Fredoka', 'Segoe UI', sans-serif;
    font-variant-numeric: tabular-nums;
    letter-spacing: -1px;
}

/* One dot per attempt: pink = failed, green = the win; past 7 pink ones, a "+n" */
.result-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.dot-fail,
.dot-win {
    flex: none;
    width: 24px;
    height: 24px;
    border: 2.5px solid var(--ink);
    border-radius: 50%;
    background: var(--pink);
}

.dot-win {
    background: var(--green);
}

.dot-more {
    font: 700 16px/1 'Fredoka', 'Segoe UI', sans-serif;
    font-variant-numeric: tabular-nums;
}

.result-line {
    margin-top: 8px;
    font: 800 15px/1.35 'Nunito', sans-serif;
    font-variant-numeric: tabular-nums;
}

#victory-rank-faster {
    display: block;
    font: 700 13px/1.3 'Nunito', sans-serif;
    opacity: 0.8;
}

#victory-rank-faster:empty,
.rank-week:empty {
    display: none;
}

/* Waiting for the server */
.result-rank.loading {
    opacity: 0.7;
}

/* Replay: a small dashed note, apart from the first win */
.result-replay {
    max-width: 100%;
    padding: 3px 12px;
    background: var(--card);
    border: 2px dashed var(--line);
    border-radius: 16px;
    font: 800 13px/1.35 'Nunito', sans-serif;
    font-variant-numeric: tabular-nums;
}

.result-best {
    display: block;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.result-chips {
    justify-content: center;
    margin: 0;
}

.chip {
    display: inline-block;
    color: var(--ink);
    border: 2.5px solid var(--line);
    border-radius: 99px;
    padding: 4px 10px;
    box-shadow: 2px 2px 0 var(--shadow);
    font: 800 13px/1.3 'Nunito', sans-serif;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    opacity: 0;
    transform: scale(0.5);
}

.chip.in {
    animation: chip-pop 0.4s cubic-bezier(0.3, 1.8, 0.5, 1) forwards;
}

@keyframes chip-pop {
    to { opacity: 1; transform: scale(1); }
}

.chip-speed { background: var(--sky); }
.chip-streak { background: #ffd0dd; }
.chip-undos { background: var(--yellow); }
.chip-hints { background: #ffffff; }

.rank-week {
    font: 800 13px/1.3 'Nunito', sans-serif;
    font-variant-numeric: tabular-nums;
}

.result-cta {
    font: 800 14px/1.3 'Nunito', sans-serif;
}

.result-url {
    display: block;
    width: max-content;
    margin: 4px auto 0;
    padding: 3px 16px;
    color: var(--ink);
    background: var(--sky);
    border: 2.5px solid var(--line);
    border-radius: 99px;
    box-shadow: 3px 3px 0 var(--shadow);
    font: 700 16px/1.3 'Fredoka', 'Segoe UI', sans-serif;
}

.victory-cta {
    width: 100%;
    margin-top: calc(var(--rgap) * 0.4);
}

.victory-next {
    font-size: 12px;
    opacity: 0.75;
    font-variant-numeric: tabular-nums;
}

/* Reopened or already-won day: everything in place, no entrance */
.result-screen.static .result-sticker,
.result-screen.static .chip {
    animation: none;
}

.result-screen.static .chip {
    opacity: 1;
    transform: none;
}

/* «Ver detalles»: the rest of the old victory modal */
.victory-details {
    width: 100%;
    text-align: left;
}

.victory-details summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    font: 700 15px 'Fredoka', 'Segoe UI', sans-serif;
    cursor: pointer;
    list-style: none;
    border-radius: 12px;
}

.victory-details summary::-webkit-details-marker {
    display: none;
}

.victory-details summary::after {
    content: '▾';
    transition: transform 0.2s ease;
}

.victory-details[open] summary::after {
    transform: rotate(180deg);
}

.victory-details summary:focus-visible {
    outline: 3px solid var(--sky-d);
    outline-offset: 2px;
}

.victory-details-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 6px;
}

.victory-stats {
    border: 2.5px solid var(--line);
    border-radius: 14px;
    padding: 6px 12px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    font-size: 14px;
}

.stat-item + .stat-item {
    border-top: 2px dashed color-mix(in srgb, var(--line) 25%, transparent);
}

.stat-value {
    font: 700 16px 'Fredoka', 'Segoe UI', sans-serif;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.share-result {
    border: 2.5px dashed var(--line);
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 14px;
    line-height: 1.5;
}

.share-buttons,
.victory-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.share-buttons .btn,
.victory-actions .btn {
    flex: 1 1 0;
    min-width: max-content;
    font-size: 15px;
    padding-left: 12px;
    padding-right: 12px;
}

.btn-twitter {
    background: var(--sky);
    color: var(--ink);
}

.btn-whatsapp {
    background: var(--green);
    color: var(--ink);
}

.name-input-section {
    border: 2.5px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px 12px;
}

.name-input-section h3 {
    font: 700 16px 'Fredoka', 'Segoe UI', sans-serif;
    margin-bottom: 2px;
}

.name-input-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#player-name-input {
    flex: 1 1 180px;
    min-width: 0;
    min-height: 48px;
    padding: 10px 12px;
    font: 600 16px 'Nunito', 'Segoe UI', sans-serif;
    color: var(--text);
    background: var(--bg);
    border: 3px solid var(--line);
    border-radius: 14px;
}

#player-name-input:focus {
    outline: 3px solid var(--sky-d);
    outline-offset: 1px;
}

#player-name-input::placeholder {
    color: var(--text);
    opacity: 0.55;
}

/* «💾 Guardar» never breaks: it goes under the input when the row is too narrow */
.name-input-container .btn {
    flex: 1 0 auto;
    white-space: nowrap;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Tutorial */
.tutorial-content {
    max-width: 420px;
    text-align: center;
}

.tutorial-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    text-align: left;
}

.tutorial-title {
    font: 700 21px/1.15 'Fredoka', 'Segoe UI', sans-serif;
    letter-spacing: -0.3px;
}

.skip-btn {
    flex: none;
    min-height: 44px;
    padding: 6px 12px;
    font-size: 14px;
    white-space: nowrap;
}

/* Same height on every step, so the buttons stay put */
.tutorial-steps {
    min-height: 342px;
}

.tutorial-step {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tutorial-step.active {
    display: block;
}

.step-number {
    width: 40px;
    height: 40px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--yellow);
    color: var(--ink);
    border: 3px solid var(--line);
    border-radius: 50%;
    box-shadow: 3px 3px 0 var(--shadow);
    font: 700 20px/1 'Fredoka', 'Segoe UI', sans-serif;
}

.tutorial-step h3 {
    font: 700 20px/1.2 'Fredoka', 'Segoe UI', sans-serif;
    margin-bottom: 6px;
}

.tutorial-step p {
    font-size: 15px;
    line-height: 1.45;
    margin-bottom: 12px;
}

.tutorial-step strong {
    font-weight: 800;
}

/* A little board behind each drawing */
.tutorial-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 186px;
    padding: 12px;
    background: var(--card);
    border: 2.5px solid var(--line);
    border-radius: 16px;
}

/* Board pieces in SVG: the same colours as the canvas */
.svg-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.mini-board {
    display: block;
    max-width: 100%;
    height: auto;
    overflow: visible;
}

.t-cell { fill: var(--cell); }
.t-cell.visited { fill: var(--cell-visited); }
.t-halo { fill: var(--yellow); }

.t-wall {
    fill: none;
    stroke: var(--wall);
    stroke-width: 5.6;
    stroke-linecap: round;
}

.sn-body,
.sn-shadow {
    fill: none;
    stroke-width: 20;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sn-body { stroke: var(--green); }
.sn-shadow { stroke: var(--green-d); }

.sn-head {
    fill: var(--green);
    stroke: var(--ink);
    stroke-width: 3;
}

.sn-tongue {
    fill: none;
    stroke: var(--tongue);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sn-eye {
    fill: #ffffff;
    stroke: var(--ink);
    stroke-width: 2;
}

.sn-pupil { fill: var(--ink); }

.t-num circle {
    fill: #ffffff;
    stroke: var(--ink);
    stroke-width: 2.8;
}

.t-num text {
    fill: var(--ink);
    font: 700 15px 'Fredoka', 'Segoe UI', sans-serif;
    text-anchor: middle;
    dominant-baseline: central;
}

.t-num.eaten circle { fill: var(--ink); }
.t-num.eaten text { fill: #ffffff; }

.t-arrow {
    fill: none;
    stroke: var(--text);
    stroke-width: 3.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.t-no {
    fill: none;
    stroke: var(--err);
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 0.8;
}

/* Step 4 */
.fill-demo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.fill-text {
    font: 700 17px/1 'Fredoka', 'Segoe UI', sans-serif;
    color: var(--ok);
}

/* Step 5 */
.speed-demo {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.timer-demo,
.share-demo {
    display: inline-block;
    color: var(--ink);
    border: 2.5px solid var(--line);
    border-radius: 99px;
    padding: 6px 14px;
    box-shadow: 3px 3px 0 var(--shadow);
    font: 700 17px/1.2 'Fredoka', 'Segoe UI', sans-serif;
    white-space: nowrap;
}

.timer-demo {
    background: var(--yellow);
    font-variant-numeric: tabular-nums;
}

.share-demo {
    background: var(--pink);
    border-radius: 14px;
}

.speed-emoji {
    font-size: 30px;
    line-height: 1;
}

/* Dots on top, buttons below: «¡Empezar a jugar! 🚀» fits on one line */
.tutorial-navigation {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
        "dots dots"
        "prev next";
    gap: 12px 10px;
    margin-top: 14px;
}

.tutorial-dots {
    grid-area: dots;
    display: flex;
    justify-content: center;
    gap: 0;
}

#tutorial-prev { grid-area: prev; }
#tutorial-next { grid-area: next; }

.tutorial-navigation .btn {
    white-space: nowrap;
    padding-left: 14px;
    padding-right: 14px;
}

/* Step dots are little pills; the current one is long and green.
   The dot itself is a 44px tap area; the pill is drawn by ::before */
.dot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    cursor: pointer;
}

.dot::before {
    content: '';
    width: 14px;
    height: 14px;
    box-sizing: border-box;
    border-radius: 99px;
    background: var(--card);
    border: 2.5px solid var(--line);
    transition: width 0.2s ease, background-color 0.2s ease;
}

.dot.active::before {
    width: 32px;
    background: var(--green);
}

/* Ranking */
.ranking-content {
    max-width: 440px;
}

.ranking-header {
    margin-bottom: 14px;
}

/* Room for the ✕ */
.ranking-title {
    margin-right: 52px;
    font: 700 24px/1.15 'Fredoka', 'Segoe UI', sans-serif;
    letter-spacing: -0.3px;
}

/* "Hoy" / "Semana": two sticker buttons, the open one pressed in green */
.ranking-tabs {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.ranking-tab {
    flex: 1 1 0;
    min-height: 44px;
    padding: 6px 12px;
    background: var(--card);
    color: var(--text);
    border: 2.5px solid var(--line);
    border-radius: 99px;
    box-shadow: 2px 2px 0 var(--shadow);
    font: 700 17px/1 'Fredoka', 'Segoe UI', sans-serif;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
}

.ranking-tab[aria-selected="true"] {
    background: var(--green);
    color: var(--ink);
    transform: translate(2px, 2px);
    box-shadow: 0 0 0 var(--shadow);
}

.ranking-tab:focus-visible,
#ranking-panel:focus-visible {
    outline: 3px solid var(--sky-d);
    outline-offset: 3px;
}

#ranking-panel {
    border-radius: 14px;
}

.item-days {
    font: 800 13px/1.4 'Nunito', sans-serif;
    background: var(--sky);
    color: var(--ink);
    border: 2px solid var(--line);
    border-radius: 99px;
    padding: 0 7px;
}

.ranking-subtitle {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 800;
}

/* The player's own result */
.ranking-user-stats {
    background: var(--sky);
    color: var(--ink);
    border: 3px solid var(--line);
    border-radius: 16px;
    box-shadow: 3px 3px 0 var(--shadow);
    padding: 12px 14px;
    margin-bottom: 14px;
}

.user-rank-card {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.user-position {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.position-number {
    font: 700 32px/1 'Fredoka', 'Segoe UI', sans-serif;
}

.position-badge {
    background: #ffffff;
    border: 2px solid var(--ink);
    border-radius: 99px;
    padding: 2px 10px;
    font: 800 12px/1.4 'Nunito', sans-serif;
}

.position-badge:empty {
    display: none;
}

.user-stats {
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-time {
    font: 700 26px/1 'Fredoka', 'Segoe UI', sans-serif;
    font-variant-numeric: tabular-nums;
}

.user-speed-emoji {
    font-size: 22px;
}

.ranking-not-ranked {
    text-align: center;
    font-size: 14px;
    border: 2.5px dashed var(--line);
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 14px;
}

.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 16px;
}

.section-title {
    font: 700 17px/1.2 'Fredoka', 'Segoe UI', sans-serif;
    margin-bottom: 8px;
}

.ranking-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Each row is a small sticker; the player's own row is yellow */
.ranking-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 6px 12px;
    background: var(--card);
    color: var(--text);
    border: 2.5px solid var(--line);
    border-radius: 14px;
    box-shadow: 2px 2px 0 var(--shadow);
}

.ranking-item.user-item {
    background: var(--yellow);
    color: var(--ink);
}

.item-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.item-position {
    flex: none;
    min-width: 32px;
    font: 700 16px/1 'Fredoka', 'Segoe UI', sans-serif;
}

.ranking-item.podium .item-position {
    font-size: 20px;
}

.item-name {
    font-weight: 800;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-right {
    flex: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.item-time {
    font: 700 16px/1 'Fredoka', 'Segoe UI', sans-serif;
    font-variant-numeric: tabular-nums;
}

.item-emoji {
    font-size: 18px;
}

.ranking-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ranking-actions .btn {
    flex: 1 1 0;
    min-width: max-content;
}

/* Loading, empty and error states: the snake with a speech bubble */
.ranking-message {
    text-align: center;
    padding: 22px 8px 22px;
}

.ranking-message-art {
    position: relative;
    display: inline-block;
    margin: 16px 0 12px;
}

.ranking-message-art svg {
    display: block;
    max-width: 100%;
    height: auto;
    overflow: visible;
}

.ranking-message-icon {
    position: absolute;
    top: -26px;
    right: -18px;
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    line-height: 1;
    background: var(--card);
    border: 2.5px solid var(--line);
    border-radius: 50%;
    box-shadow: 2px 2px 0 var(--shadow);
}

.ranking-message-title {
    font: 700 20px/1.2 'Fredoka', 'Segoe UI', sans-serif;
    margin-bottom: 6px;
}

.ranking-message-text {
    font-size: 15px;
    line-height: 1.45;
}

/* Generic hidden state */
.hidden {
    display: none !important;
}

/* Share text keeps its line breaks */
.share-result {
    white-space: pre-line;
    text-align: left;
}

.name-hint {
    font-size: 13px;
    opacity: 0.8;
    margin-bottom: 8px;
}

.btn.saved {
    background: var(--green);
    color: var(--ink);
}

/* Toasts */
.toast {
    position: fixed;
    top: 16px;
    right: 16px;
    max-width: 340px;
    background: var(--card);
    color: var(--text);
    padding: 12px 16px;
    border: 3px solid var(--line);
    border-radius: 16px;
    box-shadow: 5px 5px 0 var(--shadow);
    z-index: 10000;
    font-weight: 800;
    font-size: 15px;
    line-height: 1.35;
    animation: toastIn 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.toast small {
    font-weight: 600;
    opacity: 0.8;
}

.toast-hide {
    transform: translateY(-140%);
    opacity: 0;
}

@keyframes toastIn {
    from { transform: translateY(-140%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 480px) {
    .toast {
        left: 16px;
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .toast {
        animation: none;
        transition: opacity 0.3s ease;
    }

    .toast-hide {
        transform: none;
    }

    .btn,
    .icon-btn {
        transition: none;
    }

    .board-card.shake,
    .board-card.bump {
        animation: none;
    }

    /* The result screen appears in place, without the bounce */
    .modal,
    .result-screen.enter .result-sticker,
    .chip.in {
        animation: none;
    }

    .chip.in {
        opacity: 1;
        transform: none;
    }

    .victory-details summary::after {
        transition: none;
    }

    .tutorial-step {
        animation: none;
    }

    .dot::before {
        transition: none;
    }
}
