/* ===========================
   TETRIS CYBERPUNK EDITION
   Neon style inspired by game.h3me.xyz
   =========================== */

/* ===========================
   1. CSS VARIABLES
   =========================== */

:root {
    /* Cyberpunk Color Palette */
    --color-bg-dark: #0a0e27;
    --color-bg-gradient: linear-gradient(180deg, #0a0e27 0%, #1a1e3a 100%);
    --color-panel-bg: rgba(20, 25, 40, 0.9);

    /* Neon Colors */
    --color-cyan: #00ffff;
    --color-cyan-glow: rgba(0, 255, 255, 0.4);
    --color-cyan-bright: #00ff88;
    --color-magenta: #ff00ff;
    --color-magenta-dark: #8b1a5c;
    --color-gold: #ffcc00;
    --color-yellow: #ffff00;

    /* Shadows & Glows */
    --glow-cyan: 0 0 30px var(--color-cyan-glow);
    --glow-cyan-strong: 0 0 50px rgba(0, 255, 255, 0.6);
    --glow-text: 0 0 12px rgba(0, 255, 136, 0.5);
    --shadow-deep: 0 8px 32px rgba(0, 0, 0, 0.6);

    /* Typography */
    --font-system: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', 'Roboto', sans-serif;

    /* Spacing */
    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50%;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;

    /* Layout */
    --header-height: 60px;
    --controls-height: 100px;
}

/* ===========================
   2. BASE STYLES
   =========================== */

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

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-system);
    background: var(--color-bg-gradient);
    color: white;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-bg-gradient);
    z-index: -1;
}

/* ===========================
   3. TOP HEADER BAR
   =========================== */

.top-bar {
    min-height: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm);
    background: rgba(10, 14, 39, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--color-cyan);
    box-shadow: var(--glow-cyan);
    z-index: 100;
}

.header-stats {
    display: flex;
    gap: var(--space-md);
    align-items: center;
    flex: 1;
    justify-content: flex-start;
}

.score-display {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: auto;
    flex: 0 0 auto;
    align-items: flex-start;
}

/* Hide level/lines on desktop by default */
.level-display,
.lines-display {
    display: none;
}

.score-label {
    font-size: 0.5rem;
    font-weight: 600;
    color: var(--color-cyan);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.score-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-cyan-bright);
    font-variant-numeric: tabular-nums;
    text-shadow: var(--glow-text);
    line-height: 1;
}

.header-controls {
    display: flex;
    gap: var(--space-xs);
    flex-shrink: 0;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: 2px solid var(--color-cyan);
    border-radius: var(--radius-full);
    background: var(--color-panel-bg);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--glow-cyan);
}

.icon-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--glow-cyan-strong);
}

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

/* ===========================
   4. MAIN GAME LAYOUT
   =========================== */

.game-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    /* Add padding-bottom to account for fixed controls bar height */
    /* Controls bar: padding(24*2) + dpad-height(144) + bottom-margin(16) = ~208px */
    padding-bottom: 208px;
    overflow: hidden;
}

.game-main {
    display: flex;
    flex-direction: row;
    gap: 16px;
    align-items: flex-start;
    justify-content: center;
    max-width: 100%;
    padding: 16px;
}

/* Mobile size adjustment */
@media (max-width: 768px) {
    .game-main {
        gap: 12px;
        padding: 8px;
    }
}

/* ===========================
   5. GAME BOARD
   =========================== */

.game-board-container {
    position: relative;
    z-index: 1; /* Lower than overlay (1000) to ensure pause overlay appears on top */
    border: 3px solid var(--color-cyan);
    border-radius: var(--radius-lg);
    padding: 0;
    background: rgba(0, 0, 0, 0.8);
    box-shadow: var(--glow-cyan), var(--shadow-deep);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    max-width: 300px;
}

/* Mobile size restriction */
@media (max-width: 768px) {
    .game-board-container {
        max-width: 210px;
    }
}

#tetris {
    display: block;
    border-radius: var(--radius-sm);
    background: #000;
    flex-shrink: 0;
}

/* ===========================
   6. INFO PANEL
   =========================== */

.info-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 120px;
    min-width: 120px;
    max-width: 120px;
    flex-shrink: 0;
}

/* Mobile size adjustment */
@media (max-width: 768px) {
    .info-panel {
        gap: 6px;
        width: 100px;
        min-width: 100px;
        max-width: 100px;
    }
}

