/* Global reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-dark: #050510;
    --bg-card: rgba(10, 10, 25, 0.9);
    --accent-cyan: #2ef2ff;
    --accent-magenta: #ff2fd4;
    --accent-purple: #8f4aff;
    --accent-yellow: #ffe66d;
    --text-main: #e5f1ff;
    --text-muted: #8491b0;
    --border-glow: 0 0 14px rgba(46, 242, 255, 0.6);
    --radius-xl: 22px;
    --radius-lg: 18px;
    --radius-md: 12px;
    --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.6);
    --transition-fast: 0.18s ease-out;
    --transition-med: 0.3s ease-out;
}

html,
body {
    height: 100%;
    width: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
        sans-serif;
    background: radial-gradient(circle at top, #161633 0, #050510 52%, #020208);
    color: var(--text-main);
}

/* Animated background layer */
.bg-animated {
    position: fixed;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(circle at 10% 20%, rgba(46, 242, 255, 0.12) 0, transparent 55%),
        radial-gradient(circle at 80% 0%, rgba(255, 47, 212, 0.16) 0, transparent 55%),
        radial-gradient(circle at 50% 100%, rgba(143, 74, 255, 0.18) 0, transparent 55%),
        repeating-linear-gradient(
            120deg,
            rgba(255, 255, 255, 0.04),
            rgba(255, 255, 255, 0.04) 1px,
            transparent 1px,
            transparent 4px
        );
    opacity: 0.7;
    filter: blur(0.3px);
    pointer-events: none;
    animation: floatGrid 18s linear infinite alternate;
}

@keyframes floatGrid {
    0% {
        transform: translate3d(0, 0, 0) scale(1);
    }
    50% {
        transform: translate3d(-12px, -18px, 0) scale(1.03);
    }
    100% {
        transform: translate3d(10px, 10px, 0) scale(1.02);
    }
}

/* App shell */
.app-shell {
    position: relative;
    z-index: 1;
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 16px 24px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    padding: 16px 20px;
    border-radius: var(--radius-xl);
    background: linear-gradient(
            135deg,
            rgba(46, 242, 255, 0.1),
            rgba(255, 47, 212, 0.05)
        ),
        rgba(4, 4, 16, 0.9);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(46, 242, 255, 0.3);
}

.title-block .title {
    letter-spacing: 0.28em;
    font-size: 18px;
    font-weight: 700;
    color: #f5fbff;
    text-transform: uppercase;
    text-shadow: 0 0 16px rgba(46, 242, 255, 0.6);
}

.title-block .subtitle {
    margin-top: 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-muted);
}

.status-panel {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.status-item {
    min-width: 82px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(132, 145, 176, 0.5);
    background: radial-gradient(
        circle at top left,
        rgba(46, 242, 255, 0.22),
        rgba(5, 5, 20, 0.85)
    );
    box-shadow: 0 0 16px rgba(46, 242, 255, 0.3);
}

.status-item .label {
    font-size: 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.status-item .value {
    display: block;
    margin-top: 2px;
    font-size: 14px;
    font-weight: 600;
}

.state-idle {
    color: var(--accent-yellow);
}
.state-running {
    color: var(--accent-cyan);
}
.state-paused {
    color: var(--accent-purple);
}
.state-gameover {
    color: var(--accent-magenta);
}

/* Layout */
.main-layout {
    display: grid;
    grid-template-columns: minmax(0, 2.2fr) minmax(260px, 1.1fr);
    gap: 16px;
    flex: 1;
}

/* Game card */
.game-card {
    padding: 14px;
    border-radius: var(--radius-xl);
    background: var(--bg-card);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(143, 74, 255, 0.7);
    backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.game-frame {
    position: relative;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(46, 242, 255, 0.5);
    box-shadow: var(--border-glow);
    overflow: hidden;
    background: radial-gradient(circle at top, #151538 0, #050511 50%, #010106);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
}

/* Overlay */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(
            circle at center,
            rgba(10, 10, 30, 0.86),
            rgba(5, 5, 20, 0.98)
        ),
        repeating-linear-gradient(
            0deg,
            rgba(255, 255, 255, 0.03),
            rgba(255, 255, 255, 0.03) 1px,
            transparent 1px,
            transparent 3px
        );
    backdrop-filter: blur(5px);
    color: var(--text-main);
    text-align: center;
    animation: overlayIn 0.25s ease-out;
}

@keyframes overlayIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.overlay.hidden {
    display: none;
}

.overlay-content h2 {
    font-size: 20px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin-bottom: 10px;
    color: var(--accent-cyan);
}

.overlay-content p {
    font-size: 13px;
    margin-bottom: 8px;
    color: var(--text-main);
}

.overlay-content .hint {
    font-size: 11px;
    color: var(--text-muted);
}

.key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    padding: 2px 6px;
    margin: 0 1px;
    border-radius: 6px;
    border: 1px solid rgba(132, 145, 176, 0.7);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-cyan);
    background: rgba(7, 9, 22, 0.9);
}

/* Controls */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.btn {
    position: relative;
    border: 1px solid rgba(132, 145, 176, 0.8);
    border-radius: 999px;
    padding: 6px 16px;
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    background: radial-gradient(
        circle at top left,
        rgba(46, 242, 255, 0.16),
        rgba(10, 10, 26, 0.98)
    );
    color: var(--text-main);
    cursor: pointer;
    overflow: hidden;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast),
        border-color var(--transition-fast), background var(--transition-fast);
}

.btn::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        120deg,
        rgba(46, 242, 255, 0.32),
        rgba(255, 47, 212, 0.18)
    );
    opacity: 0;
    mix-blend-mode: screen;
    transition: opacity var(--transition-med);
}

.btn:hover::before {
    opacity: 0.9;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 18px rgba(46, 242, 255, 0.5);
    border-color: rgba(46, 242, 255, 0.9);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 0 6px rgba(46, 242, 255, 0.4);
}

.btn.primary {
    border-color: rgba(46, 242, 255, 0.9);
    background: radial-gradient(
        circle at top left,
        rgba(46, 242, 255, 0.3),
        rgba(6, 11, 35, 0.95)
    );
}

.btn.danger {
    border-color: rgba(255, 47, 212, 0.9);
    background: radial-gradient(
        circle at top left,
        rgba(255, 47, 212, 0.3),
        rgba(20, 8, 32, 0.96)
    );
}

.btn.ghost {
    background: rgba(7, 9, 22, 0.9);
}

/* Side panel */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel-card {
    padding: 12px 13px;
    border-radius: var(--radius-lg);
    background: rgba(6, 8, 24, 0.96);
    border: 1px solid rgba(132, 145, 176, 0.5);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
}

.panel-card h3 {
    font-size: 13px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin-bottom: 8px;
    color: var(--accent-cyan);
}

.panel-card p {
    font-size: 12px;
    line-height: 1.45;
    color: var(--text-muted);
}

.info-list,
.key-list {
    list-style: none;
    font-size: 12px;
    color: var(--text-muted);
}

.info-list li + li,
.key-list li + li {
    margin-top: 4px;
}

/* Footer */
.footer {
    margin-top: 18px;
    padding-top: 8px;
    border-top: 1px solid rgba(43, 52, 88, 0.9);
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

/* Responsive */
@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .side-panel {
        flex-direction: row;
        overflow-x: auto;
    }

    .panel-card {
        min-width: 240px;
    }
}

@media (max-width: 640px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .title-block .title {
        font-size: 16px;
        letter-spacing: 0.22em;
    }

    .game-card {
        padding: 10px;
    }

    .controls {
        justify-content: flex-start;
    }
}
