/* ============================================================
   Snake Game — Toxic Jungle Theme
   Accent: #84cc16 (lime)   Dark: #1a2e05
   Font: Syne (display) · DM Sans (body)
   ============================================================ */

/* ─── Layout: 3-column (ad | game | ad) ─── */
.snake-layout {
    display: grid;
    grid-template-columns: 160px minmax(0, 480px) 160px;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        ".       game   .      "
        "left    game   right  "
        ".       game   .      ";
    justify-content: center;
    gap: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1rem;
    min-height: calc(100vh - 80px);
}

/* ─── Ad Slots ─── */
.ad-slot { display: flex; align-items: flex-start; justify-content: center; }
.ad-slot--left  { grid-area: left;  padding-top: 2rem; }
.ad-slot--right { grid-area: right; padding-top: 2rem; }
.ad-slot--top, .ad-slot--bottom { display: none; }

.ad-placeholder {
    background: rgba(255,255,255,0.03);
    border: 1px dashed rgba(255,255,255,0.08);
    border-radius: 10px;
    color: rgba(255,255,255,0.12);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 3px;
    text-align: center;
    padding: 2rem 1rem;
    width: 100%;
}
.ad-placeholder--vertical {
    min-height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 5rem;
}

/* ─── Game Container ─── */
#snake-app {
    grid-area: game;
    text-align: center;
    position: relative;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ─── Cards (shared panel style) ─── */
.card {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 1rem 1.2rem;
    margin-bottom: 0.75rem;
}
.card__title {
    color: rgba(255,255,255,0.4);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 0.75rem;
}
.card-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.card--half { margin-bottom: 0; }

/* ─── Menu Header ─── */
.menu-header {
    padding: 2rem 0 1rem;
}
.menu-header h1 {
    font-size: 2.8rem;
    font-weight: 800;
    letter-spacing: 8px;
    color: #fff;
    margin: 0;
    line-height: 1;
    background: linear-gradient(180deg, #e8ffd4 20%, #84cc16 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.subtitle {
    color: rgba(255,255,255,0.35);
    font-size: 0.85rem;
    margin-top: 0.4rem;
    font-weight: 400;
    letter-spacing: 1px;
}
.control-hint {
    color: rgba(255,255,255,0.2);
    font-size: 0.75rem;
    margin-top: 0.5rem;
    letter-spacing: 0.3px;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.6rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    letter-spacing: 0.3px;
    line-height: 1.4;
}
.btn:focus-visible {
    outline: 2px solid #84cc16;
    outline-offset: 2px;
}
.btn--primary {
    background: #84cc16;
    color: #fff;
    box-shadow: 0 2px 8px rgba(132,204,22,0.3);
}
.btn--primary:hover {
    background: #93d526;
    box-shadow: 0 4px 16px rgba(132,204,22,0.35);
    transform: translateY(-1px);
}
.btn--primary:active { transform: translateY(0); box-shadow: 0 1px 4px rgba(132,204,22,0.2); }
.btn--primary:disabled {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.25);
    cursor: default;
    transform: none;
    box-shadow: none;
}
.btn--lg { padding: 0.8rem 2.4rem; font-size: 1rem; }
.btn--outline {
    background: transparent;
    color: rgba(255,255,255,0.5);
    border: 1px solid rgba(255,255,255,0.12);
}
.btn--outline:hover {
    border-color: rgba(255,255,255,0.25);
    color: rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.04);
}
.btn--ghost {
    background: transparent;
    color: rgba(255,255,255,0.4);
    border: none;
    font-size: 0.85rem;
}
.btn--ghost:hover { color: rgba(255,255,255,0.6); }

.menu-best {
    color: rgba(132,204,22,0.6);
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0.4rem 0 0;
    font-variant-numeric: tabular-nums;
}
.menu-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin: 1.2rem 0 0.5rem;
}

