/* ========================= BASE / LAYOUT GENERAL ========================= */
body {
    background: #1a1a1a;
    font-family: "Courier New", monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    color: #e6e6d6;
    margin: 0;
    padding: 0 160px;
    overflow-x: hidden;
    transition: background 0.5s ease;
}

h1 { text-align: center; color: #d8d2b0; letter-spacing: 2px; margin-bottom: 15px; display: flex; flex-direction: column; gap: 5px; }
h2 { color: #c9c3a5; font-size: 16px; margin-top: 0; text-align: center; width: 100%; }
.subtitle { font-size: 11px; color: #888; letter-spacing: 1px; }
.hidden { display: none !important; }

.app-container { display: flex; flex-direction: column; align-items: center; }
.main-layout { display: flex; justify-content: center; align-items: center; gap: 20px; }
.right-stack { display: flex; flex-direction: column; justify-content: center; height: 100%; }
.footer { margin-top: 20px; }

/* ========================= PANELS ========================= */
.panel {
    position: relative;
    width: 680px;
    background: linear-gradient(145deg, #2b2b2b, #1c1c1c);
    border: 3px solid #555;
    padding: 20px;
    box-shadow: inset 0 0 10px #000, 0 0 15px rgba(0,0,0,0.6);
    z-index: 10;
}

.valve-panel, .status-panel, .reactor-info-panel {
    background: #111;
    border: 2px solid #444;
    padding: 15px;
    margin-top: 80px;
}
.valve-panel { width: 150px; }
.status-panel, .reactor-info-panel { width: 180px; }

.config-panel {
    position: absolute; top: 20px; left: 20px;
    background: #111; border: 2px solid #444;
    padding: 15px; color: #c9c3a5; width: 200px;
}
.config-hidden { display: none; }
.config-panel label { display: block; font-size: 12px; margin-bottom: 5px; }
.config-panel input, input[type="range"] { width: 100%; background: #222; border: 1px solid #444; color: #fff; }
.config-panel input { margin-bottom: 15px; padding: 4px; }
input[type="range"] { cursor: pointer; accent-color: #c9c3a5; }

/* ========================= BUTTONS & CONTROLS ========================= */
button {
    background: linear-gradient(#3a3a3a, #2a2a2a);
    border: 2px solid #666; color: #e6e6d6;
    padding: 8px 12px; cursor: pointer; font-family: inherit;
    box-shadow: inset 0 1px 0 #777, 0 2px 0 #111;
}
button:hover { background: #444; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(1); box-shadow: none; border-color: #333; }

.scram-btn { background: linear-gradient(#7a0000, #4a0000); border-color: #a33; color: #fff; font-weight: bold; min-width: 120px; }
#simToggle { z-index: 1001; position: relative; }
.top-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }

/* ========================= DISPLAYS & SECTIONS ========================= */
.metric-box, #tempDisplay, #waterDisplay, #rodDisplay { background: #000; border: 1px solid #444; padding: 8px; color: #c2b71e; font-size: 1.1em; box-shadow: inset 0 0 8px rgba(0,255,0,0.1); }
#tempRate { font-size: 0.8em; margin-left: 10px; }
.section { background: #222; border: 1px solid #444; margin: 10px 0; padding: 15px; box-shadow: inset 0 0 5px #000; }
.info-line { padding: 6px; border-bottom: 1px solid #222; }
.reactor-info-panel { font-size: 12px; color: #c9c3a5; }
.reactor-info-panel h2 { margin-bottom: 10px; font-size: 14px; }

/* ========================= RODS ========================= */
.rod-layout, .system-grid { display: flex; justify-content: space-between; gap: 15px; }
.rod-layout { align-items: center; gap: 20px; }
.rod-info, .rod-system, .system-item { flex: 1; }
.rod-system { display: flex; justify-content: center; }
.rod-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.rod-container { display: flex; align-items: center; gap: 15px; }

.rod-scale { width: 8px; height: 140px; background: repeating-linear-gradient(to bottom, #666 0 2px, transparent 2px 14px); border-right: 1px solid #444; }
.rod-housing { width: 45px; height: 140px; background: #cacaca; border: 2px solid #000; position: relative; overflow: hidden; box-shadow: inset 0 0 10px #000; }
.rod-bar { width: 100%; height: 100%; background: linear-gradient(90deg, #1e60a2, #3fa9ff, #1e60a2); position: absolute; top: 0; transition: transform 0.2s linear; border-bottom: 3px solid #fff; }

/* ========================= COOLING SYSTEMS ========================= */
.system-item { background: #1b1b1b; border: 1px solid #444; padding: 12px; text-align: center; }
.light-indicator { display: flex; justify-content: center; align-items: center; gap: 8px; margin-bottom: 10px; }
.light { width: 12px; height: 12px; border-radius: 50%; background: #400; box-shadow: inset 0 0 3px #000; transition: all 0.3s; }
.light.on { background: #0f0; box-shadow: 0 0 10px #0f0, inset 0 0 3px #fff; }

/* ========================= STATUS & VALVES ========================= */
.status-item { padding: 8px; margin: 6px 0; text-align: center; background: #1a1a1a; color: #444; border: 1px solid #333; font-size: 13px; }
.status-active { background: #004400; color: #0f0; border-color: #0f0; box-shadow: 0 0 10px rgba(0,255,0,0.3); }
.status-meltdown { background: #440000; color: #f00; border-color: #f00; animation: dangerPulse 0.5s infinite; }
.status-scram { background: #002244; color: #09f; border-color: #09f; }
.status-inactive { background: #440000; color: #f00; border-color: #f00; }
.status-stalled { background: #222; color: #fff; animation: stalledBlink 1s infinite; }

.valves-vertical { display: flex; flex-direction: column; gap: 12px; }
.valve-group { background: #1a1a1a; padding: 8px; border: 1px solid #333; display: flex; flex-direction: column; align-items: center; }
.valve-led { width: 10px; height: 10px; border-radius: 50%; margin-bottom: 5px; background: #444; }
.led-ready { background: #f00 !important; box-shadow: 0 0 8px #f00; }
.led-active { background: #0f0 !important; box-shadow: 0 0 8px #0f0; }
.led-cooldown { background: #444 !important; }

/* ========================= ANIMATIONS ========================= */
.meltdown-timer { position: absolute; top: 15px; left: 49%; transform: translateX(-50%); background: #000; border: 3px solid #f00; color: #f00; padding: 10px 25px; font-size: 20px; font-weight: bold; z-index: 1000; white-space: nowrap; }

.panel.warning-mode { border-color: #f80; box-shadow: 0 0 20px rgba(255,136,0,0.4); }
.panel.meltdown-mode { border-color: #f00; box-shadow: 0 0 30px rgba(255,0,0,0.6); animation: meltdownPulse 0.5s infinite; }
.panel.safe-mode { border-color: #0f6; box-shadow: 0 0 25px rgba(0,255,102,0.6); animation: safePulse 1s infinite; }
body.meltdown-safe-mode { background: radial-gradient(circle, rgb(0,42,18), #1a1a1a); }

.scram-ready { background: #f00 !important; color: #fff !important; animation: dangerPulse 0.4s infinite; }
.scram-used { background: #333 !important; color: #666 !important; border-color: #444 !important; }

@keyframes safePulse { 0%, 100% { box-shadow: 0 0 15px #0f6; } 50% { box-shadow: 0 0 40px #0f6; } }
@keyframes dangerPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes meltdownPulse { 0%, 100% { box-shadow: 0 0 15px #f00; } 50% { box-shadow: 0 0 40px #f00; } }
@keyframes stalledBlink { 0%, 100% { border-color: #333; } 50% { border-color: #09f; } }

.audio-panel { margin-top: 15px; font-size: 12px; }

/* ========================= MOBILE ========================= */
@media (max-width: 900px) {
    body { padding: 0; min-height: 100vh; display: block; }
    html, body { overflow-x: hidden; }
    
    .app-container, .panel, .system-item, button { width: 100%; }
    .main-layout { flex-direction: column; gap: 0; width: 100%; display: flex; min-height: 100vh; align-items: stretch; }
    
    .panel { max-width: 100%; min-height: 100vh; border: none; box-shadow: none; padding: 12px; border-radius: 0; order: 1 !important; }
    .valve-panel, .status-panel, .reactor-info-panel { width: 100%; margin: 0; border-radius: 0; border: none; max-width: 100%; }
    
    .config-panel { position: relative !important; top: auto !important; left: auto !important; width: 100%; margin-bottom: 10px; order: 0 !important; }
    .meltdown-timer { position: fixed !important; top: 0; left: 0; transform: none !important; width: 100%; text-align: center; font-size: 14px; z-index: 3000; border-left: none; border-right: none; }
    
    button { font-size: 14px; }
    .top-controls, .system-grid, .rod-layout { flex-direction: column; gap: 8px; }
    
    .valves-vertical { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; justify-items: center; align-items: stretch; background: transparent; }
    .valve-group { display: flex; flex-direction: row; align-items: center; justify-content: space-between; width: 100%; max-width: none; padding: 10px; gap: 10px; border: none !important; background: transparent; box-shadow: none !important; }
    .valve-group button { flex: 1; font-size: 12px; padding: 6px; }
    .valve-group .valve-led { flex-shrink: 0; }
    
    #valve1::before, #valve2::before, #valve3::before, #valve4::before { color: #888; font-size: 11px; }
    
    .rod-layout { flex-direction: row; justify-content: space-between; align-items: center; }
    .rod-info { flex: 1; display: flex; flex-direction: column; justify-content: center; }
    .rod-system { flex: 1; display: flex; justify-content: center; }
    .rod-buttons { display: flex; flex-direction: column; gap: 6px; }
    .rod-container { transform: scale(0.9); }
    
    .reactor-info-panel { font-size: 14px; order: 5 !important; }
    .reactor-info-panel h2 { font-size: 16px; }
    .info-line { font-size: 13px; }

    .valve-panel { order: 2 !important; }
    .right-stack { order: 3 !important; }
    .status-panel { order: 4 !important; }
}

/* ========================= TURBINE & SYNCHROSCOPE STYLES ========================= */
.turbine-layout {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 30px;
    margin-top: 20px;
    width: 100%;
    max-width: 900px;
}

.control-group { display: flex; flex-direction: column; gap: 10px; margin-top: 15px; }

.data-screen {
    background: #000;
    border: 1px solid #1f9d34;
    padding: 15px;
    font-family: 'VT323', "Courier New", monospace;
    color: #1f9d34;
    text-align: left;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.synchroscope-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.synchro-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 18px;
    color: #1f9d34;
    border-bottom: 1px dashed #135c1f;
    padding-bottom: 10px;
    margin-bottom: 25px;
}

.status-box {
    padding: 10px;
    text-align: center;
    font-weight: bold;
    border: 1px solid #0f4d1a;
    margin-top: 10px;
    font-size: 18px;
    width: 100%;
    box-sizing: border-box;
}
.status-offline { color: #888; border-color: #555; background: #000;}
.status-synced { background: #1f9d34; color: #000; border-color: #1f9d34; }
.status-failed { background: #b81414; color: #000; border-color: #b81414; }
