/* Impact simulator page. Tokens come from ../dominion.css. The status
   colours and the chart series colours were checked with the dataviz
   palette validator against --ink: the x/y/z set and the force set each
   pass its lightness, chroma, colour-blind and contrast checks. The page is
   dark only, like the other tools/sim pages. */
:root {
  --status-in-range: #0ca30c;
  --status-clips: #fab219;
  --status-past-rating: #d03b3b;
  --axis-x: #3987e5;
  --axis-y: #d95926;
  --axis-z: #199e70;
  --force-stake: #c98500;
  --force-air: #9085e9;
  --force-inertial: #d55181;
  --rail: 300px;
  --side: 420px;
}

.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr) var(--side);
  grid-template-rows: auto minmax(360px, 1fr) auto auto;
  grid-template-areas:
    "bar bar bar"
    "inputs stage peaks"
    "inputs detail detail"
    "inputs timeline timeline";
  height: 100vh;
}

/* ---- bar ---------------------------------------------------------------- */
.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--hairline);
}
.bar-home { display: block; padding-right: 20px; border-right: 1px solid var(--hairline); }
.bar-logo { display: block; height: 26px; width: auto; }
.bar-title { font-family: var(--display); font-weight: 500; font-size: 18px; letter-spacing: -0.01em; margin: 0; }
.run-status { margin: 0 0 0 auto; color: var(--lowvis-70); font-family: var(--mono); font-size: 12px; }
.run-status.error { color: var(--status-past-rating); }

