/* Monte Carlo Risk Calculator (monte-carlo-risk-calculator.html), layered on civil.css and cpm-solver.css. */

/* Color roles: items blue, risks orange. Results stay in one hue: the curve and bars in the route
   accent, the chosen confidence in a deeper shade of it (lighter at night), estimates and targets neutral. */
.mc-item { color: var(--c-blue); }
.mc-risk { color: var(--c-orange); }
.mc-p { color: var(--ink-muted); }
.mc-conf, .mc-drv { color: var(--accent-strong); }
.mc-cont { color: var(--c-orange); }
.mc-target { color: var(--ink); }
.mc-base { color: var(--ink); }
body.night .mc-conf, body.night .mc-drv { color: var(--accent-strong); }

.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.file-btn { cursor: pointer; }
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Model: file zone and line editor */
.model-controls { margin-top: 6px; align-items: flex-start; }
.model-controls input { width: 190px; }
.model-note { flex: 1 1 300px; margin: 0; padding: 8px 12px; border-left: 3px solid var(--c-yellow); background: var(--bg-canvas); color: var(--ink-muted); font-size: .8rem; line-height: 1.5; }
.model-note strong { color: var(--ink); }
.model-note a { color: var(--accent-strong); }
.mc-explainer { margin-top: 22px; box-shadow: none; }
.mc-explainer .faq-item summary { font-size: .95rem; }
.solver-note { scroll-margin-top: 96px; }
.file-zone { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin: 20px 0 16px; padding: 16px 18px; border: 1px dashed var(--border-line); border-left: 4px solid var(--accent); background: var(--bg-canvas); transition: border-color .15s linear, background-color .15s linear; }
.file-zone.dragging { border-color: var(--accent); background: rgba(var(--accent-rgb), .08); }
.file-copy { display: grid; gap: 4px; max-width: 760px; }
.file-copy strong { font-size: .95rem; }
.file-copy span { color: var(--ink-muted); font-size: .84rem; line-height: 1.55; }
.file-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
.file-actions .btn { padding: 8px 12px; font-size: .78rem; }
.file-status { grid-column: 1 / -1; margin: 0; font-size: .84rem; font-weight: 600; color: var(--ink); }
.file-status:empty { display: none; }

/* Positioned so visually hidden labels inside stay in the scroller instead of widening the page. */
.lines-scroll { position: relative; border: 1px solid var(--border-line); }
.solver-panel .table-scroll { position: relative; }
.solver-panel .lines-table { min-width: 860px; font: 500 .82rem/1.4 Inter, sans-serif; }
.solver-panel .lines-table th, .solver-panel .lines-table td { padding: 5px 6px; vertical-align: middle; }
.solver-panel .lines-table thead th { padding: 9px 6px; font-family: 'IBM Plex Mono', monospace; background: var(--bg-canvas); }
.lines-table tbody th { width: 34px; color: var(--ink-muted); font: 700 .74rem 'IBM Plex Mono', monospace; text-align: center; }
.lines-table tbody tr { border-left: 3px solid transparent; }
.lines-table tr.line-item th { box-shadow: inset 3px 0 0 var(--c-blue); }
.lines-table tr.line-risk th { box-shadow: inset 3px 0 0 var(--c-orange); }
.solver-panel .lines-table input, .solver-panel .lines-table select { width: 100%; min-width: 0; padding: 7px 6px; font-size: .84rem; }
.lines-table td:nth-child(2) { width: 86px; }
.lines-table td:nth-child(3) { min-width: 210px; }
.lines-table td:nth-child(4) { width: 118px; }
.lines-table td:nth-child(n+5):nth-child(-n+8) { width: 108px; }
.lines-table td:nth-child(n+5) input { font-family: 'IBM Plex Mono', monospace; text-align: right; }
.solver-panel .lines-table input:disabled { background: var(--bg-canvas); color: var(--ink-muted); border-style: dashed; }
.lines-table tr.invalid input:not(:disabled), .lines-table tr.invalid select { border-color: var(--c-orange); }
.lines-table tr.invalid th { color: var(--c-orange); }
.line-remove { width: 32px; height: 32px; border: 1px solid var(--border-line); background: var(--bg-card); color: var(--ink-muted); font: 700 1rem/1 'IBM Plex Mono', monospace; cursor: pointer; }
.line-remove:hover:not(:disabled) { border-color: var(--c-orange); color: var(--c-orange); }
.line-remove:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.line-remove:disabled { opacity: .35; cursor: not-allowed; }
.model-errors, .model-warnings { margin: 14px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: .86rem; line-height: 1.5; }
.model-errors:empty, .model-warnings:empty { display: none; }
.model-errors li, .model-warnings li { padding: 8px 12px; background: var(--bg-canvas); }
.model-errors li { border-left: 3px solid var(--c-orange); color: var(--ink); font-weight: 600; }
.model-warnings li { border-left: 3px solid var(--c-yellow); color: var(--ink-muted); }

