:root {
    --bg-main: #faf8f5;
    --bg-card: #ffffff;
    --bg-elevated: #f5f2ed;
    --border: #e5e0d8;
    --text-primary: #2d2a26;
    --text-secondary: #6b6560;
    --text-muted: #9a948c;
    --accent-green: #4ade80;
    --accent-green-dim: #86efac;
    --accent-red: #f87171;
    --accent-red-dim: #fecaca;
    --accent-yellow: #fbbf24;
    --accent-blue: #60a5fa;
    --accent-purple: #c084fc;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-hover: 0 4px 16px rgba(0,0,0,0.1);
}

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

body {
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 2px dashed var(--border);
}

h1 {
    font-family: 'Fraunces', serif;
    font-size: 2.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.scenario-nav {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.scenario-btn {
    background: var(--bg-card);
    border: 2px solid var(--border);
    color: var(--text-secondary);
    padding: 0.6rem 1.2rem;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.scenario-btn:hover {
    border-color: var(--accent-blue);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.scenario-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
    font-weight: 600;
}

.scenario-btn.locked {
    display: none;
}

.scenario-btn[data-scenario="5"] {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-elevated));
}

.scenario-btn[data-scenario="5"].active {
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    border-color: #a855f7;
}

/* Scenario Pages */
.scenario-page {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.scenario-page.active {
    display: block;
}

/* Single Column Layout */
.single-column {
    max-width: 700px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Page Navigation */
.page-nav {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 2px dashed var(--border);
}

.nav-btn {
    flex: 1;
    padding: 1rem 1.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn.primary {
    background: var(--accent-blue);
    color: white;
    box-shadow: 0 4px 12px rgba(96, 165, 250, 0.3);
}

.nav-btn.primary:hover {
    background: #3b82f6;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(96, 165, 250, 0.4);
}

.nav-btn.secondary {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 2px solid var(--border);
}

.nav-btn.secondary:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.panel {
    background: var(--bg-card);
    border: 2px solid var(--border);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.panel-title {
    font-family: 'Fraunces', serif;
    font-size: 1.15rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.panel-title::before {
    content: '';
    width: 10px;
    height: 10px;
    background: var(--accent-blue);
    border-radius: 50%;
}

/* Pipeline Flow Diagram */
.pipeline {
    padding: 1rem 0;
    overflow-x: auto;
}

.flow-horizontal {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    min-width: fit-content;
}

.flow-box {
    padding: 0.6rem 1rem;
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    white-space: nowrap;
}

.flow-box.complete {
    background: rgba(74, 222, 128, 0.15);
    border-color: var(--accent-green);
    color: #16a34a;
}

.flow-box.active {
    background: rgba(96, 165, 250, 0.15);
    border-color: var(--accent-blue);
    color: #2563eb;
}

.flow-box.delayed {
    background: rgba(251, 191, 36, 0.15);
    border-color: var(--accent-yellow);
    color: #a16207;
}

.flow-box.pending {
    background: var(--bg-elevated);
    border-color: var(--border);
    color: var(--text-muted);
}

.flow-box.danger {
    background: rgba(248, 113, 113, 0.15);
    border-color: var(--accent-red);
    color: #dc2626;
}

.flow-arrow {
    color: var(--text-muted);
    font-size: 1.2rem;
    font-weight: 300;
    flex-shrink: 0;
}

/* Permit Duration Branches */
.permit-branches {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.permit-bar {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.75rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    background: rgba(251, 191, 36, 0.2);
    border: 2px solid var(--accent-yellow);
    color: #a16207;
}

.permit-bar.short {
    width: 100px;
}

.permit-bar.long {
    width: 180px;
}

/* Recursive Loop */
.flow-with-loop {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.loop-section {
    display: flex;
    align-items: flex-end;
    position: relative;
    padding-bottom: 4rem;
}

.elbow-arrow {
    position: absolute;
    bottom: -12px;
    left: 0;
    right: 0;
    height: calc(3rem - 12px);
    pointer-events: none;
}

.elbow-down {
    position: absolute;
    right: 0;
    top: -1.5rem;
    width: 2px;
    height: calc(100% + 1.5rem);
    background: var(--border);
}

.elbow-left {
    position: absolute;
    left: 0;
    bottom: 0;
    right: 0;
    height: 2px;
    background: var(--border);
}

.elbow-up {
    position: absolute;
    left: 0;
    top: -1.5rem;
    width: 2px;
    height: calc(100% + 1.5rem);
    background: var(--border);
}

.elbow-up::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -4px;
    border: 5px solid transparent;
    border-bottom-color: var(--border);
}

/* Controls */
.control-group {
    margin-bottom: 1.5rem;
}

.control-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.control-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.control-value.positive {
    color: #16a34a;
}

.control-value.negative {
    color: #dc2626;
}

input[type="range"] {
    width: 100%;
    height: 8px;
    background: var(--bg-elevated);
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    border: 2px solid var(--border);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-blue);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Results panel */
.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px dashed var(--border);
}

.result-row:last-child {
    border-bottom: none;
}

.result-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.result-value {
    font-size: 0.9rem;
    font-weight: 600;
}

.result-value.highlight {
    font-size: 1.1rem;
}

.result-value.positive {
    color: #16a34a;
}

.result-value.negative {
    color: #dc2626;
}

/* Decision indicator */
.decision-box {
    margin-top: 1.5rem;
    padding: 1.5rem;
    text-align: center;
    border: 3px solid;
    border-radius: 16px;
    position: relative;
    overflow: hidden;
}

.decision-box.invest {
    border-color: var(--accent-green);
    background: rgba(74, 222, 128, 0.15);
}

.decision-box.reject {
    border-color: var(--accent-red);
    background: rgba(248, 113, 113, 0.15);
}

.decision-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.decision-text {
    font-family: 'Fraunces', serif;
    font-size: 1.6rem;
    font-weight: 700;
}

.decision-box.invest .decision-text {
    color: #16a34a;
}

.decision-box.reject .decision-text {
    color: #dc2626;
}

.decision-reason {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Scenario explanation */
.scenario-info {
    text-align: center;
    margin-bottom: 1.5rem;
}

.scenario-title {
    font-family: 'Fraunces', serif;
    font-size: 1.8rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.scenario-desc {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.7;
    max-width: 600px;
    margin: 0 auto;
}

/* Math breakdown */
.math-breakdown {
    background: var(--bg-elevated);
    padding: 1rem;
    margin-top: 1rem;
    font-size: 0.75rem;
    border: 2px dashed var(--border);
    border-radius: 12px;
}

.math-line {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    color: var(--text-secondary);
}

.math-line.result {
    border-top: 2px solid var(--border);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    color: var(--text-primary);
    font-weight: 600;
}


/* Insight callout */
.insight {
    background: rgba(192, 132, 252, 0.12);
    border: 2px solid rgba(192, 132, 252, 0.3);
    padding: 1.25rem;
    margin-top: 1.5rem;
    font-size: 0.85rem;
    border-radius: 12px;
}

.insight-title {
    color: #a855f7;
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.insight-text {
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Toggle switch */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle.active {
    background: var(--accent-blue);
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.toggle.active::after {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.pulsing {
    animation: pulse 2s infinite;
}

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

.slide-in {
    animation: slideIn 0.3s ease-out;
}

/* Chart styles */
.chart-container {
    position: relative;
    height: 300px;
    margin-top: 1rem;
}

.chart-legend-custom {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px dashed var(--border);
}

.legend-item-custom {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-line {
    width: 20px;
    height: 4px;
    border-radius: 2px;
}

.legend-line.dashed {
    background: repeating-linear-gradient(
        90deg,
        var(--accent-blue) 0px,
        var(--accent-blue) 4px,
        transparent 4px,
        transparent 8px
    );
}

.chart-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px dashed var(--border);
}

.chart-metric {
    text-align: center;
    padding: 1rem;
    background: var(--bg-elevated);
    border-radius: 12px;
}

.chart-metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.chart-metric-value.positive {
    color: #16a34a;
}

.chart-metric-value.negative {
    color: #dc2626;
}

.chart-metric-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.delay-marker {
    position: absolute;
    top: 0;
    bottom: 40px;
    width: 2px;
    background: var(--accent-yellow);
    opacity: 0.5;
}

.delay-zone {
    position: absolute;
    top: 0;
    bottom: 40px;
    background: rgba(251, 191, 36, 0.15);
    border-left: 2px dashed var(--accent-yellow);
}

/* Probability bars */
.prob-bar-container {
    margin: 1rem 0;
}

.prob-bar {
    display: flex;
    height: 28px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.prob-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    transition: width 0.3s;
}

.prob-segment.short {
    background: var(--accent-green);
    color: #166534;
}

.prob-segment.long {
    background: var(--accent-yellow);
    color: #854d0e;
}

.prob-segment.restart {
    background: var(--accent-red);
    color: white;
}

.prob-legend {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Intro Screen */
.intro-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-main);
    padding: 2rem;
    position: relative;
}

.intro-page {
    display: none;
    width: 100%;
    animation: fadeIn 0.4s ease-out;
}

.intro-page.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

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

.intro-content {
    text-align: center;
    max-width: 600px;
}

.intro-title {
    font-family: 'Fraunces', serif;
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1rem;
    line-height: 1.1;
}

.intro-subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

.intro-heading {
    font-family: 'Fraunces', serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

.intro-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.7;
}

.intro-text.highlight {
    color: var(--text-primary);
    font-weight: 600;
    background: var(--bg-elevated);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    border-left: 4px solid var(--accent-blue);
}

.concept-box {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    text-align: left;
    box-shadow: var(--shadow);
}

.concept-box h3 {
    font-family: 'Fraunces', serif;
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.concept-box p {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.concept-box p:last-child {
    margin-bottom: 0;
}

.concept-list {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.8;
    margin: 1rem 0 0 1.5rem;
}

.concept-list li {
    margin-bottom: 0.25rem;
}

.intro-btn {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    padding: 1rem 2rem;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(96, 165, 250, 0.3);
    margin-top: 2rem;
}

.intro-btn:hover {
    background: #3b82f6;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(96, 165, 250, 0.4);
}

.intro-screen.fade-out {
    animation: fadeOut 0.4s ease-out forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        visibility: hidden;
    }
}
