:root {
    --bg-color: #050505;
    --panel-bg: rgba(15, 15, 15, 0.95);
    --accent: #d4d4d4; /* Off-white */
    --accent-hover: #fff;
    --secondary: #888; /* Gray */
    --warning: #e0e0e0; /* Light Gray */
    --text-main: #eee;
    --text-muted: #aaa;
    --grid-line: #333;
    --cell-blocked: rgba(0, 0, 0, 0.9);
    --border-style: 1px solid #444;
    --tape: #f1c40f;
    --tape-dark: #b48b11;
}

* {
    box-sizing: border-box;
    font-family: 'Special Elite', serif;
}

body {
    background-color: var(--bg-color);
    background-image: url('/img/bg.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--text-main);
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh; /* Mobile viewport fix */
    overflow: hidden;
}

/* Mobile Body Override */
@media (max-width: 500px) {
    /* Body scroll removed to prevent whole-page scrolling */
    header {
        z-index: 100;
        flex-shrink: 0;
    }
    .game-container {
        padding: 10px !important;
        gap: 10px !important;
        border-radius: 0 !important;
    }
}

header {
    position: sticky;
    top: 0;
    padding: 15px 20px;
    width: 100%;
    background: var(--panel-bg);
    border-bottom: var(--border-style);
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0,0,0,0.8);
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.level-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.level-selector select {
    background: #000;
    border: 1px solid #555;
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 0;
    font-family: 'Special Elite', serif;
    font-size: 0.9rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0;
}

.level-selector select:focus {
    outline: none;
    border-color: var(--accent);
}

h1 {
    margin: 0;
    color: var(--text-main);
    font-family: 'Special Elite', serif;
    letter-spacing: 1px;
    font-weight: 900;
    font-size: 2.2rem;
    text-transform: uppercase;
    text-shadow: 2px 2px 0px #000;
    background: none;
    -webkit-text-fill-color: initial;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9em;
    margin-top: 4px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    text-shadow: none;
    font-style: italic;
    font-family: 'Special Elite', serif;
}

.game-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 20px;
    max-width: 1400px;
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 8px;
}

.view-toggle {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    z-index: 20;
    background: #111;
    padding: 10px 20px;
    border-bottom: 1px solid #333;
    width: 100%;
    justify-content: center;
}

.view-toggle button {
    padding: 10px 20px;
    background: #222;
    border: 1px solid #555;
    color: #eee;
    border-radius: 0;
    cursor: pointer;
    font-weight: 700;
    font-size: 1em;
    transition: all 0.2s;
    box-shadow: 2px 2px 0 #000;
    font-family: 'Special Elite', serif;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.view-toggle button.active {
    background: #444;
    color: #fff;
}

.view-toggle button:hover {
    transform: translateY(-1px);
    box-shadow: 3px 3px 0 #000;
    background: #333;
    color: #fff;
}

.view {
    display: none;
    width: 100%;
    max-width: 100%;
}

.view.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* --- CLUES PANEL --- */
.sidebar {
    flex: 1;
    min-width: 300px;
    background: #111;
    padding: 20px;
    background-image: repeating-linear-gradient(45deg, transparent, transparent 20px, rgba(241, 196, 15, 0.05) 20px, rgba(241, 196, 15, 0.05) 40px);
    border-radius: 0;
    height: 100%;
    overflow-y: auto;
    box-shadow: inset 0 0 20px #000;
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
    backdrop-filter: none;
}

.sidebar h3 {
    margin-top: 0;
    color: var(--text-main);
    font-family: 'Special Elite', serif;
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
}

#clues-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: #111;
    border-left: 1px solid #333;
}
::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 0;
    box-shadow: none;
}
::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.clue-card {
    background: #1a1a1a;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 0;
    border: 1px solid #333;
    border-left: 4px solid #555;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.clue-card::before {
    display: none;
}

.clue-card:hover {
    background: #222;
    box-shadow: none;
    border-color: #555;
    transform: translateX(2px);
}

.clue-card.placed {
    opacity: 0.4;
    border-left-color: #333;
    filter: grayscale(1);
    text-decoration: line-through;
}

.clue-name {
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    font-family: 'Special Elite', serif;
    letter-spacing: 0;
    font-size: 1em;
    text-transform: uppercase;
    border-bottom: 1px dashed #333;
    padding-bottom: 4px;
}