.info-box {
    background: var(--color-panel-bg);
    border: 2px solid var(--color-cyan);
    border-radius: var(--radius-md);
    padding: 5px 6px;
    box-shadow: var(--glow-cyan);
    text-align: center;
}

.info-label {
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--color-cyan);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.info-value {
    font-size: 1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

/* Mobile size adjustment */
@media (max-width: 768px) {
    .info-label {
        font-size: 0.45rem;
        margin-bottom: 1px;
    }

    .info-value {
        font-size: 0.85rem;
    }
}

.best-value {
    color: var(--color-gold);
    text-shadow: 0 0 12px rgba(255, 204, 0, 0.5);
}

.level-value {
    color: var(--color-cyan-bright);
    text-shadow: var(--glow-text);
}

.lines-value {
    color: var(--color-cyan);
    text-shadow: var(--glow-text);
}

.next-box {
    padding: 6px;
}

#next-piece {
    display: block;
    margin: var(--space-sm) auto 0;
    background: rgba(0, 0, 0, 0.5);
    border-radius: var(--radius-sm);
    width: 100px;
    height: 100px;
}

/* Mobile size adjustment */
@media (max-width: 768px) {
    #next-piece {
        width: 84px;
        height: 84px;
    }
}

/* ===========================
   7. BOTTOM CONTROLS
   =========================== */

.controls-bar {
    position: fixed;
    bottom: var(--space-md);
    left: 0;
    right: 0;
    height: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    background: rgba(10, 14, 39, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 2px solid var(--color-cyan);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6), var(--glow-cyan);
    z-index: 100;
}

.controls-left {
    flex: 0 0 auto;
}

.controls-right {
    flex: 0 0 auto;
}

/* D-Pad Wrapper */
.dpad-wrapper {
    display: grid;
    grid-template-columns: repeat(3, 70px);
    grid-template-rows: repeat(2, 70px);
    gap: 4px;
    position: relative;
}

.dpad-btn {
    border: 3px solid var(--color-cyan);
    background: var(--color-panel-bg);
    color: var(--color-cyan);
    font-size: 2rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--glow-cyan);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.dpad-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0, 255, 255, 0.1), transparent);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.dpad-btn:active {
    transform: scale(0.92);
    box-shadow: inset var(--glow-cyan);
    background: rgba(0, 255, 255, 0.2);
}

.dpad-btn:active::before {
    opacity: 1;
}

.btn-icon {
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 0 0 10px currentColor;
    position: relative;
    z-index: 1;
}

/* D-Pad positioning */
.dpad-up {
    grid-column: 2;
    grid-row: 1;
    border-radius: 12px 12px 4px 4px;
    border-color: var(--color-gold);
    color: var(--color-gold);
    box-shadow: 0 0 20px rgba(255, 204, 0, 0.4);
}

.dpad-up:active {
    background: rgba(255, 204, 0, 0.2);
    box-shadow: inset 0 0 20px rgba(255, 204, 0, 0.4);
}

.dpad-left {
    grid-column: 1;
    grid-row: 2;
    border-radius: 12px 4px 4px 12px;
}

.dpad-down {
    grid-column: 2;
    grid-row: 2;
    border-radius: 8px;
}

.dpad-right {
    grid-column: 3;
    grid-row: 2;
    border-radius: 4px 12px 12px 4px;
}

/* Action Button */
.action-btn {
    width: 110px;
    height: 110px;
    border: 4px solid var(--color-magenta);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-magenta-dark) 0%, rgba(139, 26, 92, 0.7) 100%);
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: 0 0 30px rgba(255, 0, 255, 0.5), 0 4px 15px rgba(0, 0, 0, 0.5);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255, 0, 255, 0.3), transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.action-btn:active {
    transform: scale(0.9);
    box-shadow: inset 0 0 30px rgba(255, 0, 255, 0.5);
}

.action-btn:active::before {
    opacity: 1;
}

.action-btn .btn-icon {
    font-size: 2.5rem;
}

.btn-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(255, 0, 255, 0.8);
    position: relative;
    z-index: 1;
}

/* ===========================
   8. OVERLAYS
   =========================== */

.overlay {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999999 !important;
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: auto;
}

.overlay.show {
    display: flex !important;
    opacity: 1 !important;
}