/* ---- inputs ------------------------------------------------------------- */
.inputs {
  grid-area: inputs;
  overflow-y: auto;
  border-right: 1px solid var(--hairline);
  padding: 4px 16px 24px;
}
.group { border: 0; border-bottom: 1px solid var(--hairline-soft); margin: 0; padding: 14px 0; display: grid; gap: 10px; }
.group-title { font-family: var(--display); font-size: 14px; font-weight: 500; color: var(--paper); padding: 0; }
details.group > summary { cursor: pointer; }
details.group[open] > summary { margin-bottom: 4px; }
.sub { font-size: 12px; font-weight: 600; color: var(--lowvis-70); margin: 6px 0 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field > span { font-size: 9.5px; letter-spacing: 0.14em; }
.field input, .field select { width: 100%; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline select { width: auto; }
.field input:placeholder-shown { color: var(--graphite-70); }
.field input[aria-invalid="true"] { border-color: var(--status-past-rating); }
.hint, .derived { margin: 0; font-size: 12px; color: var(--graphite-70); }
.derived { color: var(--lowvis-70); font-family: var(--mono); }
.ring { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.probe-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.probe-table th { text-align: left; font-weight: 400; color: var(--graphite-70); font-size: 10px; padding: 0 4px 4px 0; }
.probe-table td { padding: 2px 4px 2px 0; }
.probe-table input { width: 100%; min-height: 28px; padding: 3px 6px; }
.probe-table tr[aria-selected="true"] td:first-child { color: var(--paper); text-decoration: underline; text-underline-offset: 3px; }
.probe-table .remove { min-height: 28px; padding: 0 8px; background: transparent; color: var(--graphite-70); letter-spacing: 0; font-size: 14px; }
.probe-table .remove:hover { color: var(--paper); background: var(--ink-80); }
.probe-id { cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- site --------------------------------------------------------------- */
.stage { grid-area: stage; position: relative; min-height: 0; overflow: hidden; background: var(--ink); }
.stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.stage-canvas:active { cursor: grabbing; }
.stage-canvas:focus-visible { outline: 1px solid var(--lowvis); outline-offset: -2px; }
.stage-overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.stage-fallback { position: absolute; inset: auto 16px 50% 16px; text-align: center; color: var(--lowvis-70); }
.stage-legend {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 14px; flex-wrap: wrap;
  padding: 6px 10px; background: rgba(10, 11, 13, 0.8); border: 1px solid var(--hairline-soft); border-radius: 4px;
  font-size: 12px; color: var(--lowvis-70);
}
.stage-reset { position: absolute; right: 12px; bottom: 12px; min-height: 30px; background: var(--ink-80); }
.key { display: inline-flex; align-items: center; gap: 6px; }
.mark { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.mark.ring { background: transparent; border: 2px solid currentColor; }
.mark.square { border-radius: 1px; }
.status-in-range { color: var(--status-in-range); }
.status-clips { color: var(--status-clips); }
.status-past-rating { color: var(--status-past-rating); }

/* ---- side panel ---------------------------------------------------------- */
.peaks { grid-area: peaks; border-left: 1px solid var(--hairline); padding: 14px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.panel-title { font-family: var(--display); font-weight: 500; font-size: 15px; margin: 0; }
.panel-sub { margin: 0 0 4px; font-size: 12px; color: var(--graphite-70); }
.chart { position: relative; }
.chart-peaks { height: 300px; flex: none; }
.table-wrap { overflow-x: auto; }
.summary { width: 100%; border-collapse: collapse; font-size: 12px; }
.summary th { text-align: left; font-weight: 400; color: var(--graphite-70); font-size: 10.5px; padding: 6px 6px 6px 0; border-bottom: 1px solid var(--hairline); }
.summary td { padding: 6px 6px 6px 0; border-bottom: 1px solid var(--hairline-soft); font-variant-numeric: tabular-nums; vertical-align: top; }
.summary .num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.summary tbody tr { cursor: pointer; }
.summary tbody tr:hover { background: var(--ink-90); }
.summary tbody tr[aria-selected="true"] { background: var(--ink-80); }
.summary .note { display: block; color: var(--graphite-70); font-size: 11px; }
.summary .state { display: inline-flex; align-items: center; gap: 6px; color: var(--paper); }

/* ---- probe detail --------------------------------------------------------- */
.detail { grid-area: detail; border-top: 1px solid var(--hairline); padding: 10px 16px 12px; min-height: 0; }
.detail-head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.detail-facts { margin: 0; color: var(--lowvis-70); font-size: 12px; flex: 1; }
.detail-head button { min-height: 30px; }
.detail-body { display: grid; grid-template-columns: minmax(260px, 360px) minmax(0, 1fr); gap: 16px; height: 300px; }
.probe-view { display: flex; flex-direction: column; border: 1px solid var(--hairline-soft); border-radius: 4px; overflow: hidden; }
.probe-canvas { position: relative; flex: 1; min-height: 0; }
.forces { border-collapse: collapse; font-size: 11px; font-family: var(--mono); margin: 4px 8px 8px; }
.forces th { font-weight: 400; color: var(--graphite-70); text-align: left; padding: 2px 4px; font-size: 10px; }
.forces td { padding: 2px 4px; color: var(--paper); }
.forces .num { text-align: right; }
.forces .swatch { display: inline-block; width: 8px; height: 8px; border-radius: 1px; margin-right: 6px; }
.detail-charts { display: flex; flex-direction: column; min-width: 0; }
.chart-head { display: flex; align-items: center; gap: 16px; }
.chart-series { flex: 1; min-height: 0; }

/* ---- timeline ------------------------------------------------------------- */
.timeline { grid-area: timeline; display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--hairline); }
.timeline input[type="range"] { flex: 1; accent-color: var(--lowvis); }
.clock { font-family: var(--mono); font-size: 12px; min-width: 9ch; text-align: right; font-variant-numeric: tabular-nums; }
.play { min-width: 76px; }
button:disabled, input:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- charts --------------------------------------------------------------- */
.chart-svg { display: block; overflow: visible; }
.chart-tick { font-family: var(--mono); font-size: 10px; fill: var(--graphite-70); }
.chart-note { font-family: var(--mono); font-size: 10px; fill: var(--lowvis); }
.chart-direct { font-family: var(--mono); font-size: 10.5px; fill: var(--lowvis-70); }
.chart-grid line { stroke: var(--paper); stroke-opacity: 0.07; }
.chart-grid line.chart-zero { stroke-opacity: 0.25; }
.chart-axis { stroke: var(--graphite); }
.chart-zone { fill: var(--paper); fill-opacity: 0.04; }
.chart-limit { stroke: var(--lowvis); stroke-opacity: 0.55; stroke-dasharray: 2 3; }
.chart-line { fill: none; stroke: var(--lowvis-70); stroke-width: 2; stroke-linejoin: round; }
.chart-series { fill: none; stroke-width: 1.5; stroke-linejoin: round; }
.chart-marker { stroke: var(--lowvis); stroke-opacity: 0.45; stroke-dasharray: 3 3; }
.chart-cursor { stroke: var(--paper); stroke-width: 1.5; }
.chart-cross { stroke: var(--paper); stroke-opacity: 0.35; }
.chart-hit { fill: transparent; }
.chart-point { cursor: pointer; }
.chart-point circle, .chart-point rect { fill: currentColor; stroke: var(--ink); stroke-width: 2; }
.chart-point circle.ring { fill: var(--ink); stroke: currentColor; stroke-width: 2.5; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 2; padding: 6px 8px; max-width: 260px;
  background: var(--ink-90); border: 1px solid var(--ink-60); border-radius: 4px;
  font-size: 11.5px; line-height: 1.5; color: var(--paper); font-variant-numeric: tabular-nums;
}
.tip-key { display: inline-block; width: 8px; height: 8px; border-radius: 1px; margin-right: 6px; }

/* ---- narrow screens -------------------------------------------------------- */
@media (max-width: 1100px) {
  .app {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "bar" "stage" "timeline" "detail" "peaks" "inputs";
  }
  .stage { height: 62vh; min-height: 320px; }
  .inputs { border-right: 0; border-top: 1px solid var(--hairline); }
  .peaks { border-left: 0; border-top: 1px solid var(--hairline); }
  .detail-body { grid-template-columns: minmax(0, 1fr); height: auto; }
  .probe-view { height: 360px; }
  .chart-series { height: 240px; flex: none; }
  .timeline { position: sticky; bottom: 0; background: var(--ink); z-index: 3; }
}
@media (max-width: 560px) {
  .bar { flex-wrap: wrap; gap: 10px 14px; padding: 10px 16px; }
  .bar-home { padding-right: 14px; }
  .run-status { order: 3; width: 100%; margin: 0; }
  .pair { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