.clue-text {
    font-size: 0.9em;
    color: var(--text-muted);
    line-height: 1.5;
    font-family: 'Special Elite', serif;
}

.plot-text {
    font-family: 'Special Elite', serif;
    color: var(--accent);
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px dashed #333;
    font-size: 0.95em;
    line-height: 1.4;
    font-style: italic;
}

/* --- GRID AREA --- */
.board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: center;
    overflow: hidden; /* CRITICAL: Never allow scroll */
    padding: 10px;
}

.grid {
    /* Cell size is controlled by JavaScript based on actual available space */
    --cell-size: 50px; /* Default fallback */
    
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    grid-template-rows: repeat(9, var(--cell-size));
    gap: 3px;
    background-color: #333;
    border-radius: 0;
    overflow: hidden;
    box-shadow: 10px 10px 20px rgba(0,0,0,0.5);
    border: 4px solid #111;
    position: relative;
    flex-shrink: 0;
}

.area-label {
    position: absolute;
    pointer-events: none;
    color: #fff;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    text-align: center;
    z-index: 10; /* Layer 1: Above background */
    text-shadow: 1px 1px 0 #000;
    line-height: 1.1;
    user-select: none;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 0;
    border: 1px solid #555;
    border-radius: 0;
    font-family: sans-serif;
    letter-spacing: 0;
    white-space: normal;
    overflow-wrap: break-word;
    word-wrap: break-word;
    overflow: hidden;
    
    /* Center in parent cell */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.cell {
    position: relative;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--cell-size) * 0.5); /* Responsive font size */
    transition: all 0.2s;
    background-color: #222;
    color: #fff;
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
    /* Let the grid control the size, don't set explicit width/height */
}

/* Area Coloring - Assigned dynamically in JS */

.cell:hover:not(.blocked) {
    box-shadow: inset 0 0 0 2px #fff;
    z-index: 2;
    background-color: #444;
}

.cell.blocked {
    cursor: not-allowed;
}

.cell.blocked::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        45deg,
        rgba(0, 0, 0, 0.85),
        rgba(0, 0, 0, 0.85) 10px,
        rgba(50, 50, 50, 0.5) 10px,
        rgba(50, 50, 50, 0.5) 20px
    );
    border: 1px solid #000;
    z-index: 25; /* Above items */
    opacity: 1 !important; /* Ensure visibility */
}

