/* ==========================================================================
   TETRIS: MASTER EDITION — HIGH PERFORMANCE ARCADE STYLES
   MAZE STUDIO Game Engine & Arcade Library
   ========================================================================== */

:root {
    --bg-deep: #07080e;
    --bg-panel: rgba(15, 18, 30, 0.78);
    --border-glass: rgba(255, 255, 255, 0.10);
    --border-glass-hover: rgba(255, 255, 255, 0.22);
    
    /* Standard Tetromino Palette */
    --piece-cyan: #00f0ff;    /* I */
    --piece-yellow: #ffe600;  /* O */
    --piece-purple: #a855f7;  /* T */
    --piece-green: #10b981;   /* S */
    --piece-red: #ef4444;     /* Z */
    --piece-blue: #3b82f6;    /* J */
    --piece-orange: #f97316;  /* L */
    
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --board-border: rgba(0, 240, 255, 0.35);
    --board-glow: rgba(0, 240, 255, 0.18);
}

/* 5 Visual Themes */
body.theme-cyber {
    --bg-deep: #07080e;
    --bg-panel: rgba(15, 18, 30, 0.78);
    --board-border: rgba(0, 240, 255, 0.4);
    --board-glow: rgba(0, 240, 255, 0.22);
}

body.theme-obsidian {
    --bg-deep: #000000;
    --bg-panel: rgba(14, 14, 16, 0.88);
    --board-border: rgba(255, 255, 255, 0.28);
    --board-glow: rgba(255, 255, 255, 0.08);
}

body.theme-synthwave {
    --bg-deep: #120422;
    --bg-panel: rgba(30, 12, 50, 0.82);
    --board-border: rgba(255, 0, 128, 0.45);
    --board-glow: rgba(255, 100, 0, 0.25);
}

body.theme-matrix {
    --bg-deep: #030d08;
    --bg-panel: rgba(6, 26, 16, 0.82);
    --board-border: rgba(0, 255, 136, 0.45);
    --board-glow: rgba(0, 255, 136, 0.25);
}

body.theme-amethyst {
    --bg-deep: #0d0618;
    --bg-panel: rgba(26, 12, 45, 0.82);
    --board-border: rgba(168, 85, 247, 0.5);
    --board-glow: rgba(234, 179, 8, 0.22);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-deep);
    font-family: var(--font-main);
    color: var(--text-primary);
    touch-action: none;
    transition: background-color 0.3s ease;
}

/* Background Atmosphere */
.ambient-glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 50% 15%, rgba(60, 30, 110, 0.35) 0%, transparent 65%),
        radial-gradient(circle at 85% 85%, rgba(0, 180, 255, 0.15) 0%, transparent 55%);
    pointer-events: none;
    z-index: 0;
    transition: background 0.4s ease;
}

body.theme-synthwave .ambient-glow {
    background: 
        radial-gradient(circle at 50% 10%, rgba(255, 0, 128, 0.3) 0%, transparent 60%),
        radial-gradient(circle at 80% 80%, rgba(255, 136, 0, 0.2) 0%, transparent 55%);
}

body.theme-matrix .ambient-glow {
    background: 
        radial-gradient(circle at 50% 15%, rgba(0, 255, 136, 0.25) 0%, transparent 65%),
        radial-gradient(circle at 85% 85%, rgba(0, 180, 200, 0.12) 0%, transparent 55%);
}

body.theme-amethyst .ambient-glow {
    background: 
        radial-gradient(circle at 50% 15%, rgba(168, 85, 247, 0.3) 0%, transparent 65%),
        radial-gradient(circle at 85% 85%, rgba(234, 179, 8, 0.15) 0%, transparent 55%);
}

body.theme-obsidian .ambient-glow {
    background: 
        radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.05) 0%, transparent 70%);
}

/* Master Container */
.app-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

/* Game Stage Viewport */
.stage-wrapper {
    position: relative;
    width: 100%;
    max-width: 520px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #090a12;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.7);
}

/* Glassmorphic Top HUD */
.hud-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-glass);
    z-index: 10;
    flex-shrink: 0;
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-center {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hud-title {
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, #ffffff 40%, var(--piece-cyan) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hud-mode-pill {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    padding: 1px 7px;
    border-radius: 10px;
    background: rgba(0, 240, 255, 0.15);
    color: var(--piece-cyan);
    border: 1px solid rgba(0, 240, 255, 0.35);
    margin-top: 1px;
}

.hud-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.hud-btn:active {
    transform: scale(0.94);
}

.hud-btn svg {
    width: 17px;
    height: 17px;
}

/* Playfield Workspace Layout */
.playfield-workspace {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    position: relative;
    overflow: hidden;
}

/* Side Panels (HOLD and NEXT) */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 82px;
    flex-shrink: 0;
}

