/* Mortgage Atlas. Scoped to this page; nothing here is shared
   with /styles.css. Palette follows mtgmon's dark shell (#0a0a0a ground,
   #0a84ff accent, rgba(255,255,255,.1) hairlines, JetBrains Mono numerals). */
:root {
  --bg: #0a0a0a;
  --panel: #131316;
  --panel-2: #1b1b20;
  --line: rgba(255, 255, 255, 0.1);
  --text: #ebebf5;
  --muted: #9a9aa6;
  --accent: #0a84ff;
  --lock: #62b8ff;
  --cross: #ffb547;
  --hot: #ff4d3d;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; scrollbar-color: #35353c transparent; scrollbar-width: thin; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.45 var(--ui); }
::selection { background: rgba(10, 132, 255, 0.35); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
b { font-weight: 600; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.atlas {
  display: grid;
  height: 100vh;
  height: 100dvh;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top top" "controls controls" "stage detail" "release release";
}

.atlas.details-collapsed {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "controls" "stage" "release";
}

.release-footer { grid-area: release; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding: 4px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10.5px; }
.release-footer a { color: inherit; }

/* header */
.atlas-top { grid-area: top; display: flex; align-items: baseline; gap: 14px; padding: 10px 18px 9px; border-bottom: 1px solid var(--line); }
.brand { color: var(--text); text-decoration: none; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.brand svg { width: 13px; height: 13px; fill: currentColor; position: relative; top: 1px; }
.crumb { color: var(--muted); }
.crumb::before { content: "/"; margin-right: 14px; color: rgba(255, 255, 255, 0.22); }
h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.coverage { margin: 0 0 0 auto; color: var(--muted); font-size: 12px; text-align: right; }
.coverage b { color: var(--text); }
.btn.details-toggle { flex-shrink: 0; min-width: 104px; font-size: 12px; white-space: nowrap; }
.hdr-select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font: inherit; font-size: 12px; margin-right: 2px; }

/* control strip */
.controls { grid-area: controls; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.ctl { display: flex; align-items: center; gap: 10px; }
.ctl-label { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.ctl-label em { font-style: normal; color: var(--cross); margin-left: 6px; text-transform: uppercase; font-size: 10px; letter-spacing: 0.08em; }
.ctl-rate { flex: 1 1 340px; }
.shock-control { display: flex; align-items: center; gap: 10px; }
.shock-slider { flex: 1; min-width: 80px; }
.shock-slider input { display: block; width: 100%; min-width: 0; }
.shock-control output { min-width: 70px; }
.shock-ticks { display: flex; color: var(--muted); font: 9px var(--mono); margin-top: 2px; }
.shock-ticks span { width: 33.333%; text-align: center; }
.shock-ticks span:first-child { text-align: left; }
.shock-ticks span:last-child { text-align: right; }
.rate-reference { color: var(--muted); font-size: 10.5px; margin-top: 4px; }
#primaryStatus { margin-left: 8px; }
input[type="range"] { flex: 1; min-width: 140px; accent-color: var(--cross); margin: 0; }
output { font-family: var(--mono); font-size: 14px; min-width: 56px; text-align: right; }
select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font: inherit; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 6px 12px; font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.09); color: var(--text); }
.seg button:disabled { opacity: 0.4; cursor: default; }
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; font: inherit; cursor: pointer; }
.btn:hover { border-color: rgba(255, 255, 255, 0.28); }
.btn[aria-pressed="true"] { background: rgba(255, 181, 71, 0.14); border-color: var(--cross); color: var(--cross); }
.btn:disabled { opacity: 0.45; cursor: default; }
.actions { gap: 8px; }

/* stage */
.stage { grid-area: stage; position: relative; display: flex; flex-direction: column; min-height: 0; }
#viz, #atlas { flex: 1; min-height: 0; opacity: 0; transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1); outline-offset: -2px; }
#viz.ready, #atlas.ready { opacity: 1; }
#viz[hidden], #atlas[hidden] { display: none; }

/* Atlas (Three.js) renderer */
.atlas3d { position: relative; overflow: hidden; cursor: grab; }
.atlas3d:active { cursor: grabbing; }
.atlas-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.atlas-labels { position: absolute; z-index: 2; top: 0; left: 0; pointer-events: none; overflow: hidden; }
.atlas-axis-leaders { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.atlas-axis-leaders line { stroke: #a3a3ae; stroke-width: 1; stroke-opacity: 0.6; }
.atlas-label { font-family: var(--mono); font-size: 10.5px; color: var(--muted); white-space: nowrap; pointer-events: none; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
.atlas-label.tick { color: #c4c4cd; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 1px 1px #000; }
.atlas-label.tick.right { transform: translate(-50%, -50%) translateX(-6px); }
.atlas-label.title { left: 0; top: 0; max-width: calc(100% - 16px); padding: 3px 6px; border: 1px solid #3a3a46; border-radius: 4px; background: rgba(15, 15, 20, 0.94); font-family: var(--ui); font-size: 11px; color: #dedee6; letter-spacing: 0.01em; white-space: normal; text-align: center; overflow-wrap: anywhere; }
.atlas-label.sel { font-size: 11.5px; color: var(--text); background: rgba(20, 20, 22, 0.92); border: 1px solid #3a3a42; border-radius: 6px; padding: 3px 8px; transform: translate(-50%, -100%); }
.atlas-tip { position: absolute; z-index: 4; pointer-events: none; background: #141416; border: 1px solid #3a3a42; border-radius: 6px; padding: 6px 9px; font-family: var(--mono); font-size: 11.5px; color: var(--text); line-height: 1.45; max-width: 280px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }
.atlas-tip[hidden] { display: none; }
.atlas-legend { position: absolute; z-index: 3; right: 14px; top: 12px; width: 150px; font-family: var(--mono); font-size: 10px; color: var(--muted); pointer-events: none; }
.atlas-legend .bar { height: 8px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.12); }
.atlas-legend .ticks { display: flex; justify-content: space-between; margin-top: 3px; }
.atlas-legend .cap { font-family: var(--ui); font-size: 10.5px; color: #a3a3ae; margin-bottom: 4px; }
.rate-markers { display: grid; gap: 3px; margin-top: 8px; }
.rate-markers > span { display: flex; align-items: center; gap: 5px; }
.rate-markers b { margin-left: auto; color: var(--text); font-weight: 500; }
.rate-markers i { width: 14px; border-top: 2px solid var(--cross); }
.rate-markers .primary-mark { border-top: 2px dotted var(--text); }
@media (max-width: 760px) {
  .atlas-legend { top: auto; bottom: 10px; left: 12px; right: auto; width: 150px; }
  .atlas-label { font-size: 9.5px; }
  .atlas-label.title { font-size: 10px; }
}
.stage-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 5px 18px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); }
.seg-sm { flex-shrink: 0; }
.seg-sm button { padding: 3px 9px; font-size: 11px; }
#status { flex: 1; font-family: var(--mono); font-size: 11px; color: var(--text); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Keyboard hint appears only while the visualization has keyboard focus. */
.keys { margin: 0; flex-basis: 100%; display: none; }
.stage:has(#viz:focus-visible, #atlas:focus-visible) .keys { display: block; }
.keys kbd { font-family: var(--mono); font-size: 10.5px; background: rgba(255, 255, 255, 0.08); border-radius: 4px; padding: 1px 5px; color: var(--text); }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; pointer-events: none; }
.loading.gone { display: none; }

/* detail rail */
.detail { grid-area: detail; border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 14px 16px 28px; display: flex; flex-direction: column; gap: 18px; }
.detail[hidden] { display: none; }
.detail h2 { font-size: 13px; color: var(--text); margin: 0 0 8px; font-weight: 600; }
.detail h3 { font-size: 11.5px; color: var(--muted); margin: 14px 0 0; font-weight: 500; }
.detail p { margin: 0 0 8px; }
.panel-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.panel-heading .num { color: var(--muted); font-size: 12px; }
.balance-headline { font-size: 30px; line-height: 1.15; }
.compact > div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.compact dd { margin: 0; text-align: right; }
.breakdown { margin-top: 16px; }
.share { display: inline-block; min-width: 44px; margin-left: 6px; color: var(--muted); font-size: 11px; }
.detail details { margin-top: 10px; border-top: 1px solid var(--line); }
.detail summary { padding: 7px 0; cursor: pointer; color: var(--muted); font-size: 12px; }
.detail summary:hover, .detail details[open] > summary { color: var(--text); }
.detail details > dl { padding: 3px 0 8px; }
.src details { margin-top: 0; }
.def { color: var(--muted); font-size: 12px; }
.def b { color: var(--text); }
dl { margin: 0; display: grid; gap: 9px; }
dt { color: var(--muted); font-size: 11.5px; }
dd { margin: 2px 0 0; font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
dd .muted { color: var(--muted); font-family: var(--ui); font-size: 11.5px; }
.big { font-size: 22px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.2; }
.src dd { font-family: var(--ui); font-size: 12px; }
.src dd .num { font-size: 11.5px; }
.vlist { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 3px; }
.vlist button {
  width: 100%; display: flex; justify-content: space-between; gap: 8px;
  background: linear-gradient(90deg, rgba(255, 181, 71, 0.16) var(--w, 0%), transparent 0);
  border: 1px solid transparent; color: var(--text); padding: 5px 8px; border-radius: 6px;
  font: inherit; cursor: pointer; text-align: left;
}
.vlist button:hover { border-color: var(--line); }
.vlist button[aria-pressed="true"] { border-color: var(--cross); }
.hint { color: var(--muted); }
.cohort-name { font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-family: var(--mono); }
.pill.cross { background: rgba(255, 181, 71, 0.16); color: var(--cross); }
.pill.lock { background: rgba(98, 184, 255, 0.16); color: var(--lock); }
.pill.strad { background: rgba(242, 242, 245, 0.14); color: var(--text); }
.row-actions { display: flex; gap: 8px; margin-top: 12px; }
.warn { color: var(--cross); font-size: 12px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 11.5px; margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

@media (max-width: 760px) {
  .atlas { height: auto; min-height: 100dvh; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto auto; grid-template-areas: "top" "controls" "stage" "detail" "release"; }
  .stage { min-width: 0; }
  #status { white-space: normal; }
  .atlas-top { flex-wrap: wrap; gap: 4px 12px; }
  .coverage { order: 1; margin-left: 0; text-align: left; flex-basis: 100%; }
  .details-toggle { margin-left: auto; }
  .controls { gap: 8px 14px; padding: 8px 12px; }
  .ctl-rate { flex-basis: 100%; }
  input[type="range"] { min-width: 0; }
  .stage { height: 60vh; min-height: 400px; }
  .stage-foot { padding: 6px 12px; }
  #status { flex-basis: 100%; white-space: normal; }
  .stage:has(#viz:focus-visible, #atlas:focus-visible) .keys { display: none; }
  .detail { border-left: 0; border-top: 1px solid var(--line); padding: 14px 12px 32px; }
}
@media (max-width: 400px) {
  .controls .ctl:not(.seg) { flex-wrap: wrap; gap: 4px 10px; }
  .controls select { max-width: 100%; }
  .seg button { padding: 6px 9px; }
}
