:root {
    /* Colors - Zebra X2 Theme */
    --bg-dark: #020b1c;
    --bg-light: #0d2d5e;
    --primary: #ff9d00;
    /* Orange */
    --secondary: #00e5ff;
    /* Blue */
    --text: #ffffff;
    --card-bg: rgba(5, 22, 48, 0.7);
    --border: rgba(0, 229, 255, 0.3);
    --grid-bg: rgba(0, 0, 0, 0.4);
    --header-bg: #1a4a91;
    --cell-empty: transparent;
    --cell-x: #ff4d4d;
    --cell-ok: #00e676;

    /* Responsive Tokens */
    --root-padding: 2vmin;
    --app-gap: 2vmin;
    --main-radius: 1.5vmin;
    --home-size: 8vmin;
    --cell-size: 40px;
    --side-header-width: 100px;
    --top-header-height: 100px;
}

/* --- SAFETY OVERLAY (Same as Fifteen) --- */
#size-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(2, 11, 28, 0.98);
    z-index: 10000;
    display: none;
    justify-content: center;
    align-items: center;
    color: white;
    padding: 10vw;
    text-align: center;
}

.warning-box {
    background: #051630;
    padding: 6vmin;
    border-radius: 4vmin;
    border: 2px solid var(--primary);
    box-shadow: 0 0 5vmin var(--primary);
}

.warning-icon {
    font-size: 12vmin;
    display: block;
    margin-bottom: 2vmin;
}

.warning-box h2 {
    font-size: 6vmin;
    margin: 0 0 2vmin 0;
    color: var(--primary);
}

.warning-box p {
    font-size: 3.5vmin;
    color: var(--secondary);
    margin: 0;
}

/* Base Resets */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(circle at center, var(--bg-light) 0%, var(--bg-dark) 100%);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
}

#app-root {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    padding: var(--root-padding);
    gap: var(--app-gap);
    position: relative;
}

/* Header Container */
#top-bar {
    display: flex;
    justify-content: flex-start;
    /* Move everything to the left */
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
    padding: 1.5vmin 3vmin;
    border-radius: var(--main-radius);
    border-bottom: 2px solid var(--secondary);
    gap: 4vmin;
    /* Gap between buttons and title */
}

.info-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.info-group h1 {
    font-size: clamp(1rem, 4vmin, 1.8rem);
    margin: 0;
    color: var(--primary);
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    background: var(--secondary);
    color: #000;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 800;
    margin-top: 5px;
}

.actions-group {
    display: flex;
    gap: 1.5vmin;
}

.nav-btn-rect {
    background: transparent;
    border: 1.5px solid var(--primary);
    color: var(--primary);
    padding: 0.8vmin 2vmin;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    font-size: 2.2vmin;
}

.nav-btn-rect:active {
    transform: scale(0.95);
}

/* Main Content Structure */
#main-content {
    flex: 1;
    display: flex;
    gap: var(--app-gap);
    overflow: hidden;
}

/* LEFT: The Grid */
#scene-container {
    flex: 2;
    background: var(--card-bg);
    border-radius: var(--main-radius);
    display: block;
    /* Using block to prevent flex-centering clipping */
    padding: 2vmin;
    overflow: auto;
    border: 1px solid var(--border);
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5);
    text-align: center;
    /* Center horizontally when not overflowing */
}

#logic-grid-wrapper {
    display: inline-block;
    /* Essential for text-align: center to work while allowing overflow */
    text-align: left;
    /* Reset alignment for the grid itself */
}

#logic-grid {
    display: grid;
    border: 2px solid var(--secondary);
    background: var(--grid-bg);
}

/* RIGHT: Clues & Controls */
#interaction-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--app-gap);
    overflow: hidden;
}