/* Walls */
.cell.wall-top { border-top: 3px solid #fff; }
.cell.wall-bottom { border-bottom: 3px solid #fff; }
.cell.wall-left { border-left: 3px solid #fff; }
.cell.wall-right { border-right: 3px solid #fff; }

/* Doors */
.cell.door-top { border-top: 3px dashed #2ecc71; }
.cell.door-bottom { border-bottom: 3px dashed #2ecc71; }
.cell.door-left { border-left: 3px dashed #2ecc71; }
.cell.door-right { border-right: 3px dashed #2ecc71; }

/* Windows */
.cell.window-top { border-top: 3px dashed #3498db; }
.cell.window-bottom { border-bottom: 3px dashed #3498db; }
.cell.window-left { border-left: 3px dashed #3498db; }
.cell.window-right { border-right: 3px dashed #3498db; }

.item-icon {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--cell-size) * 0.6); /* Responsive font size */
    opacity: 0.7;
    color: #fff;
    filter: drop-shadow(1px 1px 0 #000);
    pointer-events: none;
    z-index: 20; /* Layer 3: Above hover effect */
}

.suspect-token {
    z-index: 30; /* Layer 4: Topmost content */
    font-weight: 700;
    color: #f1c40f;
    text-shadow: 1px 1px 0 #000;
    font-size: calc(var(--cell-size) * 0.7); /* Responsive font size */
    font-family: 'Special Elite', serif;
    pointer-events: none;
}

/* --- CONTROLS --- */
.controls {
    margin-top: 20px;
    display: flex;
    gap: 15px;
    flex-shrink: 0;
}

button {
    padding: 12px 24px;
    background: #222;
    border: 1px solid #555;
    color: #eee;
    border-radius: 0;
    cursor: pointer;
    font-weight: 700;
    font-size: 1em;
    transition: all 0.2s;
    box-shadow: 2px 2px 0 #000;
    font-family: 'Special Elite', serif;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 3px 3px 0 #000;
    background: #333;
    color: #fff;
}

button.secondary {
    background: #111;
    color: #aaa;
    border: 1px solid #333;
    box-shadow: none;
}

button.secondary:hover {
    background: #222;
    color: #eee;
    border-color: #555;
}

/* --- MODAL --- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: #1a1a1a;
    padding: 40px;
    border-radius: 0;
    text-align: center;
    border: 1px solid #555;
    box-shadow: 10px 10px 0 #000;
    max-width: 400px;
    position: relative;
}

.modal-content::before {
    display: none;
}

.modal-content h2 {
    color: #fff;
    margin-top: 0;
    font-family: 'Special Elite', serif;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0 #000;
}

/* --- CONTEXT MENU (Character Selector) --- */
#char-selector {
    display: none;
    position: absolute;
    background: #111;
    border: 1px solid #555;
    padding: 0;
    border-radius: 0;
    z-index: 50;
    flex-direction: column;
    box-shadow: 5px 5px 0 #000;
    min-width: 180px;
    backdrop-filter: none;
}

.char-option {
    padding: 12px 15px;
    cursor: pointer;
    color: #eee;
    display: flex;
    justify-content: space-between;
    gap: 15px;
    border-radius: 0;
    transition: background 0.1s;
    font-family: 'Special Elite', serif;
    font-weight: 400;
    border-bottom: 1px solid #333;
}

.char-option:hover {
    background: #333;
    color: #fff;
    text-shadow: none;
    font-weight: 500;
}

.char-option:hover {
    background: var(--accent);
    color: #0f172a;
}

.char-option span:last-child {
    font-weight: 800;
    opacity: 0.7;
}

@media (max-width: 960px) {
    body {
        /* Ensure body stays locked */
        overflow: hidden;
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
    }
    .game-container {
        overflow: hidden;
        height: 100%;
        margin-bottom: 0;
        padding-bottom: 0;
        display: flex;
        flex-direction: column;
    }
    .view {
        overflow-y: auto;
        height: 100%;
        padding-bottom: 80px; /* Space for fixed bottom bar */
        -webkit-overflow-scrolling: touch;
    }
    .sidebar, .board-wrapper {
        height: auto;
        overflow: visible;
    }
    
    /* Fixed bottom bar for mobile */
    .view-toggle {
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        width: 100%;
        margin: 0;
        padding: 15px 0;
        background: #000;
        border-top: 1px solid #333;
        border-bottom: none;
        box-shadow: 0 -5px 15px rgba(0,0,0,0.5);
        justify-content: center;
    }
}

@media (min-width: 961px) {
    .board-wrapper {
        padding: 20px;
    }
    .sidebar {
        border: none;
        box-shadow: none;
        /* Keep background pattern */
    }
}

@media (max-width: 500px) {
    .game-container {
        padding: 10px;
        width: 100%;
        max-width: 100vw;
    }
    .board-wrapper {
        width: 100%;
        overflow-x: auto;
        display: flex; /* Use flex to center */
        align-items: center;
        justify-content: center;
        text-align: center;
        min-height: 0;
    }
    .grid {
        /* Cell size is controlled by JavaScript */
        margin: 0 auto;
        flex-shrink: 0; /* Prevent grid from squishing */
    }
    .cell {
        font-size: calc(var(--cell-size) * 0.5);
    }
    .item-icon {
        font-size: calc(var(--cell-size) * 0.6);
    }
    .suspect-token {
        font-size: calc(var(--cell-size) * 0.7);
    }
    .controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }
    button {
        padding: 10px 16px;
        font-size: 0.9em;
    }
    /* Removed legacy header-content column layout to fix height issues */
    .level-selector {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        width: 100%;
    }
    .level-selector select {
        max-width: 200px;
    }
    h1 {
        font-size: 1.5rem;
    }
    
    /* Fix modal on small screens */
    .modal-content {
        width: 90%;
        max-width: 90vw;
        padding: 20px;
        margin: 0 auto;
        box-sizing: border-box; /* Ensure padding is included in width */
    }
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none;
    transform: none;
}
/* --- LEGEND --- */
.legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    font-size: 0.85em;
    color: #aaa;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-icon {
    width: 24px;
    height: 24px;
    background: #222;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wall-legend {
    border-bottom: 3px solid #fff;
    height: 12px; /* Half height to show border clearly */
    margin-bottom: 12px;
}

.door-legend {
    border-bottom: 3px dashed #2ecc71;
    height: 12px;
    margin-bottom: 12px;
}

.window-legend {
    border-bottom: 3px dashed #3498db;
    height: 12px;
    margin-bottom: 12px;
}

.legend-item i {
    width: 24px;
    text-align: center;
    color: #fff;
}


/* --- INTRO MODAL --- */
.intro-content {
    max-width: 600px;
    text-align: center;
}

.intro-body {
    text-align: left;
    margin: 20px 0;
    line-height: 1.6;
    color: #ccc;
}

.intro-list {
    list-style-type: none;
    padding: 0;
    margin: 20px 0;
}

.intro-list li {
    margin-bottom: 10px;
    padding-left: 20px;
    position: relative;
}

.intro-list li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--tape);
}


.icon-btn {
    padding: 5px 8px;
    font-size: 0.9em;
    margin-left: 5px;
    background: #333;
    border: 1px solid #555;
    color: #ccc;
    min-width: 30px;
}
.icon-btn:hover {
    background: #444;
    color: #fff;
}
.icon-btn.delete:hover {
    background: #c0392b;
    border-color: #e74c3c;
}
.suspect-actions {
    display: flex;
    align-items: center;
}

.footer-credits {
    position: fixed;
    bottom: 5px;
    right: 10px;
    font-size: 10px;
    color: #d7d7d7;
    z-index: 9999;
    pointer-events: none;
    font-family: 'Special Elite', cursive;
    opacity: 0.6;
}

@media (max-width: 960px) {
    .footer-credits {
        bottom: 70px;
    }
}

/* Enhanced UI Styles for Sudokiller */

/* --- 1. General Polish & Atmosphere --- */

/* Add a subtle vignette to the body to focus attention on the center */
body::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-shadow: inset 0 0 150px rgba(0,0,0,0.9);
    pointer-events: none;
    z-index: 1;
}

/* Ensure content is above the vignette */
header, .container, .game-container {
    z-index: 2;
    position: relative;
}

/* --- 2. Header & Navigation --- */

header {
    background: rgba(15, 15, 15, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #333;
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

h1 {
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    letter-spacing: 2px;
}

.subtitle {
    color: var(--tape);
    font-weight: bold;
    letter-spacing: 1px;
    opacity: 0.9;
}

/* Styled Buttons in Header */
#btn-menu, #lang-select {
    background: #222 !important;
    border: 1px solid #444 !important;
    color: #ccc !important;
    border-radius: 4px !important;
    transition: all 0.2s ease;
    box-shadow: 0 2px 0 #000;
}

#btn-menu:hover, #lang-select:hover {
    background: #333 !important;
    color: #fff !important;
    border-color: #666 !important;
    transform: translateY(-1px);
}

#btn-menu:active {
    transform: translateY(1px);
    box-shadow: none;
}

/* --- 3. View Toggles (Game / Clues) --- */

.view-toggle {
    background: transparent;
    border-bottom: none;
    gap: 0;
    padding: 0;
    margin-bottom: 20px;
}

.view-toggle button {
    background: #1a1a1a;
    border: 1px solid #333;
    color: #888;
    flex: 1;
    max-width: 200px;
    padding: 12px;
    font-size: 1.1em;
    box-shadow: inset 0 -2px 5px rgba(0,0,0,0.5);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.view-toggle button:first-child {
    border-radius: 6px 0 0 6px;
    border-right: none;
}

.view-toggle button:last-child {
    border-radius: 0 6px 6px 0;
    border-left: none;
}

.view-toggle button.active {
    background: #2c2c2c;
    color: var(--tape);
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.2);
    border-color: #555;
    z-index: 1;
    text-shadow: 0 0 5px rgba(241, 196, 15, 0.3);
}

.view-toggle button:hover:not(.active) {
    background: #222;
    color: #ccc;
}

/* --- 4. Clue Cards (The "Case File" Look) --- */

.clue-card {
    background: #222;
    border: 1px solid #333;
    border-left: 4px solid #555;
    border-radius: 4px;
    margin-bottom: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.4);
    transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
}

.clue-card:hover {
    transform: translateX(4px);
    background: #282828;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    border-color: #555;
    border-left-color: var(--tape);
}

.clue-name {
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 6px;
    margin-bottom: 10px;
    color: #ddd;
}

.clue-text {
    color: #bbb;
    line-height: 1.5;
    font-size: 0.95em;
}

/* Completed Clues */
.clue-card.placed {
    opacity: 0.5;
    background: #111;
    border-left-color: #222;
    transform: scale(0.98);
}

/* --- 5. Animations --- */

@keyframes slideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.view.active {
    animation: slideIn 0.3s ease-out;
}

/* --- 6. Scrollbars --- */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #0f0f0f;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* --- 7. Level Selector --- */
.level-selector select {
    background-color: #222;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 6px 10px;
    box-shadow: 0 2px 0 #000;
    transition: border-color 0.2s;
}

.level-selector select:hover {
    border-color: #666;
}

/* --- 8. Game Board Polish --- */
.cell:not(.blocked):hover {
    background-color: rgba(255,255,255,0.05);
}

/* --- 9. Level Selection Screen --- */

.series-block h3 {
    color: var(--tape) !important;
    border-bottom: 1px dashed #444 !important;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.level-card {
    background: #222 !important; /* Override inline JS style base */
    border: 1px solid #444;
    box-shadow: 0 4px 0 #000;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
    overflow: hidden;
}

.level-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 0 #000;
    border-color: #666;
    z-index: 1;
}

.level-card:active {
    transform: translateY(0);
    box-shadow: 0 2px 0 #000;
}

.level-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom right, rgba(255,255,255,0.1), rgba(0,0,0,0.2));
    pointer-events: none;
}

