/* ============================================================
   Tetris — Neon Grid Theme
   Accent: #a855f7 (violet)   Glow: #c084fc
   Font: Syne (display) · DM Sans (body) · JetBrains Mono (data)
   ============================================================ */

/* ─── Layout: 3-column ─── */
.tt-layout {
    display: grid;
    grid-template-columns: 160px minmax(0, 560px) 160px;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        ".       game   .      "
        "left    game   right  "
        ".       game   .      ";
    justify-content: center;
    gap: 1.5rem;
    max-width: 980px;
    margin: 0 auto;
    padding: 0 1rem;
    min-height: calc(100vh - 80px);
}

/* ─── Ad Slots ─── */
.ad-slot { display: flex; align-items: flex-start; justify-content: center; }
.ad-slot--left  { grid-area: left;  padding-top: 2rem; }
.ad-slot--right { grid-area: right; padding-top: 2rem; }
.ad-slot--top, .ad-slot--bottom { display: none; }

.ad-placeholder {
    background: rgba(255,255,255,0.02);
    border: 1px dashed rgba(255,255,255,0.06);
    border-radius: 8px;
    color: rgba(255,255,255,0.08);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 4px;
    text-align: center;
    padding: 2rem 0.5rem;
    width: 100%;
}
.ad-placeholder--vertical {
    min-height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 5rem;
}

/* ─── Game Container ─── */
#tetris-app {
    grid-area: game;
    text-align: center;
    position: relative;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ─── Cards ─── */
.card {
    background: rgba(168,85,247,0.04);
    border: 1px solid rgba(168,85,247,0.12);
    border-radius: 12px;
    padding: 1rem 1.2rem;
    margin-bottom: 0.75rem;
}
.card__title {
    color: rgba(168,85,247,0.6);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 0.75rem;
}

/* ─── Header ─── */
.tt-header {
    padding: 2rem 0 1rem;
}
.tt-header h1 {
    font-family: 'Syne', sans-serif;
    font-size: 3.2rem;
    font-weight: 800;
    letter-spacing: 12px;
    color: #fff;
    margin: 0;
    line-height: 1;
    background: linear-gradient(180deg, #f0e0ff 20%, #a855f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
}
.subtitle {
    color: rgba(168,85,247,0.45);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    font-weight: 400;
    letter-spacing: 2px;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.6rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    letter-spacing: 0.3px;
    line-height: 1.4;
}
.btn:focus-visible {
    outline: 2px solid #a855f7;
    outline-offset: 2px;
}
.btn--primary {
    background: #a855f7;
    color: #fff;
    box-shadow: 0 2px 12px rgba(168,85,247,0.35);
}
.btn--primary:hover {
    background: #b06af8;
    box-shadow: 0 4px 20px rgba(168,85,247,0.45);
    transform: translateY(-1px);
}
.btn--primary:active { transform: translateY(0); box-shadow: 0 1px 6px rgba(168,85,247,0.2); }
.btn--primary:disabled {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.25);
    cursor: default;
    transform: none;
    box-shadow: none;
}
.btn--lg { padding: 0.8rem 2.4rem; font-size: 1rem; }
.btn--outline {
    background: transparent;
    color: rgba(255,255,255,0.5);
    border: 1px solid rgba(168,85,247,0.25);
}
.btn--outline:hover {
    border-color: rgba(168,85,247,0.5);
    color: rgba(255,255,255,0.7);
    background: rgba(168,85,247,0.06);
}
.btn--ghost {
    background: transparent;
    color: rgba(255,255,255,0.4);
    border: none;
    font-size: 0.85rem;
}
.btn--ghost:hover { color: rgba(168,85,247,0.7); }
.btn--sm { padding: 0.35rem 0.8rem; font-size: 0.8rem; }

/* ─── Menu ─── */
.menu-best {
    color: rgba(168,85,247,0.6);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0.4rem 0 0;
    font-variant-numeric: tabular-nums;
}
.menu-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin: 1.2rem 0 0.5rem;
}

/* ─── Difficulty ─── */
.difficulty-grid {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
}
.diff-btn {
    flex: 1;
    padding: 0.5rem 0.3rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    color: rgba(255,255,255,0.4);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.78rem;
    font-weight: 500;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}
