/* ═══ §7 · SHARED · MODALS ════════════════════════════════════════════════════════════
   Three chassis, and every modal in the app is one of them:
     .modal            a bottom sheet with a grabber   — ticker · scanner · replay
     .composite-modal  a centred card                  — statik · why · session plan · brain · regime
     .council-modal    the round table                 — the Fusion
   §7.1 is the sheet chrome; §7.2–§7.9 are the individual modals in that order. */

/* ── §7.1 the bottom-sheet chassis ── */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10001;
  gap: var(--sp-md);
  /* side padding only — the content owns its own top/bottom so the sheet can sit flush */
  padding-left: var(--sp-md);
  padding-right: var(--sp-md);
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  padding-bottom: 0;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-content {
  position: relative;
  width: 100%;
  max-width: 400px;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  /* flush to the viewport bottom (the sheet covers the nav while open); max-height keeps the
     TOP edge where it was before the sheet was allowed to extend down. */
  max-height: calc(100vh - env(safe-area-inset-top, 0px) - 20px);
  margin-bottom: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: transform;
}
@keyframes slideUp {
  from { transform: translateY(100px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.modal-grabber {
  width: 52px;
  height: 5px;
  background: rgba(255, 255, 255, 0.42);
  border-radius: 3px;
  margin: 10px auto 6px;
  cursor: grab;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}
/* `:hover` only where hovering is real — iOS Safari sticks :hover after a tap and left the
   grabber permanently scale-stretched, which read as a broken modal. */
@media (hover: hover) {
  .modal-grabber:hover { background: rgba(255, 255, 255, 0.65); transform: scaleX(1.1); }
}
.modal-grabber:active { cursor: grabbing; background: rgba(255, 255, 255, 0.75); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--sp-lg);
  border-bottom: 1px solid var(--glass-border);
}
.modal-title {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-cyan);
}
.modal-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 4px;
}
.modal-subtitle.positive { color: var(--accent-green); }
.modal-subtitle.negative { color: var(--accent-red); }
.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 51, 102, 0.15);
  border: 1px solid rgba(255, 51, 102, 0.3);
  color: var(--accent-red);
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.modal-close:active { transform: scale(0.9); }

.modal-body {
  padding: var(--sp-lg);
  padding-bottom: calc(var(--sp-lg) + 24px);
  display: flex;
  flex-direction: column;
  gap: var(--sp-lg);
  flex: 1;
  overflow-y: auto;
}
.modal-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}
.modal-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.modal-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-md);
}
.modal-stat {
  padding: var(--sp-md);
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  text-align: center;
}
.modal-stat-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.modal-stat-value {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-cyan);
}
.modal-footer {
  padding: var(--sp-lg);
  border-top: 1px solid var(--glass-border);
  display: flex;
  gap: var(--sp-sm);
}
.modal-btn {
  flex: 1;
  padding: 10px;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-cyan);
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid rgba(0, 229, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}
.modal-btn:active { transform: scale(0.97); }

/* ── §7.2 the TICKER modal — the score breakdown block it owns ── */
.score-breakdown {
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
  padding: var(--sp-md);
  background: rgba(0, 229, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
}
.score-breakdown-formula {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent-cyan);
  letter-spacing: 0.02em;
}
.score-breakdown-note {
  font-size: 0.7rem;
  color: var(--text-dim);
  line-height: 1.4;
}
.score-breakdown-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-xs);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}
.score-breakdown-grid .kv {
  display: flex;
  justify-content: space-between;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 229, 255, 0.04);
}
.score-breakdown-grid .kv .k { color: var(--text-dim); }
.score-breakdown-grid .kv .v { color: var(--text-primary); }
.score-breakdown-grid .kv .v.pending { color: var(--text-dim); font-style: italic; }

/* ── §7.3 the CHART, inside the ticker modal, and its FULLSCREEN ──────────────────────
   The chart is not a modal of its own: it is a section of the ticker sheet, and pressing it
   takes the whole viewport the same way the theater does. */

/* the timeframe toolbar — one scrolling row, never two wrapped ones on a phone */
.modal-chart-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 2px;
}
.modal-chart-toolbar::-webkit-scrollbar { height: 4px; }
.modal-chart-toolbar::-webkit-scrollbar-thumb {
  background: rgba(0, 229, 255, 0.25);
  border-radius: 2px;
}
.modal-chart-toolbar .tf-btn { flex: 0 0 auto; }

