/* op9.rs - CPU Pipeline Visualization */

:root {
    --bg-primary: #0A1210;
    --bg-secondary: #141C18;
    --pipeline-active: #4AE68A;
    --pipeline-idle: #1A3A2A;
    --register-accent: #E6A84A;
    --branch-path: #4AB8B8;
    --text-primary: #D4E8DC;
    --text-secondary: #7A9A88;
    --error: #E65A5A;
    --border: #2A3A2A;
}

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

body {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow-x: hidden;
}

/* Scan lines overlay */
#scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        180deg,
        rgba(74, 230, 138, 0.02) 0px,
        rgba(74, 230, 138, 0.02) 1px,
        transparent 1px,
        transparent 4px
    );
}

/* Boot Overlay */
#boot-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease;
}

#boot-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

#boot-overlay.hidden {
    display: none;
}

#boot-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    color: #4AE68A;
    white-space: pre-wrap;
    max-width: 600px;
    padding: 2rem;
}

.cursor {
    animation: blink 0.8s step-end infinite;
}

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

/* Pipeline Header */
#pipeline-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 120px;
    background: var(--bg-primary);
    z-index: 100;
    display: flex;
    border-bottom: 1px solid var(--border);
    opacity: 0;
    transition: opacity 0.5s ease;
}

#pipeline-header.visible {
    opacity: 1;
}

.pipeline-stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--pipeline-idle);
    border-right: 1px solid var(--bg-primary);
    transition: background-color 0.15s ease;
    gap: 8px;
}

.pipeline-stage:last-child {
    border-right: none;
}

.pipeline-stage.active {
    background: var(--pipeline-active);
}

.stage-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-secondary);
    transition: color 0.15s ease;
}

.pipeline-stage.active .stage-label {
    color: var(--bg-primary);
    font-weight: 700;
}

.stage-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    opacity: 0.4;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

.pipeline-stage.active .stage-indicator {
    background: var(--bg-primary);
    opacity: 1;
}

/* Sections */
.section {
    min-height: 100vh;
    padding: 140px 6vw 80px;
    position: relative;
}

/* Boot Section */
#boot-section {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

#boot-section .section-inner {
    text-align: center;
}

.main-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 6rem);
    letter-spacing: 0.08em;
    color: var(--pipeline-active);
    margin-bottom: 0.3em;
}

.subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 2em;
}

.init-readout {
    display: flex;
    flex-direction: column;
    gap: 0.3em;
    align-items: center;
}

.hex-val {
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--register-accent);
    opacity: 0.7;
}

/* Section Titles */
.section-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    letter-spacing: 0.08em;
    color: var(--pipeline-active);
    margin-bottom: 1.5em;
}

.body-text {
    color: var(--text-primary);
    margin-bottom: 1.2em;
    max-width: 600px;
}

.body-text em {
    color: var(--pipeline-active);
    font-style: normal;
    font-weight: 700;
}

/* Instruction Panel */
#instruction-panel {
    background: var(--bg-primary);
}

.panel-columns {
    display: flex;
    gap: 0;
    align-items: flex-start;
}

.panel-left {
    flex: 0 0 55%;
    padding-right: 3vw;
}

.panel-divider {
    width: 1px;
    background: #3A4A3A;
    align-self: stretch;
    flex-shrink: 0;
}

.panel-right {
    flex: 0 0 40%;
    padding-left: 3vw;
}

.register-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-secondary);
    margin-bottom: 1.5em;
}

#register-table {
    display: flex;
    flex-direction: column;
}

.reg-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    border-left: 3px solid transparent;
    transition: border-left-color 0.2s ease;
}

.reg-row.active {
    border-left-color: var(--pipeline-active);
}

.reg-name {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--text-secondary);
}

.reg-value {
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--register-accent);
}

/* Pipeline Depth */
#pipeline-depth {
    background: var(--bg-secondary);
    min-height: 150vh;
    overflow: hidden;
}

.pipeline-intro {
    color: var(--text-secondary);
    margin-bottom: 3em;
}

.timing-waveform {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100px;
    opacity: 0.3;
    pointer-events: none;
}

#pipeline-grid {
    position: relative;
}

.grid-header {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    margin-bottom: 2em;
    padding-bottom: 1em;
    border-bottom: 1px solid var(--border);
}

.grid-header span {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-secondary);
    text-align: center;
}

.instruction-bar {
    height: 40px;
    background: var(--pipeline-idle);
    border-radius: 2px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    width: 20%;
    transition: transform 0.4s ease, background-color 0.3s ease;
    position: relative;
}

.instruction-bar.in-execute {
    background: var(--pipeline-active);
}

.instruction-bar.in-execute .instr-label {
    color: var(--bg-primary);
}

.instruction-bar.hazard.in-execute {
    background: var(--error);
}

.instr-label {
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Branch Prediction */
#branch-section {
    background: #0C1210;
    min-height: 100vh;
}

.branch-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto 3em;
}

#branch-tree {
    width: 100%;
    height: auto;
}

.branch-path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 0.8s ease, opacity 0.5s ease;
}

.branch-path.revealed {
    stroke-dashoffset: 0;
    opacity: 0.6;
}

.branch-path.taken.revealed {
    opacity: 0.8;
}

.branch-text-nodes {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.branch-text {
    position: absolute;
    font-family: 'Fira Code', monospace;
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity 0.8s ease;
}

.branch-text.visible {
    opacity: 0.8;
}

.branch-desc {
    text-align: center;
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto;
}

/* Retirement */
#retirement {
    background: var(--bg-secondary);
}

.retirement-stack {
    max-width: 500px;
    margin-bottom: 3em;
}

.retired-instr {
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.retired-instr.visible {
    opacity: 1;
    transform: translateY(0);
}

.instr-status {
    color: var(--pipeline-active);
    margin-right: 1em;
}

.hazard-text {
    color: var(--error) !important;
}

.retirement-summary {
    max-width: 500px;
    margin-top: 3em;
}

/* Responsive */
@media (max-width: 768px) {
    .panel-columns {
        flex-direction: column;
    }

    .panel-left,
    .panel-right {
        flex: 1 1 auto;
        padding: 0;
    }

    .panel-divider {
        width: 100%;
        height: 1px;
        margin: 2em 0;
    }

    .instruction-bar {
        width: 100%;
    }

    #pipeline-header {
        height: 80px;
    }

    .stage-label {
        font-size: 10px;
    }

    .section {
        padding: 100px 4vw 60px;
    }
}
