/* ============================================
   TETRIS ARCADE - Classic Retro Style
   ============================================ */

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

:root {
    --bg-dark: #0a0a0a;
    --bg-cabinet: #1a1a2e;
    --bg-panel: #16213e;
    --border-neon: #00ffff;
    --text-primary: #00ffff;
    --text-secondary: #ffcc00;
    --text-white: #e0e0e0;
    --neon-pink: #ff00ff;
    --neon-green: #00ff41;
    --neon-blue: #00bfff;
    --neon-orange: #ff8c00;
    --neon-red: #ff3333;
    --board-bg: #0d0d1a;
    --board-grid: #1a1a30;
    --glow-cyan: 0 0 10px #00ffff, 0 0 20px #00ffff44;
    --glow-pink: 0 0 10px #ff00ff, 0 0 20px #ff00ff44;
    --font-arcade: 'Press Start 2P', monospace;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    font-family: var(--font-arcade);
    color: var(--text-white);
    user-select: none;
    -webkit-user-select: none;
}

/* CRT Scanline Effect */
.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.1) 0px,
        rgba(0, 0, 0, 0.1) 1px,
        transparent 1px,
        transparent 3px
    );
}

/* ============================================
   Screens
   ============================================ */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Title Screen
   ============================================ */
#title-screen {
    background: radial-gradient(ellipse at center, #1a1a3e 0%, #0a0a1a 70%);
}

.arcade-cabinet {
    text-align: center;
    padding: 40px;
}

.title-glow {
    margin-bottom: 60px;
    animation: titlePulse 2s ease-in-out infinite;
}

.title-text {
    font-size: 72px;
    color: var(--text-primary);
    text-shadow: 
        0 0 10px #00ffff,
        0 0 30px #00ffff,
        0 0 60px #00ffff,
        0 0 100px #0088ff;
    letter-spacing: 16px;
    animation: titleGlow 1.5s ease-in-out infinite alternate;
}

.title-sub {
    font-size: 16px;
    color: var(--text-secondary);
    letter-spacing: 12px;
    margin-top: 16px;
    text-shadow: 0 0 10px #ffcc0088;
}