/* --- 10. Sidebar Tabs & Layout --- */

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 0 !important; /* Reset padding as sections will handle it */
    background: transparent !important; /* Reset background */
    border: none !important; /* Reset border */
    box-shadow: none !important; /* Reset shadow */
    height: 100%;
}

.sidebar-section {
    background: #111;
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* For scrolling */
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.sidebar-tabs {
    display: flex;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-right: 1px solid #333;
    color: #888;
    padding: 12px;
    cursor: pointer;
    font-family: 'Special Elite', serif;
    text-transform: uppercase;
    font-size: 0.9em;
    transition: all 0.2s;
}

.tab-btn:last-child {
    border-right: none;
}

.tab-btn:hover {
    background: #222;
    color: #ccc;
}

.tab-btn.active {
    background: #111;
    color: var(--tape);
    box-shadow: inset 0 3px 0 var(--tape);
    font-weight: bold;
}

.sidebar-content {
    flex: 1;
    position: relative;
    overflow: hidden;
    padding: 15px;
    background-image: repeating-linear-gradient(45deg, transparent, transparent 20px, rgba(241, 196, 15, 0.02) 20px, rgba(241, 196, 15, 0.02) 40px);
}

.tab-pane {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Adjust existing elements to fit */
#clues-list {
    height: 100%;
    padding-right: 5px;
}

.plot-text {
    color: #ccc;
    line-height: 1.6;
    font-size: 0.95em;
}

.rules-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.rules-list li {
    margin-bottom: 10px;
    padding-left: 15px;
    position: relative;
    color: #aaa;
    font-size: 0.9em;
}

.rules-list li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--tape);
}

