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

:root {
    --bg: #080810;
    --surface: #0e0e1a;
    --surface-light: #16162a;
    --surface-hover: #1e1e38;
    --primary: #6c5ce7;
    --primary-light: #a29bfe;
    --accent: #00cec9;
    --accent-light: #55efc4;
    --danger: #ff6b6b;
    --warning: #ffd166;
    --text: #e8e8f0;
    --text-dim: #6a6a80;
    --glass-border: rgba(108, 92, 231, 0.15);
    --cell: 30px;
}

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    height: 100vh;
    height: 100dvh;
}

.screen { display: none; min-height: 100vh; flex-direction: column; }
.screen.active { display: flex; }

/* ============ LOADING ============ */

.loading-container {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 20px; padding: 24px;
}

.loading-tetris-preview {
    display: flex; gap: 6px; margin-bottom: 10px;
}

.lt-block {
    width: 28px; height: 28px; border-radius: 4px;
    animation: letterBounce 1.2s ease-in-out infinite;
}
.lt-i { background: #00b8d4; animation-delay: 0s; }
.lt-o { background: #ffd600; animation-delay: 0.15s; }
.lt-t { background: #aa00ff; animation-delay: 0.3s; }
.lt-s { background: #00c853; animation-delay: 0.45s; }

@keyframes letterBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.loading-title {
    font-family: 'Orbitron', monospace; font-size: 2rem; font-weight: 900;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.loading-subtitle { color: var(--text-dim); font-size: 0.9rem; }
.loading-bar-container { width: 260px; height: 4px; background: var(--surface-light); border-radius: 2px; overflow: hidden; }
.loading-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 2px; transition: width 0.3s; }
.loading-text { font-size: 0.75rem; color: var(--text-dim); }

/* ============ HOME ============ */

.back-to-hub {
    position: fixed; top: 16px; left: 16px; z-index: 50;
    padding: 8px 18px; background: rgba(108,92,231,0.1);
    border: 1px solid rgba(108,92,231,0.25); border-radius: 50px;
    color: var(--primary-light); text-decoration: none; font-size: 0.8rem;
    transition: all 0.3s; backdrop-filter: blur(10px);
}
.back-to-hub:hover { background: rgba(108,92,231,0.2); color: #fff; }

.home-container {
    position: relative; z-index: 1; min-height: 100vh;
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 60px 24px 40px; gap: 30px;
}

.home-header { text-align: center; }
.home-title {
    font-family: 'Orbitron', monospace; font-size: 2.8rem; font-weight: 900;
    color: #fff; margin-bottom: 8px;
}
.home-title span {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.home-subtitle { color: var(--text-dim); font-size: 1rem; }
.home-version { margin-top: auto; font-size: 0.7rem; color: var(--text-dim); opacity: 0.4; }

.home-menu {
    display: flex; flex-direction: column; gap: 10px;
    width: 100%; max-width: 400px;
}
.menu-btn {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 20px; background: var(--surface);
    border: 1px solid var(--glass-border); border-radius: 14px;
    color: var(--text); font-family: 'Poppins'; font-size: 1rem;
    font-weight: 500; cursor: pointer; transition: all 0.3s;
}
.menu-btn:hover { background: var(--surface-light); border-color: rgba(108,92,231,0.3); transform: translateX(4px); }
.menu-btn.primary { background: linear-gradient(135deg, rgba(108,92,231,0.15), rgba(108,92,231,0.05)); border-color: rgba(108,92,231,0.3); }
.btn-icon { font-size: 1.3rem; }
.btn-label { flex: 1; text-align: left; }
.btn-arrow { color: var(--text-dim); font-size: 1.2rem; }

/* ============ SCORES ============ */

.screen-container { max-width: 600px; margin: 0 auto; padding: 40px 24px; width: 100%; }
.back-btn {
    background: none; border: 1px solid rgba(108,92,231,0.2);
    color: var(--primary-light); padding: 8px 18px; border-radius: 8px;
    cursor: pointer; font-family: 'Poppins'; font-size: 0.85rem;
    transition: all 0.3s; margin-bottom: 24px;
}
.back-btn:hover { background: rgba(108,92,231,0.1); }
.screen-title { font-family: 'Orbitron', monospace; font-size: 1.4rem; font-weight: 700; margin-bottom: 20px; text-align: center; }

.scores-tabs { display: flex; gap: 8px; margin-bottom: 20px; justify-content: center; }
.score-tab {
    padding: 8px 16px; background: var(--surface);
    border: 1px solid var(--glass-border); border-radius: 8px;
    color: var(--text-dim); font-family: 'Poppins'; font-size: 0.8rem;
    cursor: pointer; transition: all 0.3s;
}
.score-tab.active { background: rgba(108,92,231,0.15); border-color: var(--primary); color: var(--primary-light); font-weight: 600; }

.scores-table-container { overflow-x: auto; }
.scores-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.scores-table th { padding: 10px 12px; text-align: left; color: var(--text-dim); font-weight: 500; border-bottom: 1px solid var(--glass-border); font-size: 0.75rem; text-transform: uppercase; }
.scores-table td { padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.scores-table tr:first-child td { color: var(--warning); font-weight: 700; }
.scores-empty { text-align: center; color: var(--text-dim); font-size: 0.85rem; margin-top: 30px; }

/* ============ GAME SCREEN ============ */

#screenGame.active {
    height: 100vh; height: 100dvh;
    background: var(--bg); overflow: hidden;
}

.game-layout {
    flex: 1; display: flex; align-items: stretch;
    justify-content: center; gap: 12px;
    padding: 8px 12px; min-height: 0;
}

.game-sidebar {
    display: flex; flex-direction: column; gap: 8px;
    width: 110px; flex-shrink: 0;
}

.sidebar-box {
    background: var(--surface); border: 1px solid var(--glass-border);
    border-radius: 10px; padding: 8px; text-align: center;
}
.sidebar-label {
    font-family: 'Orbitron', monospace; font-size: 0.55rem;
    font-weight: 700; color: var(--text-dim); letter-spacing: 2px; margin-bottom: 4px;
}
.sidebar-value {
    font-family: 'Orbitron', monospace; font-size: 1.1rem;
    font-weight: 900; color: var(--primary-light);
}

#holdCanvas, #nextCanvas { width: 100%; height: auto; display: block; }

.combo-box {
    background: linear-gradient(135deg, rgba(255,209,102,0.1), rgba(255,107,53,0.05));
    border-color: rgba(255,209,102,0.3);
}
.combo-label { color: var(--warning); }
.combo-value {
    font-family: 'Orbitron', monospace; font-size: 1.4rem;
    font-weight: 900; color: var(--warning);
    animation: comboPulse 0.6s ease-in-out infinite;
}
@keyframes comboPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.game-board-wrapper {
    display: flex; flex-direction: column; align-items: center;
    min-height: 0;
}

.game-top-info {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 0 6px; width: 100%;
}
.game-back-btn {
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; padding: 4px; display: flex; transition: color 0.3s;
}
.game-back-btn:hover { color: var(--primary); }
.game-mode-badge {
    font-size: 0.65rem; background: rgba(108,92,231,0.15);
    color: var(--primary-light); padding: 3px 10px; border-radius: 12px;
    border: 1px solid rgba(108,92,231,0.2);
}
.game-timer {
    font-family: 'Orbitron', monospace; font-size: 0.8rem;
    font-weight: 700; color: var(--accent); margin-left: auto;
}

#gameCanvas {
    border: 2px solid var(--glass-border);
    border-radius: 4px;
    background: rgba(0,0,0,0.4);
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
}

/* ============ GAME TIPS ============ */

.game-tips {
    text-align: center;
    padding: 6px 12px;
    background: rgba(108, 92, 231, 0.06);
    border-top: 1px solid rgba(108, 92, 231, 0.1);
    flex-shrink: 0;
}

.tip-text {
    font-size: 0.72rem;
    color: var(--text-dim);
    line-height: 1.4;
}

/* ============ MOBILE CONTROLS ============ */

.mobile-controls {
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 6px 8px calc(env(safe-area-inset-bottom, 0px) + 6px);
    background: var(--surface);
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
}

.ctrl-row {
    display: flex; gap: 6px; justify-content: center;
}

.ctrl-btn {
    flex: 1; max-width: 80px; height: 50px;
    border: 1px solid var(--glass-border); border-radius: 10px;
    background: var(--surface-light); color: var(--text);
    font-size: 1.3rem; cursor: pointer; transition: all 0.15s;
    display: flex; align-items: center; justify-content: center;
}
.ctrl-btn:active { background: var(--surface-hover); transform: scale(0.93); }
.ctrl-arrow { background: rgba(108,92,231,0.12); border-color: rgba(108,92,231,0.25); }
.ctrl-down { color: var(--accent); }
.ctrl-drop {
    background: linear-gradient(135deg, rgba(108,92,231,0.2), rgba(0,206,201,0.1));
    border-color: rgba(108,92,231,0.35); color: var(--primary-light);
}
.ctrl-hold {
    font-size: 0.7rem; font-weight: 700; font-family: 'Orbitron', monospace;
    letter-spacing: 1px; color: var(--warning);
    background: rgba(255,209,102,0.08); border-color: rgba(255,209,102,0.2);
}

.hidden { display: none !important; }

/* ============ TOAST ============ */

.toast-container {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000; display: flex; flex-direction: column;
    align-items: center; gap: 8px; pointer-events: none;
}
.toast {
    padding: 10px 28px; border-radius: 10px;
    font-size: 0.95rem; font-weight: 700; font-family: 'Orbitron', monospace;
    animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 1s forwards;
    white-space: nowrap;
}
.toast.success { background: rgba(6,214,160,0.9); color: #fff; }
.toast.error { background: rgba(239,71,111,0.9); color: #fff; }
.toast.bonus {
    background: linear-gradient(135deg, rgba(255,209,102,0.95), rgba(108,92,231,0.95));
    color: #fff; font-size: 1.2rem;
}
.toast.clear { background: rgba(108,92,231,0.9); color: #fff; }

@keyframes toastIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes toastOut { 0% { opacity: 1; } 100% { opacity: 0; transform: scale(0.8); } }

/* ============ MODAL ============ */

.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.7); z-index: 500;
    align-items: center; justify-content: center; padding: 20px;
    backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--surface); border: 1px solid var(--glass-border);
    border-radius: 20px; padding: 28px; max-width: 440px;
    width: 100%; max-height: 85vh; overflow-y: auto;
    animation: modalIn 0.3s ease-out;
}
.modal h2 { font-family: 'Orbitron', monospace; font-size: 1.3rem; text-align: center; margin-bottom: 16px; }
.modal h3 { font-size: 0.9rem; color: var(--primary-light); margin: 14px 0 8px; }
.modal p { font-size: 0.85rem; color: var(--text-dim); line-height: 1.6; }
@keyframes modalIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-btn {
    display: block; width: 100%; padding: 12px; margin-top: 12px;
    border: 1px solid var(--glass-border); border-radius: 10px;
    background: var(--surface-light); color: var(--text);
    font-family: 'Poppins'; font-size: 0.9rem; font-weight: 600;
    cursor: pointer; transition: all 0.3s;
}
.modal-btn.primary { background: linear-gradient(135deg, rgba(108,92,231,0.2), rgba(108,92,231,0.1)); border-color: rgba(108,92,231,0.3); color: var(--primary-light); }
.modal-btn:hover { transform: scale(1.02); }

.modal-score {
    text-align: center; font-family: 'Orbitron', monospace;
    font-size: 2.5rem; font-weight: 900; color: var(--warning); margin: 10px 0;
}
.modal-stat {
    display: flex; justify-content: space-between; padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 0.85rem;
}
.modal-stat span:first-child { color: var(--text-dim); }
.modal-stat span:last-child { font-weight: 700; color: var(--primary-light); }

.modal-input {
    width: 100%; padding: 10px 14px; background: var(--surface-light);
    border: 2px solid var(--glass-border); border-radius: 8px;
    color: var(--text); font-family: 'Poppins'; font-size: 0.9rem;
    outline: none; margin-top: 8px;
}
.modal-input:focus { border-color: var(--primary); }

/* ============ RESPONSIVE ============ */

@media (max-width: 768px) {
    .game-sidebar { display: none; }
    .game-layout { padding: 4px 0; }

    .mobile-controls { display: flex; }

    .game-board-wrapper { width: 100%; }
    .game-top-info { padding: 4px 10px; }

    #gameCanvas {
        max-height: calc(100vh - 200px);
        max-height: calc(100dvh - 200px);
        width: 100%;
    }

    .mobile-info {
        display: flex; justify-content: space-around;
        padding: 4px 10px; font-size: 0.7rem;
        color: var(--text-dim); background: var(--surface);
    }
    .mobile-info .mi-val {
        font-family: 'Orbitron', monospace; font-weight: 700;
        color: var(--primary-light); font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    :root { --cell: 28px; }
    .ctrl-btn { height: 46px; font-size: 1.1rem; }
}

@media (max-width: 360px) {
    :root { --cell: 24px; }
    .ctrl-btn { height: 42px; font-size: 1rem; }
}