/* Results: controls, readouts, chart */
.run-controls { margin: 0 0 16px; }
.run-controls select, .run-controls input[type=number] { width: 120px; }
.run-controls input[type=text] { width: 180px; }
.conf-label { min-width: 220px; }
.conf-row { display: flex; align-items: center; gap: 10px; }
.solver-panel .conf-row input[type=range] { accent-color: var(--accent); width: 150px; }
.conf-row output { min-width: 44px; padding: 6px 8px; color: var(--accent); font: 700 .9rem 'IBM Plex Mono', monospace; text-align: center; background: var(--bg-canvas); box-shadow: var(--shadow-inset-ao); }
body.night .conf-row output { color: var(--accent-strong); }

.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 1px; margin: 1px 1px 13px; }
/* Outlines meet in the 1px gaps, so a short last row ends cleanly instead of showing a filled gap. */
.readouts:empty { display: none; }
.readouts div { padding: 10px 12px; background: var(--bg-card); outline: 1px solid var(--border-line); }
.readouts dt { color: var(--ink-muted); font: 700 .6rem/1.3 'IBM Plex Mono', monospace; letter-spacing: .06em; text-transform: uppercase; }
.readouts dd { margin: 4px 0 0; font: 700 1.02rem/1.15 'IBM Plex Mono', monospace; color: var(--ink); overflow-wrap: anywhere; }
.readouts .mc-conf dd, .readouts .mc-conf dt { color: var(--accent-strong); }
body.night .readouts .mc-conf dd, body.night .readouts .mc-conf dt { color: var(--accent-strong); }
.readouts .mc-cont dd { color: var(--c-orange); }
.readouts .mc-target dd { color: var(--ink); }
.readouts .mc-conf { box-shadow: inset 0 -3px 0 var(--accent-strong); }

.chart-frame {
  overflow: hidden; border: 1px solid var(--border-line);
  background-color: var(--bg-canvas);
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 16px 16px;
  box-shadow: var(--shadow-inset-ao);
}
#chart { display: block; width: 100%; height: auto; max-width: 100%; font-family: 'IBM Plex Mono', monospace; }
#chart text { font-size: 11px; }
#chart .ax { stroke: var(--ink-muted); stroke-width: 1; }
#chart .grid-v, #chart .grid-h { stroke: var(--border-line); stroke-width: 1; }
#chart .ax-text { fill: var(--ink-muted); font-weight: 600; }
#chart .ax-title { fill: var(--ink-muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
#chart .bar { fill: rgba(var(--accent-rgb), .45); }
#chart .bar.tail { fill: var(--ink-muted); fill-opacity: .28; }
#chart .mk { stroke-width: 1.4; }
#chart .mk-text { font-weight: 700; paint-order: stroke; stroke: var(--bg-canvas); stroke-width: 4px; stroke-linejoin: round; }
#chart .mk-p { stroke: var(--ink-muted); stroke-dasharray: 2 3; fill: var(--ink-muted); }
#chart .mk-conf { stroke: var(--accent-strong); fill: var(--accent-strong); stroke-width: 2; }
#chart .mk-base { stroke: var(--ink); stroke-dasharray: 6 4; fill: var(--ink); }
#chart .mk-target { stroke: var(--ink); stroke-dasharray: 1 3; fill: var(--ink); }
#chart text.mk-p, #chart text.mk-conf, #chart text.mk-base, #chart text.mk-target { stroke: var(--bg-canvas); stroke-dasharray: none; }
#chart path.guide, body.night #chart path.guide { fill: none; stroke-dasharray: 5 4; stroke-width: 1.4; }
#chart .dot { stroke: var(--bg-canvas); stroke-width: 2; stroke-dasharray: none; }
#chart .curve { fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linejoin: round; }
#chart:focus { outline: none; }
#chart:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
#chart .hover-line { stroke: var(--ink-muted); stroke-width: 1; stroke-dasharray: 3 3; }
#chart .hover-dot { fill: var(--accent-strong); stroke: var(--bg-canvas); stroke-width: 2; }
#chart .hover-box { fill: var(--bg-card); stroke: var(--ink-muted); stroke-width: 1; }
#chart .hover-text { fill: var(--ink); font-weight: 700; }
.chart-frame { touch-action: pan-y; }
.chart-hint { margin: 8px 0 0; }
.chart-hint[hidden] { display: none; }
#chart .curve-ghost { fill: none; stroke: var(--ink-muted); stroke-width: 1.6; stroke-dasharray: 6 5; opacity: .8; }
#chart .row-label { fill: var(--ink); font-family: Inter, sans-serif; font-size: 12px; font-weight: 600; }
#chart .tornado-row.item .tbar, #chart .key-item { fill: rgba(var(--rgb-blue), .7); }
#chart .tornado-row.risk .tbar, #chart .key-risk { fill: rgba(var(--rgb-orange), .75); }
#chart .chart-message { fill: var(--ink-muted); font-family: Inter, sans-serif; font-size: 14px; font-weight: 600; }
body.night #chart .mk-conf { stroke: var(--accent-strong); fill: var(--accent-strong); }
body.night #chart text.mk-conf { stroke: var(--bg-canvas); }
#run-error { color: var(--c-orange); font-weight: 600; }
#run-error:empty { display: none; }
.whatif-answer fieldset { flex-wrap: wrap; gap: 8px 18px; }