.tf-btn {
  background: rgba(0, 229, 255, 0.06);
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  font: 600 0.7rem/1 var(--font-mono);
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tf-btn:hover { color: var(--text-primary); background: rgba(0, 229, 255, 0.12); }
.tf-btn.active {
  color: var(--accent-cyan);
  background: rgba(0, 229, 255, 0.18);
  border-color: rgba(0, 229, 255, 0.55);
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.18) inset;
}
.tf-rth {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  color: var(--text-dim);
  font: 600 0.65rem/1 var(--font-mono);
  cursor: pointer;
  user-select: none;
}
.tf-rth input { accent-color: var(--accent-cyan); }

/* the crosshair OHLCV readout — absolutely placed inside the chart wrapper, pointer-events off
   so the SVG underneath still receives movement */
.chart-crosshair-wrap { touch-action: none; }
.chart-crosshair-legend {
  position: absolute;
  pointer-events: none;
  min-width: 118px;
  padding: 6px 8px;
  background: rgba(8, 16, 24, 0.92);
  border: 1px solid rgba(0, 229, 255, 0.35);
  border-radius: 6px;
  color: var(--ink-panel);
  font: 500 0.68rem/1.25 var(--font-mono);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  z-index: 4;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.chart-crosshair-legend.up   { border-color: rgba(46, 204, 113, 0.55); }
.chart-crosshair-legend.down { border-color: rgba(232, 93, 42, 0.55); }
.chart-crosshair-legend .xh-time {
  font-size: 0.62rem;
  color: var(--text-dim);
  margin-bottom: 3px;
  letter-spacing: 0.04em;
}
.chart-crosshair-legend .xh-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
  row-gap: 1px;
}
.chart-crosshair-legend .xh-k { color: var(--text-dim); font-weight: 700; }
.chart-crosshair-legend .xh-v { text-align: right; font-variant-numeric: tabular-nums; }

/* the session legend under the chart (pre / RTH / after-hours / overnight) */
#modal-chart-legend .sess-swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}
#modal-chart-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  letter-spacing: 0.02em;
}

/* the scroll box — the chart can be wider than the viewport on a long timeframe */
#modal-chart-scroll {
  scrollbar-width: thin;
  /* iOS Safari needs `pan-x` to allow horizontal panning inside a fixed-height overflow box
     nested in a sheet; without it the parent's vertical pan handler captures the touch. */
  touch-action: pan-x;
  overscroll-behavior-x: contain;
}
#modal-chart-scroll::-webkit-scrollbar { height: 4px; }
#modal-chart-scroll::-webkit-scrollbar-thumb {
  background: rgba(0, 229, 255, 0.25);
  border-radius: 2px;
}

/* FULLSCREEN — the same two paths the theater uses, so both surfaces behave identically:
   `.is-fullscreen` on the scroll box, and `body.chart-fullscreen` to take the app chrome out
   of the shot. Two root causes had to be released for it to work at all:
     (1) `.modal-content` carries `will-change: transform`, which per spec makes IT the
         containing block for any position:fixed descendant — so `inset: 0` anchored to the
         400px sheet, not the viewport;
     (2) `glass-heavy`'s backdrop-filter traps fixed descendants the same way.
   Both are released below, along with filter/perspective/contain for safety. */
#modal-chart-scroll.is-fullscreen {
  position: fixed;
  inset: 0;
  height: 100dvh !important;
  width: 100vw !important;
  z-index: 12000;
  background: #05070b;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px) 0;
}
#modal-chart-scroll.is-fullscreen #modal-chart { transform-origin: left center; }
body.chart-fullscreen .modal-overlay { display: none; }
body.chart-fullscreen .modal-content {
  transform: none !important;
  will-change: auto;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  filter: none !important;
  perspective: none !important;
  contain: none !important;
  overflow: visible;
  /* hide the sheet's in-flow children so they do not paint over the fullscreen chart; the rule
     below re-shows only the scroll box. */
  visibility: hidden;
}
body.chart-fullscreen #modal-chart-scroll.is-fullscreen {
  visibility: visible;
  /* the chart renderer sets an inline 5%-cyan background on the scroll container, which without
     !important wins over this and lets the tab underneath leak through. */
  background: #05070b !important;
}
/* the app chrome steps out of the shot, same as the theater */
body.chart-fullscreen .status-bar,
body.chart-fullscreen .holo-nav { display: none; }