.panel-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.panel-title {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.preview-canvas {
    display: block;
    width: 64px;
    height: 64px;
}

.next-canvas {
    display: block;
    width: 64px;
    height: 180px;
}

/* Stat Box in Side Panel */
.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 0;
    width: 100%;
}

.stat-val {
    font-size: 17px;
    font-weight: 900;
    color: #ffffff;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat-sub-val {
    font-size: 9.5px;
    font-weight: 800;
    color: var(--piece-cyan);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.4px;
}

.stat-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* Primary Game Board Canvas Container */
.board-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(4, 5, 10, 0.94);
    border: 1.5px solid var(--board-border);
    border-radius: var(--radius-md);
    box-shadow: 0 0 35px var(--board-glow), inset 0 0 25px rgba(0, 0, 0, 0.9);
    overflow: hidden;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#tetris-canvas {
    display: block;
}

/* Toast Banners (TETRIS / LEVEL UP) */
.board-toast {
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(15, 18, 30, 0.95);
    border: 1.5px solid var(--piece-cyan);
    box-shadow: 0 0 25px rgba(0, 240, 255, 0.5);
    border-radius: 20px;
    padding: 6px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    z-index: 20;
    opacity: 0;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.board-toast.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.toast-text {
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 2px;
    color: #ffffff;
    text-shadow: 0 0 10px var(--piece-cyan);
}

/* Mobile Virtual Touch Controls */
.mobile-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px 14px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    flex-shrink: 0;
}

.dpad-cluster, .action-cluster {
    display: flex;
    align-items: center;
    gap: 8px;
}

.touch-btn {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-glass);
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.1s ease, transform 0.1s ease;
    touch-action: none;
}

.touch-btn:active {
    background: rgba(255, 255, 255, 0.22);
    transform: scale(0.92);
}

.touch-btn svg {
    width: 22px;
    height: 22px;
}

.touch-btn.btn-harddrop {
    background: rgba(0, 240, 255, 0.14);
    border-color: rgba(0, 240, 255, 0.35);
    color: var(--piece-cyan);
}

.touch-btn.btn-rotate {
    background: rgba(168, 85, 247, 0.14);
    border-color: rgba(168, 85, 247, 0.35);
    color: var(--piece-purple);
}

.touch-btn.btn-hold {
    background: rgba(255, 230, 0, 0.14);
    border-color: rgba(255, 230, 0, 0.35);
    color: var(--piece-yellow);
}

/* Overlays and Modals */
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(7, 8, 14, 0.90);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: 20px;
}

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

.modal-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 360px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px 20px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
    transform: scale(0.94);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay-screen.active .modal-card {
    transform: scale(1);
}

.modal-title {
    font-size: 24px;
    font-weight: 900;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #ffffff 40%, var(--piece-cyan) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.modal-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 10px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-item-num {
    font-size: 22px;
    font-weight: 800;
    color: #ffffff;
}

.stat-item-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.new-best-badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--piece-yellow), #ff9900);
    color: #000;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 3px 10px;
    border-radius: 12px;
    margin-top: -10px;
    margin-bottom: 14px;
}

.new-best-badge.hidden {
    display: none;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--piece-cyan) 0%, #00a8ff 100%);
    border: none;
    color: #040914;
    font-family: var(--font-main);
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.5px;
    padding: 12px 18px;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 240, 255, 0.35);
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 13px;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--border-glass-hover);
}

.btn-secondary:active {
    transform: scale(0.97);
}

/* Mode Options List in Mode Modal */
.mode-options-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.mode-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    color: inherit;
    font-family: inherit;
    width: 100%;
}

.mode-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-glass-hover);
}

.mode-card.active {
    background: rgba(0, 240, 255, 0.09);
    border-color: var(--piece-cyan);
    box-shadow: 0 0 16px rgba(0, 240, 255, 0.25);
}

.mode-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 240, 255, 0.15);
    color: var(--piece-cyan);
    flex-shrink: 0;
}

.mode-card-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
}

.mode-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mode-name {
    font-size: 13px;
    font-weight: 800;
    color: #ffffff;
}

.mode-best-badge {
    font-size: 10px;
    font-weight: 700;
    color: var(--piece-yellow);
    background: rgba(255, 230, 0, 0.12);
    border: 1px solid rgba(255, 230, 0, 0.3);
    padding: 1px 6px;
    border-radius: 8px;
}

.mode-desc {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Mobile Responsive Optimization */
@media (max-width: 480px) {
    .stage-wrapper {
        max-width: 100%;
    }
    
    .playfield-workspace {
        gap: 6px;
        padding: 4px 6px;
    }
    
    .side-panel {
        width: 68px;
        gap: 6px;
    }
    
    .preview-canvas {
        width: 52px;
        height: 52px;
    }
    
    .next-canvas {
        width: 52px;
        height: 140px;
    }
    
    .stat-val {
        font-size: 14px;
    }
    
    .touch-btn {
        width: 42px;
        height: 42px;
    }
}
