:root {
    --amber: #FFB000;
    --green: #00FF88;
    --green-dark: #00CC66;
    --green-glow: #00FF8844;
    --bg-dark: #0a0a0c;
    --bg-panel: #111116;
    --bg-panel-border: #1a1a22;
    --text-dim: #556;
    --text-mid: #99a;
    --red-warn: #FF3344;
    --coral: #FF6B5B;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-dark);
    color: var(--amber);
    font-family: 'JetBrains Mono', monospace;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    cursor: default;
}

#scene-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* TOP BAR */
#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: linear-gradient(180deg, #0d0d12 0%, #0a0a0e 100%);
    border-bottom: 1px solid #1a1a22;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    font-size: 12px;
    letter-spacing: 0.1em;
}

.top-bar-left, .top-bar-center, .top-bar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.classification {
    background: var(--amber);
    color: #000;
    padding: 2px 8px;
    font-weight: 800;
    font-size: 10px;
}

.item-number {
    color: var(--amber);
    font-weight: 700;
}

.object-class {
    color: var(--text-mid);
}

.safe-tag {
    color: var(--green);
    font-weight: 700;
}

.hud-btn {
    background: transparent;
    border: 1px solid #333;
    color: var(--amber);
    padding: 4px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.3s;
    letter-spacing: 0.05em;
}

.hud-btn:hover {
    border-color: var(--green);
    color: var(--green);
    box-shadow: 0 0 10px var(--green-glow);
}

/* SIDEBARS */
.sidebar {
    position: fixed;
    top: 48px;
    width: 260px;
    bottom: 36px;
    background: rgba(10, 10, 14, 0.92);
    border-right: 1px solid var(--bg-panel-border);
    z-index: 90;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
}

.sidebar.right {
    right: 0;
    left: auto;
    border-right: none;
    border-left: 1px solid var(--bg-panel-border);
}

.sidebar.collapsed {
    transform: translateX(-260px);
}

.sidebar.right.collapsed {
    transform: translateX(260px);
}

