/* ═══════════════════════════════════════════════════════════════════════════
   Singleplayer Game Page Styles
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Game Wrapper ────────────────────────────────────────────────────────── */
.game-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 72px);
    padding: 1.5rem;
    overflow: hidden;
}

/* ─── Game Container (3-column layout) ────────────────────────────────────── */
.game-container {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 1.5rem;
    max-width: 900px;
    width: 100%;
}

/* ─── Sidebars ────────────────────────────────────────────────────────────── */
.game-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-shrink: 0;
}

.game-sidebar-left {
    width: 160px;
    align-items: stretch;
}

.game-sidebar-right {
    width: 160px;
    align-items: stretch;
}

/* ─── Panels ──────────────────────────────────────────────────────────────── */
.panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    box-shadow: var(--card-shadow);
    transition: background var(--transition-base), border-color var(--transition-base);
}

.panel-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    text-align: center;
}

/* ─── Hold & Next Canvas ──────────────────────────────────────────────────── */
.hold-panel canvas,
.next-panel canvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}

/* ─── Stats Panel ─────────────────────────────────────────────────────────── */
.stats-panel {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.stat-value {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-primary);
    letter-spacing: -0.02em;
}

/* ─── Audio Toggle ────────────────────────────────────────────────────────── */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 44px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    padding: 0;
}

.btn-icon:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: var(--accent-primary-light);
}

.btn-icon svg {
    flex-shrink: 0;
}

/* ─── Game Board Wrapper ──────────────────────────────────────────────────── */
.game-board-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transition: border-color var(--transition-base), background var(--transition-base);
}

[data-theme="dark"] .game-board-wrapper {
    border-color: var(--accent-primary);
    box-shadow: 0 0 20px rgba(0, 188, 212, 0.1), var(--shadow-lg);
}

#gameCanvas {
    display: block;
    background: var(--bg-secondary);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ─── Game Overlays ───────────────────────────────────────────────────────── */
.game-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10;
    animation: overlay-fade-in 0.3s ease;
}

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

.game-overlay-start {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

@keyframes overlay-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.overlay-content {
    text-align: center;
    color: #ffffff;
    padding: 2rem;
    max-width: 380px;
    width: 100%;
}

.overlay-content h2 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: #ffffff;
}

.overlay-hint {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 1.5rem;
}

/* ─── Countdown Overlay ───────────────────────────────────────────────────── */
.countdown-number {
    font-size: 6rem;
    font-weight: 900;
    color: var(--accent-primary);
    text-shadow: 0 0 30px rgba(0, 188, 212, 0.5);
    animation: countdown-pulse 1s ease infinite;
}

@keyframes countdown-pulse {
    0%   { transform: scale(0.5); opacity: 0; }
    50%  { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0.8; }
}

/* ─── Game Over - Final Stats ─────────────────────────────────────────────── */
.final-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    text-align: left;
}

.final-stat {
    display: flex;
    flex-direction: column;
    padding: 0.6rem 0.75rem;
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.final-stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.5);
}

.final-stat-value {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent-primary);
}

/* ─── Overlay Buttons ─────────────────────────────────────────────────────── */
.overlay-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.overlay-buttons .btn {
    min-width: 140px;
}

/* ─── Line Clear Notification ─────────────────────────────────────────────── */
.line-clear-notify {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    pointer-events: none;
}

.line-clear-notify span {
    display: inline-block;
    font-size: 1.3rem;
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 0 15px rgba(0, 188, 212, 0.8), 0 2px 4px rgba(0, 0, 0, 0.5);
    animation: line-clear-anim 1.2s ease forwards;
}

@keyframes line-clear-anim {
    0%   { opacity: 0; transform: scale(0.7) translateY(10px); }
    20%  { opacity: 1; transform: scale(1.15) translateY(0); }
    80%  { opacity: 1; transform: scale(1) translateY(-10px); }
    100% { opacity: 0; transform: scale(0.9) translateY(-30px); }
}

/* ─── Start Screen ────────────────────────────────────────────────────────── */
.start-content {
    max-width: 420px;
}

.start-title {
    font-size: 3rem;
    font-weight: 900;
    color: var(--accent-primary);
    letter-spacing: -0.03em;
    margin-bottom: 0.5rem;
    text-shadow: 0 0 40px rgba(0, 188, 212, 0.3);
}

.start-subtitle {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 2rem;
}

.start-options {
    margin-bottom: 1.5rem;
}

.start-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.start-option-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
}

.start-select {
    width: auto;
    min-width: 80px;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
}

.start-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.start-btn {
    padding: 1rem 3rem;
    font-size: 1.2rem;
    margin-bottom: 2rem;
}

.btn-large {
    padding: 0.9rem 2.5rem;
    font-size: 1.1rem;
}

/* ─── Controls Help ───────────────────────────────────────────────────────── */
.controls-help {
    text-align: left;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1.5rem;
}

.controls-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 0.75rem;
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 1rem;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.6);
}

.control-item kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 24px;
    padding: 0 0.35rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.72rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    white-space: nowrap;
}

/* ─── Touch Controls ──────────────────────────────────────────────────────── */
.touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem 0.75rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.touch-controls.hidden {
    display: none !important;
}