.overlay-content {
    background: var(--color-panel-bg);
    border: 3px solid var(--color-cyan);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--glow-cyan-strong), var(--shadow-deep);
    max-width: 400px;
    width: 90%;
    text-align: center;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.cyber-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--color-cyan);
    text-transform: uppercase;
    letter-spacing: 4px;
    margin-bottom: var(--space-lg);
    text-shadow: var(--glow-text);
}

.cyber-glow {
    display: block;
    font-size: 1.2rem;
    color: var(--color-cyan-bright);
    letter-spacing: 8px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        text-shadow: 0 0 20px var(--color-cyan-glow);
    }
    50% {
        opacity: 0.8;
        text-shadow: 0 0 40px var(--color-cyan-glow);
    }
}

/* Tutorial Steps */
.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin: var(--space-lg) 0;
}

.tutorial-step {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--color-cyan);
    border-radius: var(--radius-md);
    text-align: left;
}

.step-icon {
    font-size: 1.8rem;
    color: var(--color-cyan);
    min-width: 50px;
    text-align: center;
}

.step-text {
    font-size: 1rem;
    font-weight: 600;
    color: white;
}

/* Buttons */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    border: 3px solid var(--color-cyan);
    border-radius: var(--radius-md);
    font-family: var(--font-system);
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: linear-gradient(135deg, rgba(0, 255, 255, 0.2) 0%, rgba(0, 255, 136, 0.2) 100%);
    color: var(--color-cyan);
    box-shadow: var(--glow-cyan);
}

.btn-primary:hover {
    background: linear-gradient(135deg, rgba(0, 255, 255, 0.3) 0%, rgba(0, 255, 136, 0.3) 100%);
    box-shadow: var(--glow-cyan-strong);
    transform: translateY(-2px);
}

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

.btn-secondary {
    background: rgba(0, 0, 0, 0.5);
    color: white;
    margin-top: var(--space-sm);
}

.btn-secondary:hover {
    background: rgba(0, 0, 0, 0.7);
    box-shadow: var(--glow-cyan);
}

.overlay-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

/* Final Score Display */
.final-score-display {
    margin: var(--space-lg) 0;
    padding: var(--space-lg);
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--color-cyan);
    border-radius: var(--radius-md);
}

.final-score-label {
    font-size: 0.8rem;
    color: var(--color-cyan);
    letter-spacing: 2px;
    margin-bottom: var(--space-xs);
}

.final-score-value {
    font-size: 3rem;
    font-weight: 900;
    color: var(--color-cyan-bright);
    font-variant-numeric: tabular-nums;
    text-shadow: var(--glow-text);
}

.final-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.final-stat {
    padding: var(--space-sm);
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid var(--color-cyan);
    border-radius: var(--radius-sm);
}

.final-stat-label {
    font-size: 0.7rem;
    color: var(--color-cyan);
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.final-stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: white;
    font-variant-numeric: tabular-nums;
}

/* ===========================
   9. ANIMATIONS
   =========================== */

.score-pulse {
    animation: scorePulse 0.3s ease-out;
}

@keyframes scorePulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
        color: var(--color-yellow);
        text-shadow: 0 0 20px rgba(255, 255, 0, 0.8);
    }
    100% {
        transform: scale(1);
    }
}

/* ===========================
   10. RESPONSIVE DESIGN
   =========================== */

@media (max-width: 768px) {
    /* Mobile-specific overrides - most styles are now default */
}

@media (max-width: 480px) {
    /* Very small screens - compact controls */
    .game-wrapper {
        /* Adjust padding for smaller controls bar */
        /* Controls bar: padding(12*2) + dpad-height(113) + bottom-margin(16) = ~153px */
        padding-bottom: 153px;
    }

    .controls-bar {
        padding: var(--space-sm);
    }

    .dpad-wrapper {
        grid-template-columns: repeat(3, 55px);
        grid-template-rows: repeat(2, 55px);
        gap: 3px;
    }

    .btn-icon {
        font-size: 1.5rem;
    }

    .action-btn {
        width: 85px;
        height: 85px;
    }

    .action-btn .btn-icon {
        font-size: 2rem;
    }

    .btn-label {
        font-size: 0.65rem;
    }

    .game-main {
        padding: 6px;
        gap: 8px;
    }

    .game-board-container {
        max-width: 190px;
    }

    .info-panel {
        width: 85px;
        min-width: 85px;
        max-width: 85px;
    }

    .info-box {
        padding: 4px 5px;
    }

    .info-label {
        font-size: 0.4rem;
    }

    .info-value {
        font-size: 0.75rem;
    }

    #next-piece {
        width: 75px;
        height: 75px;
    }

    .top-bar {
        padding: 6px 8px;
    }

    .header-stats {
        gap: 10px;
    }

    .score-label {
        font-size: 0.45rem;
    }

    .score-value {
        font-size: 0.9rem;
    }

    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
}

