/* ===== Design Tokens ===== */
:root {
    --color-bg: #0a0a1a;
    --color-bg-subtle: #12122a;
    --color-surface: rgba(255, 255, 255, 0.04);
    --color-surface-hover: rgba(255, 255, 255, 0.08);
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-glow: rgba(120, 100, 255, 0.25);
    --color-text: #e8e6f0;
    --color-text-muted: #8a87a0;
    --color-accent: #7c6aff;
    --color-accent-glow: rgba(124, 106, 255, 0.4);
    --color-cyan: #56e8e8;
    --color-yellow: #ffd84a;
    --color-green: #4ae88a;
    --color-red: #ff5a6e;
    --color-orange: #ff8c42;
    --color-blue: #4a8aff;
    --color-purple: #b06aff;
    --font-primary: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow-glow: 0 0 30px rgba(124, 106, 255, 0.15);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-primary);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ===== Background Grid ===== */
.bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(124, 106, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(124, 106, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

/* ===== App Layout ===== */
.app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
}

/* ===== Header ===== */
.header {
    text-align: center;
    padding: 20px 0 12px;
}

.logo {
    font-size: 2.8rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    background: linear-gradient(135deg, var(--color-accent), var(--color-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 20px var(--color-accent-glow));
    animation: logoPulse 3s ease-in-out infinite alternate;
}

.logo-accent {
    background: linear-gradient(135deg, var(--color-cyan), var(--color-green));
    -webkit-background-clip: text;
    background-clip: text;
}

@keyframes logoPulse {
    0% { filter: drop-shadow(0 0 20px var(--color-accent-glow)); }
    100% { filter: drop-shadow(0 0 35px var(--color-accent-glow)); }
}

/* ===== Game Container ===== */
.game-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    flex: 1;
}

/* ===== Panels ===== */
.panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 160px;
}

.panel-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.panel-card:hover {
    border-color: var(--color-border-glow);
    box-shadow: var(--shadow-glow);
}

.panel-title {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    color: var(--color-text-muted);
    margin-bottom: 10px;
    text-transform: uppercase;
}

.panel-card canvas {
    display: block;
    width: 100%;
    border-radius: var(--radius-sm);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-text), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== Controls Card ===== */
.controls-list {
    list-style: none;
    font-size: 0.72rem;
    color: var(--color-text-muted);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.controls-list kbd {
    display: inline-block;
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--color-text);
    margin-right: 4px;
}

/* ===== Board ===== */
.board-wrapper {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid var(--color-border);
    box-shadow:
        0 0 60px rgba(124, 106, 255, 0.08),
        inset 0 0 60px rgba(0, 0, 0, 0.3);
    background: rgba(0, 0, 0, 0.5);
}

#gameCanvas {
    display: block;
}

/* ===== Overlay ===== */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 26, 0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 1;
    transition: opacity 0.4s ease;
}

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

.overlay-content {
    text-align: center;
    animation: overlayFadeIn 0.5s ease;
}

@keyframes overlayFadeIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.overlay-title {
    font-size: 2.4rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    background: linear-gradient(135deg, var(--color-accent), var(--color-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.overlay-subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

/* ===== Buttons ===== */
.btn {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 36px;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-accent), #5b4ad4);
    color: #fff;
    box-shadow: 0 0 20px var(--color-accent-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 35px var(--color-accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

/* ===== Mobile Controls ===== */
.mobile-controls {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 12px 0 24px;
}

.mobile-btn {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-primary);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background var(--transition), border-color var(--transition);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.mobile-btn:active {
    background: var(--color-surface-hover);
    border-color: var(--color-accent);
}

.mobile-btn-wide {
    width: 120px;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
}

/* ===== Line Clear Flash ===== */
@keyframes lineClear {
    0% { background: rgba(124, 106, 255, 0.6); }
    50% { background: rgba(86, 232, 232, 0.8); }
    100% { background: transparent; }
}

/* ===== Responsive ===== */
@media (max-width: 780px) {
    .panel-left .controls-card { display: none; }
    .panel { width: 100px; }
    .panel-card { padding: 10px; }
    .stat-value { font-size: 1.2rem; }
    .logo { font-size: 2rem; }
}

@media (max-width: 600px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }
    .panel {
        flex-direction: row;
        width: 100%;
        justify-content: center;
    }
    .panel-left { order: 2; }
    .panel-right { order: 3; }
    .board-wrapper { order: 1; }
    .mobile-controls { display: flex; }
}