.touch-row {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
}

.touch-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 52px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    color: #ffffff;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    transition: background 0.1s ease;
}

.touch-btn:active {
    background: rgba(0, 188, 212, 0.4);
    border-color: var(--accent-primary);
}

.touch-btn-wide {
    flex: 1;
    max-width: 120px;
}

.touch-btn svg {
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Tablet (max-width: 900px) ───────────────────────────────────────────── */
@media (max-width: 900px) {
    .game-container {
        gap: 1rem;
    }

    .game-sidebar-left,
    .game-sidebar-right {
        width: 130px;
    }

    .stat-value {
        font-size: 1rem;
    }
}

/* ─── Small Tablet / Large Phone (max-width: 768px) ──────────────────────── */
@media (max-width: 768px) {
    .game-wrapper {
        padding: 0.75rem;
        padding-bottom: 0;
        justify-content: flex-start;
    }

    .game-container {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
    }

    .game-sidebar-left {
        flex-direction: row;
        width: 100%;
        max-width: 400px;
        order: -1;
    }

    .game-sidebar-left .hold-panel {
        flex-shrink: 0;
    }

    .game-sidebar-left .stats-panel {
        flex: 1;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0;
    }

    .game-sidebar-left .stats-panel .stat-item {
        flex: 1 1 45%;
        min-width: 80px;
        padding: 0.35rem 0.5rem;
        border-bottom: none;
        border-right: 1px solid var(--border-color);
    }

    .game-sidebar-left .stats-panel .stat-item:last-child {
        border-right: none;
    }

    .game-sidebar-left .btn-icon {
        width: 44px;
        height: auto;
        align-self: stretch;
    }

    .game-sidebar-right {
        width: 100%;
        max-width: 400px;
    }

    .game-sidebar-right .next-panel {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }

    .game-sidebar-right .next-panel .panel-title {
        margin-bottom: 0;
        writing-mode: vertical-rl;
        transform: rotate(180deg);
    }

    .game-sidebar-right .next-panel canvas {
        width: auto;
        height: 80px;
    }

    .controls-help {
        display: none;
    }

    .start-title {
        font-size: 2.25rem;
    }

    .overlay-content {
        padding: 1.25rem;
    }
}

/* ─── Phone (max-width: 480px) ────────────────────────────────────────────── */
@media (max-width: 480px) {
    .game-wrapper {
        padding: 0.5rem;
        padding-bottom: 0;
    }

    .stat-label {
        font-size: 0.7rem;
    }

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

    .panel {
        padding: 0.6rem;
    }

    .panel-title {
        font-size: 0.7rem;
        margin-bottom: 0.5rem;
    }

    .overlay-content h2 {
        font-size: 1.5rem;
    }

    .final-stats {
        grid-template-columns: 1fr 1fr;
        gap: 0.35rem;
    }

    .final-stat {
        padding: 0.4rem 0.5rem;
    }

    .final-stat-label {
        font-size: 0.65rem;
    }

    .final-stat-value {
        font-size: 0.95rem;
    }

    .overlay-buttons {
        flex-direction: column;
    }

    .overlay-buttons .btn {
        min-width: unset;
        width: 100%;
    }

    .countdown-number {
        font-size: 4rem;
    }

    .start-title {
        font-size: 2rem;
    }

    .start-btn {
        padding: 0.8rem 2rem;
        font-size: 1rem;
    }

    .touch-btn {
        width: 52px;
        height: 48px;
    }
}

/* ─── Landscape Phone ─────────────────────────────────────────────────────── */
@media (max-width: 900px) and (orientation: landscape) {
    .game-wrapper {
        min-height: calc(100vh - 72px);
        padding: 0.5rem;
    }

    .game-container {
        flex-direction: row;
        align-items: flex-start;
    }

    .game-sidebar-left,
    .game-sidebar-right {
        flex-direction: column;
        width: 110px;
    }

    .game-sidebar-left .stats-panel {
        flex-direction: column;
    }

    .game-sidebar-left .stats-panel .stat-item {
        flex: unset;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .game-sidebar-left .btn-icon {
        width: 100%;
        height: 36px;
    }

    .game-sidebar-right .next-panel {
        flex-direction: column;
    }

    .game-sidebar-right .next-panel .panel-title {
        writing-mode: horizontal-tb;
        transform: none;
    }

    .game-sidebar-right .next-panel canvas {
        width: 100%;
        height: auto;
    }

    .touch-controls {
        flex-direction: row;
        justify-content: space-between;
        padding: 0.3rem 0.5rem;
        padding-bottom: calc(0.3rem + env(safe-area-inset-bottom, 0px));
    }

    .touch-row {
        flex: 1;
    }

    .touch-btn {
        width: 48px;
        height: 42px;
    }
}

/* ─── Focus States for Accessibility ──────────────────────────────────────── */
.btn:focus-visible,
.touch-btn:focus-visible,
.start-select:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ─── Reduced Motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .countdown-number {
        animation: none;
    }

    .line-clear-notify span {
        animation: none;
    }

    .game-overlay {
        animation: none;
    }
}
