/* ─── Script Brain Analyzer HUD (always dark, like a scanner screen) ─── */
.hud {
  --hb: #050505; --hp: #0b0b0c; --hp2: #111113; --hl: rgba(255,255,255,.08); --hl2: rgba(167,139,250,.3);
  --lime: #a78bfa; --lime-soft: rgba(167,139,250,.14); --ht: #ececee; --hd: #8b8b93; --hf: #4e4e55;
  --hred: #ff6f5e; --hamber: #f0c04c;
  container: hud / inline-size;
  position: relative; margin: 6px 0 0; padding: 10px; border-radius: 18px; background: var(--hb);
  border: 1px solid var(--hl); color: var(--ht); font-family: var(--mono); font-size: 11.5px;
  box-shadow: 0 30px 80px -30px rgba(0,0,0,.7); overflow: hidden;
}
.hud::before { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.012) 0 1px, transparent 1px 3px); }
.hud * { scrollbar-width: thin; scrollbar-color: #2c2c31 transparent; }
.hud button { font-family: var(--mono); }
.hud-row { display: grid; gap: 8px; margin-top: 8px; }
.hud-row:first-child { margin-top: 0; }

/* Stats strip */
.hud-stats { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.stat { padding: 9px 12px 10px; background: var(--hp); border: 1px solid var(--hl); border-radius: 8px; min-width: 0; }
.stat span { display: block; font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--hd); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat b { display: block; margin-top: 4px; font: 500 22px/1.1 var(--mono); color: var(--ht); letter-spacing: -.02em; }
.stat b small { font-size: 11px; color: var(--hd); margin-left: 3px; }
.stat.hi b { color: var(--lime); }
.stat.warn b { color: var(--hamber); }

/* Panels */
.panel { position: relative; display: flex; flex-direction: column; min-width: 0; background: var(--hp); border: 1px solid var(--hl); border-radius: 8px; overflow: hidden; }
.panel > header { display: flex; align-items: center; gap: 10px; height: 30px; padding: 0 10px; border-bottom: 1px solid var(--hl); color: var(--hd); font-size: 10.5px; white-space: nowrap; overflow: hidden; }
.panel > header .tag { padding: 2px 7px; border-radius: 3px; background: #f2f2f2; color: #0a0a0a; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; font-size: 9.5px; }
.panel > header .tag.dim { background: transparent; color: var(--ht); border: 1px solid var(--hl2); }
.panel > header .sp { flex: 1; }
.panel > header .live { color: var(--lime); }
.panel > header .live::before { content: '●'; margin-right: 6px; animation: pulse 1.4s infinite; }

.hud-main { grid-template-columns: minmax(0, 1fr) 260px; }
.cortex { min-height: 470px; }
.stage { position: relative; flex: 1; min-height: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cortex .stage { min-height: 438px; }
.cortex canvas { cursor: grab; touch-action: none; }
.cortex canvas:active { cursor: grabbing; }
.cortex .cx-overlay { position: absolute; left: 12px; bottom: 9px; color: var(--hf); font-size: 10px; pointer-events: none; }
.cortex .legend-h { position: absolute; right: 12px; bottom: 9px; display: flex; gap: 12px; color: var(--hd); font-size: 10px; }
.cortex .legend-h i { display: inline-block; width: 7px; height: 7px; margin-right: 5px; background: var(--lime); }
.session { position: absolute; top: 40px; left: 10px; width: 210px; border: 1px solid var(--hl2); background: rgba(6,8,6,.82); backdrop-filter: blur(4px); font-size: 10.5px; z-index: 2; }
.session .sh { padding: 5px 8px; background: #f2f2f2; color: #0a0a0a; font-weight: 600; letter-spacing: .06em; }
.session dl { margin: 0; padding: 6px 8px; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.session dt { color: var(--hd); }
.session dd { margin: 0; text-align: right; color: var(--ht); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.slices { display: grid; grid-template-rows: repeat(3, 1fr); gap: 8px; }
.slices .stage { min-height: 120px; }

.hud-bottom { grid-template-columns: minmax(0, .9fr) minmax(0, 1.5fr) minmax(0, 1fr); height: 300px; }
.hud-bottom .panel { height: 300px; }
.scroll { overflow-y: auto; flex: 1; }

/* Maps list */
.map { display: grid; grid-template-columns: 22px minmax(0, 1fr) 54px 50px; gap: 8px; align-items: center; width: 100%; padding: 7px 10px; text-align: left; color: var(--ht); border-bottom: 1px solid rgba(255,255,255,.03); transition: background .15s; }
.map:hover, .map.on { background: var(--lime-soft); }
.map .n { color: var(--hf); }
.map .l { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map .l small { color: var(--hd); margin-left: 6px; }
.map .mb { height: 4px; background: #1c1c20; position: relative; }
.map .mb i { position: absolute; inset: 0 auto 0 0; background: var(--lime); }
.map .st { text-align: right; font-size: 10px; }
.st.strong { color: var(--lime); } .st.ok { color: var(--hd); } .st.risk { color: var(--hred); }
.empty-h { padding: 18px 12px; color: var(--hf); line-height: 1.7; }

/* Editor */
.editor textarea { flex: 1; width: 100%; resize: none; border: 0; outline: 0; padding: 12px 14px; background: transparent; color: var(--ht); font: 12.5px/1.75 var(--mono); }
.editor textarea::placeholder { color: var(--hf); }
.editor .go { display: inline-flex; align-items: center; gap: 7px; height: 22px; padding: 0 10px; border-radius: 3px; background: var(--lime); color: #fff; font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.editor .go:disabled { opacity: .35; }
.editor .ghost-btn { color: var(--hd); font-size: 10.5px; }
.editor .ghost-btn:hover { color: var(--lime); }
.seg-block { display: grid; grid-template-columns: 34px minmax(0, 1fr); padding: 4px 0; border-left: 2px solid transparent; transition: background .2s; }
.seg-block .g { color: var(--hf); text-align: right; padding-right: 10px; font-size: 10.5px; padding-top: 2px; }
.seg-block p { margin: 0; font: 12.5px/1.7 var(--mono); color: var(--ht); white-space: pre-wrap; padding-right: 12px; }
.seg-block.risk { border-left-color: var(--hred); }
.seg-block.strong { border-left-color: var(--lime); }
.seg-block.on { background: var(--lime-soft); }
.seg-block .lab { display: inline-block; margin-right: 8px; color: var(--lime); }

/* Log */
.log .scroll { padding: 8px 10px; font-size: 10.5px; line-height: 1.75; }
.log .ln { white-space: pre-wrap; word-break: break-word; animation: fade .2s; }
.log .ln time { color: var(--hf); margin-right: 8px; }
.log .ln.ok { color: var(--lime); } .log .ln.warn { color: var(--hamber); } .log .ln.err { color: var(--hred); } .log .ln.dim { color: var(--hd); }
.cursor::after { content: '▋'; color: var(--lime); animation: pulse 1s infinite; }

.hud-foot { display: flex; gap: 18px; align-items: center; margin-top: 8px; padding: 7px 10px; border: 1px solid var(--hl); border-radius: 8px; background: var(--hp); color: var(--hd); font-size: 10px; white-space: nowrap; overflow: hidden; }
.hud-foot b { color: var(--lime); font-weight: 500; }
.hud-foot .bar-h { flex: 1; height: 3px; background: #1c1c20; position: relative; min-width: 60px; }
.hud-foot .bar-h i { position: absolute; inset: 0 auto 0 0; background: var(--lime); transition: width .4s; }

/* ─── Simple steps around the scanner (follow the portal theme) ─── */
:root, :root[data-theme="dark"] { --purple: #a78bfa; --purple-soft: rgba(167, 139, 250, .15); }
:root[data-theme="light"] { --purple: #7c3aed; --purple-soft: rgba(124, 58, 237, .1); }
.step-card { padding: 26px; }
.step-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 18px; }
.step-head h2, .ch-title { font-size: 18px; font-weight: 500; letter-spacing: -.01em; }
.step-head p { margin-top: 3px; font-size: 13.5px; }
.step-n { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--purple); color: #fff; font: 600 13px var(--font); }
.step-n.sm { width: 22px; height: 22px; font-size: 11px; }
.step-label { display: flex; align-items: center; gap: 10px; margin: 34px 0 12px; font-size: 14px; font-weight: 500; }
.script-input { min-height: 240px; font-size: 15px; line-height: 1.7; padding: 16px 18px; border-radius: 14px; }
.script-input:focus { box-shadow: 0 0 0 4px var(--purple-soft); border-color: var(--purple); }
.btn.brain-go { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.brain-go:hover { opacity: .92; }
.done-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.done-bar .ok { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--purple-soft); color: var(--purple); }
.done-bar .ok svg { width: 14px; height: 14px; }
.step-card.collapsed { padding: 16px 20px; }
.step-card.collapsed .step-head { display: none; }

.up-card { border-color: color-mix(in srgb, var(--purple) 35%, var(--line)); }
.up-top { display: flex; justify-content: space-between; align-items: center; gap: 18px; flex-wrap: wrap; }
.score-pair { display: flex; align-items: center; gap: 18px; }
.sp-n { font: 400 54px/1 var(--serif); color: var(--text-2); }
.sp-n.after { color: var(--purple); }
.sp-l { font-size: 12px; margin-top: 6px; }
.sp-arrow svg { width: 22px; height: 22px; color: var(--text-3); }
.up-delta { background: var(--purple); color: #fff; border-color: transparent; height: 28px; font-size: 13px; }
.up-card .btn.primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.copied { background: var(--good-soft) !important; color: var(--good) !important; border-color: transparent !important; }
.up-note { margin-top: 16px; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 13px; }
.up-doc { margin-top: 18px; padding: 22px 24px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); font-size: 15.5px; line-height: 1.8; white-space: pre-wrap; max-height: 560px; overflow-y: auto; }
.up-doc mark { background: var(--purple-soft); color: inherit; border-bottom: 2px solid var(--purple); padding: 1px 2px; border-radius: 3px; cursor: help; }
.mark-key { display: inline-block; width: 14px; height: 10px; margin-right: 8px; border-radius: 2px; background: var(--purple-soft); border-bottom: 2px solid var(--purple); }
.ch-list { display: grid; gap: 10px; margin-top: 12px; }
.ch { display: grid; grid-template-columns: 28px 1fr; gap: 12px; padding: 16px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.ch-n { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--purple-soft); color: var(--purple); font: 600 12px var(--mono); }
.ch b { font-weight: 500; font-size: 14.5px; }
.ch-ba { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.ch-ba span { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.ch-ba p { margin-top: 4px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.ch-ba p.was { color: var(--text-3); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text-3) 60%, transparent); }
.dz { padding: 12px 0; border-top: 1px solid var(--line); margin-top: 12px; }
.dz p { font-size: 14px; } .dz span { font-size: 13px; color: var(--text-2); }
@media (max-width: 640px) {
  .step-card { padding: 18px; }
  .ch-ba { grid-template-columns: 1fr; }
  .up-top .row, .up-top .row .btn { width: 100%; }
  .sp-n { font-size: 44px; }
}

@container hud (max-width: 1000px) {
  .hud-bottom { grid-template-columns: 1fr 1fr; height: auto; }
  .hud-bottom .editor { grid-column: 1 / -1; order: -1; }
}
@container hud (max-width: 740px) {
  .hud-main { grid-template-columns: 1fr; }
  .slices { grid-template-columns: repeat(3, 1fr); grid-template-rows: 150px; }
  .hud-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@container hud (max-width: 560px) {
  .hud { padding: 6px; border-radius: 14px; }
  .hud-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat b { font-size: 18px; }
  .cortex .stage { min-height: 320px; }
  .session { width: 170px; font-size: 9.5px; }
  .slices { grid-template-rows: 110px; }
  .hud-bottom { grid-template-columns: 1fr; }
  .hud-bottom .panel { height: 260px; }
  .up-score { grid-template-columns: auto auto auto; }
  .up-score .rbars { grid-column: 1 / -1; }
  .big-n { font-size: 48px; }
  .hud-foot .hide-sm, .cortex .legend-h { display: none; }
}
