/* ===== Snake 2 — Estilos ===== */
:root {
    --bg-0: #0b1020;
    --bg-1: #131a35;
    --board-bg: #0f1730;
    --board-grid: rgba(255, 255, 255, 0.04);
    --snake-head: #4ade80;
    --snake-body: #22c55e;
    --snake-body-2: #16a34a;
    --food: #f43f5e;
    --food-glow: rgba(244, 63, 94, 0.6);
    --accent: #38bdf8;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --card: #1e2748;
    --border: rgba(148, 163, 184, 0.2);
}

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

html, body {
    height: 100%;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: radial-gradient(1200px 600px at 50% -10%, #1a2350 0%, transparent 60%),
                linear-gradient(180deg, var(--bg-0) 0%, #070b1c 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    -webkit-font-smoothing: antialiased;
}

.game-shell {
    width: 100%;
    max-width: 460px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.game-header {
    text-align: center;
}

.game-header h1 {
    font-size: 2.2rem;
    letter-spacing: 0.5px;
    font-weight: 800;
    background: linear-gradient(135deg, #4ade80, #38bdf8);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.game-header h1 .accent {
    background: linear-gradient(135deg, #f43f5e, #fbbf24);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.subtitle {
    color: var(--text-dim);
    font-size: 0.95rem;
    margin-top: 4px;
}

/* ===== HUD ===== */
.hud {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.hud-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.hud-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.hud-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 2px;
    color: #fff;
}

/* ===== Tablero ===== */
.board-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--board-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4),
                inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

#board {
    display: block;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(var(--board-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--board-grid) 1px, transparent 1px);
    background-size: 5% 5%;
}

/* ===== Overlay ===== */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(7, 11, 28, 0.78);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity 0.25s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-card {
    text-align: center;
    background: var(--card);
    border: 1px solid var(--border);
    padding: 24px 22px;
    border-radius: 14px;
    max-width: 320px;
    width: 100%;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.overlay-card h2 {
    font-size: 1.3rem;
    margin-bottom: 10px;
    color: #fff;
}

.overlay-card p {
    color: var(--text-dim);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 16px;
}

kbd {
    background: #0b1230;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
    font-size: 0.85em;
    color: #fff;
}

button {
    cursor: pointer;
    font-family: inherit;
    border: none;
}

#start-btn {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    font-weight: 700;
    padding: 10px 22px;
    border-radius: 10px;
    font-size: 1rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.35);
}

#start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.5);
}

#start-btn:active {
    transform: translateY(0);
}

/* ===== Controles ===== */
.controls {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.touch-pad {
    display: grid;
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
    gap: 6px;
}

.touch-btn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.4rem;
    border-radius: 12px;
    width: 56px;
    height: 56px;
    transition: background 0.15s ease, transform 0.1s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:hover {
    background: #25305a;
}

.touch-btn:active {
    transform: scale(0.94);
    background: var(--accent);
    color: #0b1020;
}

.touch-btn[data-dir="up"]    { grid-column: 2; grid-row: 1; }
.touch-btn[data-dir="left"]  { grid-column: 1; grid-row: 2; }
.touch-btn[data-dir="down"]  { grid-column: 2; grid-row: 2; }
.touch-btn[data-dir="right"] { grid-column: 3; grid-row: 2; }

.action-buttons {
    display: flex;
    gap: 10px;
}

.action {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.15s ease, transform 0.1s ease;
}

.action:hover {
    background: #25305a;
}

.action:active {
    transform: scale(0.97);
}

.game-footer {
    color: var(--text-dim);
    text-align: center;
    font-size: 0.8rem;
}

/* ===== Responsive ===== */
@media (max-width: 420px) {
    .game-header h1 { font-size: 1.8rem; }
    .hud-value { font-size: 1.25rem; }
    .touch-pad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(2, 50px); }
    .touch-btn { width: 50px; height: 50px; }
}