/* ─── Skin Grid ─── */
.skin-grid {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    flex-wrap: wrap;
}
.skin-card {
    width: 80px;
    height: 100px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0.4rem;
}
.skin-card:hover:not(.locked) {
    border-color: rgba(132,204,22,0.4);
    background: rgba(132,204,22,0.05);
}
.skin-card.selected {
    border-color: #84cc16;
    background: rgba(132,204,22,0.08);
    box-shadow: 0 0 0 1px rgba(132,204,22,0.2);
}
.skin-card.locked {
    opacity: 0.3;
    cursor: not-allowed;
}
.skin-card:focus-visible {
    outline: 2px solid #84cc16;
    outline-offset: 2px;
}
.skin-card canvas { margin-bottom: 0.25rem; }
.skin-card span {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.45);
    font-weight: 500;
}
.skin-card.selected span { color: #84cc16; }

.skin-info {
    margin-top: 0.6rem;
    padding: 0.6rem;
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 8px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.4);
    min-height: 40px;
}
.skin-info .stat-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.15rem 0;
}
.skin-info .stat-label {
    width: 50px;
    text-align: right;
    color: rgba(255,255,255,0.3);
    font-size: 0.75rem;
}
.skin-info .stat-track {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    overflow: hidden;
}
.skin-info .stat-fill {
    height: 100%;
    background: #84cc16;
    border-radius: 2px;
    transition: width 0.3s;
}

/* ─── Difficulty ─── */
.difficulty-grid {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
}
.diff-btn {
    flex: 1;
    padding: 0.5rem 0.3rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    color: rgba(255,255,255,0.4);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}
.diff-btn:hover { border-color: rgba(255,255,255,0.2); color: rgba(255,255,255,0.6); }
.diff-btn.selected {
    border-color: #84cc16;
    background: rgba(132,204,22,0.08);
    color: #84cc16;
}
.diff-btn:focus-visible { outline: 2px solid #84cc16; outline-offset: 2px; }
.diff-icon { font-size: 0.7rem; line-height: 1; }
.diff-desc {
    font-size: 0.6rem;
    color: rgba(255,255,255,0.2);
    font-weight: 400;
}
.diff-btn.selected .diff-desc { color: rgba(132,204,22,0.6); }

/* ─── Volume ─── */
.volume-controls {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.vol-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}
.vol-name {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.35);
    width: 28px;
    text-align: right;
    font-weight: 500;
}
.vol-slider {
    flex: 1;
    height: 4px;
    accent-color: #84cc16;
    cursor: pointer;
}
.vol-val {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.3);
    width: 22px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ─── HUD ─── */