/* Legend Grid adjustments */
.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
    color: #bbb;
}

.legend-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- 11. Sidebar Sizing & Buttons --- */

.sidebar-section.top-section {
    flex: 1; /* Takes remaining space */
    min-height: 0;
}

.sidebar-section.bottom-section {
    flex: none; /* Don't grow */
    height: auto;
    max-height: 200px; /* Approx 4-5 lines + tabs */
    min-height: 150px;
}

/* Game Action Buttons */
.game-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
    padding: 10px;
    background: rgba(0,0,0,0.5);
    border-radius: 8px;
    width: 100%;
    max-width: 500px;
}

.action-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Special Elite', serif;
    font-size: 1em;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    text-transform: uppercase;
    font-weight: bold;
    color: #fff;
    box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}

.action-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.3);
}

.btn-check {
    background-color: #27ae60;
    border: 1px solid #2ecc71;
}

.btn-check:hover {
    background-color: #2ecc71;
}

.btn-reset {
    background-color: #c0392b;
    border: 1px solid #e74c3c;
}

.btn-reset:hover {
    background-color: #e74c3c;
}

.btn-solve {
    background-color: #8e44ad;
    border: 1px solid #9b59b6;
}

/* --- 12. Game View Layout Fix (Sticky Actions) --- */

#game-view.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}

