:root {
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --bg-overlay: rgba(15, 23, 42, 0.85);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-secondary: #475569;
    --danger: #ef4444;

    --border-radius: 12px;
    --border-radius-sm: 8px;

    --font-heading: 'Press Start 2P', cursive;
    --font-body: 'Outfit', sans-serif;

    --block-size: 30px;
    /* Base for desktop */
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-body);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    touch-action: none;
    /* Prevent zooming and pulling on mobile */
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
}

/* --- Persistent Quit Button --- */
.quit-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 10px 15px;
    background-color: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    text-decoration: none;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    border-radius: 8px;
    z-index: 100;
    transition: all 0.2s;
}

.quit-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: white;
}

/* --- Layout --- */
.app-container {
    display: flex;
    flex-direction: row;
    gap: 2rem;
    max-width: 1200px;
    padding: 2rem;
    align-items: flex-start;
}

/* --- Game Canvas Area --- */
.game-wrapper {
    position: relative;
    border-radius: 4px;
    background-color: #000;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5), 0 0 0 4px var(--bg-panel);
    overflow: hidden;
}

canvas {
    display: block;
}

/* --- Panels (Score, Next, Hold) --- */
.panels-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 200px;
}

.panel-box {
    background: var(--bg-panel);
    border-radius: var(--border-radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.score-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.value {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    color: var(--text-main);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.side-panels {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.hold-panel canvas,
.next-panel canvas {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius-sm);
    margin-top: 0.5rem;
}

/* --- Overlays --- */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-overlay);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
    z-index: 10;
}

.overlay.active {
    opacity: 1;
    pointer-events: all;
}

.overlay h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    margin-bottom: 2rem;
    text-align: center;
    line-height: 1.5;
}

.logo {
    font-family: var(--font-heading);
    font-size: 2.25rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6, #ec4899);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.glow {
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

.text-danger {
    color: var(--danger);
}

.high-score-display,
.score-summary {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    font-weight: 600;
    color: var(--text-muted);
}

.score-summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.instruction-text {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    animation: flash 1.5s infinite;
}

@keyframes flash {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/* --- Buttons --- */
.btn {
    font-family: var(--font-body);
    font-weight: 800;
    font-size: 1.1rem;
    padding: 1rem 2rem;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s, box-shadow 0.2s;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    width: 80%;
    max-width: 250px;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background-color: var(--accent-primary);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.btn-primary:hover {
    background-color: var(--accent-primary-hover);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-main);
    border: 2px solid var(--accent-secondary);
    margin-top: 1rem;
}

/* --- Mobile Controls --- */
.mobile-controls {
    display: none;
    /* Hidden on desktop by default */
    flex-direction: column;
    width: 100%;
    padding: 1rem;
    gap: 0.5rem;
}

.control-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.control-btn {
    background: var(--bg-panel);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: var(--border-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    touch-action: manipulation;
    user-select: none;
}

.control-btn.active-state:active {
    background: rgba(255, 255, 255, 0.2);
}

.icon-btn {
    width: 44px;
    height: 44px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 50%;
}

.control-grid {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
}

.dpad {
    display: grid;
    grid-template-columns: 60px 60px 60px;
    grid-template-rows: 60px;
    gap: 0.5rem;
}

.dpad-btn {
    height: 60px;
    font-size: 1.5rem;
}

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

.action-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    font-size: 2rem;
    background: var(--accent-primary);
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

/* --- Notifications --- */
.notification-area {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 5;
    text-align: center;
    width: 100%;
}

.score-float {
    color: #ffd700;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 1);
    animation: floatUp 1s ease-out forwards;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

@keyframes floatUp {
    0% {
        transform: translate(-50%, 0) scale(0.5);
        opacity: 0;
    }

    20% {
        opacity: 1;
        transform: translate(-50%, -10px) scale(1.2);
    }

    80% {
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -40px) scale(1);
        opacity: 0;
    }
}

/* --- Responsive Layout --- */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        align-items: center;
        padding: 1rem;
        gap: 1rem;
        height: 100vh;
        width: 100vw;
    }

    .game-wrapper {
        flex-grow: 1;
        display: flex;
        justify-content: center;
        max-height: 55vh;
    }

    canvas#gameCanvas {
        height: 100%;
        width: auto;
        object-fit: contain;
    }

    .panels-container {
        flex-direction: row;
        width: 100%;
        justify-content: space-between;
        gap: 0.5rem;
    }

    .score-panel {
        flex-direction: row;
        width: 100%;
        justify-content: space-evenly;
        padding: 0.5rem;
    }

    .panel-box {
        padding: 0.5rem;
    }

    .value {
        font-size: 1rem;
    }

    .side-panels {
        display: none;
        /* Hide hold/next next to board, maybe pop them into mobile controls context if space permits */
    }

    .mobile-controls {
        display: flex;
    }
}