/* ===== CSS Variables & Theme ===== */
:root {
    /* Telegram theme integration */
    --tg-theme-bg: var(--tg-theme-bg-color, #0f0f23);
    --tg-theme-text: var(--tg-theme-text-color, #ffffff);
    --tg-theme-accent: var(--tg-theme-button-color, #00d4ff);

    /* Game colors */
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-card: rgba(20, 20, 50, 0.8);
    --border-glow: rgba(0, 212, 255, 0.3);

    /* Tetromino colors - neon palette */
    --piece-i: #00f5ff;
    --piece-o: #ffd700;
    --piece-t: #bf00ff;
    --piece-s: #00ff88;
    --piece-z: #ff3366;
    --piece-j: #4169ff;
    --piece-l: #ff8c00;

    /* Typography */
    --font-display: 'Orbitron', monospace;
    --font-body: 'Inter', sans-serif;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
}

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

html,
body {
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--tg-theme-text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ===== Background Effects ===== */
.background-effects {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.grid-overlay {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
}

.glow-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
}

.orb-1 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--piece-i), transparent 70%);
    top: -100px;
    left: -100px;
    animation: float 8s ease-in-out infinite;
}

.orb-2 {
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, var(--piece-t), transparent 70%);
    bottom: -50px;
    right: -50px;
    animation: float 10s ease-in-out infinite reverse;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(30px, 30px);
    }
}

/* ===== Game Container ===== */
.game-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
}

/* ===== Header ===== */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 400px;
}

.game-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 900;
    letter-spacing: 4px;
    background: linear-gradient(135deg, var(--piece-i), var(--piece-t));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px rgba(0, 212, 255, 0.5);
}

.header-stats {
    display: flex;
    gap: var(--spacing-md);
}

/* ===== Game Area ===== */
.game-area {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
}

/* ===== Side Panels ===== */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    width: 80px;
}

.panel-card {
    background: var(--bg-card);
    border: 1px solid var(--border-glow);
    border-radius: 12px;
    padding: var(--spacing-sm);
    backdrop-filter: blur(10px);
}

.panel-title {
    font-family: var(--font-display);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    margin-bottom: var(--spacing-xs);
}

.panel-card canvas {
    display: block;
    margin: 0 auto;
}

/* ===== Stats ===== */
.stats-card {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.stat-row,
.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-family: var(--font-display);
    font-size: 0.55rem;
    font-weight: 400;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.5);
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: white;
}

.glow-text {
    color: var(--piece-i);
    text-shadow: 0 0 10px var(--piece-i);
}

/* ===== Game Board ===== */
.board-wrapper {
    position: relative;
    background: var(--bg-card);
    border: 2px solid var(--border-glow);
    border-radius: 12px;
    padding: var(--spacing-xs);
    box-shadow:
        0 0 30px rgba(0, 212, 255, 0.1),
        inset 0 0 30px rgba(0, 0, 0, 0.3);
}

#game-canvas {
    display: block;
    border-radius: 8px;
}

/* ===== Game Overlay ===== */
.game-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    z-index: 10;
}

.game-overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
}

.overlay-content h2 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: var(--spacing-sm);
    background: linear-gradient(135deg, var(--piece-z), var(--piece-l));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overlay-content p {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: var(--spacing-lg);
}

/* ===== Buttons ===== */
.btn {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 2px;
    padding: var(--spacing-md) var(--spacing-lg);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--piece-i), var(--piece-t));
    color: white;
    box-shadow: 0 4px 20px rgba(0, 212, 255, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 212, 255, 0.6);
}

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

/* ===== Mobile Controls ===== */
.mobile-controls {
    display: none;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
}

.control-row {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
}

.control-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--border-glow);
    background: var(--bg-card);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    backdrop-filter: blur(10px);
}

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

.control-btn:active {
    background: rgba(0, 212, 255, 0.3);
    transform: scale(0.95);
}

.control-btn.large {
    width: 72px;
    height: 72px;
}

.control-btn.large svg {
    width: 32px;
    height: 32px;
}

.control-btn.wide {
    width: auto;
    border-radius: 28px;
    padding: 0 var(--spacing-lg);
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 2px;
}

/* ===== Responsive ===== */

/* Show mobile controls on touch devices OR small screens */
@media (pointer: coarse),
(max-width: 600px) {
    .mobile-controls {
        display: flex;
    }
}

@media (max-width: 500px) {
    .game-title {
        font-size: 1.4rem;
    }

    .side-panel {
        width: 60px;
    }

    .panel-card canvas {
        width: 50px !important;
        height: auto !important;
    }

    .next-card canvas {
        height: 150px !important;
    }
}

@media (max-width: 360px) {
    .side-panel {
        width: 50px;
    }

    .game-area {
        gap: 4px;
    }
}

/* ===== Line Clear Animation ===== */
@keyframes line-clear {
    0% {
        opacity: 1;
        transform: scaleX(1);
    }

    50% {
        opacity: 1;
        background: white;
    }

    100% {
        opacity: 0;
        transform: scaleX(0);
    }
}

.clearing {
    animation: line-clear 0.3s ease-out forwards;
}