#game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
}
.hud__cell {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.hud__cell--right { text-align: right; align-items: flex-end; }
.hud__label {
    font-size: 0.6rem;
    font-weight: 600;
    color: rgba(255,255,255,0.25);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.hud__value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #84cc16;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.hud__value--sub { font-size: 0.95rem; color: rgba(255,255,255,0.4); }
.hud__combo {
    font-size: 0.85rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    background: rgba(132,204,22,0.12);
    letter-spacing: 0.5px;
    animation: comboPulse 0.3s ease;
}
@keyframes comboPulse {
    0% { transform: scale(1.3); }
    100% { transform: scale(1); }
}
.hud__item {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    background: rgba(255,255,255,0.06);
}

/* ─── Canvas ─── */
.canvas-wrap {
    position: relative;
    line-height: 0;
}
#game-canvas {
    background: #0a0a0a;
    border: 1px solid rgba(255,255,255,0.06);
    border-top: none;
    border-radius: 0 0 12px 12px;
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    touch-action: none;
}

/* ─── D-Pad ─── */
.dpad {
    display: none;
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0.8rem auto 0;
}
.dpad-btn {
    position: absolute;
    width: 52px;
    height: 52px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    color: rgba(255,255,255,0.5);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.08s ease;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.dpad-btn:active {
    background: rgba(132,204,22,0.25);
    border-color: rgba(132,204,22,0.4);
    color: #84cc16;
    transform: scale(0.94);
}
.dpad-up    { top: 0;    left: 50%; transform: translateX(-50%); }
.dpad-down  { bottom: 0; left: 50%; transform: translateX(-50%); }
.dpad-left  { left: 0;   top: 50%;  transform: translateY(-50%); }
.dpad-right { right: 0;  top: 50%;  transform: translateY(-50%); }
.dpad-up:active    { transform: translateX(-50%) scale(0.94); }
.dpad-down:active  { transform: translateX(-50%) scale(0.94); }
.dpad-left:active  { transform: translateY(-50%) scale(0.94); }
.dpad-right:active { transform: translateY(-50%) scale(0.94); }

@media (pointer: coarse) {
    .dpad { display: block; }
}

/* Mobile pause */
.mobile-pause-btn {
    display: none;
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    color: rgba(255,255,255,0.6);
    font-size: 1rem;
    cursor: pointer;
    z-index: 50;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
@media (pointer: coarse) {
    .mobile-pause-btn { display: flex; align-items: center; justify-content: center; }
}

/* ─── Overlays ─── */
.overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.overlay__box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    padding: 2rem 3rem;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
}
.overlay__box h2 {
    color: #fff;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 1px;
    margin-bottom: 0.3rem;
}

/* Pause stats */
.pause-stats {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 0.5rem;
}
.pause-stat {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}
.pause-stat span {
    color: #84cc16;
    font-weight: 700;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

/* New Best */
.new-best-overlay {
    background: rgba(0,0,0,0.6) !important;
    pointer-events: none;
}
.new-best-text {
    color: #ffd54f !important;
    font-size: 2.8rem !important;
    font-weight: 800;
    letter-spacing: 2px;
    text-shadow: 0 0 40px rgba(255,213,79,0.5), 0 0 80px rgba(255,213,79,0.2);
    animation: newBestPulse 0.6s ease-out;
}
@keyframes newBestPulse {
    0%   { transform: scale(0.5); opacity: 0; }
    50%  { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

/* ─── Result Card (Game Over) ─── */
.result-card {
    max-width: 380px;
    margin: 2rem auto;
    padding: 2rem 1.5rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.result-card h2 {
    color: #fff;
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
}
.result-score {
    font-size: 2rem;
    font-weight: 800;
    color: #84cc16;
    font-variant-numeric: tabular-nums;
}
.result-best {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.35);
}
.result-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.8rem;
}
#nickname {
    padding: 0.55rem 1rem;
    font-size: 0.9rem;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    color: #e0e0e0;
    border-radius: 8px;
    width: 200px;
    text-align: center;
    transition: border-color 0.15s;
}
#nickname:focus {
    outline: none;
    border-color: #84cc16;
}
#nickname::placeholder { color: rgba(255,255,255,0.2); }

/* ─── Game Stats ─── */
.game-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
    margin: 0.5rem 0;
    width: 100%;
}
.game-stats .stat-item {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 8px;
    padding: 0.35rem 0.7rem;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.game-stats .stat-item .stat-val {
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
}

/* ─── Leaderboard ─── */
.lb-card {
    max-width: 400px;
    margin: 2rem auto;
    padding: 1.5rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    text-align: center;
}
.lb-card h2 {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 1px;
    margin-bottom: 1rem;
}
#leaderboard-list {
    text-align: left;
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}
#leaderboard-list li {
    display: flex;
    align-items: center;
    padding: 0.55rem 0.6rem;
    border-radius: 8px;
    transition: background 0.15s;
}
#leaderboard-list li:nth-child(odd) {
    background: rgba(255,255,255,0.02);
}
#leaderboard-list li:hover {
    background: rgba(132,204,22,0.06);
}
#leaderboard-list li .rank {
    color: rgba(255,255,255,0.3);
    font-weight: 700;
    width: 28px;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}
#leaderboard-list li:nth-child(1) .rank { color: #ffd54f; }
#leaderboard-list li:nth-child(2) .rank { color: #b0bec5; }
#leaderboard-list li:nth-child(3) .rank { color: #a1887f; }
#leaderboard-list li .lb-name {
    flex: 1;
    color: rgba(255,255,255,0.6);
    font-size: 0.85rem;
}
#leaderboard-list li .lb-score {
    color: #84cc16;
    font-weight: 700;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}
#leaderboard-list li .lb-time {
    color: rgba(255,255,255,0.2);
    font-size: 0.7rem;
    margin-left: 0.6rem;
    white-space: nowrap;
}

