* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: contain;
    background: #1a1a2e;
    color: #fff;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    touch-action: none;
}

#game-canvas {
    display: block;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
}

.menu-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: 1px solid rgba(255, 215, 0, 0.4);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.menu-btn[hidden] {
    display: none;
}

.menu-btn:hover {
    background: rgba(0, 0, 0, 0.85);
    border-color: rgba(255, 215, 0, 0.7);
}

/* HUD */
#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    padding: 14px 14px 10px 64px;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 100%);
}

.hud-row {
    display: flex;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 6px;
}

.hud-buffs {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    min-height: 18px;
}

.hud-buff {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6rem;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(221, 170, 68, 0.7);
    color: #ffd700;
    padding: 2px 6px;
    border-radius: 3px;
    line-height: 1;
}

.hud-block {
    flex: 1;
    min-width: 0;
}

.hud-block-wide {
    flex: 3;
}

.hud-block-right {
    flex: 0 0 auto;
    text-align: right;
    min-width: 70px;
}

.hud-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55rem;
    color: #ffd700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 3px;
}

.hud-bar {
    height: 14px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

.hud-bar-fill {
    height: 100%;
    background: linear-gradient(180deg, #4CAF50, #388E3C);
    width: 100%;
    transition: width 0.18s linear, background 0.3s linear;
}

.hud-bar-fill.warning {
    background: linear-gradient(180deg, #f4a460, #c47a32);
}

.hud-bar-fill.danger {
    background: linear-gradient(180deg, #e74c3c, #b03020);
}

.hud-bar-fill.sprinting {
    box-shadow: inset 0 0 8px rgba(255, 255, 255, 0.6);
    animation: sprintPulse 0.4s linear infinite;
}

@keyframes sprintPulse {
    0%, 100% { filter: brightness(1.0); }
    50% { filter: brightness(1.4); }
}

.hud-bar-fill.progreso {
    background: linear-gradient(180deg, #ff8c42, #d96a20);
    width: 0%;
}

.hud-bar-fill.encuentro {
    background: linear-gradient(180deg, #ffd700, #c2a000);
    width: 100%;
    transition: width 0.05s linear;
}

.hud-value {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.85rem;
    color: #fff;
    line-height: 1.4;
}

/* Overlays */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(10, 10, 25, 0.92);
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.overlay.overlay-active {
    display: flex;
}

.overlay-content {
    background: linear-gradient(180deg, #1e2a4a, #121826);
    border: 2px solid rgba(255, 140, 66, 0.5);
    border-radius: 16px;
    padding: 30px 24px;
    max-width: 500px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.overlay-content h1 {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(1rem, 4vw, 1.6rem);
    color: #ff8c42;
    margin-bottom: 16px;
    text-shadow: 2px 2px 0 #000;
    line-height: 1.3;
}

.overlay-content h2 {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(0.9rem, 3.5vw, 1.2rem);
    color: #ffd700;
    margin-bottom: 14px;
    line-height: 1.3;
}

.overlay-tagline {
    color: #ffd700;
    font-weight: bold;
    margin-bottom: 18px;
    font-size: 1rem;
}

.overlay-text {
    color: #ccc;
    line-height: 1.55;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.overlay-frase {
    color: #fff;
    font-style: italic;
    font-size: 1.05rem;
    margin: 14px 0 18px;
    line-height: 1.4;
}

.overlay-prompt {
    color: #ffd700;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.8rem;
    margin: 14px 0 10px;
    text-transform: uppercase;
}

.overlay-controls {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 20px;
    text-align: left;
}

.overlay-controls p {
    color: #bbb;
    font-size: 0.85rem;
    line-height: 1.55;
    margin-bottom: 4px;
}

.overlay-encuentro-content {
    border-color: rgba(255, 215, 0, 0.6);
}

#encuentro-sprite {
    width: 96px;
    height: 96px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    border: 3px solid #ffd700;
}

/* Buttons */
.btn-primary, .btn-secondary {
    display: inline-block;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 14px 26px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    margin: 6px 6px 0;
    text-decoration: none;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn-primary {
    background: linear-gradient(180deg, #ff8c42 0%, #d96a20 100%);
    color: #fff;
    box-shadow: 0 4px 0 #a04e10, 0 6px 10px rgba(0, 0, 0, 0.3);
}

.btn-primary:hover, .btn-primary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #a04e10, 0 4px 8px rgba(0, 0, 0, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: #ccc;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* Pausa & Ayuda */
.overlay-pausa-content,
.overlay-ayuda-content {
    border-color: rgba(255, 215, 0, 0.55);
}

.pausa-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 18px 0 8px;
}

.pausa-buttons .btn-primary,
.pausa-buttons .btn-secondary {
    margin: 0;
    width: 100%;
    text-align: center;
}

.btn-kofi {
    background: linear-gradient(180deg, #ff5e5b 0%, #d93838 100%);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 4px 0 #8a1c1c;
}

.btn-kofi:hover {
    background: linear-gradient(180deg, #ff7a78 0%, #e64a4a 100%);
    color: #fff;
}

.pausa-audio {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 14px 0 4px;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.pausa-audio-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.65rem;
    color: #ffd700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.pausa-audio-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.pausa-audio-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.pausa-hint {
    color: #888;
    font-size: 0.78rem;
    margin-top: 10px;
    text-align: center;
}

.overlay-ayuda-content {
    max-width: 560px;
    text-align: left;
}

.overlay-ayuda-content h2 {
    text-align: center;
}

.ayuda-section {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    margin-bottom: 8px;
    padding: 8px 12px;
}

.ayuda-section[open] {
    border-color: rgba(255, 140, 66, 0.4);
}

.ayuda-section summary {
    cursor: pointer;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7rem;
    color: #ffd700;
    padding: 4px 0;
    list-style: none;
    outline: none;
}

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

.ayuda-section summary::before {
    content: '▸ ';
    color: #ff8c42;
    display: inline-block;
    transition: transform 0.15s ease;
}

.ayuda-section[open] summary::before {
    content: '▾ ';
}

.ayuda-body {
    padding: 6px 0 4px;
}

.ayuda-body p {
    color: #ddd;
    font-size: 0.92rem;
    line-height: 1.55;
    margin: 8px 0;
}

.ayuda-body b {
    color: #ff8c42;
}

.overlay-ayuda-content > .btn-primary {
    display: block;
    margin: 14px auto 0;
}

/* Nickname & Ranking */
.nickname-input {
    display: block;
    width: 100%;
    margin: 14px 0 6px;
    padding: 12px 14px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.95rem;
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: 2px solid rgba(255, 215, 0, 0.5);
    border-radius: 8px;
    outline: none;
    text-transform: none;
}

.nickname-input:focus {
    border-color: #ffd700;
}

.nickname-error {
    color: #ff7a5a;
    font-size: 0.85rem;
    margin: 4px 0 12px;
    min-height: 1.2em;
}

.overlay-ranking-content {
    max-width: 560px;
    text-align: left;
}

.overlay-ranking-content h2 {
    text-align: center;
}

.ranking-nick-info {
    color: #ffd700;
    font-size: 0.85rem;
    margin: 0 0 12px;
    text-align: center;
}

.ranking-list {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    max-height: 50vh;
    overflow-y: auto;
    margin-bottom: 16px;
}

.ranking-row {
    display: grid;
    grid-template-columns: 42px 1fr auto auto;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.92rem;
}

.ranking-row:last-child {
    border-bottom: none;
}

.ranking-row.is-me {
    background: rgba(255, 215, 0, 0.12);
    color: #ffd700;
}

.ranking-rank {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7rem;
    color: #ff8c42;
}

.ranking-row.is-top1 .ranking-rank { color: #ffd700; }
.ranking-row.is-top2 .ranking-rank { color: #c0c0c0; }
.ranking-row.is-top3 .ranking-rank { color: #cd7f32; }

.ranking-nick {
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ranking-level {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7rem;
    color: #ff8c42;
}

.ranking-time {
    color: #bbb;
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
    min-width: 60px;
    text-align: right;
}

.ranking-loading,
.ranking-empty,
.ranking-error {
    text-align: center;
    color: #aaa;
    padding: 20px;
    font-size: 0.9rem;
}

.ranking-error {
    color: #ff7a5a;
}

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

.ranking-actions .btn-primary,
.ranking-actions .btn-secondary {
    margin: 0;
}

/* Powerup pickup flash */
#powerup-flash {
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translate(-50%, 0);
    font-family: 'Press Start 2P', monospace;
    font-size: 1rem;
    color: #ffd700;
    text-shadow: 2px 2px 0 #000, 0 0 12px rgba(255, 215, 0, 0.6);
    pointer-events: none;
    opacity: 0;
    z-index: 80;
    text-align: center;
    white-space: nowrap;
}

#powerup-flash.show {
    animation: flashUp 1.6s forwards;
}

@keyframes flashUp {
    0% { opacity: 0; transform: translate(-50%, 12px); }
    18% { opacity: 1; transform: translate(-50%, 0); }
    78% { opacity: 1; transform: translate(-50%, -14px); }
    100% { opacity: 0; transform: translate(-50%, -28px); }
}

/* Bocadillos in-world */
#bocadillos-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 60;
}

.bocadillo {
    position: absolute;
    transform: translate(-50%, -100%);
    background: #fff;
    color: #1a1a2e;
    border: 2px solid #1a1a2e;
    border-radius: 10px;
    padding: 6px 10px;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    max-width: 220px;
    line-height: 1.25;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
    pointer-events: none;
    white-space: pre-wrap;
    text-align: center;
    will-change: left, top, opacity;
}

.bocadillo::after {
    content: "";
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1a1a2e;
    border-bottom: 0;
}

.bocadillo::before {
    content: "";
    position: absolute;
    bottom: -7px;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #fff;
    border-bottom: 0;
    z-index: 1;
}

.bocadillo.alarm {
    background: #ffe9c0;
    border-color: #b03020;
    color: #b03020;
}

.bocadillo.alarm::before {
    border-top-color: #ffe9c0;
}

.bocadillo.alarm::after {
    border-top-color: #b03020;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition: none !important;
        animation: none !important;
    }
}