.board-wrapper {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 20px;
}

.game-actions {
    position: sticky;
    bottom: 0;
    flex-shrink: 0;
    margin-top: 0;
    padding: 15px;
    background: #111;
    border-top: 1px solid #333;
    border-radius: 0;
    width: 100%;
    max-width: 100%;
    z-index: 10;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.5);
}

/* --- MODERN NOIR (Glassmorphism & Animations) --- */

:root {
    --glass-bg: rgba(20, 20, 20, 0.65);
    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Apply to main containers */
.game-container, .sidebar, .modal-content, .login-box, .level-card {
    background: var(--glass-bg) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: var(--glass-border) !important;
    box-shadow: var(--glass-shadow) !important;
    border-radius: 16px; /* Softer corners */
}

/* Modernize Buttons */
button, .action-btn, .tab-btn {
    border-radius: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

button:hover, .action-btn:hover, .tab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

/* Optimized Cell Interactions - High Performance */
.cell {
    transition: none !important;
    position: relative;
    /* overflow: hidden; REMOVED to allow labels to span multiple cells */
}

/* Hover Effect Layer */
.cell::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    pointer-events: none;
    z-index: 15; /* Layer 2: Between Label and Items */
    will-change: opacity;
}

.cell:hover::after {
    opacity: 1;
}

.cell:hover {
    cursor: pointer;
    /* z-index: 5; REMOVED to prevent stacking context issues */
}

/* Pulse animation for the active cell - Simplified */
.cell.selected {
    box-shadow: inset 0 0 15px var(--tape);
    border-color: var(--tape);
    z-index: 40; /* Layer 5: Selected cell pops out */
}

/* --- MOBILE FRIENDLY HEADER --- */

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: auto;
    min-height: 50px;
    padding: 0;
}

.brand {
    display: flex;
    flex-direction: column;
    cursor: pointer;
    user-select: none;
}

.brand h1 {
    font-size: 1.5rem; /* Mobile default */
    line-height: 1;
    margin: 0;
    text-shadow: 2px 2px 0px #000;
}

.brand .subtitle {
    font-size: 0.7rem;
    opacity: 0.7;
    line-height: 1.2;
    letter-spacing: 1px;
}

.header-nav {
    display: flex;
    gap: 12px;
    align-items: center;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.2rem;
    padding: 0;
    cursor: pointer;
    border-radius: 50%;
    width: 44px; /* Minimum touch target */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    box-shadow: none; /* Reset default button shadow */
}

.nav-btn:hover {
    background: rgba(255,255,255,0.1);
    transform: none; /* Reset default button transform */
    box-shadow: none;
}

.lang-selector-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(255,255,255,0.05);
    border-radius: 20px;
    padding: 5px 12px;
    border: 1px solid rgba(255,255,255,0.1);
    height: 36px;
}

.lang-selector-wrapper i {
    font-size: 0.9rem;
    margin-right: 8px;
    color: #aaa;
}

.lang-selector-wrapper select {
    background: transparent;
    border: none;
    color: #eee;
    font-family: 'Special Elite', serif;
    font-size: 0.9rem;
    cursor: pointer;
    appearance: none; /* Remove default arrow */
    padding: 0;
    margin: 0;
    width: auto;
}

.lang-selector-wrapper select:focus {
    outline: none;
}

/* Desktop Adjustments */
@media (min-width: 600px) {
    .brand h1 { font-size: 2.2rem; }
    .brand .subtitle { font-size: 1rem; }
    .header-content { padding: 0 10px; }
}

