:root {
  --bg: #070a0f;
  --panel: #0b1017;
  --line: #1b2532;
  --line-soft: #131b26;
  --text: #c7d3e0;
  --muted: #6b7a8c;
  --dim: #3d4b5c;
  --e: #f0b45a;
  --ne: #5aa9e6;
  --i: #9fe8e2;
  --s: #b79bf5;
  --ok: #34d399;
  --warn: #f59e0b;
  --bad: #f87171;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100vh; display: flex; flex-direction: column; }
header {
  height: 36px; flex: none; display: flex; align-items: center; gap: 16px;
  padding: 0 12px; border-bottom: 1px solid var(--line); background: #090d13;
}
.brand { letter-spacing: 0.18em; color: #e2ecf7; font-size: 11px; }
.unit { color: var(--muted); font-size: 10px; letter-spacing: 0.08em; }
.lib { color: var(--dim); font-size: 10px; }
.status { margin-left: auto; color: var(--muted); font-size: 10px; }
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 292px minmax(0, 1fr) 330px; }
aside { min-height: 0; overflow: auto; background: var(--panel); }
.shelf { border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.shelf-head {
  flex: none; padding: 8px 10px; border-bottom: 1px solid var(--line);
  background: var(--panel); display: flex; flex-direction: column; gap: 6px;
}
.shelf-row { display: flex; align-items: center; gap: 6px; min-width: 0; flex-wrap: wrap; }
.shelf-title { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; }
.shelf-label { color: var(--muted); font-size: 9px; min-width: 46px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; min-width: 0; }
.shelf-head input {
  flex: 1; min-width: 0; background: #0e1520; border: 1px solid var(--line); color: var(--text);
  padding: 4px 6px; font: inherit; font-size: 11px; outline: none;
}
.shelf-head .sel { flex: 1; min-width: 0; }
.chip {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 2px 7px; font: inherit; font-size: 10px; cursor: pointer;
}
.chip.on { color: #eaf2fb; border-color: #2b3b50; background: #0d141d; }
.chip.readout { cursor: default; color: var(--dim); border-style: dashed; }
.shelf-count { color: var(--dim); font-size: 9px; }
.shelf-legend { color: var(--dim); font-size: 8px; line-height: 1.4; }
.cards-empty { color: var(--dim); font-size: 10px; padding: 8px; }
#cards { flex: 1; min-height: 0; overflow: auto; }
#moreBtn { flex: none; margin: 6px 10px; width: calc(100% - 20px); }
.hidden { display: none !important; }
.hud { border-left: 1px solid var(--line); }
.head {
  position: sticky; top: 0; z-index: 2; display: flex; gap: 8px; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.head span { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; }
.head input {
  flex: 1; min-width: 0; background: #0e1520; border: 1px solid var(--line); color: var(--text);
  padding: 4px 6px; font: inherit; font-size: 11px; outline: none;
}
.cards { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.card {
  position: relative;
  display: flex; flex-direction: column; gap: 3px; text-align: left; cursor: pointer;
  background: #0d141d; border: 1px solid var(--line-soft); border-left: 2px solid #233246;
  color: var(--text); padding: 7px 42px 7px 8px; font: inherit;
}
.card-glyph { position: absolute; right: 6px; top: 6px; width: 30px; height: 30px; pointer-events: none; }
.card:hover { border-color: #2b3b50; background: #101925; }
.card.bundle { border-left-color: #3a2c55; }
.card .formula { color: #eaf2fb; font-size: 12px; }
.card .family { color: var(--muted); font-size: 10px; }
.card .meta { color: var(--muted); font-size: 10px; line-height: 1.5; }
.bench { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.slots { flex: none; min-height: 62px; display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.slot {
  flex: none; min-width: 128px; background: #0d141d; border: 1px solid var(--line-soft);
  padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; position: relative;
}
.slot .formula { color: #eaf2fb; font-size: 11px; }
.slot .meta { color: var(--muted); font-size: 9px; }
.slot .x {
  position: absolute; top: 3px; right: 5px; color: var(--dim); cursor: pointer; font-size: 12px;
  background: none; border: 0; padding: 0 2px; line-height: 1; font-family: inherit;
}
.slot .x:focus-visible { outline: 1px solid var(--cold); }
.slot .x:hover { color: var(--bad); }
.slot.pending { border-style: dashed; border-left-style: solid; border-left-width: 2px; cursor: pointer; }
.slot.pending .formula { color: var(--e); }
.slot.pending:hover { background: #101925; }
.slot-hint { color: var(--dim); font-size: 10px; align-self: center; }
.stage-wrap { flex: 1; position: relative; min-height: 220px; overflow: hidden; }
#stage { display: block; width: 100%; height: 100%; }
.hint {
  position: absolute; left: 10px; bottom: 8px; color: var(--dim); font-size: 10px;
  letter-spacing: 0.04em; pointer-events: none;
}
.tape-wrap { flex: none; height: 78px; border-top: 1px solid var(--line); background: #090d13; }
#tape { display: block; width: 100%; height: 100%; cursor: crosshair; }
.transport {
  flex: none; min-height: 40px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 5px 10px; border-top: 1px solid var(--line); background: #090d13;
}
.sel {
  background: #0e1520; border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 10px; padding: 3px 4px; outline: none;
}
.sel:focus { border-color: #355273; }
.bench { position: relative; }
.result-card {
  position: absolute; right: 14px; bottom: 92px; width: 380px; max-height: 60%; overflow: auto;
  background: #0b1017; border: 1px solid #2b3b50; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55); z-index: 5;
}
.result-card.hidden { display: none; }
.result-head {
  display: flex; justify-content: space-between; align-items: center; padding: 7px 10px;
  border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; letter-spacing: 0.1em;
}
.result-head .x { cursor: pointer; font-size: 14px; color: var(--dim); }
.result-head .x:hover { color: var(--bad); }
.result-body { padding: 8px 10px; color: var(--muted); font-size: 10px; line-height: 1.7; }
.result-body b { color: #eaf2fb; font-weight: normal; }
.result-actions { display: flex; gap: 6px; padding: 0 10px 10px; }
.goal-grid { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.goal { border: 1px solid var(--line-soft); padding: 1px 5px; font-size: 9px; }
.goal.ok { color: var(--ok); border-color: #1d4d3a; }
.goal.no { color: var(--dim); }
.cause, .conditions { color: var(--muted); font-size: 10px; line-height: 1.7; }
.cause .row, .conditions .row { display: flex; gap: 6px; }
.cause .tag, .conditions .tag { min-width: 30px; color: var(--text); }
.conditions .ok { color: var(--ok); }
.conditions .no { color: var(--dim); }
.conditions .read { color: var(--muted); }

.tabs { display: flex; gap: 3px; margin-left: 10px; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 3px 8px; font: inherit; font-size: 10px; cursor: pointer;
}
.tab.on { color: #eaf2fb; border-color: #2b3b50; background: #0d141d; }
.records {
  position: fixed; inset: 36px 0 0 0; z-index: 30; background: var(--bg);
  display: none; grid-template-columns: 300px minmax(0, 1fr);
}
body.view-records .records { display: grid; }
.records-side {
  border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.history { overflow: auto; min-height: 100px; max-height: 36%; display: flex; flex-direction: column; gap: 2px; padding: 6px; }
.hist {
  text-align: left; background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 4px 5px; font: inherit; font-size: 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.hist:hover { border-color: var(--line); color: var(--text); }
.hist b { color: #eaf2fb; font-weight: normal; }
.compare-pick { display: flex; gap: 6px; padding: 6px 10px; }
.compare-pick .sel { flex: 1; min-width: 0; }
.records-main { overflow: auto; padding: 10px 14px; }
.panel-head { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; margin: 8px 0 6px; }
.panel { border: 1px solid var(--line-soft); background: #0b1017; padding: 8px; min-height: 40px; overflow: auto; }
.wide { width: calc(100% - 20px); margin: 4px 10px 6px; }
.mini { background: transparent; border: 1px solid var(--line); color: var(--dim); font-size: 9px; padding: 2px 6px; cursor: pointer; }
.mini:hover { color: var(--bad); border-color: #5a2a2a; }
.meta { color: var(--dim); font-size: 9px; padding: 0 10px 6px; line-height: 1.5; }
table.cmp, table.scan { width: 100%; border-collapse: collapse; font-size: 10px; }
table.cmp th, table.cmp td, table.scan th, table.scan td { border: 1px solid var(--line-soft); padding: 3px 5px; text-align: left; }
table.cmp th, table.scan th { color: var(--muted); font-weight: normal; }
table.scan td.cell { cursor: pointer; }
table.scan td.cell:hover { background: #101925; }
table.scan td.hit { color: var(--ok); }
table.scan td.zero { color: var(--dim); }

.world {
  position: fixed; inset: 36px 0 0 0; z-index: 30; background: var(--bg);
  display: none; flex-direction: column;
}
body.view-world .world { display: flex; }
.world-top {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: #090d13; flex-wrap: wrap;
}
.world-title { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; }
.world-note { color: var(--dim); font-size: 9px; padding: 0 12px 4px; }
.w-lanes {
  flex: 1; overflow: auto; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px; padding: 10px 12px; min-height: 0;
}
.w-lane {
  background: #0b1017; border: 1px solid var(--line-soft); border-top: 2px solid var(--wc, #5aa9e6);
  padding: 8px; display: flex; flex-direction: column; gap: 6px; min-height: 0;
}
.w-lane .w-name { color: #eaf2fb; font-size: 12px; }
.w-lane .w-wx { color: var(--muted); font-size: 9px; }
.w-lane .w-nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.w-lane .w-num { background: #0d141d; border: 1px solid var(--line-soft); padding: 2px 4px; }
.w-lane .w-k { color: var(--muted); font-size: 8px; }
.w-lane .w-v { color: #eaf2fb; font-size: 10px; }
.w-lane canvas { width: 100%; height: 120px; background: #0a0f16; border: 1px solid var(--line-soft); }
.w-lane .w-stock { color: var(--dim); font-size: 9px; }
.w-lane .w-flow { color: var(--muted); font-size: 9px; }
.w-lane .w-events { color: var(--dim); font-size: 9px; }
.w-lane .w-jump { color: var(--dim); font-size: 9px; }
.w-lane .w-jump a { color: #7ec8ff; text-decoration: none; border-bottom: 1px dotted #35506a; }
.w-lane .w-jump a:hover { color: #bfe4ff; }
.w-lane.marked { border-top-color: #f0b45a; box-shadow: inset 0 0 0 1px rgba(240, 180, 90, 0.35); }
#wSeek { width: min(420px, 40vw); vertical-align: middle; accent-color: #5aa9e6; }
#wStatus .firstStop { font-weight: 600; }
#wStatus .firstStop.w { color: #f0b45a; }
#wStatus .firstStop.d { color: #5aa9e6; }
#wStatus .ackbar { display: inline-block; width: 36px; height: 3px; background: #1b2a3a; margin-left: 4px; vertical-align: middle; overflow: hidden; }
#wStatus .ackbar b { display: block; height: 100%; width: 100%; background: #5aa9e6; transition: width .12s linear; }
#wStatus .ackbar b.w { background: #f0b45a; }
#wStatus .ackbar b.d { background: #5aa9e6; }
#wStatus .ackleft { font-size: 10px; color: #6b8299; margin-left: 3px; }
#wStatus .acksep { display: inline-block; width: 1px; height: 10px; background: #3a5a78; margin: 0 6px; vertical-align: middle; cursor: pointer; }
#wStatus .acksep.w { background: #f0b45a; }
#wStatus .acksep.d { background: #5aa9e6; }
.seekwrap { position: relative; display: inline-block; vertical-align: middle; }
.seekwrap i { position: absolute; top: -3px; bottom: -3px; width: 1px; background: #f0b45a; pointer-events: none; display: none; }
.world-actions {
  border-top: 1px solid var(--line); padding: 6px 12px; display: flex; gap: 10px;
  align-items: center; background: #090d13;
}
button {
  background: #101a26; border: 1px solid #243449; color: var(--text); padding: 4px 10px;
  font: inherit; font-size: 11px; cursor: pointer;
}
button:hover { border-color: #355273; color: #fff; }
button:active { background: #0c1520; }
button:disabled { opacity: 0.38; cursor: not-allowed; }
button:disabled:hover { border-color: #243449; color: var(--text); }
.steps { color: var(--muted); font-size: 10px; display: flex; align-items: center; gap: 4px; }
.steps input {
  width: 62px; background: #0e1520; border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 11px; padding: 3px 4px; outline: none;
}
.frame-label { color: var(--muted); font-size: 10px; }
.hash { margin-left: auto; color: var(--dim); font-size: 10px; }
.block { border-bottom: 1px solid var(--line); padding: 8px 10px; }
.block.grow { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
.hud { display: flex; flex-direction: column; }
.block-head { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; margin-bottom: 6px; }
.ledger { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.ledger .cell { background: #0d141d; border: 1px solid var(--line-soft); padding: 4px 5px; }
.ledger .k { color: var(--muted); font-size: 9px; }
.ledger .v { color: #eaf2fb; font-size: 11px; }
.ledger .sub { color: var(--dim); font-size: 9px; }
#ledgerTrace, #wave { display: block; width: 100%; height: 64px; margin-top: 6px; background: #0a0f16; border: 1px solid var(--line-soft); }
#wave { height: 96px; }
#f3d { display: block; width: 100%; height: 112px; margin-top: 6px; background: #0a0f16; border: 1px solid var(--line-soft); }
.selected3d { display: block; width: 100%; height: 152px; margin-top: 6px; background: #0a0f16; border: 1px solid var(--line-soft); cursor: grab; touch-action: none; }
.selected { color: var(--muted); font-size: 10px; line-height: 1.7; }
.selected b { color: #eaf2fb; font-weight: normal; }
.bond-opportunity { margin-top: 7px; padding: 7px 8px; border: 1px solid #243447; border-radius: 6px; background: #0b1420; }
.bond-opportunity h4 { margin: 0 0 4px; color: #e2ecf7; font-size: 10px; letter-spacing: .08em; font-weight: normal; }
.bond-opportunity .bond-row { margin: 1px 0; color: #a9b8c7; font-size: 10px; line-height: 1.55; }
.bond-opportunity .bond-row b { color: #8fa6bd; font-weight: normal; }
.bond-opportunity .ok { color: #9fe8e2; }
.bond-opportunity .warn { color: #f0b45a; }
.bond-opportunity .next { margin-top: 4px; color: #e2ecf7; }
.events { overflow: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; }
.ev {
  text-align: left; background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 3px 4px; font: inherit; font-size: 10px; cursor: pointer; display: flex; gap: 6px;
}
.ev:hover { border-color: var(--line); color: var(--text); }
.ev.now { border-color: #2b3b50; background: #0d141d; color: #eaf2fb; }
.ev .f { color: var(--dim); min-width: 44px; }
.ev .k { color: var(--text); }
.card-marks { display: flex; flex-wrap: wrap; gap: 3px; margin: 2px 0 1px; }
.card-marks .mark { font-size: 9px; line-height: 1.5; padding: 0 4px; border: 1px solid #243447; border-radius: 3px; color: #8fa6bd; white-space: nowrap; }
.card-marks .mark.ok { color: #9fe8e2; border-color: #2a4a52; }
.card-marks .mark.warn { color: #f0b45a; border-color: #4a3a22; }
.card-marks .mark.src { color: #b79bf5; border-color: #3a3052; }
.w-stock { min-height: 14px; color: #8fa6bd; font-size: 9px; line-height: 1.5; }


/* 窄屏：台面占满；材料架与读数各是一个可开合的抽屉。 */
.mtab { display: none; background: transparent; border: 1px solid transparent; color: var(--muted); padding: 3px 8px; font: inherit; font-size: 10px; cursor: pointer; }

@media (max-width: 900px) {
  header { flex-wrap: wrap; gap: 4px; }
  .lib { display: none; }
  main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr); }
  .bench { min-height: 0; }
  .shelf, .hud { display: none; }
  .mtab { display: inline-block; }
  .mtab.on { color: #eaf2fb; border-color: #2b3b50; background: #0d141d; }
  body.show-shelf .shelf,
  body.show-hud .hud {
    display: flex; position: fixed; left: 0; right: 0; top: 46px; bottom: 0;
    z-index: 40; border: 0; background: var(--panel);
  }
  .records { grid-template-columns: 1fr; }
}

/* 键盘焦点可见：输入框与按钮都保留焦点框。 */
:focus-visible { outline: 1px solid var(--cold); outline-offset: 1px; }
.mode-switch { display: inline-flex; gap: 2px; margin-left: 6px; }
.mode-switch .chip { padding: 3px 8px; font-size: 10px; }
.formal-result { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.formal-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 11px; }
.formal-line select { max-width: 120px; }
.asset-card { border: 1px solid var(--line); background: #101923; padding: 6px 8px; margin-bottom: 5px; cursor: pointer; }
.asset-card:hover { border-color: #33506b; }
.asset-card.on { border-color: #f0b45a; box-shadow: inset 2px 0 0 #f0b45a; }
.asset-card .a-head { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.asset-card .a-id { font-size: 10px; color: #dce7f0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-card .a-tag { font-size: 9px; color: #6d8498; border: 1px solid #1d2a38; padding: 0 4px; }
.asset-card .a-kv { font-size: 10px; color: #6d8498; line-height: 1.4; }
.asset-card .a-actions { display: flex; gap: 4px; margin-top: 4px; }
.asset-card .a-actions button { font: inherit; font-size: 9px; padding: 2px 6px; }
.contracts { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; }
.contract { border: 1px solid var(--line); background: #101923; padding: 7px 8px; display: flex; flex-direction: column; gap: 4px; }
.contract-top { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.contract-title { font-size: 12px; color: #eaf2fb; }
.contract-kind { font-size: 9px; color: #6d8498; border: 1px solid #1d2a38; padding: 0 4px; }
.contract-line { font-size: 10px; color: #9fb2c4; line-height: 1.45; }
.contract-clue { font-size: 9px; color: #6d8498; line-height: 1.4; }
.contract-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.contract-actions button, .contract-actions select { font: inherit; font-size: 9px; padding: 2px 6px; }
.contract.done { opacity: 0.62; }
.trades { display:flex; flex-direction:column; gap:5px; max-height:240px; overflow:auto; }
.trade { border:1px solid var(--line); background:#101923; padding:5px 7px; display:flex; flex-direction:column; gap:3px; }
.trade-top { display:flex; justify-content:space-between; gap:5px; font-size:10px; color:#eaf2fb; }
.trade-line { font-size:9px; color:#9fb2c4; line-height:1.4; }
.trade-line b { color:#f0b45a; font-weight:600; }
.trade-actions { display:flex; gap:4px; align-items:center; flex-wrap:wrap; }
.trade-actions button, .trade-actions select { font:inherit; font-size:9px; padding:2px 5px; }
.trade-create { display:flex; flex-direction:column; gap:4px; margin-top:6px; padding-top:6px; border-top:1px solid var(--line); }
.trade-create input, .trade-create select { background:#0b1017; border:1px solid var(--line); color:var(--ink); font:inherit; font-size:9px; padding:3px 4px; }
.trade-create button { font:inherit; font-size:9px; padding:3px 5px; }