/* Understand */
.dist-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin-top: 12px; border: 1px solid var(--border-line); background: var(--border-line); }
.dist-card { margin: 0; padding: 16px 18px; background: var(--bg-card); }
.dist-card svg { display: block; width: 100%; max-width: 180px; height: auto; margin-bottom: 10px; }
.dist-fill { fill: rgba(var(--accent-rgb), .14); }
.dist-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.dist-card figcaption { display: grid; gap: 4px; }
.dist-card strong { font-size: .95rem; }
.dist-card span { color: var(--ink-muted); font-size: .84rem; line-height: 1.55; }
.walkthrough li strong { color: var(--accent); }
body.night .walkthrough li strong { color: var(--accent-strong); }
.explanation-grid + .walkthrough-title { margin-top: 28px; }
.formula-card h3.mc-item, .formula-card h3.mc-risk, .formula-card h3.mc-conf, .formula-card h3.mc-p { font-size: 1rem; }

/* Drivers and worked example tables */
.drivers-table { margin-top: 14px; }
.drivers-table tbody th { font: 600 .84rem/1.4 Inter, sans-serif; }
.drivers-table tr.item th { box-shadow: inset 3px 0 0 var(--c-blue); }
.drivers-table tr.risk th { box-shadow: inset 3px 0 0 var(--c-orange); }
.drivers-table td { white-space: nowrap; }
#trace:not([hidden]) { margin-top: 18px; }
.trace-table td { white-space: nowrap; text-align: right; }
.trace-table thead th:not(:first-child) { text-align: right; }
.trace-table tbody th { min-width: 220px; font: 600 .84rem/1.35 Inter, sans-serif; }
.trace-range { display: block; margin-top: 2px; color: var(--ink-muted); font: 500 .72rem/1.3 'IBM Plex Mono', monospace; }
.trace-table tr.item th { box-shadow: inset 3px 0 0 var(--c-blue); }
.trace-table tr.risk th { box-shadow: inset 3px 0 0 var(--c-orange); }
.trace-table tfoot th, .trace-table tfoot td { font-weight: 700; color: var(--ink); border-top: 2px solid var(--ink-muted); }
.no-event { color: var(--ink-muted); font-style: italic; opacity: .8; }
.trace-steps { display: grid; gap: 10px; margin: 18px 0 0; padding-left: 20px; color: var(--ink-muted); line-height: 1.65; }
.trace-steps strong { color: var(--ink); }

@media (max-width: 860px) {
  .dist-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .run-controls > label, .model-controls > label { width: 100%; }
  .run-controls select, .run-controls input[type=number], .run-controls input[type=text], .model-controls input, .model-controls select { width: 100%; }
  .readouts div:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .conf-row { width: 100%; }
  .solver-panel .conf-row input[type=range] { flex: 1; width: auto; }
  .readouts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-actions .btn { width: 100%; justify-content: center; }
  .file-actions .btn { flex: 1 1 calc(50% - 8px); justify-content: center; }
}
@media (prefers-reduced-motion: reduce) { .file-zone { transition: none; } }