/* --- MOBILE MENU --- */
.mobile-menu {
    position: fixed;
    top: 60px; /* Below header */
    right: 0;
    width: 220px;
    background: var(--panel-bg);
    border: 1px solid #444;
    border-right: none;
    border-radius: 10px 0 0 10px;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    box-shadow: -5px 5px 20px rgba(0,0,0,0.5);
    backdrop-filter: blur(10px);
}

.mobile-menu.active {
    transform: translateX(0);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    color: #eee;
    text-decoration: none;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    cursor: pointer;
    font-family: 'Special Elite', serif;
    font-size: 1.1rem;
    width: 100%;
    text-align: left;
    transition: background 0.2s;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:hover {
    background: rgba(255,255,255,0.05);
}

.menu-item i {
    width: 20px;
    text-align: center;
    color: var(--tape);
}

.menu-item select {
    background: transparent;
    border: none;
    color: #eee;
    font-family: 'Special Elite', serif;
    font-size: 1.1rem;
    cursor: pointer;
    width: 100%;
    padding: 5px 0;
}

.menu-item select:focus {
    outline: none;
}

/* Fix Dropdown Colors */
.menu-item select option {
    background-color: #222;
    color: #eee;
}

/* --- LEVEL SELECTION SCREEN --- */

.series-block {
    margin-bottom: 40px;
    animation: fadeIn 0.5s ease-out;
}

.series-title {
    color: var(--tape);
    border-bottom: 2px dashed #444;
    padding-bottom: 10px;
    margin-bottom: 20px;
    font-size: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0 #000;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
}

.level-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: rgba(30, 30, 30, 0.6);
    border: 1px solid #444;
    padding: 20px;
    border-radius: 8px;
    text-decoration: none;
    color: #eee;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
    min-height: 120px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.level-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    border-color: var(--tape);
    background: rgba(40, 40, 40, 0.8);
}

.level-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 4px; height: 100%;
    background: #555;
    transition: background 0.3s;
}

.level-card.status-solved::before { background: #27ae60; }
.level-card.status-inprogress::before { background: #d35400; }
.level-card.status-new::before { background: #444; }

.level-card-title {
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 10px;
    z-index: 2;
    line-height: 1.3;
}

.level-card-meta {
    font-size: 0.8rem;
    color: #888;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 2;
}

.status-stamp {
    position: absolute;
    bottom: -15px;
    right: -10px;
    font-size: 4rem;
    opacity: 0.1;
    transform: rotate(-15deg);
    font-weight: 900;
    pointer-events: none;
    transition: opacity 0.3s;
}

.level-card:hover .status-stamp {
    opacity: 0.2;
}

.status-solved .status-stamp { color: #27ae60; }
.status-inprogress .status-stamp { color: #d35400; }

/* Staggered Animation for cards */
@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.level-card {
    animation: slideUpFade 0.4s ease-out backwards;
}

.level-card:nth-child(1) { animation-delay: 0.05s; }
.level-card:nth-child(2) { animation-delay: 0.1s; }
.level-card:nth-child(3) { animation-delay: 0.15s; }
.level-card:nth-child(4) { animation-delay: 0.2s; }
.level-card:nth-child(5) { animation-delay: 0.25s; }
.level-card:nth-child(6) { animation-delay: 0.3s; }
.level-card:nth-child(7) { animation-delay: 0.35s; }
.level-card:nth-child(8) { animation-delay: 0.4s; }
.level-card:nth-child(9) { animation-delay: 0.45s; }
.level-card:nth-child(10) { animation-delay: 0.5s; }

/* --- Desktop Layout Fixes --- */
@media (min-width: 961px) {
    #game-view.active {
        display: flex !important;
        flex-direction: column;
        height: 100% !important;
        overflow: hidden;
        position: relative; /* Establish positioning context */
    }
    
    .board-wrapper {
        flex: 1;
        height: 0 !important; /* Force flex sizing */
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 20px;
    }
    
    .game-actions {
        position: sticky;
        bottom: 0;
        flex-shrink: 0;
        margin-top: 0;
        padding: 15px;
        background: #111;
        border-top: 1px solid #333;
        border-radius: 0;
        width: 100%;
        max-width: 100%;
        z-index: 10;
        box-shadow: 0 -4px 10px rgba(0,0,0,0.5);
    }
    
    /* Ensure grid doesn't get cut off if it fits */
    .grid {
        margin: auto;
        flex-shrink: 0;
    }
}
