/* ============================================
   genpatsu.quest -- Reactor Control Room UI
   ============================================ */

/* CSS Custom Properties */
:root {
    --bg-primary: #0A0F0D;
    --bg-panel: #0D1512;
    --border: #1A3A2E;
    --text-primary: #C8E6DC;
    --text-secondary: #6B9B8A;
    --text-tertiary: #3D6B5A;
    --accent-neon: #00FF9C;
    --alert-warm: #FF6B3D;
    --alert-critical: #FF3D5C;
    --data-highlight: #3DE8FF;
    --subtle-warm: #2A1F1A;
    --deep-green: #0D3B2E;

    --font-primary: 'Share Tech Mono', monospace;
    --font-data: 'IBM Plex Mono', monospace;
    --font-annotation: 'Space Mono', monospace;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-variant-numeric: tabular-nums;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-weight: 400;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    line-height: 1.75;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Kanji Watermark */
#kanji-watermark {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 40vw;
    color: #0D1512;
    font-family: serif;
    z-index: 0;
    pointer-events: none;
    user-select: none;
    will-change: transform;
    line-height: 1;
}

/* Circuit Background */
#circuit-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 500ms ease-out;
}

#circuit-bg.visible {
    opacity: 0.3;
}

#circuit-bg line {
    stroke: var(--border);
    stroke-width: 1;
}

#circuit-bg circle {
    fill: var(--border);
}

/* Viewport Frame */
#viewport-frame {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
}

#inset-border {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    bottom: 16px;
    border: 1px solid var(--deep-green);
    opacity: 0;
    transition: opacity 300ms ease-out;
}

#inset-border.visible {
    opacity: 1;
}

.corner-bracket {
    position: absolute;
    width: 24px;
    height: 24px;
    z-index: 101;
}

.corner-bracket path {
    fill: none;
    stroke: var(--accent-neon);
    stroke-width: 2;
    stroke-dasharray: 24;
    stroke-dashoffset: 24;
    transition: stroke-dashoffset 400ms ease-out;
}

.corner-bracket.animated path {
    stroke-dashoffset: 0;
}

.corner-bracket.top-left {
    top: 10px;
    left: 10px;
}

.corner-bracket.top-right {
    top: 10px;
    right: 10px;
}

.corner-bracket.bottom-left {
    bottom: 10px;
    left: 10px;
}

.corner-bracket.bottom-right {
    bottom: 10px;
    right: 10px;
}

/* Bracket flicker for SCRAM */
.corner-bracket.flicker path {
    animation: bracketFlicker 200ms ease-out;
}

@keyframes bracketFlicker {
    0% { opacity: 1; }
    33% { opacity: 0.3; }
    66% { opacity: 1; }
    100% { opacity: 1; }
}

/* Header Zone */
#header-zone {
    position: sticky;
    top: 0;
    z-index: 50;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 80px;
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-primary);
    font-size: clamp(0.85rem, 1.2vw, 1rem);
}

.header-left {
    display: flex;
    align-items: center;
    color: var(--text-primary);
    letter-spacing: 0.1em;
}

#cursor-blink {
    color: var(--accent-neon);
    animation: cursorBlink 800ms infinite;
}

@keyframes cursorBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.header-center {
    font-family: var(--font-data);
    font-weight: 300;
    font-size: clamp(1rem, 1.5vw, 1.2rem);
    color: var(--text-secondary);
    letter-spacing: 0.05em;
}

.header-right {
    color: var(--accent-neon);
    font-size: 0.85rem;
    letter-spacing: 0.05em;
}

/* Side Channel Telemetry */
#side-telemetry {
    position: fixed;
    left: 20px;
    top: 120px;
    width: 60px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 20px;
    opacity: 0;
    transition: opacity 500ms ease-out;
}

#side-telemetry.visible {
    opacity: 1;
}

.telemetry-block {
    text-align: center;
}