/* ── §7.4 the SCANNER modal ── */
.scanner-modal-top20 {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.scanner-modal-row {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(0, 229, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s ease;
}
.scanner-modal-row:active { background: rgba(0, 229, 255, 0.12); }
.scanner-modal-rank {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}
.scanner-modal-tick {
  font-weight: 600;
  letter-spacing: 0.03em;
  font-size: 0.86rem;
}
.scanner-modal-price {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-dim);
}
.scanner-modal-pct {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  min-width: 56px;
  text-align: right;
}

/* ── §7.5 the REPLAY modal — the board re-read from the engram, seeked and fast-forwarded.
   Window pills across the top, the session date under them, transport at the foot. ── */
.replay-modal-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 4px;
}
.replay-window-pills {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.replay-pill {
  padding: 7px 6px;
  border: 1px solid rgba(0, 229, 255, 0.28);
  background: rgba(0, 229, 255, 0.04);
  color: var(--text-secondary);
  border-radius: 999px;
  font-family: 'Orbitron', monospace;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.replay-pill:hover { border-color: rgba(0, 229, 255, 0.55); color: var(--text-primary); }
.replay-pill.active {
  background: rgba(0, 229, 255, 0.22);
  border-color: rgba(0, 229, 255, 0.7);
  color: #fff;
}
.replay-date-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.replay-date-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.replay-date-input {
  flex: 1;
  background: rgba(10, 15, 26, 0.8);
  border: 1px solid rgba(0, 229, 255, 0.3);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: 8px;
}

/* THE TRANSPORT — play/pause · the seek scrubber · the clock. It is `hidden` until frames
   load, so an empty window shows controls for nothing. */
.replay-transport {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px 4px;
}
.replay-transport[hidden] { display: none; }
.replay-play {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(0, 229, 255, 0.4);
  background: rgba(0, 229, 255, 0.12);
  color: var(--accent-cyan);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease;
}
.replay-play:hover { background: rgba(0, 229, 255, 0.22); }
.replay-seek {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: var(--accent-cyan);
  height: 44px;
}
.replay-clock {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  text-align: right;
  min-width: 0;
  overflow-wrap: anywhere;
}
/* the fast-forward multiplier — a packed chip row, so 44px is taken in flow */
.replay-speeds {
  display: flex;
  gap: 6px;
  padding: 2px 2px 6px;
}
.replay-speed {
  flex: 1 1 0;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(0, 229, 255, 0.28);
  background: rgba(0, 229, 255, 0.04);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.replay-speed.active {
  background: rgba(0, 229, 255, 0.22);
  border-color: rgba(0, 229, 255, 0.7);
  color: #fff;
}

.replay-modal-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
/* ONE REPLAYED MINUTE'S ROW — rank · symbol · price · move. The board repaints this list once
   per frame, so the row must not reflow when a value changes width: every numeric cell is
   tabular and right-aligned at a fixed minimum. */
.replay-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(0, 229, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s ease;
}
.replay-row:active { background: rgba(0, 229, 255, 0.14); }
.replay-row .rnk {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}
.replay-row .sym {
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 0.86rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.replay-row .px {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  min-width: 58px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.replay-row .pct {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 62px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.replay-row .pct.pos { color: var(--outcome-win); }
.replay-row .pct.neg { color: var(--outcome-fade); }

/* ── §7.6 the CORPUS panel — the RAG surface inside the ticker/why modal. This is where the
   brain's learned corpus is read back: a passage, where it came from, and how strongly it
   matched. ── */
.corpus-subtitle {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 10px;
}
.corpus-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--accent-cyan);
  letter-spacing: 0.04em;
}
.corpus-input-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.corpus-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  background: rgba(0, 229, 255, 0.04);
  color: var(--text-primary);
  font-size: 0.82rem;
}
.corpus-input::placeholder { color: var(--text-dim); }
.corpus-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.corpus-card {
  padding: 10px 12px;
  background: rgba(0, 229, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
}
.corpus-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}
.corpus-card-source {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-cyan);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.corpus-card-source:hover { text-decoration: underline; }
.corpus-card-score {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--outcome-win);
  font-weight: 700;
}
.corpus-card-meta {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.corpus-card-text {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-primary);
  max-height: 190px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  padding-right: 4px;
}
.corpus-empty {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-style: italic;
  padding: 8px 0;
  text-align: center;
}
.corpus-empty code {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 5px;
  background: rgba(0, 229, 255, 0.1);
  border-radius: 4px;
  font-style: normal;
}

/* ── §7.7 the COMPOSITE chassis — a centred card. Statik chat, Why, Session Plan, The Brain
   and Market Regime all use it. ── */
.composite-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.composite-modal {
  background: rgba(20, 20, 30, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 18px 16px;
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  font-family: var(--font-display);
  color: var(--ink-panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.composite-modal-hdr {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
}
.composite-modal-title {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.04em;
}
.composite-modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.composite-modal-close:hover { color: var(--ink-panel); }

/* the factor rows — used by the P.R.E.P breakdown in Why AND by the regime mix bars */
.composite-factor-row {
  display: grid;
  grid-template-columns: 130px 1fr 50px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}
.composite-factor-name {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.64rem;
}
.composite-factor-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.composite-factor-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--outcome-win), #00d9ff);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.composite-factor-fill.is-neutral { background: rgba(180, 180, 180, 0.5); }
.composite-factor-fill.is-drag { background: linear-gradient(90deg, #ff8aa0, #ff4060); }
.composite-factor-val {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-panel);
}

/* the Session Plan modal's markdown body */
.session-plan-body {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #cfe;
  line-height: 1.55;
  padding: 4px 4px 16px;
}
.session-plan-body h1,
.session-plan-body h2,
.session-plan-body h3 {
  color: var(--accent-cyan);
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 18px 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(0, 229, 255, 0.18);
  padding-bottom: 4px;
}
.session-plan-body h1 { font-size: 14px; }
.session-plan-body p { margin: 6px 0; color: #9cf; }
.session-plan-body strong, .session-plan-body b { color: #fde047; font-weight: 600; }
.session-plan-body em, .session-plan-body i { color: var(--accent-cyan-bright); font-style: normal; }
.session-plan-body ul, .session-plan-body ol { margin: 6px 0 10px 18px; padding: 0; }
.session-plan-body li { margin: 3px 0; color: #cfe; }
.session-plan-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 11px;
}
.session-plan-body th {
  text-align: left;
  color: var(--accent-cyan);
  border-bottom: 1px solid rgba(0, 229, 255, 0.25);
  padding: 4px 6px;
  font-weight: 700;
}
.session-plan-body td {
  padding: 3px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: #9cf;
}
.session-plan-body code, .session-plan-body pre {
  background: rgba(0, 229, 255, 0.06);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  color: #fde047;
}
.session-plan-body pre {
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}
.session-plan-body hr {
  border: none;
  border-top: 1px solid rgba(0, 229, 255, 0.15);
  margin: 14px 0;
}
.session-plan-body img, .session-plan-body svg { max-width: 24px; vertical-align: middle; }

/* ── §7.8 STATIK CHAT — a composite modal that owns the whole viewport height, because a
   conversation needs the log to scroll and the composer to stay put. The composer is pinned
   to the bottom of the CARD, not the page: app.js re-pins the backdrop to the VISIBLE viewport
   on every visualViewport resize so the on-screen keyboard shrinks the panel instead of
   covering the input. ── */
.composite-modal.statik-chat {
  display: flex;
  flex-direction: column;
  max-width: 620px;
  height: 100%;
  max-height: 100%;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  overflow: hidden;          /* the LOG scrolls, not the card */
}
#statik-chat-backdrop { padding: 10px; align-items: stretch; }

.statik-chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 8px;
  scroll-behavior: smooth;
}
.statik-chat-log::-webkit-scrollbar { width: 6px; }
.statik-chat-log::-webkit-scrollbar-thumb {
  background: rgba(0, 229, 255, 0.28);
  border-radius: 3px;
}

/* ONE TURN — avatar beside a bubble. The operator's turn mirrors to the right; the organism's
   and an error stay left, so the column reads as a conversation at a glance. */
.statik-chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
}
.statik-chat-msg.op { flex-direction: row-reverse; }
.statik-chat-avatar {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  line-height: 1;
  background: rgba(6, 12, 22, 0.9);
  border: 1px solid rgba(0, 229, 255, 0.25);
  color: var(--accent-cyan);
}
.statik-chat-msg.op .statik-chat-avatar {
  border-color: rgba(58, 255, 138, 0.4);
  color: var(--outcome-win);
  font-size: 0.66rem;
  font-weight: 700;
  font-family: var(--font-mono);
}
.statik-chat-msg.err .statik-chat-avatar {
  border-color: rgba(255, 90, 122, 0.45);
  color: var(--outcome-fade);
}
/* THE BUBBLE MUST BE ABLE TO SHRINK. Without `min-width: 0` a long unbroken token forces the
   flex item wider than the card and the operator's own message renders one letter per line. */
.statik-chat-bubble {
  min-width: 0;
  max-width: 100%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 0.78rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
  background: rgba(0, 229, 255, 0.06);
  border: 1px solid rgba(0, 229, 255, 0.18);
  color: #d3eef5;
}
.statik-chat-msg.op .statik-chat-bubble {
  background: rgba(58, 255, 138, 0.09);
  border-color: rgba(58, 255, 138, 0.25);
  color: #d3f5e0;
  white-space: pre-wrap;
}
.statik-chat-msg.err .statik-chat-bubble {
  background: rgba(255, 90, 122, 0.08);
  border-color: rgba(255, 90, 122, 0.3);
  color: #ffb3c0;
  white-space: pre-wrap;
}
.statik-chat-bubble p { margin: 0 0 6px; }
.statik-chat-bubble p:last-child { margin-bottom: 0; }
.statik-chat-bubble ul, .statik-chat-bubble ol { margin: 4px 0 6px 18px; padding: 0; }
.statik-chat-bubble li { margin: 2px 0; }
.statik-chat-bubble code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 229, 255, 0.10);
  color: #fde047;
}
.statik-chat-bubble strong { color: var(--accent-cyan); font-weight: 700; }

/* a fenced code block in a reply — header row with the language and a copy button */
.statik-code-block {
  margin: 6px 0;
  border: 1px solid rgba(0, 229, 255, 0.18);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(3, 7, 14, 0.85);
}
.statik-code-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  background: rgba(0, 229, 255, 0.07);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.statik-code-copy {
  background: transparent;
  border: 1px solid rgba(0, 229, 255, 0.3);
  color: var(--accent-cyan);
  border-radius: 5px;
  padding: 1px 8px;
  font-size: 0.58rem;
  font-family: inherit;
  cursor: pointer;
}
.statik-code-copy:hover { background: rgba(0, 229, 255, 0.12); }
.statik-code-block pre {
  margin: 0;
  padding: 8px 10px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.5;
  color: #9cf;
}

.statik-chat-empty {
  margin: auto;
  padding: 24px 12px;
  text-align: center;
}
.statik-chat-empty-icon { font-size: 2rem; opacity: 0.5; margin-bottom: 8px; }
.statik-chat-empty-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.statik-chat-empty-sub {
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.5;
  max-width: 34ch;
  margin: 0 auto;
}

/* the in-flight strip between the log and the composer */
.statik-chat-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--accent-cyan);
  flex: 0 0 auto;
}
.statik-chat-status[hidden] { display: none; }
.statik-chat-spinner {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid rgba(0, 229, 255, 0.25);
  border-top-color: var(--accent-cyan);
  animation: statikSpin 0.7s linear infinite;
}
@keyframes statikSpin { to { transform: rotate(360deg); } }

/* THE COMPOSER — never scrolls out of reach. `flex: 0 0 auto` on a flex column keeps it at the
   card's foot however long the log grows. */
.statik-chat-inputbar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 229, 255, 0.16);
}
.statik-chat-wrap { flex: 1 1 auto; min-width: 0; }
.statik-chat-textarea {
  width: 100%;
  min-height: 22px;
  max-height: 104px;
  resize: none;
  background: rgba(20, 24, 32, 0.95);
  border: 1px solid rgba(0, 229, 255, 0.20);
  border-radius: 12px;
  color: #d3eef5;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.45;
  padding: 9px 12px;
  overflow-y: auto;
}
.statik-chat-textarea:focus { outline: none; border-color: rgba(0, 229, 255, 0.55); }
.statik-chat-textarea::placeholder { color: var(--text-dim); }
.statik-chat-send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 229, 255, 0.18);
  border: 1px solid rgba(0, 229, 255, 0.45);
  color: var(--accent-cyan);
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s;
}
.statik-chat-send svg { width: 18px; height: 18px; }
.statik-chat-send:hover:not(:disabled) { background: rgba(0, 229, 255, 0.34); color: #fff; }
.statik-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.statik-chat-foot {
  flex: 0 0 auto;
  padding-top: 6px;
  font-size: 0.55rem;
  line-height: 1.5;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

/* ── §7.9 the COUNCIL modal — the Fusion's round table ── */
.council-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  backdrop-filter: blur(6px);
}
.council-modal {
  position: relative;
  background: linear-gradient(135deg, rgba(10, 16, 28, 0.96), rgba(6, 10, 20, 0.96));
  border: 1px solid rgba(108, 248, 255, 0.18);
  border-radius: 18px;
  padding: 18px 16px 14px;
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  font-family: var(--font-display);
  color: var(--ink-panel);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7),
              inset 0 0 80px rgba(108, 248, 255, 0.04);
}
.council-hdr {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.council-title { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.council-decision {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 4px;
  width: fit-content;
}
.council-decision.is-emit {
  background: rgba(58, 255, 138, 0.16);
  color: var(--outcome-win);
  border: 1px solid rgba(58, 255, 138, 0.5);
}
.council-decision.is-block {
  background: rgba(255, 90, 122, 0.16);
  color: #ff8aa0;
  border: 1px solid rgba(255, 90, 122, 0.5);
}
.council-decision.is-standing {
  background: rgba(108, 248, 255, 0.16);
  color: rgba(108, 248, 255, 0.95);
  border: 1px solid rgba(108, 248, 255, 0.5);
}
.council-ticker {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--ink-panel);
}
.council-sub {
  font-size: 0.66rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.council-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.council-close:hover { color: var(--ink-panel); }
.council-empty {
  padding: 40px 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.council-table {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 580px;
  margin: 4px auto 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%,
              rgba(58, 255, 138, 0.06) 0%,
              rgba(108, 248, 255, 0.04) 35%,
              rgba(6, 10, 20, 0.0) 70%);
  box-shadow: inset 0 0 60px rgba(108, 248, 255, 0.05);
}
.council-table-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: rgba(108, 248, 255, 0.78);
  text-shadow: 0 0 12px rgba(108, 248, 255, 0.4);
  line-height: 1.1;
}
.council-table-tag {
  display: block;
  margin-top: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}
/* each seat is placed around the rim; --i is the agent index, --N the total */
.council-seat {
  position: absolute;
  --angle: calc((var(--i) / var(--N)) * 360deg - 90deg);
  --radius: 38%;
  left: calc(50% + cos(var(--angle)) * var(--radius));
  top:  calc(50% + sin(var(--angle)) * var(--radius));
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 138px;
  pointer-events: auto;
}
.council-avatar {
  font-size: 1.4rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 20, 0.85);
  border: 1px solid rgba(108, 248, 255, 0.25);
  border-radius: 50%;
  margin-bottom: 4px;
  box-shadow: 0 0 8px rgba(108, 248, 255, 0.18);
}
.council-bubble {
  background: rgba(14, 22, 36, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 0.62rem;
  line-height: 1.3;
  text-align: left;
  max-width: 100%;
  /* long knight lines are CAPPED per seat so the round table's seats never grow tall enough to
     bury each other */
  max-height: 128px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  animation: council-bubble-in 0.4s ease;
}
@keyframes council-bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.council-agent {
  font-weight: 700;
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(108, 248, 255, 0.88);
  margin-bottom: 2px;
}
.council-line { color: var(--ink-panel); font-family: var(--font-mono); }

.council-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.council-chip {
  padding: 4px 8px;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  font-weight: 700;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.council-chip:hover { background: rgba(108, 248, 255, 0.08); color: var(--ink-panel); }
.council-chip.active {
  background: rgba(58, 255, 138, 0.14);
  color: var(--outcome-win);
  border-color: rgba(58, 255, 138, 0.5);
}

/* ≤640px: the round table cannot fit 12 READABLE seats on a phone — 12×138px seats around a
   ~220px rim overlap into an unreadable pile. On phones the decorative table is ABANDONED and
   the knights stack as a legible vertical list. !important overrides the inline absolute
   positioning the JS sets per seat. */
@media (max-width: 640px) {
  .council-modal { padding: 12px 10px 12px; }
  .council-table {
    position: relative;
    aspect-ratio: auto;
    max-width: 100%;
    border-radius: 0;
    background: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 6px 0 0;
  }
  .council-table-center {
    position: static;
    transform: none;
    margin: 0 0 4px;
    font-size: 0.85rem;
    order: -1;
  }
  .council-seat,
  .council-seat.statik-head {
    position: static !important;
    transform: none !important;
    left: auto !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .council-seat.statik-head { flex-direction: column; }
  .council-seat:not(.statik-head) {
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(14, 22, 36, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
  }
  .council-seat:not(.statik-head) .council-avatar { flex: 0 0 auto; margin-bottom: 0; }
  .council-bubble {
    max-width: none !important;
    flex: 1 1 auto;
    font-size: 0.72rem;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    max-height: none;
    overflow-y: visible;
  }
  .council-agent { font-size: 0.66rem; margin-bottom: 3px; }
  .council-line { font-size: 0.72rem; }
}