.sidebar-toggle {
    position: absolute;
    right: -28px;
    top: 12px;
    background: rgba(10, 10, 14, 0.9);
    border: 1px solid #222;
    color: var(--text-dim);
    width: 28px;
    height: 28px;
    font-size: 10px;
    cursor: pointer;
    z-index: 91;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar.right .sidebar-toggle {
    right: auto;
    left: -28px;
}

.sidebar-content {
    padding: 16px;
    overflow-y: auto;
    height: 100%;
}

.panel-section {
    margin-bottom: 20px;
    border-bottom: 1px solid #1a1a22;
    padding-bottom: 16px;
}

.panel-section h3 {
    font-size: 10px;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    margin-bottom: 8px;
    font-weight: 500;
}

.readout {
    font-size: 20px;
    font-weight: 700;
    color: var(--green);
    margin-bottom: 6px;
    font-variant-numeric: tabular-nums;
}

.battery-ok {
    color: var(--green);
}

.sub-readout {
    font-size: 10px;
    color: var(--text-dim);
}

.warning-bar {
    height: 4px;
    border-radius: 2px;
    background: #222;
    margin-top: 4px;
    transition: background 1s;
}

.warning-bar.yellow {
    background: linear-gradient(90deg, var(--amber), #aa8800);
    box-shadow: 0 0 8px rgba(255, 176, 0, 0.4);
}

.warning-bar.red {
    background: linear-gradient(90deg, var(--red-warn), #cc0022);
    box-shadow: 0 0 12px rgba(255, 51, 68, 0.6);
    animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.meter-bar {
    height: 6px;
    background: #1a1a22;
    border-radius: 3px;
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    background: var(--green);
    border-radius: 3px;
    transition: width 0.5s;
    width: 50%;
}

.meter-fill.telepathy {
    background: linear-gradient(90deg, var(--green), var(--coral));
}

/* DREAM LOG */
.dream-log-container {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

.dream-entry {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: 14px;
    color: #8899aa;
    margin-bottom: 12px;
    line-height: 1.5;
    opacity: 0;
    animation: fadeInDream 2s forwards;
}

.dream-entry .dream-time {
    font-family: 'JetBrains Mono', monospace;
    font-style: normal;
    font-size: 9px;
    color: var(--text-dim);
    display: block;
    margin-bottom: 2px;
}

@keyframes fadeInDream {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* PUZZLE OVERLAY */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease-in-out;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#puzzle-overlay {
    background: radial-gradient(ellipse at center, #0d1a14 0%, #060a08 70%, #000 100%);
}

#puzzle-container {
    width: min(600px, 90vw);
    text-align: center;
}

.puzzle-header {
    margin-bottom: 24px;
}

.puzzle-header h2 {
    font-size: 24px;
    font-weight: 300;
    letter-spacing: 0.3em;
    color: var(--green);
    text-shadow: 0 0 20px var(--green-glow);
    margin-bottom: 8px;
}

#puzzle-level {
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 0.2em;
    margin-bottom: 12px;
}

#island-grid {
    display: grid;
    gap: 2px;
    margin: 0 auto 20px;
    max-width: 360px;
}

.grid-cell {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 3px;
    transition: background 0.5s, box-shadow 0.5s;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell-water { background: #0d4a5e; }
.cell-sand { background: #c2a366; }
.cell-palm { background: #2d7a3a; }
.cell-rock { background: #3a3a3a; }
.cell-coral { background: #c06050; }
.cell-empty { background: #0a2a38; }

.cell-water.target { box-shadow: inset 0 0 8px rgba(13, 74, 94, 0.8); }
.cell-sand.target { box-shadow: inset 0 0 8px rgba(194, 163, 102, 0.8); }
.cell-palm.target { box-shadow: inset 0 0 8px rgba(45, 122, 58, 0.8); }

#puzzle-status {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 16px;
    min-height: 20px;
}

#pulse-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.pulse-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 2px solid;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 700;
}

.pulse-btn:hover {
    transform: scale(1.15);
}

.pulse-btn.active {
    animation: pulseGlow 0.4s;
}

@keyframes pulseGlow {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); filter: brightness(2); }
    100% { transform: scale(1); }
}

.pulse-btn-water { border-color: #0d4a5e; color: #0d4a5e; background: rgba(13, 74, 94, 0.15); }
.pulse-btn-sand { border-color: #c2a366; color: #c2a366; background: rgba(194, 163, 102, 0.15); }
.pulse-btn-palm { border-color: #2d7a3a; color: #2d7a3a; background: rgba(45, 122, 58, 0.15); }
.pulse-btn-rock { border-color: #3a3a3a; color: #666; background: rgba(58, 58, 58, 0.15); }
.pulse-btn-coral { border-color: #c06050; color: #c06050; background: rgba(192, 96, 80, 0.15); }

.pulse-btn-water:hover { background: rgba(13, 74, 94, 0.4); box-shadow: 0 0 16px rgba(13, 74, 94, 0.5); }
.pulse-btn-sand:hover { background: rgba(194, 163, 102, 0.4); box-shadow: 0 0 16px rgba(194, 163, 102, 0.5); }
.pulse-btn-palm:hover { background: rgba(45, 122, 58, 0.4); box-shadow: 0 0 16px rgba(45, 122, 58, 0.5); }
.pulse-btn-rock:hover { background: rgba(58, 58, 58, 0.4); box-shadow: 0 0 16px rgba(100, 100, 100, 0.5); }
.pulse-btn-coral:hover { background: rgba(192, 96, 80, 0.4); box-shadow: 0 0 16px rgba(192, 96, 80, 0.5); }

#puzzle-message {
    font-size: 14px;
    color: var(--green);
    min-height: 24px;
    text-shadow: 0 0 10px var(--green-glow);
}

/* PROTOCOL MODAL */
#protocol-modal {
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(12px);
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid #222;
    max-width: 680px;
    width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    padding: 32px;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: 1px solid #333;
    color: var(--text-mid);
    width: 32px;
    height: 32px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    border-color: var(--red-warn);
    color: var(--red-warn);
}

.protocol-text {
    font-size: 13px;
    line-height: 1.8;
    color: #aab;
}

.doc-header {
    text-align: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--amber);
}

.stamp {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.3em;
    color: var(--amber);
}

.doc-line {
    font-size: 10px;
    letter-spacing: 0.4em;
    color: var(--text-dim);
    margin-top: 4px;
}

.protocol-text h2 {
    font-size: 14px;
    letter-spacing: 0.15em;
    color: var(--amber);
    margin: 20px 0 10px;
    font-weight: 700;
}

.protocol-text p {
    margin-bottom: 12px;
}

.highlight {
    color: var(--green);
}

.redacted {
    background: var(--red-warn);
    color: #000;
    padding: 1px 6px;
    font-weight: 700;
}

/* BREACH WARNING */
#breach-warning {
    background: rgba(0, 0, 0, 0.95);
    z-index: 500;
}

.breach-content {
    text-align: center;
    animation: breachFlash 0.5s infinite alternate;
}

@keyframes breachFlash {
    from { opacity: 0.8; }
    to { opacity: 1; }
}

.breach-flash {
    font-size: 80px;
    color: var(--red-warn);
    animation: breachPulse 0.8s infinite;
}

@keyframes breachPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.breach-content h1 {
    font-size: 22px;
    color: var(--red-warn);
    letter-spacing: 0.15em;
    margin: 16px 0;
}

.breach-content p {
    font-size: 14px;
    color: var(--amber);
    margin-bottom: 8px;
}

.breach-sub {
    font-size: 11px !important;
    color: var(--text-dim) !important;
    margin-top: 16px !important;
}

.breach-btn {
    margin-top: 24px;
    border-color: var(--red-warn);
    color: var(--red-warn);
    font-size: 13px;
    padding: 8px 24px;
}

.breach-btn:hover {
    background: var(--red-warn);
    color: #000;
}

/* DREAM OVERLAY */
.dream-effects {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 50;
    transition: all 2s;
}

/* HINT */
.hint {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    letter-spacing: 0.2em;
    color: var(--text-dim);
    z-index: 80;
    animation: hintPulse 3s infinite;
    text-align: center;
}

@keyframes hintPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* FOOTER */
#footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: #060608;
    border-top: 1px solid #1a1a22;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 10px;
    color: var(--text-dim);
    z-index: 100;
    letter-spacing: 0.05em;
}

#footer a {
    color: var(--green);
    text-decoration: none;
}

#footer a:hover {
    text-decoration: underline;
}

#weight-reduction {
    color: var(--green);
    font-variant-numeric: tabular-nums;
}

/* SCANLINE EFFECT */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.03) 2px,
        rgba(0, 0, 0, 0.03) 4px
    );
    pointer-events: none;
    z-index: 9999;
}

/* MOBILE */
@media (max-width: 768px) {
    .sidebar {
        width: 220px;
    }
    .sidebar.collapsed {
        transform: translateX(-220px);
    }
    .sidebar.right.collapsed {
        transform: translateX(220px);
    }
    #top-bar {
        font-size: 10px;
        padding: 0 8px;
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    .top-bar-center {
        display: none;
    }
    .hint {
        bottom: 80px;
        font-size: 10px;
    }
    #footer {
        font-size: 8px;
        gap: 6px;
        flex-wrap: wrap;
        height: auto;
        padding: 4px 8px;
    }
    .hud-btn {
        font-size: 9px;
        padding: 3px 8px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 180px;
    }
    .sidebar.collapsed {
        transform: translateX(-180px);
    }
    .sidebar.right.collapsed {
        transform: translateX(180px);
    }
    .readout {
        font-size: 16px;
    }
}