.telemetry-label {
    font-family: var(--font-annotation);
    font-size: 8px;
    color: var(--text-tertiary);
    letter-spacing: 0.1em;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.telemetry-value {
    font-family: var(--font-data);
    font-weight: 400;
    font-size: 10px;
    color: var(--accent-neon);
    letter-spacing: 0.05em;
}

#oscilloscope-side {
    display: block;
    margin: 0 auto;
}

/* Data Font Class */
.data-font {
    font-family: var(--font-data);
    letter-spacing: 0.05em;
}

/* Main Content Area */
#content-area {
    position: relative;
    z-index: 10;
    padding: 80px 80px 60px 80px;
    margin-left: 80px;
    min-height: 100vh;
}

/* Log Section */
.log-section {
    margin-bottom: 60px;
}

.section-header {
    margin-bottom: 16px;
}

.section-label {
    font-family: var(--font-annotation);
    font-size: 10px;
    color: var(--text-tertiary);
    letter-spacing: 0.15em;
}

.section-title {
    font-family: var(--font-primary);
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 32px;
    letter-spacing: 0.05em;
}

.section-body {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
}

/* Content Blocks */
.content-block {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 24px;
    position: relative;
}

.content-block.full-width {
    width: 100%;
}

.content-block.panel-left {
    width: calc(62% - 12px);
}

.content-block.panel-right {
    width: calc(38% - 12px);
}

/* Corner decorations on content blocks */
.content-block::before,
.content-block::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-color: var(--text-tertiary);
    border-style: solid;
}

.content-block::before {
    top: -1px;
    left: -1px;
    border-width: 1px 0 0 1px;
}

.content-block::after {
    top: -1px;
    right: -1px;
    border-width: 1px 1px 0 0;
}

.content-block p {
    color: var(--text-primary);
    margin-bottom: 12px;
}

.content-block p:last-child {
    margin-bottom: 0;
}

/* Fade-in animation */
.fade-in {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 600ms ease-out, transform 600ms ease-out;
}

.fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}

.fade-in.slow-reveal {
    transition-duration: 1000ms;
}

/* Section Divider */
.section-divider {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 40px 0;
    position: relative;
}

.section-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 0;
    border-top: 1px dashed var(--border);
    background: repeating-linear-gradient(
        to right,
        var(--border) 0,
        var(--border) 4px,
        transparent 4px,
        transparent 12px
    );
}

.divider-label {
    font-family: var(--font-annotation);
    font-size: 10px;
    color: var(--text-tertiary);
    letter-spacing: 0.15em;
    background-color: var(--bg-primary);
    padding: 0 16px;
    position: relative;
    z-index: 1;
}

/* Data Readouts */
.data-readout {
    margin-bottom: 20px;
}

.data-readout:last-child {
    margin-bottom: 0;
}

.readout-label {
    font-family: var(--font-annotation);
    font-size: 10px;
    color: var(--text-tertiary);
    letter-spacing: 0.15em;
    margin-bottom: 4px;
}

.readout-value {
    font-family: var(--font-data);
    font-weight: 300;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    color: var(--data-highlight);
    letter-spacing: 0.05em;
    line-height: 1.2;
}

.readout-unit {
    font-family: var(--font-annotation);
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Timeline */
.timeline-container {
    position: relative;
    height: 100px;
    width: 100%;
    margin: 20px 0;
}

.timeline-line {
    position: absolute;
    top: 30px;
    left: 0;
    right: 0;
    height: 1px;
    background-color: var(--border);
}

.timeline-node {
    position: absolute;
    top: 20px;
    transform: translateX(-50%);
    text-align: center;
}

.node-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin: 0 auto 8px;
    border: 1px solid;
}

.timeline-node.operational .node-dot {
    background-color: var(--data-highlight);
    border-color: var(--data-highlight);
}

.timeline-node.incident .node-dot {
    background-color: var(--alert-warm);
    border-color: var(--alert-warm);
}

.timeline-node.decommissioned .node-dot {
    background-color: var(--text-secondary);
    border-color: var(--text-secondary);
}

.node-label {
    font-family: var(--font-annotation);
    font-size: 9px;
    color: var(--text-secondary);
    line-height: 1.4;
    white-space: nowrap;
}