@media (orientation: landscape) and (max-height: 600px) {
    /* Landscape mode - compact layout */
    .game-wrapper {
        /* Adjust padding for landscape controls bar */
        /* Controls bar: padding(12*2) + dpad-height(100) + bottom-margin(16) = ~140px */
        padding-bottom: 140px;
    }

    .controls-bar {
        padding: var(--space-sm);
    }

    .dpad-wrapper {
        grid-template-columns: repeat(3, 50px);
        grid-template-rows: repeat(2, 50px);
    }

    .action-btn {
        width: 75px;
        height: 75px;
    }
}

/* ===========================
   11. ACCESSIBILITY
   =========================== */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

button:focus-visible {
    outline: 3px solid var(--color-cyan-bright);
    outline-offset: 3px;
}

/* SNS Share Section */
.share-section {
    margin: var(--space-lg) 0;
    padding: var(--space-md);
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--color-cyan);
    border-radius: var(--radius-md);
}

.share-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-cyan);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-bottom: var(--space-sm);
}

.share-buttons {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
    align-items: center;
}

.share-btn {
    width: 60px;
    height: 60px;
    border: 2px solid;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.share-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.share-btn:hover {
    transform: translateY(-4px) scale(1.05);
}

.share-btn:active {
    transform: translateY(-2px) scale(0.98);
}

.share-btn svg {
    width: 28px;
    height: 28px;
    position: relative;
    z-index: 1;
}

/* Kakao - Yellow */
.share-kakao {
    background: rgba(254, 229, 0, 0.1);
    border-color: #FEE500;
    color: #FEE500;
    box-shadow: 0 0 20px rgba(254, 229, 0, 0.3);
}

.share-kakao::before {
    background: radial-gradient(circle at center, rgba(254, 229, 0, 0.2), transparent 70%);
}

.share-kakao:hover {
    box-shadow: 0 0 30px rgba(254, 229, 0, 0.6), 0 4px 15px rgba(0, 0, 0, 0.5);
}

.share-kakao:active::before {
    opacity: 1;
}

/* X (Twitter) - White/Light Gray */
.share-x {
    background: rgba(255, 255, 255, 0.1);
    border-color: #E7E9EA;
    color: #E7E9EA;
    box-shadow: 0 0 20px rgba(231, 233, 234, 0.3);
}

.share-x::before {
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.2), transparent 70%);
}

.share-x:hover {
    box-shadow: 0 0 30px rgba(231, 233, 234, 0.6), 0 4px 15px rgba(0, 0, 0, 0.5);
}

.share-x:active::before {
    opacity: 1;
}

/* Threads - Pink/Purple */
.share-threads {
    background: rgba(255, 0, 255, 0.1);
    border-color: #FF00FF;
    color: #FF00FF;
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.3);
}

.share-threads::before {
    background: radial-gradient(circle at center, rgba(255, 0, 255, 0.2), transparent 70%);
}

.share-threads:hover {
    box-shadow: 0 0 30px rgba(255, 0, 255, 0.6), 0 4px 15px rgba(0, 0, 0, 0.5);
}

.share-threads:active::before {
    opacity: 1;
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .share-btn {
        width: 50px;
        height: 50px;
    }

    .share-btn svg {
        width: 24px;
        height: 24px;
    }

    .share-label {
        font-size: 0.6rem;
    }
}

/* ===========================
   UTILITY CLASSES
   =========================== */

.hidden {
    display: none !important;
}

/* ===========================
   12. PERFORMANCE
   =========================== */

/* Removed .game-board-container from transform to avoid stacking context issues with overlay */
#tetris,
.controls-bar,
.top-bar {
    transform: translateZ(0);
    will-change: transform;
}

button {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
}

/* Loading state */
body {
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.loaded {
    opacity: 1;
}
