:root {
    --bg-color: #050505;
    --panel-bg: rgba(7, 7, 7, 0.9);
    --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;
    overflow: hidden;
}

/* Mobile Body Override */
@media (max-width: 500px) {
    /* Body scroll removed to prevent whole-page scrolling */
    header {
        z-index: 100;
        flex-shrink: 0;
    }
}

header {
    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);
}

.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: 20px;
    padding: 20px;
    max-width: 1400px;
    width: 100%;
    justify-content: center;
    align-items: center;
    flex: 1;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 8px;
}

.view-toggle {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    /* Default sticky for tablet/desktop if shown */
    position: sticky;
    top: 0;
    z-index: 20;
    background: #111;
    padding: 10px 0;
    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: block;
}

/* --- 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-y: auto;
}

.grid {
    display: grid;
    grid-template-columns: repeat(9, 55px);
    grid-template-rows: repeat(9, 55px);
    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: 5;
    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: 'Special Elite', 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: 24px;
    transition: all 0.2s;
    background-color: #222;
}

/* 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: 2;
}

/* 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 #3498db; }
.cell.door-bottom { border-bottom: 3px dashed #3498db; }
.cell.door-left { border-left: 3px dashed #3498db; }
.cell.door-right { border-right: 3px dashed #3498db; }

/* Windows */
.cell.window-top { border-top: 3px double #3498db; }
.cell.window-bottom { border-bottom: 3px double #3498db; }
.cell.window-left { border-left: 3px double #3498db; }
.cell.window-right { border-right: 3px double #3498db; }

.item-icon {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    opacity: 0.7;
    color: #fff;
    filter: drop-shadow(1px 1px 0 #000);
    pointer-events: none;
}

.suspect-token {
    z-index: 3;
    font-weight: 700;
    color: #fff;
    text-shadow: 1px 1px 0 #000;
    font-size: 1.6em;
    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) {
    .view-toggle {
        display: none;
    }
    .game-container {
        flex-direction: row;
        align-items: stretch;
        padding: 0;
        gap: 0;
    }
    .view {
        display: block !important;
        height: 100%;
        overflow: hidden;
    }
    #clues-view {
        width: 350px;
        flex-shrink: 0;
        border-right: 1px solid rgba(255, 255, 255, 0.1);
    }
    #game-view {
        flex: 1;
        display: block;
    }
    .sidebar {
        border: none;
        box-shadow: none;
        /* Keep background pattern */
    }
    .board-wrapper {
        padding: 20px;
    }
}

@media (max-width: 500px) {
    .game-container {
        padding: 10px;
        width: 100%;
        max-width: 100vw;
    }
    .board-wrapper {
        width: 100%;
        overflow-x: auto; /* Allow scroll if needed */
        display: block; /* Reset flex to allow scroll */
        text-align: center;
    }
    .grid {
        /* Dynamic cell size to fill width: (100vw - padding - borders - gaps) / 9 */
        /* Padding 20px + Border 8px + Gaps (8*3=24px) = 52px. Using 60px for safety */
        --cell-size: calc((100vw - 60px) / 9);
        grid-template-columns: repeat(9, var(--cell-size));
        grid-template-rows: repeat(9, var(--cell-size));
        margin: 0 auto; /* Center grid */
    }
    .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;
    }
    .header-content {
        flex-direction: column;
        gap: 10px;
        text-align: center;
        width: 100%;
    }
    .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 #3498db;
    height: 12px;
    margin-bottom: 12px;
}

.window-legend {
    border-bottom: 3px double #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);
}

