:root {
  --bg: #14171c;
  --bg2: #1b1f26;
  --bg3: #232833;
  --line: #2f3643;
  --fg: #d7dce5;
  --fg-dim: #8b93a3;
  --accent: #4ea3ff;
  --accent-dim: #2d5f96;
  --warn: #e0a33e;
  --good: #57c98a;
  --bad: #e0625f;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans CJK SC", sans-serif;
  overflow: hidden;
}
button {
  background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 5px; padding: 4px 10px; cursor: pointer; font: inherit;
}
button:hover { background: #2c3341; border-color: #3d4557; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent-dim); border-color: #3a76b8; }
button.primary:hover { background: #35709f; }
button.warn:not(:disabled) { background: #6b4f18; border-color: #8a6520; }
button.on { background: var(--accent-dim); border-color: #3a76b8; }
input, select {
  background: #10131a; color: var(--fg); border: 1px solid var(--line);
  border-radius: 4px; padding: 3px 6px; font: inherit;
}
input:focus, select:focus { outline: 1px solid var(--accent); }
code { font-family: var(--mono); }
.hidden { display: none !important; }

/* ------------------------------------------------------------------ topbar */
#topbar {
  height: 42px; display: flex; align-items: center; gap: 10px;
  padding: 0 10px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .3px; color: var(--accent); }
.asset-name {
  font-family: var(--mono); font-size: 12px; color: var(--fg-dim);
  max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  direction: rtl; text-align: left;
}
.spacer { flex: 1; }
.field { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--fg-dim); }
.field select { max-width: 220px; }
.purposes { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--fg-dim); }
.purposes label { display: flex; align-items: center; gap: 3px; cursor: pointer; }

/* ------------------------------------------------------------------ layout */
#layout { display: flex; height: calc(100% - 42px); }
#left { width: 300px; display: flex; flex-direction: column; min-width: 180px; background: var(--bg2); }
#right { width: 430px; min-width: 260px; display: flex; flex-direction: column; background: var(--bg2); }
#centre { flex: 1; position: relative; min-width: 200px; display: flex; flex-direction: column; }
.dragbar { width: 4px; cursor: col-resize; background: var(--line); flex: none; }
.dragbar:hover { background: var(--accent); }

.pane { display: flex; flex-direction: column; min-height: 0; }
#left .pane:first-child { flex: 3; border-bottom: 1px solid var(--line); }
#left .pane:last-child { flex: 2; }
.pane-head {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  font-size: 12px; color: var(--fg-dim); background: var(--bg3);
  border-bottom: 1px solid var(--line);
}
.pane-head span { flex: none; }
.pane-head input { flex: 1; min-width: 0; }
.pane-body { flex: 1; overflow: auto; padding: 4px 0; }

/* -------------------------------------------------------------------- tree */
.tree { font-family: var(--mono); font-size: 12px; }
.tnode { white-space: nowrap; }
.trow {
  display: flex; align-items: center; gap: 3px; padding: 1px 6px; cursor: pointer;
  border-left: 2px solid transparent;
}
.trow:hover { background: #232a36; }
.trow.sel { background: #1e3category; }
.trow.sel { background: #1d3450; border-left-color: var(--accent); }
.twist { width: 12px; text-align: center; color: var(--fg-dim); flex: none; }
.twist.leaf { visibility: hidden; }
.tname { overflow: hidden; text-overflow: ellipsis; }
.ttype { color: var(--fg-dim); font-size: 11px; }
.tbadge {
  font-size: 9px; padding: 0 3px; border-radius: 3px; background: #35405a; color: #9fb5d8;
}
.tbadge.guide { background: #4a3a1e; color: #d8b877; }
.tbadge.proxy { background: #3a2a4a; color: #c0a0d8; }
.tbadge.inst { background: #1e4a3e; color: #7fd8b8; }
.tbadge.inv { background: #4a1e1e; color: #d89a9a; }
.tkids { padding-left: 12px; }

/* ---------------------------------------------------------------- viewport */
#viewport { flex: 1; min-height: 0; position: relative; }
#viewport canvas { display: block; }
#view-overlay { position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 5px; pointer-events: none; }
.chip {
  background: rgba(16,19,26,.82); border: 1px solid var(--line); border-radius: 5px;
  padding: 3px 8px; font-family: var(--mono); font-size: 11px; color: var(--fg-dim);
}
#viewtools {
  position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; align-items: center;
  background: rgba(16,19,26,.82); border: 1px solid var(--line); border-radius: 6px; padding: 4px;
}
#viewtools button { padding: 2px 7px; font-size: 11px; }
#viewtools .sep { width: 1px; height: 16px; background: var(--line); }
#statusbar {
  height: 24px; flex: none; background: var(--bg2); border-top: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 10px; font-size: 11px; color: var(--fg-dim);
}
#statusbar code { color: var(--accent); }

/* -------------------------------------------------------------------- tabs */
.tabs { display: flex; background: var(--bg3); border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; border: none; border-radius: 0; background: transparent; padding: 7px 0;
  color: var(--fg-dim); border-bottom: 2px solid transparent; font-size: 12px;
}
.tab.on { color: var(--fg); border-bottom-color: var(--accent); background: var(--bg2); }
.tabbody { display: none; flex: 1; overflow: auto; padding: 8px; }
.tabbody.on { display: block; }
#prim-head {
  padding: 6px 8px; border-bottom: 1px solid var(--line); background: #191d24;
  font-family: var(--mono); font-size: 11px; line-height: 1.6;
}
#prim-head .p { color: var(--accent); word-break: break-all; }
#prim-head .meta { color: var(--fg-dim); }

/* --------------------------------------------------------------- attr rows */
.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--fg-dim);
  margin: 10px 0 4px; padding-bottom: 3px; border-bottom: 1px solid var(--line);
}
.section-title:first-child { margin-top: 0; }
.attr { border-bottom: 1px solid #20252f; padding: 3px 0; }
.attr-row { display: flex; align-items: baseline; gap: 6px; cursor: pointer; }
.attr-row:hover { background: #1e232d; }
.attr-name { font-family: var(--mono); font-size: 11.5px; flex: 1; overflow-wrap: anywhere; }
.attr-name.authored { color: var(--fg); }
.attr-name.fallback { color: #6b7385; }
.attr-type { font-size: 10px; color: #6b7385; font-family: var(--mono); flex: none; }
.attr-val {
  font-family: var(--mono); font-size: 11px; color: var(--good);
  max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none;
}
.attr-detail { padding: 5px 0 7px 10px; border-left: 2px solid var(--line); margin: 3px 0 3px 4px; }
.stack-row {
  display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px;
  padding: 2px 4px; border-radius: 3px;
}
.stack-row.win { background: #1c3a2c; }
.stack-row .lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-dim); }
.stack-row.win .lname { color: var(--good); }
.stack-row .lval { color: var(--fg); flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.badge {
  font-size: 9px; padding: 0 4px; border-radius: 3px; background: #2a3140; color: #9fb5d8; flex: none;
}
.badge.win { background: var(--good); color: #0d2418; }
.editor { display: flex; gap: 4px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.editor input { width: 84px; font-family: var(--mono); font-size: 11px; }
.editor input.wide { width: 100%; }
.muted { color: var(--fg-dim); }
.err { color: var(--bad); }

/* ------------------------------------------------------------------ layers */
.layer {
  border: 1px solid var(--line); border-radius: 5px; margin-bottom: 6px; overflow: hidden;
  background: #191d24;
}
.layer.target { border-color: var(--accent); }
.layer.muted { opacity: .45; }
.layer-head { display: flex; align-items: center; gap: 6px; padding: 5px 7px; }
.layer-name { flex: 1; font-family: var(--mono); font-size: 11.5px; overflow-wrap: anywhere; }
.layer-sub { font-size: 10px; color: var(--fg-dim); padding: 0 7px 5px; font-family: var(--mono); }
.layer-actions { display: flex; gap: 3px; }
.layer-actions button { padding: 1px 6px; font-size: 10px; }
.sublayers { padding-left: 14px; border-left: 1px dashed var(--line); margin-left: 10px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #444; flex: none; }
.dot.dirty { background: var(--warn); }
.dot.ro { background: #555; }
.dot.rw { background: var(--good); }

/* --------------------------------------------------------------- comp/phys */
.arc { display: flex; gap: 6px; font-family: var(--mono); font-size: 11px; padding: 3px 0; align-items: baseline; }
.arc .at { color: var(--accent); flex: none; }
.arc .ap { color: var(--fg-dim); overflow-wrap: anywhere; }
.joint { border: 1px solid var(--line); border-radius: 5px; padding: 6px 7px; margin-bottom: 6px; background: #191d24; }
.joint h4 { margin: 0 0 4px; font-size: 11.5px; font-family: var(--mono); font-weight: 600; }
.joint .kv { display: flex; gap: 6px; font-size: 11px; font-family: var(--mono); }
.joint .kv b { color: var(--fg-dim); font-weight: 400; min-width: 76px; }
.joint .warnrow { color: var(--warn); font-size: 11px; margin-top: 3px; }
.joint input[type=range] { width: 100%; margin-top: 5px; }

/* ------------------------------------------------------------------- modal */
#modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  width: min(760px, 92vw); height: min(620px, 86vh); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.modal-head button { margin-left: auto; background: none; border: none; font-size: 20px; line-height: 1; }
.modal-tools { display: flex; gap: 8px; align-items: center; padding: 8px 12px; }
.modal-tools input { flex: 1; }
.modal-tools code { font-size: 11px; color: var(--fg-dim); }
#browse-list { flex: 1; overflow: auto; padding: 4px 0; }
.brow {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px; cursor: pointer;
  font-family: var(--mono); font-size: 12px;
}
.brow:hover { background: #232a36; }
.brow .ic { width: 14px; color: var(--fg-dim); }
.brow .sz { margin-left: auto; color: var(--fg-dim); font-size: 11px; }

/* ------------------------------------------------------------------- misc */
#tab-text pre {
  margin: 0; font-family: var(--mono); font-size: 11px; line-height: 1.45;
  white-space: pre; overflow: auto; color: #c8d0dc;
}
#toast {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 100; align-items: center;
}
.toast-item {
  background: #232833; border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 5px; padding: 7px 14px; font-size: 12px; max-width: 70vw;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.toast-item.bad { border-left-color: var(--bad); }
.toast-item.good { border-left-color: var(--good); }
.spin { display: inline-block; animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.warnchip { pointer-events: auto; border-color: var(--warn); color: var(--warn); display: flex; gap: 6px; align-items: center; }
.warnchip button { padding: 1px 6px; font-size: 10px; }

/* --------------------------------------------------------------- launcher */
#launcher {
  position: fixed; inset: 0; z-index: 60; background: rgba(10,12,16,.9);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.launch-box {
  width: min(1080px, 96vw); max-height: 92vh; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.launch-head { display: flex; gap: 16px; padding: 18px 22px 12px; border-bottom: 1px solid var(--line); }
.launch-head h1 { margin: 0 0 6px; font-size: 19px; color: var(--accent); letter-spacing: .3px; }
.launch-head p { margin: 0; color: var(--fg-dim); font-size: 12.5px; line-height: 1.65; max-width: 78ch; }
.launch-head p b { color: var(--fg); font-weight: 600; }
.launch-head button { margin-left: auto; background: none; border: none; font-size: 22px; line-height: 1; align-self: flex-start; }
#launch-cards {
  flex: 1; overflow: auto; padding: 14px 18px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px;
}
.card {
  border: 1px solid var(--line); border-radius: 8px; background: #191d24; padding: 12px 14px;
  cursor: pointer; display: flex; flex-direction: column; gap: 7px; transition: border-color .12s, transform .12s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card.self { border-left: 3px solid var(--good); }
.card h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.card .blurb { font-size: 11.5px; color: var(--fg-dim); line-height: 1.6; }
.card .blurb b { color: var(--fg); font-weight: 600; }
.card .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.card .tag { font-size: 9.5px; padding: 1px 6px; border-radius: 3px; background: #2a3140; color: #9fb5d8; }
.card.self .tag { background: #1e4a3e; color: #7fd8b8; }
.card .facts {
  font-family: var(--mono); font-size: 10.5px; color: #6b7385;
  border-top: 1px solid #232935; padding-top: 6px; margin-top: auto;
}
.launch-foot {
  display: flex; align-items: center; gap: 12px; padding: 10px 22px;
  border-top: 1px solid var(--line); font-size: 11px; color: var(--fg-dim);
}
.launch-foot span { flex: 1; line-height: 1.5; }

#navhint { opacity: .55; transition: opacity .3s; }
#viewport:hover ~ #view-overlay #navhint, #view-overlay:hover #navhint { opacity: 1; }

/* --------------------------------------------------- material / annotation */
.mrow { display: flex; align-items: center; gap: 7px; padding: 3px 0; flex-wrap: wrap; }
/* fixed basis + min-width:0 on the growers, or a long input name gets squeezed to
   one character per line by the texture thumbnail and the select next to it */
.mrow .mname {
  font-family: var(--mono); font-size: 11px;
  flex: 0 0 132px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mrow .mkind { font-size: 9.5px; color: #6b7385; }
.mrow input[type=color] { width: 34px; height: 22px; padding: 0; border-radius: 4px; }
.mrow input[type=range] { flex: 1; min-width: 60px; }
.mrow input[type=number] { width: 66px; }
.mrow select { flex: 1 1 150px; min-width: 0; max-width: 100%; }
.mrow .mkind { flex: 1 1 auto; min-width: 0; }
.mrow .hex { width: 78px; font-family: var(--mono); font-size: 11px; }
.texprev {
  width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 4px;
  object-fit: cover; background: #10131a; flex: none;
}
.matcard { border: 1px solid var(--line); border-radius: 6px; padding: 8px 9px; margin-bottom: 8px; background: #191d24; }
.matcard h4 { margin: 0 0 2px; font-size: 12px; font-family: var(--mono); }
.matcard .sub { font-size: 10.5px; color: var(--fg-dim); margin-bottom: 6px; }
.chip-set { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip-tag {
  font-size: 10.5px; padding: 2px 7px; border-radius: 10px; background: #2a3140;
  color: #9fb5d8; cursor: pointer; border: 1px solid transparent;
}
.chip-tag.on { background: #1e4a3e; color: #7fd8b8; border-color: #2f6b57; }
.chip-tag:hover { border-color: var(--accent); }
.fieldrow { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.fieldrow label {
  font-family: var(--mono); font-size: 11px; width: 128px; flex: none; color: var(--fg-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* namespace headers are longer than the field-name column; let them size to content
   instead of spilling over the value next to them */
.fieldrow label.wide { width: auto; flex: 0 0 auto; margin-right: 8px; }
.fieldrow label.set { color: var(--fg); }
.fieldrow select, .fieldrow input { flex: 1; min-width: 0; }
.hint { font-size: 10.5px; color: var(--fg-dim); line-height: 1.55; margin: 4px 0 8px; }
.hint b { color: var(--warn); font-weight: 600; }

#gizmo-modes { display: inline-flex; gap: 3px; margin-left: 2px; }
#gizmo-modes.hidden { display: none; }
