/* ========================================
   DESIGN SYSTEM (Restored Original)
   ======================================== */

:root {
    /* === COLOR PALETTE === */
    --color-honey-50: #fffbeb;
    --color-honey-100: #fef3c7;
    --color-honey-200: #fcebb6;
    --color-honey-300: #fcd34d;
    --color-honey-400: #fbbf24;
    --color-honey-500: #f59e0b;
    --color-honey-600: #dba617;
    --color-honey-700: #b8860b;
    --color-honey-800: #92400e;
    --color-honey-900: #78350f;

    --color-brown-50: #fdf8f6;
    --color-brown-100: #f2e8e5;
    --color-brown-200: #eaddd7;
    --color-brown-300: #e0cfc7;
    --color-brown-400: #d2bab0;
    --color-brown-500: #bfa094;
    --color-brown-600: #a18072;
    --color-brown-700: #2b1d0e;
    /* Base BG */
    --color-brown-800: #1f1610;
    --color-brown-900: #1a1108;
    /* Card BG */
    --color-brown-950: #151008;

    /* Semantic Colors */
    --color-bg: var(--color-brown-700);
    --color-bg-card: var(--color-brown-900);
    --color-text: var(--color-honey-200);
    /* Improved Contrast */
    --color-text-muted: rgba(255, 235, 210, 0.75);
    --color-primary: var(--color-honey-600);

    /* Spacing & Font */
    --font-family-display: 'Orbitron', 'Segoe UI', sans-serif;
    --font-family-body: 'Outfit', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

    --radius-md: 8px;
    --shadow-glow: 0 0 20px rgba(219, 166, 23, 0.4);
}

/* Base Restores */
body {
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-family-body);
    margin: 0;
    padding: 0;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    /* Strict Layout */
}

/* Override Bootstrap text-muted for dark mode visibility */
.text-muted {
    color: var(--color-text-muted) !important;
}

.text-white-50 {
    color: var(--color-text-muted) !important;
}

/* ========================================
   STRICT LAYOUT SYSTEM (The Fix)
   ======================================== */

#app-layout {
    display: grid;
    grid-template-columns: 420px 1fr 420px;
    /* Increased to 420px for user request */
    grid-template-rows: 100vh;
    width: 100%;
    height: 100%;
}

/* Sidebars - Independent Scrolling */
.sidebar {
    height: 100%;
    overflow: hidden;
    /* Force hide scrollbar */
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

/* Ensure contents flex correctly */
.sidebar>.card {
    flex-shrink: 0;
    /* Stats cards don't shrink */
}

.sidebar>.card.flex-grow-1 {
    min-height: 0;
    /* Critical for flex scrolling */
}

/* Score Card Centering IS MOVED TO HTML CLASS */
.sidebar .card-body {
    /* REMOVED global centering */
    display: block;
    /* Default */
}

/* Game Area - Centered & Scaled */
#game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 20px;
    /* Add padding to prevent edge touches */
    overflow: hidden;
}

/* Container Logic */
#game-container-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-container {
    position: relative;
    aspect-ratio: 2 / 3;

    /* REDUCED SCALE (80%) to prevent bottom cut-off */
    height: 80%;
    width: auto;

    /* Fallbacks */
    max-height: 90vh;
    max-width: 100%;

    border: 4px solid #dba617;
    border-radius: 10px;
    box-shadow: var(--shadow-glow);
    background-color: #1a1108;

    display: flex;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ========================================
   COMPONENT STYLES (Restored)
   ======================================== */

/* Typography */
.game-title {
    font-family: var(--font-family-display);
    text-shadow: 0 0 15px rgba(219, 166, 23, 0.4);
    color: var(--color-honey-400);
}

/* Cards */
.card {
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-honey-600);
    margin-bottom: 1rem;
    width: 100%;
    /* Ensure fits width */
}

.card-body {
    padding: 1rem;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--color-text-muted);
    letter-spacing: 0.1em;
    margin-bottom: 0.25rem;
}

.score-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--color-honey-400);
    line-height: 1.1;
    /* text-align: center; REMOVED global center text */
}

/* Stats Badges (New) */
#achievements-count {
    background: var(--color-honey-600);
    color: #000 !important;
    /* Force darker black text */
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 900;
    /* Extra bold */
    font-style: normal !important;
    box-shadow: 0 0 5px rgba(219, 166, 23, 0.3);
}

/* Buttons */
.btn-warning {
    background-color: var(--color-honey-500);
    border-color: var(--color-honey-500);
    color: #1a1108;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-warning:hover {
    background-color: var(--color-honey-400);
    border-color: var(--color-honey-400);
}

.btn-outline-warning {
    color: var(--color-honey-400);
    border-color: var(--color-honey-600);
}

.btn-outline-warning:hover {
    background-color: var(--color-honey-600);
    color: #1a1108;
}

/* Next Piece Canvas */
#nextCanvas {
    background: radial-gradient(circle, #2b1d0e 0%, #1a1108 100%);
}

/* Achievements Grid */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    /* No horizontal scroll */
    flex-grow: 1;
    padding-right: 5px;
    align-content: start;
    width: 100%;
    margin-top: 1rem;
    /* SPACING FIX ADDED */
}

.achievement-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 0.5rem 0.2rem;
    transition: all 0.2s;
    min-height: 50px;
    cursor: pointer;
    /* REQUESTED FIX */
}

.achievement-item.locked {
    opacity: 0.7;
    filter: grayscale(100%);
}

.achievement-item.unlocked {
    border-color: var(--color-honey-600);
    background: rgba(219, 166, 23, 0.1);
    box-shadow: 0 0 10px rgba(219, 166, 23, 0.1);
    opacity: 1;
}

.ach-icon {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

.ach-name {
    font-size: 0.75rem;
    line-height: 1.1;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.achievement-item.unlocked .ach-name {
    color: #fff;
    font-weight: bold;
}

/* Game Over Modal Styling (Custom) */
#gameOverModal .modal-content {
    background-color: var(--color-brown-900);
    border: 2px solid var(--color-honey-600);
    box-shadow: 0 0 30px rgba(219, 166, 23, 0.3);
    border-radius: 16px;
}

#gameOverModal .modal-header {
    border-bottom: 1px solid rgba(219, 166, 23, 0.3);
    background: rgba(0, 0, 0, 0.2);
}

#gameOverModal .modal-footer {
    border-top: 1px solid rgba(219, 166, 23, 0.3);
    background: rgba(0, 0, 0, 0.2);
}

#gameOverModal .display-4 {
    font-family: var(--font-family-display);
    text-shadow: 0 0 10px rgba(219, 166, 23, 0.5);
}

/* Scrollbar Customization (Subtle) */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: var(--color-honey-700);
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 992px) {
    #app-layout {
        display: flex;
        flex-direction: column;
        grid-template: none;
        overflow-y: auto;
    }

    body {
        overflow: hidden;
    }

    #game-area {
        height: auto;
        min-height: 100vh;
        padding: 0;
    }

    .sidebar {
        display: none;
    }

    #game-container {
        max-height: 75vh;
        width: 100%;
        max-width: 400px;
        border-width: 2px;
    }
}

.mobile-header {
    background: linear-gradient(180deg, #1a1108 0%, transparent 100%);
    padding: 10px;
}

.mobile-controls .btn {
    min-width: 50px;
    min-height: 50px;
    font-size: 1.5rem;
}