.diff-btn:hover { border-color: rgba(168,85,247,0.3); color: rgba(255,255,255,0.6); }
.diff-btn.selected {
    border-color: #a855f7;
    background: rgba(168,85,247,0.1);
    color: #c084fc;
}
.diff-btn:focus-visible { outline: 2px solid #a855f7; outline-offset: 2px; }
.diff-icon { font-size: 0.65rem; line-height: 1; }
.diff-desc {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    color: rgba(255,255,255,0.2);
    font-weight: 400;
}
.diff-btn.selected .diff-desc { color: rgba(168,85,247,0.6); }

/* ─── Volume ─── */
.volume-controls {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.vol-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.vol-name {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.35);
    width: 28px;
    text-align: right;
    font-weight: 500;
}
.vol-slider {
    flex: 1;
    height: 4px;
    accent-color: #a855f7;
    cursor: pointer;
}
.vol-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: rgba(255,255,255,0.3);
    width: 22px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ─── HUD ─── */
#game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    background: rgba(168,85,247,0.05);
    border: 1px solid rgba(168,85,247,0.12);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
}
.hud__cell {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.hud__cell--right { text-align: right; align-items: flex-end; }
.hud__label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.55rem;
    font-weight: 600;
    color: rgba(168,85,247,0.45);
    text-transform: uppercase;
    letter-spacing: 2px;
}
.hud__value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.3rem;
    font-weight: 700;
    color: #c084fc;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.hud__value--sub { font-size: 0.95rem; color: rgba(255,255,255,0.5); }

/* ─── Game Area (hold | canvas | next) ─── */
.tt-game-area {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 0.75rem;
}
.tt-side-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-top: 0;
}
.tt-hold-box,
.tt-next-box {
    background: rgba(168,85,247,0.04);
    border: 1px solid rgba(168,85,247,0.1);
    border-radius: 10px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}
.tt-panel-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.55rem;
    font-weight: 700;
    color: rgba(168,85,247,0.5);
    letter-spacing: 3px;
    text-transform: uppercase;
}
.tt-hold-box canvas,
.tt-next-box canvas {
    display: block;
    border-radius: 4px;
}

/* ─── Canvas ─── */
.canvas-wrap {
    position: relative;
    line-height: 0;
}
#tetris-canvas {
    background: #08060e;
    border: 1px solid rgba(168,85,247,0.15);
    border-top: none;
    border-radius: 0 0 12px 12px;
    display: block;
    max-width: 100%;
    height: auto;
    box-shadow: 0 0 40px rgba(168,85,247,0.08), inset 0 0 60px rgba(0,0,0,0.3);
}

/* Mobile pause */
.mobile-pause-btn {
    display: none;
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    background: rgba(0,0,0,0.6);
    border: 1px solid rgba(168,85,247,0.3);
    border-radius: 50%;
    color: rgba(255,255,255,0.6);
    font-size: 1rem;
    cursor: pointer;
    z-index: 50;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
@media (pointer: coarse) {
    .mobile-pause-btn { display: flex; align-items: center; justify-content: center; }
}

/* ─── Mobile Controls ─── */
.tt-mobile-controls {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0.75rem auto 0;
    max-width: 300px;
}
.tt-ctrl-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}
.tt-ctrl-btn {
    width: 64px;
    height: 56px;
    background: rgba(168,85,247,0.08);
    border: 1px solid rgba(168,85,247,0.2);
    border-radius: 12px;
    color: rgba(255,255,255,0.6);
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.08s ease;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.tt-ctrl-btn:active {
    background: rgba(168,85,247,0.3);
    border-color: #a855f7;
    color: #fff;
    transform: scale(0.94);
}
.tt-ctrl-down {
    width: 80px;
}
.tt-ctrl-action {
    background: rgba(168,85,247,0.12);
    border-color: rgba(168,85,247,0.25);
}
.tt-ctrl-drop {
    width: 80px;
    font-size: 1.5rem;
}

@media (pointer: coarse) {
    .tt-mobile-controls { display: flex; }
}

/* ─── Overlays ─── */
.overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.overlay__box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    padding: 2rem 3rem;
    background: rgba(168,85,247,0.06);
    border: 1px solid rgba(168,85,247,0.15);
    border-radius: 16px;
}
.overlay__box h2 {
    font-family: 'Syne', sans-serif;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 0.3rem;
}

/* Pause stats */
.pause-stats {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 0.5rem;
}
.pause-stat {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}
.pause-stat span {
    font-family: 'JetBrains Mono', monospace;
    color: #c084fc;
    font-weight: 700;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

/* ─── Result Card (Game Over) ─── */
.result-card {
    max-width: 380px;
    margin: 2rem auto;
    padding: 2rem 1.5rem;
    background: rgba(168,85,247,0.05);
    border: 1px solid rgba(168,85,247,0.12);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.result-card h2 {
    font-family: 'Syne', sans-serif;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 3px;
    margin-bottom: 0.3rem;
}
.result-score {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.2rem;
    font-weight: 800;
    color: #c084fc;
    font-variant-numeric: tabular-nums;
}
.result-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.8rem;
}
.game-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
    margin: 0.5rem 0;
    width: 100%;
}
.game-stats .stat-item {
    background: rgba(168,85,247,0.08);
    border: 1px solid rgba(168,85,247,0.12);
    border-radius: 8px;
    padding: 0.35rem 0.7rem;
    font-size: 0.72rem;
    color: rgba(255,255,255,0.4);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.game-stats .stat-item .stat-val {
    font-family: 'JetBrains Mono', monospace;
    color: #fff;
    font-weight: 600;
    font-size: 0.82rem;
}

#nickname {
    padding: 0.55rem 1rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    background: rgba(168,85,247,0.06);
    border: 1px solid rgba(168,85,247,0.2);
    color: #e0e0e0;
    border-radius: 8px;
    width: 200px;
    text-align: center;
    transition: border-color 0.15s;
}
#nickname:focus {
    outline: none;
    border-color: #a855f7;
    box-shadow: 0 0 0 3px rgba(168,85,247,0.2);
}
#nickname::placeholder { color: rgba(255,255,255,0.2); }