/* ─── Responsive: Tablet ─── */
@media (max-width: 860px) {
    .snake-layout {
        grid-template-columns: 1fr;
        grid-template-areas: "game";
        max-width: 480px;
        gap: 0;
    }
    .ad-slot--left, .ad-slot--right { display: none; }
    .ad-slot--top, .ad-slot--bottom {
        display: flex;
        grid-area: unset;
        justify-content: center;
        padding: 0.5rem 0;
    }
    .snake-layout {
        grid-template-areas:
            "top"
            "game"
            "bottom";
        grid-template-rows: auto 1fr auto;
    }
    .ad-slot--top    { grid-area: top; }
    .ad-slot--bottom { grid-area: bottom; }
    .ad-placeholder--vertical { min-height: unset; position: static; }
    .ad-placeholder {
        min-height: 60px;
        padding: 1rem;
    }
}

/* ─── Responsive: Mobile ─── */
@media (max-width: 480px) {
    .snake-layout { padding: 0 0.5rem; }
    .menu-header { padding: 1.2rem 0 0.8rem; }
    .menu-header h1 { font-size: 2rem; letter-spacing: 5px; }
    .card { padding: 0.8rem; }
    .card-row { grid-template-columns: 1fr; gap: 0.6rem; }
    .skin-card { width: 70px; height: 90px; }
    .skin-grid { gap: 0.4rem; }
    .btn--lg { padding: 0.7rem 2rem; font-size: 0.9rem; }
    #game-hud { padding: 0.4rem 0.7rem; }
    .hud__value { font-size: 1.1rem; }
    #nickname { width: 170px; }
    .result-card { margin: 1rem auto; padding: 1.5rem 1rem; }
    .dpad { width: 150px; height: 150px; }
    .dpad-btn { width: 48px; height: 48px; font-size: 1rem; }
    .difficulty-grid { gap: 0.3rem; }
    .diff-btn { padding: 0.4rem 0.2rem; font-size: 0.75rem; }
}

/* ─── Achievement Toast ─── */
.achievement-toast {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%) translateY(-80px);
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 1px solid #ffd700;
    border-radius: 10px;
    padding: 0.5rem 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 180px;
    max-width: 280px;
    z-index: 200;
    transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.35s ease;
    opacity: 0;
    pointer-events: none;
}
.achievement-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.ach-icon { font-size: 1.4rem; flex-shrink: 0; }
.ach-body { display: flex; flex-direction: column; }
.ach-label { font-size: 0.6rem; color: #ffd700; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
.ach-name  { font-size: 0.8rem; color: #eee; font-weight: 600; }

/* ─── Achievement Summary (gameover) ─── */
.achievement-summary {
    margin: 0.6rem 0;
}
.ach-summary-title {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.45);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.4rem;
}
.ach-badge-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    justify-content: center;
}
.ach-badge {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: default;
}
.ach-badge.earned {
    background: rgba(255,215,0,0.15);
    border: 1px solid rgba(255,215,0,0.4);
}
.ach-badge.locked {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.2);
    font-size: 0.75rem;
}

/* ─── Tutorial Overlay ─── */
.tutorial-overlay {
    background: rgba(0,0,0,0.85);
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 300;
}
.tutorial-overlay.hidden { display: none !important; }
.tutorial-box {
    max-width: 360px;
    width: 92%;
    padding: 1.5rem;
    text-align: left;
}
.tutorial-box h2 {
    font-size: 1.1rem;
    margin-bottom: 0.8rem;
    color: #eee;
}
.tut-content {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.75);
    line-height: 1.6;
    min-height: 90px;
    margin-bottom: 1rem;
}
.tut-items { display: flex; flex-direction: column; gap: 0.3rem; }
.tut-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.tut-step-indicator {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
}
#tut-skip {
    display: block;
    margin: 0 auto;
    opacity: 0.5;
}

/* ─── Extra button sizes ─── */
.btn--sm  { padding: 0.35rem 0.8rem; font-size: 0.8rem; }
.btn--xs  { padding: 0.25rem 0.6rem; font-size: 0.72rem; }