.node-desc {
    color: var(--text-tertiary);
    font-size: 8px;
}

/* Instrument Dashboard */
.instrument-dashboard {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    width: 100%;
}

.instrument-panel {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 16px;
    flex: 1;
    min-width: 180px;
    position: relative;
}

.instrument-panel.wide-panel {
    flex: 2;
    min-width: 380px;
}

.instrument-panel::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    width: 8px;
    height: 8px;
    border-top: 1px solid var(--text-tertiary);
    border-left: 1px solid var(--text-tertiary);
}

.instrument-panel::after {
    content: '';
    position: absolute;
    top: -1px;
    right: -1px;
    width: 8px;
    height: 8px;
    border-top: 1px solid var(--text-tertiary);
    border-right: 1px solid var(--text-tertiary);
}

.instrument-label {
    font-family: var(--font-annotation);
    font-size: 9px;
    color: var(--text-tertiary);
    letter-spacing: 0.15em;
    margin-bottom: 12px;
    text-transform: uppercase;
}

#oscilloscope-main {
    width: 100%;
    height: 80px;
    display: block;
}

#radial-gauge {
    width: 120px;
    height: 75px;
    display: block;
    margin: 0 auto;
}

.gauge-readout {
    text-align: center;
    font-family: var(--font-data);
    font-weight: 300;
    font-size: 1.2rem;
    color: var(--accent-neon);
    margin-top: 8px;
    letter-spacing: 0.05em;
}

/* Bar Charts */
.bar-chart-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bar-label {
    font-family: var(--font-data);
    font-size: 10px;
    color: var(--text-secondary);
    width: 120px;
    flex-shrink: 0;
    letter-spacing: 0.05em;
}

.bar-track {
    flex: 1;
    height: 3px;
    background-color: var(--bg-primary);
    position: relative;
}

.bar-fill {
    height: 100%;
    background-color: var(--data-highlight);
    width: 0%;
    transition: width 800ms ease-out;
}

.bar-value {
    font-family: var(--font-data);
    font-size: 10px;
    color: var(--data-highlight);
    width: 50px;
    text-align: right;
    flex-shrink: 0;
    letter-spacing: 0.05em;
}

/* Pressure Display */
.pressure-display {
    text-align: center;
    padding: 10px 0;
}

.pressure-value {
    font-family: var(--font-data);
    font-weight: 300;
    font-size: 2rem;
    color: var(--accent-neon);
    display: block;
    letter-spacing: 0.05em;
}

.pressure-unit {
    font-family: var(--font-annotation);
    font-size: 10px;
    color: var(--text-tertiary);
    display: block;
    margin-top: 4px;
}

/* Control Rod Display */
.rod-position-display {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
}

.rod-bar {
    flex: 1;
    height: 12px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    position: relative;
}

.rod-fill {
    height: 100%;
    background-color: var(--accent-neon);
    width: 72%;
    transition: width 1s ease-out;
}

.rod-value {
    font-family: var(--font-data);
    font-size: 1rem;
    color: var(--accent-neon);
    letter-spacing: 0.05em;
}

/* Incident Section (Section 03 SCRAM) */
.incident-header {
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.incident-date {
    font-family: var(--font-data);
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    color: var(--alert-warm);
    letter-spacing: 0.05em;
}

.earthy-block {
    background-color: var(--subtle-warm);
    padding: 20px;
    border-left: 2px solid var(--alert-warm);
    margin: 0;
}

/* SCRAM state palette shift */
body.scram-active {
    --accent-neon: #FF6B3D;
}

body.scram-active .corner-bracket path {
    stroke: var(--alert-warm);
    transition: stroke 2s ease-out;
}

body.scram-active #status-coolant .status-text {
    color: var(--alert-warm);
}

body.scram-active #status-coolant .status-dot {
    background-color: var(--alert-warm);
    box-shadow: 0 0 6px var(--alert-warm);
}

/* Post-SCRAM persistent amber on coolant */
body.scram-triggered #status-coolant .status-dot {
    background-color: var(--alert-warm);
    box-shadow: 0 0 6px var(--alert-warm);
    animation: none;
}