/* ─── Leaderboard ─── */
.lb-card {
    max-width: 400px;
    margin: 2rem auto;
    padding: 1.5rem;
    background: rgba(168,85,247,0.05);
    border: 1px solid rgba(168,85,247,0.12);
    border-radius: 16px;
    text-align: center;
}
.lb-card h2 {
    font-family: 'Syne', sans-serif;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 1rem;
}
#leaderboard-list {
    text-align: left;
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
}
#leaderboard-list li {
    display: flex;
    align-items: center;
    padding: 0.55rem 0.6rem;
    border-radius: 8px;
    transition: background 0.15s;
}
#leaderboard-list li:nth-child(odd) {
    background: rgba(168,85,247,0.04);
}
#leaderboard-list li:hover {
    background: rgba(168,85,247,0.1);
}
#leaderboard-list li .rank {
    font-family: 'JetBrains Mono', monospace;
    color: rgba(255,255,255,0.3);
    font-weight: 700;
    width: 28px;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}
#leaderboard-list li:nth-child(1) .rank { color: #ffd54f; }
#leaderboard-list li:nth-child(2) .rank { color: #b0bec5; }
#leaderboard-list li:nth-child(3) .rank { color: #a1887f; }
#leaderboard-list li .lb-name {
    flex: 1;
    color: rgba(255,255,255,0.6);
    font-size: 0.85rem;
}
#leaderboard-list li .lb-score {
    font-family: 'JetBrains Mono', monospace;
    color: #c084fc;
    font-weight: 700;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}
#leaderboard-list li .lb-time {
    color: rgba(255,255,255,0.2);
    font-size: 0.7rem;
    margin-left: 0.6rem;
    white-space: nowrap;
}

/* ─── Tutorial ─── */
.tutorial-overlay {
    background: rgba(0,0,0,0.88);
    z-index: 300;
}
.tutorial-box {
    max-width: 360px;
    width: 92%;
    text-align: left;
}
.tutorial-box h2 {
    margin-bottom: 1rem;
}
.tut-content {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
    line-height: 1.7;
    margin-bottom: 1.2rem;
}
.tut-items {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.tut-items div {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(168,85,247,0.08);
}

/* ─── Line Clear Flash ─── */
@keyframes lineClear {
    0%   { background: rgba(168,85,247,0.5); }
    100% { background: transparent; }
}

/* ─── Responsive: Tablet ─── */
@media (max-width: 900px) {
    .tt-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "top"
            "game"
            "bottom";
        grid-template-rows: auto 1fr auto;
        max-width: 560px;
        gap: 0;
    }
    .ad-slot--left, .ad-slot--right { display: none; }
    .ad-slot--top, .ad-slot--bottom {
        display: flex;
        grid-area: unset;
        justify-content: center;
        padding: 0.5rem 0;
    }
    .ad-slot--top { grid-area: top; }
    .ad-slot--bottom { grid-area: bottom; }
    .ad-placeholder--vertical { min-height: unset; position: static; }
    .ad-placeholder { min-height: 60px; padding: 1rem; }
}

/* ─── Responsive: Mobile ─── */
@media (max-width: 480px) {
    .tt-layout { padding: 0 0.25rem; }
    .tt-header h1 { font-size: 2.2rem; letter-spacing: 6px; }
    .card { padding: 0.8rem; }
    .difficulty-grid { gap: 0.25rem; }
    .diff-btn { padding: 0.4rem 0.2rem; font-size: 0.72rem; }
    .btn--lg { padding: 0.7rem 2rem; font-size: 0.9rem; }
    #game-hud { padding: 0.4rem 0.7rem; }
    .hud__value { font-size: 1.1rem; }
    #nickname { width: 170px; }
    .result-card { margin: 1rem auto; padding: 1.5rem 1rem; }
    .tt-side-panel { display: none; }
    .tt-ctrl-btn { width: 56px; height: 50px; font-size: 1.1rem; }
    .tt-ctrl-down { width: 70px; }
    .tt-ctrl-drop { width: 70px; }
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; }
}