.clues-card {
    flex: 1;
    background: var(--card-bg);
    border-radius: var(--main-radius);
    padding: 2.5vmin;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.clues-card h3 {
    margin: 0 0 1.5vmin 0;
    color: var(--secondary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 1vmin;
}

#clue-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#clue-list li {
    padding: 1.2vmin;
    background: rgba(255, 255, 255, 0.05);
    margin-bottom: 0.8vmin;
    border-radius: 6px;
    cursor: pointer;
    font-size: clamp(0.85rem, 2vmin, 1.1rem);
}

#clue-list li.marked {
    opacity: 0.3;
    text-decoration: line-through;
    background: rgba(0, 0, 0, 0.2);
}

.btn-group {
    display: flex;
    gap: 1.5vmin;
}

.action-btn {
    flex: 2;
    background: var(--primary);
    color: black;
    border: none;
    padding: 2vmin;
    font-weight: 800;
    border-radius: 12px;
    cursor: pointer;
    font-size: 2.5vmin;
}

.secondary-btn {
    flex: 1;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 12px;
    cursor: pointer;
    font-size: 2vmin;
}

/* Grid Specifics (Headers & Cells) */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2rem;
}

.cell.x {
    color: var(--cell-x);
}

.cell.ok {
    color: var(--cell-ok);
    background: rgba(0, 230, 118, 0.1);
}

.cell.wrong {
    background: rgba(255, 0, 0, 0.3);
    animation: shake 0.3s;
}

.h-cell {
    background: var(--header-bg);
    font-weight: bold;
    font-size: 0.9rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid var(--border);
    color: white;
}

.h-side {
    width: var(--side-header-width);
    position: sticky;
    left: 0;
    z-index: 10;
    text-align: right;
    padding-right: 5px;
    justify-content: flex-end;
}

.h-top {
    height: var(--top-header-height);
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.corner {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 20;
    color: var(--primary);
    font-size: 0.9rem;
    cursor: pointer;
    flex-direction: column;
}

/* UI Layer */
.ui-layer {
    position: absolute;
    z-index: 1000;
}

.home-btn {
    width: var(--home-size);
    height: var(--home-size);
    background: var(--primary);
    border: 0.6vmin solid white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
    font-size: calc(var(--home-size) * 0.5);
    box-shadow: 0 1vmin 2vmin rgba(0, 0, 0, 0.3);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--bg-light);
    padding: 4vmin;
    border-radius: 3vmin;
    text-align: center;
    border: 2px solid var(--primary);
    max-width: 90%;
}

.level-selector {
    max-height: 85vh;
    overflow-y: auto;
    width: 500px;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1.5vmin;
    margin: 2vmin 0;
}

.level-item {
    background: rgba(13, 45, 94, 0.6);
    border: 1px solid var(--secondary);
    padding: 1.5vmin;
    border-radius: 12px;
    cursor: pointer;
    text-align: center;
}

.level-item.current {
    border: 2px solid var(--primary);
    box-shadow: 0 0 10px var(--primary);
}

/* =========================================
   ASPECT RATIO SPECIFIC LAYOUTS
   ========================================= */

/* --- 1. WIDE/COMPACT --- */
.layout-wide #main-content,
.layout-compact #main-content {
    flex-direction: row;
}

.layout-wide .ui-layer,
.layout-compact .ui-layer {
    top: var(--root-padding);
    right: var(--root-padding);
}

/* --- 3. SQUARE --- */
.layout-square #main-content {
    flex-direction: column;
}

.layout-square #scene-container {
    height: 60%;
}

.layout-square .ui-layer {
    top: 2vmin;
    right: 2vmin;
}

/* --- 4. PORTRAIT --- */
.layout-portrait #app-root {
    padding: 0.5vmin;
}

.layout-portrait #main-content {
    flex-direction: column;
}

.layout-portrait #scene-container {
    height: 50%;
    box-shadow: none;
    padding: 1vmin;
}

.layout-portrait #interaction-container {
    height: 45%;
}

.layout-portrait .ui-layer {
    top: 2vmin;
    right: 2vmin;
}

.layout-portrait :root {
    --side-header-width: 70px;
    --top-header-height: 70px;
    --cell-size: 32px;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}