@keyframes titleGlow {
    from { text-shadow: 0 0 10px #00ffff, 0 0 30px #00ffff, 0 0 60px #00ffff; }
    to { text-shadow: 0 0 20px #00ffff, 0 0 50px #00ffff, 0 0 100px #00ffff, 0 0 150px #0088ff; }
}

@keyframes titlePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Menu */
.menu-options {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 50px;
}

.menu-item {
    font-size: 18px;
    color: var(--text-white);
    padding: 12px 40px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    letter-spacing: 3px;
    outline: none;
}

.menu-item .arrow {
    opacity: 0;
    position: absolute;
    left: 8px;
    color: var(--text-secondary);
    transition: opacity 0.15s;
}

.menu-item.selected .arrow,
.menu-item:hover .arrow {
    opacity: 1;
    animation: arrowBlink 0.5s steps(1) infinite;
}

.menu-item.selected,
.menu-item:hover {
    color: var(--text-secondary);
    text-shadow: 0 0 10px #ffcc0088;
}

@keyframes arrowBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

.insert-coin {
    font-size: 14px;
    color: var(--neon-green);
    letter-spacing: 3px;
    margin-bottom: 30px;
}

.menu-options.hidden {
    display: none;
}

/* Difficulty Selection Menu */
.menu-subtitle {
    font-size: 14px;
    color: var(--text-primary);
    letter-spacing: 4px;
    margin-bottom: 12px;
    text-shadow: var(--glow-cyan);
}

.diff-item {
    font-size: 14px;
    color: var(--text-white);
    padding: 10px 30px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    letter-spacing: 2px;
    outline: none;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 380px;
}

.diff-item .arrow {
    opacity: 0;
    color: var(--text-secondary);
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.diff-item.selected .arrow,
.diff-item:hover .arrow {
    opacity: 1;
    animation: arrowBlink 0.5s steps(1) infinite;
}

.diff-item.selected,
.diff-item:hover {
    text-shadow: 0 0 10px currentColor;
}

.diff-name {
    font-size: 16px;
    font-weight: bold;
    min-width: 110px;
    text-align: left;
}

.diff-desc {
    font-size: 9px;
    color: #888;
    letter-spacing: 1px;
    white-space: nowrap;
}

.diff-item.selected .diff-desc,
.diff-item:hover .diff-desc {
    color: #aaa;
}

/* Difficulty colors */
.easy-color { color: #00ff41; text-shadow: 0 0 8px #00ff4166; }
.normal-color { color: #00bfff; text-shadow: 0 0 8px #00bfff66; }
.hard-color { color: #ff8c00; text-shadow: 0 0 8px #ff8c0066; }
.extreme-color { color: #ff3333; text-shadow: 0 0 8px #ff333366; animation: extremePulse 0.8s ease-in-out infinite alternate; }

@keyframes extremePulse {
    from { text-shadow: 0 0 8px #ff333366; }
    to { text-shadow: 0 0 16px #ff3333aa, 0 0 30px #ff000044; }
}

.diff-back {
    font-size: 10px;
    color: #666;
    letter-spacing: 2px;
    margin-top: 8px;
}

.credit-text {
    font-size: 10px;
    color: #555;
    letter-spacing: 2px;
}

.blink {
    animation: blinkAnim 1s steps(1) infinite;
}

@keyframes blinkAnim {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* ============================================
   Controls Screen
   ============================================ */
#controls-screen {
    background: radial-gradient(ellipse at center, #1a1a3e 0%, #0a0a1a 70%);
}

.controls-panel {
    text-align: center;
    padding: 40px;
    max-width: 800px;
}

.section-title {
    font-size: 32px;
    color: var(--text-primary);
    text-shadow: var(--glow-cyan);
    margin-bottom: 40px;
    letter-spacing: 8px;
}

.controls-grid {
    display: flex;
    gap: 60px;
    justify-content: center;
    margin-bottom: 50px;
}

.control-column {
    text-align: left;
}

.control-column h3 {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    letter-spacing: 3px;
    text-shadow: 0 0 8px #ffcc0066;
}

.key-row {
    font-size: 11px;
    color: var(--text-white);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.key {
    display: inline-block;
    background: #2a2a4a;
    border: 1px solid #444;
    border-bottom: 3px solid #333;
    border-radius: 4px;
    padding: 4px 10px;
    font-family: var(--font-arcade);
    font-size: 10px;
    color: var(--text-primary);
    min-width: 36px;
    text-align: center;
}

.back-hint {
    font-size: 12px;
    color: var(--neon-green);
    letter-spacing: 2px;
}

/* ============================================
   Game Screen
   ============================================ */
#game-screen {
    background: radial-gradient(ellipse at center, #12122a 0%, #08081a 70%);
}

.game-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    height: 100%;
    padding: 10px;
}

.game-container.mode-1p {
    gap: 0;
    justify-content: center;
}

/* 1P mode: hide left panel entirely, all info goes to right panel */
.game-container.mode-1p .player-area {
    flex-direction: row;
}

.game-container.mode-1p .left-panel {
    display: none;
}

.game-container.mode-1p .right-panel {
    min-width: 120px;
    gap: 10px;
}

.game-container.mode-1p .right-panel .info-box-extra {
    display: block;
}

.game-container.mode-2p {
    gap: 0;
    transform-origin: center center;
}

/* Player Area */
.player-area {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.player-area.hidden {
    display: none;
}

.player-header {
    display: none;
}

.game-container.mode-2p .player-header {
    display: block;
}

.player-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    letter-spacing: 3px;
    margin-bottom: 8px;
    text-shadow: 0 0 8px #ffcc0044;
}

/* Side Panels */
.game-side-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 110px;
}

/* Hidden by default, shown in 1P right panel */
.info-box-extra {
    display: none;
}

.info-box {
    background: rgba(10, 10, 30, 0.8);
    border: 1px solid #333;
    border-radius: 4px;
    padding: 8px;
    text-align: center;
}

.info-label {
    font-size: 10px;
    color: var(--text-primary);
    letter-spacing: 2px;
    margin-bottom: 6px;
    text-shadow: 0 0 6px #00ffff44;
}

.info-value {
    font-size: 18px;
    color: var(--text-secondary);
    text-shadow: 0 0 8px #ffcc0044;
}

.info-box canvas {
    display: block;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 2px;
}

/* Board Frame */
.board-frame {
    position: relative;
    border: 3px solid #333;
    border-color: #555 #222 #222 #555;
    box-shadow: 
        inset 0 0 20px rgba(0, 0, 0, 0.5),
        0 0 15px rgba(0, 255, 255, 0.1);
    background: var(--board-bg);
    line-height: 0;
}

.board-frame canvas {
    display: block;
}

/* VS Divider */
.vs-divider {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    height: 600px;
    position: relative;
}

.game-container.mode-2p .vs-divider {
    display: flex;
}

.vs-text {
    font-size: 28px;
    color: var(--neon-red);
    text-shadow: 0 0 15px #ff333388, 0 0 30px #ff333344;
    letter-spacing: 4px;
    animation: vsPulse 1s ease-in-out infinite alternate;
}

@keyframes vsPulse {
    from { opacity: 0.7; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1.05); }
}

.attack-indicator {
    position: absolute;
    opacity: 0;
    transition: opacity 0.3s;
}

.attack-indicator.active {
    opacity: 1;
    animation: attackFlash 0.3s ease-out;
}

.attack-arrow {
    font-size: 14px;
    color: var(--neon-red);
    text-shadow: 0 0 10px #ff3333;
}

#attack-p1 { left: -10px; top: 50%; }
#attack-p2 { right: -10px; top: 50%; }

@keyframes attackFlash {
    from { transform: scale(1.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ============================================
   Overlays
   ============================================ */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.overlay-box {
    text-align: center;
    padding: 40px 60px;
    border: 2px solid var(--text-primary);
    box-shadow: var(--glow-cyan);
    background: rgba(10, 10, 40, 0.95);
}

.overlay-title {
    font-size: 36px;
    color: var(--text-primary);
    text-shadow: var(--glow-cyan);
    margin-bottom: 24px;
    letter-spacing: 6px;
}

.overlay-stats {
    font-size: 12px;
    color: var(--text-white);
    margin-bottom: 24px;
    line-height: 2.2;
}

.overlay-stats .winner {
    font-size: 18px;
    color: var(--text-secondary);
    text-shadow: 0 0 10px #ffcc0066;
    margin-bottom: 12px;
}

.overlay-text {
    font-size: 12px;
    color: var(--neon-green);
    letter-spacing: 2px;
}

/* ============================================
   Mobile Controls
   ============================================ */
.mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 6px 10px calc(env(safe-area-inset-bottom, 8px) + 6px);
    background: rgba(5, 5, 20, 0.95);
    border-top: 1px solid #1a1a40;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: center;
}

.mobile-controls.hidden {
    display: none;
}

.mobile-row {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.mobile-btn {
    width: 56px;
    height: 44px;
    border: 2px solid var(--text-primary);
    background: rgba(0, 30, 60, 0.9);
    color: var(--text-primary);
    font-family: var(--font-arcade);
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mobile-btn.wide {
    width: 190px;
    font-size: 10px;
    height: 40px;
}

.mobile-btn:active {
    background: rgba(0, 255, 255, 0.3);
    box-shadow: var(--glow-cyan);
}

/* ============================================
   Sound Toggle & Menu Button
   ============================================ */
.sound-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 200;
    background: rgba(20, 20, 40, 0.8);
    border: 1px solid #444;
    color: white;
    font-size: 20px;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 4px;
    line-height: 1;
}

.sound-toggle:hover {
    border-color: var(--text-primary);
    box-shadow: var(--glow-cyan);
}

/* Back to Menu Button */
.btn-back-menu {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: rgba(20, 20, 40, 0.85);
    border: 1px solid #555;
    color: #aaa;
    font-family: var(--font-arcade);
    font-size: 10px;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    line-height: 1;
    letter-spacing: 1px;
    transition: all 0.2s;
    display: none; /* hidden on title/controls screens, shown only in game */
}

.btn-back-menu:hover {
    border-color: var(--neon-red);
    color: var(--neon-red);
    box-shadow: 0 0 8px #ff333344;
}

/* Pause Menu Options */
.pause-options {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin: 24px 0 20px;
}

.pause-item {
    font-size: 14px;
    color: var(--text-white);
    padding: 8px 30px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    letter-spacing: 2px;
    outline: none;
}

.pause-item .arrow {
    opacity: 0;
    position: absolute;
    left: 4px;
    color: var(--text-secondary);
    transition: opacity 0.15s;
}

.pause-item.selected .arrow,
.pause-item:hover .arrow {
    opacity: 1;
    animation: arrowBlink 0.5s steps(1) infinite;
}

.pause-item.selected,
.pause-item:hover {
    color: var(--text-secondary);
    text-shadow: 0 0 10px #ffcc0088;
}

.pause-hint {
    font-size: 9px;
    color: #555;
    letter-spacing: 2px;
}

/* Global Credit Watermark */
.global-credit {
    position: fixed;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-arcade);
    font-size: 8px;
    color: #333;
    letter-spacing: 2px;
    z-index: 1;
    pointer-events: none;
    white-space: nowrap;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1200px) {
    .game-container.mode-2p {
        transform: scale(0.75);
    }
}

@media (max-width: 900px) {
    .title-text {
        font-size: 48px;
        letter-spacing: 10px;
    }
    .title-sub {
        font-size: 12px;
    }
    .menu-item {
        font-size: 14px;
    }
    .game-container.mode-1p {
        transform: scale(0.85);
        transform-origin: center top;
    }
    .game-container.mode-2p {
        transform: scale(0.55);
    }
}

@media (max-width: 600px) {
    .title-text {
        font-size: 36px;
        letter-spacing: 6px;
    }
    .title-sub {
        font-size: 10px;
        letter-spacing: 6px;
    }
    .menu-item {
        font-size: 12px;
        padding: 10px 20px;
    }
    .insert-coin {
        font-size: 10px;
    }
    .diff-item {
        width: 300px;
        padding: 8px 16px;
        font-size: 12px;
    }
    .diff-name {
        font-size: 13px;
        min-width: 85px;
    }
    .diff-desc {
        font-size: 8px;
    }
    .controls-grid {
        flex-direction: column;
        gap: 30px;
    }
    .game-container.mode-1p {
        transform: scale(0.65);
        transform-origin: center top;
    }
    .game-side-panel {
        min-width: 85px;
    }
    .info-value {
        font-size: 14px;
    }
    .info-label {
        font-size: 8px;
    }
}

/* When mobile controls are visible, shrink game to fit above them */
body.has-mobile-controls #game-screen {
    height: calc(100% - 160px);
    overflow: hidden;
}

body.has-mobile-controls .game-container.mode-1p {
    height: 100%;
    align-items: flex-start;
    padding-top: 5px;
}

/* Line clear animation */
@keyframes lineClear {
    0% { opacity: 1; background: white; }
    50% { opacity: 0.5; background: var(--text-primary); }
    100% { opacity: 0; background: white; }
}

/* Combo text */
.combo-text {
    position: absolute;
    font-family: var(--font-arcade);
    font-size: 24px;
    color: var(--text-secondary);
    text-shadow: 0 0 15px #ffcc00;
    pointer-events: none;
    animation: comboFloat 1s ease-out forwards;
    z-index: 10;
    white-space: nowrap;
}

@keyframes comboFloat {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-60px) scale(1.5); }
}

/* Screen shake for attacks */
.screen-shake {
    animation: shake 0.3s ease-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* Ghost piece style handled in JS via canvas */

/* Garbage warning indicator */
.garbage-warning {
    position: absolute;
    left: -8px;
    bottom: 0;
    width: 6px;
    background: var(--neon-red);
    box-shadow: 0 0 8px #ff3333;
    transition: height 0.3s;
    border-radius: 2px;
}

/* K.O. Banner - shown on dead player's board in 2P */
.ko-banner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-arcade);
    font-size: 48px;
    color: var(--neon-red);
    text-shadow: 
        0 0 20px #ff3333,
        0 0 40px #ff3333,
        0 0 80px #ff000088;
    letter-spacing: 12px;
    z-index: 10;
    animation: koAppear 0.5s ease-out;
    pointer-events: none;
}

@keyframes koAppear {
    0% { transform: translate(-50%, -50%) scale(3); opacity: 0; }
    60% { transform: translate(-50%, -50%) scale(0.9); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Dim the dead player's board */
.player-area .board-frame:has(.ko-banner)::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
}
