@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Outfit:wght@400;600;700;800&display=swap');

:root {
    --bg-dark: #0f172a;
    --arcade-red: #e52521;
    --arcade-yellow: #fbd000;
    --arcade-blue: #00247d;
    --arcade-green: #43b047;
    --sky-blue: #5c94fc;
    --pipe-green: #00a800;
    --hud-gold: #ffd700;
    --font-pixel: 'Press Start 2P', monospace, cursive;
    --font-sans: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body {
    background-color: #0b0f19;
    background-image: 
        radial-gradient(circle at 50% 20%, rgba(92, 148, 252, 0.15), transparent 70%),
        radial-gradient(circle at 80% 80%, rgba(229, 37, 33, 0.1), transparent 50%);
    color: #ffffff;
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-x: hidden;
    padding-bottom: 2rem;
}

/* Header & Nav */
.game-header {
    width: 100%;
    max-width: 960px;
    padding: 1.25rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: #94a3b8;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.back-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateX(-2px);
}

.header-title {
    font-family: var(--font-pixel);
    font-size: 1.25rem;
    letter-spacing: 1px;
    background: linear-gradient(185deg, #ffffff 0%, #fbd000 50%, #e52521 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 12px rgba(229, 37, 33, 0.3);
    text-align: center;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: var(--font-pixel);
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: var(--arcade-yellow);
    transform: translateY(-1px);
}

.icon-btn.active {
    background: rgba(251, 208, 0, 0.2);
    border-color: var(--arcade-yellow);
    color: var(--arcade-yellow);
    box-shadow: 0 0 10px rgba(251, 208, 0, 0.4);
}

/* World Selection Tabs */
.world-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    width: 100%;
    max-width: 960px;
    padding: 0 1rem;
    overflow-x: auto;
}

.tab-btn {
    background: #1e293b;
    border: 2px solid #334155;
    color: #94a3b8;
    font-family: var(--font-pixel);
    font-size: 0.65rem;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    background: #334155;
    color: #ffffff;
    border-color: #475569;
}

.tab-btn.active {
    background: var(--arcade-red);
    color: #ffffff;
    border-color: #ffffff;
    box-shadow: 0 0 12px rgba(229, 37, 33, 0.5);
}

/* Main Container */
.game-container {
    width: 100%;
    max-width: 960px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 1rem;
    position: relative;
}

/* Arcade Frame */
.arcade-frame {
    width: 100%;
    background: #1e293b;
    border-radius: 16px;
    border: 4px solid #334155;
    box-shadow: 
        0 20px 50px rgba(0, 0, 0, 0.7),
        0 0 30px rgba(92, 148, 252, 0.2),
        inset 0 2px 4px rgba(255, 255, 255, 0.1);
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Arcade HUD Top Bar */
.arcade-hud {
    background: #000000;
    padding: 0.85rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-pixel);
    font-size: 0.75rem;
    color: #ffffff;
    border-bottom: 3px solid #334155;
    z-index: 10;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

.hud-label {
    color: #94a3b8;
    font-size: 0.6rem;
    text-transform: uppercase;
}

.hud-value {
    color: #ffffff;
    letter-spacing: 1px;
}

.hud-value.gold {
    color: var(--arcade-yellow);
    text-shadow: 0 0 8px rgba(251, 208, 0, 0.5);
}

.hud-value.star-invincible {
    animation: starPulse 0.2s infinite alternate;
    color: #ff00ff;
    text-shadow: 0 0 10px #00ffff;
}

@keyframes starPulse {
    0% { color: #ff0055; text-shadow: 0 0 8px #ffff00; }
    50% { color: #00ffcc; text-shadow: 0 0 8px #ff00ff; }
    100% { color: #ffff00; text-shadow: 0 0 8px #00ff55; }
}

/* Viewport & Canvas Area */
.canvas-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--sky-blue);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Retro CRT Mode Scanlines Effect */
.canvas-wrapper.crt-mode::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    z-index: 5;
    background-size: 100% 4px, 6px 100%;
    pointer-events: none;
}

.canvas-wrapper.crt-mode::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6);
    z-index: 6;
    pointer-events: none;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
}

/* Overlay UI Screens */
.game-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    z-index: 20;
    opacity: 1;
    transition: opacity 0.3s ease;
}

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

.overlay-title {
    font-family: var(--font-pixel);
    font-size: 2rem;
    color: var(--arcade-yellow);
    text-shadow: 4px 4px 0 #e52521, -2px -2px 0 #000;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.overlay-subtitle {
    font-size: 1.05rem;
    color: #cbd5e1;
    margin-bottom: 2rem;
    max-width: 550px;
    line-height: 1.5;
}

.btn-primary {
    font-family: var(--font-pixel);
    font-size: 0.9rem;
    padding: 1rem 2rem;
    background: linear-gradient(180deg, #e52521 0%, #b91c1c 100%);
    color: #ffffff;
    border: 3px solid #ffffff;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 6px 0 #7f1d1d, 0 10px 20px rgba(0, 0, 0, 0.5);
    transition: all 0.15s ease;
    text-transform: uppercase;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #7f1d1d, 0 14px 25px rgba(229, 37, 33, 0.4);
    background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
}

.btn-primary:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #7f1d1d, 0 4px 10px rgba(0, 0, 0, 0.5);
}

/* Controls Info Card */
.controls-card {
    margin-top: 1.5rem;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 1rem;
    width: 100%;
    max-width: 650px;
}

.ctrl-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.ctrl-key {
    background: #334155;
    border: 1px solid #475569;
    border-bottom-width: 3px;
    color: #ffffff;
    font-family: var(--font-pixel);
    font-size: 0.6rem;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    text-align: center;
}

.ctrl-desc {
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    font-weight: 600;
    text-align: center;
}

/* Mobile Controller Overlay */
.mobile-controls {
    display: none;
    width: 100%;
    padding: 1rem 1.5rem;
    background: #0f172a;
    border-top: 2px solid #334155;
    justify-content: space-between;
    align-items: center;
}

@media (max-width: 820px) {
    .mobile-controls {
        display: flex;
    }
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 4px;
}

.dpad-btn {
    background: #334155;
    border: 2px solid #475569;
    color: #ffffff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    user-select: none;
    -webkit-user-select: none;
}

.dpad-btn:active, .dpad-btn.active {
    background: var(--arcade-yellow);
    color: #000;
    border-color: #ffffff;
}

.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 3; }

.action-buttons {
    display: flex;
    gap: 1rem;
}

.action-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid #ffffff;
    font-family: var(--font-pixel);
    font-size: 0.75rem;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    user-select: none;
}

.action-btn.btn-b {
    background: #e52521;
}

.action-btn.btn-a {
    background: #fbd000;
    color: #000;
}

.action-btn:active, .action-btn.active {
    transform: scale(0.92);
    filter: brightness(1.2);
}

/* Features Grid Footer */
.features-section {
    width: 100%;
    max-width: 960px;
    margin-top: 2rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

.feature-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.feature-card:hover {
    transform: translateY(-2px);
    border-color: rgba(92, 148, 252, 0.3);
}

.feature-icon {
    font-size: 1.5rem;
}

.feature-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: #f8fafc;
}

.feature-desc {
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.5;
}