/* Decommission Timeline */
.decom-timeline {
    width: 100%;
}

.decom-bar-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.decom-bar-row {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.decom-label {
    font-family: var(--font-data);
    font-size: 10px;
    color: var(--text-secondary);
    width: 260px;
    flex-shrink: 0;
    letter-spacing: 0.05em;
}

.decom-bar-track {
    flex: 1;
    height: 4px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    overflow-x: auto;
    min-width: 200px;
}

.decom-bar-fill {
    height: 100%;
    transition: width 1200ms ease-out;
}

.decom-bar-fill.phase-1 {
    background-color: var(--data-highlight);
}

.decom-bar-fill.phase-2 {
    background-color: var(--alert-warm);
}

.decom-bar-fill.phase-3 {
    background-color: var(--text-secondary);
}

.decom-status {
    font-family: var(--font-data);
    font-size: 10px;
    color: var(--text-tertiary);
    flex-shrink: 0;
    letter-spacing: 0.05em;
}

/* Monitoring Counter */
.monitoring-counter {
    text-align: center;
    padding: 40px 0;
}

.counter-label {
    font-family: var(--font-annotation);
    font-size: 11px;
    color: var(--text-tertiary);
    letter-spacing: 0.15em;
    margin-bottom: 16px;
}

.counter-value {
    font-family: var(--font-data);
    font-weight: 300;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    color: var(--accent-neon);
    letter-spacing: 0.05em;
}

#oscilloscope-final {
    width: 100%;
    max-width: 400px;
    height: 80px;
    display: block;
    margin: 0 auto;
}

/* Bottom Status Bar */
#status-bar {
    position: sticky;
    bottom: 0;
    z-index: 50;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 80px;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border);
    font-family: var(--font-primary);
    font-size: 0.75rem;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 300ms ease-out;
}

.status-item.visible {
    opacity: 1;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--accent-neon);
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 0.6; box-shadow: 0 0 2px var(--accent-neon); }
    50% { opacity: 1; box-shadow: 0 0 6px var(--accent-neon); }
}

.status-text {
    color: var(--text-secondary);
    letter-spacing: 0.1em;
}

/* Dot Matrix Background Texture */
.dot-matrix-bg {
    background-image: radial-gradient(circle, var(--border) 0.5px, transparent 0.5px);
    background-size: 8px 8px;
    opacity: 0.15;
}

/* Topographic Contour Lines (Section 04) */
#section-04 {
    position: relative;
}

#section-04::before {
    content: '';
    position: absolute;
    top: 0;
    left: -40px;
    right: -40px;
    bottom: 0;
    background-image:
        radial-gradient(ellipse 300px 200px at 30% 40%, transparent 60%, var(--border) 60.5%, transparent 61%),
        radial-gradient(ellipse 250px 180px at 70% 60%, transparent 55%, var(--border) 55.5%, transparent 56%),
        radial-gradient(ellipse 400px 280px at 50% 50%, transparent 65%, var(--border) 65.5%, transparent 66%),
        radial-gradient(ellipse 350px 240px at 40% 70%, transparent 58%, var(--border) 58.5%, transparent 59%);
    opacity: 0.2;
    pointer-events: none;
    z-index: 0;
    transition: opacity 1s ease-out;
}

#section-04.enhanced-topo::before {
    opacity: 0.4;
}

#section-04 > * {
    position: relative;
    z-index: 1;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    #header-zone {
        padding: 0 20px;
        font-size: 0.75rem;
    }

    #content-area {
        padding: 20px;
        margin-left: 0;
    }

    #side-telemetry {
        display: none;
    }

    .content-block.panel-left,
    .content-block.panel-right {
        width: 100%;
    }

    #status-bar {
        padding: 0 20px;
        font-size: 0.65rem;
    }

    .instrument-panel.wide-panel {
        min-width: 100%;
    }

    .bar-label {
        width: 80px;
        font-size: 8px;
    }

    .decom-label {
        width: 100%;
    }

    .decom-bar-row {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .header-center {
        display: none;
    }
}
