:root {
  color-scheme: dark;
  --header: #1d1d1d;
  --editor: #303030;
  --box: #282828;
  --panel: #3d3d3d;
  --widget: #545454;
  --widget-hi: #656565;
  --field: #232323;
  --outline: #232323;
  --text: #e5e5e5;
  --dim: #9a9a9a;
  --accent: #4772b3;
  --accent-hi: #5b8ad4;
  --brand: #ee7c26;
  --radius: 4px;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--header);
  color: var(--text);
  font-size: 12px;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 8px;
  height: 26px;
  background: var(--header);
}
.titlebar .app { font-weight: 700; letter-spacing: 0.04em; color: var(--dim); }
.titlebar .app b { color: var(--brand); }
.titlebar .doc { margin-left: auto; color: var(--dim); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 4px 6px;
  background: var(--header);
  border-top: 1px solid #00000055;
  border-bottom: 1px solid var(--outline);
}
.toolbar .sep { width: 1px; height: 18px; background: #ffffff1a; margin: 0 5px; }
.toolbar .hint { margin-left: auto; color: var(--dim); padding-right: 4px; }

button, .filebtn {
  font: inherit;
  color: var(--text);
  cursor: pointer;
  background: var(--widget);
  border: none;
  border-radius: var(--radius);
  padding: 0 9px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover, .filebtn:hover { background: var(--widget-hi); }
button:disabled { opacity: 0.45; cursor: default; }
button:disabled:hover { background: var(--widget); }
button.on { background: var(--accent); color: #fff; }
button.on:hover { background: var(--accent-hi); }
button:focus-visible, .filebtn:focus-visible { outline: 1px solid var(--accent-hi); outline-offset: 1px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 260px;
  gap: 1px;
  background: var(--outline);
  min-height: 0;
}
.panel {
  background: var(--editor);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 0;
  height: 31px;
  color: var(--dim);
  background: var(--header);
  flex: none;
}
.panel-head .count, .count { margin-left: auto; font-variant-numeric: tabular-nums; }
.panel-head .meta { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.panel-head input[type="search"] {
  width: 160px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  font: inherit;
}


.viewport {
  position: relative;
  background: #202020;
  min-width: 0;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.empty { margin: auto; text-align: center; color: var(--dim); }
.empty .dim { opacity: 0.8; }
.combined {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 0 12px;
  font: 11px/18px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #cfcfcf;
}
.hrow {
  display: grid;
  grid-template-columns: 86px max-content 18ch minmax(0, 1fr);
  gap: 0 10px;
  padding: 0 12px;
  white-space: nowrap;
}
.hrow:nth-child(even of .hrow) { background: #ffffff06; }
.hrow:hover { background: #ffffff0c; }
.hrow .off { color: var(--accent-hi); }
.hrow .hx b { font-weight: normal; background: #4772b355; color: #fff; border-radius: 2px; }
.hrow .asc { color: var(--dim); overflow: hidden; text-overflow: ellipsis; }
.hrow .asc b { font-weight: normal; color: #fff; }
.hrow .hx b.map { font-weight: normal; background: #ee7c2655; color: #fff; border-radius: 2px; outline: 1px solid #ee7c2688; }
.hrow .asc b.map { font-weight: normal; color: #ee7c26; }
.hrow .hx b.map.hover, .hrow .asc b.map.hover { background: #ee7c26; color: #101010; outline-color: #ee7c26; }
.map-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  max-width: 340px;
  background: #101010f2;
  border: 1px solid #ee7c26;
  border-radius: var(--radius);
  padding: 4px 8px;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hrow .str {
  color: #9fc48a;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.hrow .str::before { content: "▸ "; color: var(--dim); }
.gap {
  padding: 6px 12px 2px;
  color: var(--dim);
  font-family: system-ui, sans-serif;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.inspector { overflow-y: auto; padding: 0 4px 4px; gap: 3px; }
.inspector > .panel-head { position: sticky; top: 0; z-index: 2; margin: 0 -4px -3px; }
.inspector details {
  background: var(--box);
  border-radius: var(--radius);
  margin-top: 4px;
}
.inspector summary {
  cursor: pointer;
  padding: 5px 8px;
  color: var(--text);
  font-weight: 600;
  list-style: none;
  display: flex;
  gap: 6px;
  align-items: center;
}
.inspector summary::-webkit-details-marker { display: none; }
.inspector summary::before { content: "▸"; color: var(--dim); }
.inspector details[open] summary::before { content: "▾"; }
.props { margin: 0; padding: 2px 4px 6px; display: grid; gap: 3px; }
.props .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: baseline;
  background: var(--widget);
  border-radius: var(--radius);
  padding: 3px 8px;
}
.props dt { color: #ffffffc0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.props dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-family: ui-monospace, Menlo, monospace; }
.props .sub { grid-column: 1 / -1; color: var(--dim); font-size: 10px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.props .empty-note { color: var(--dim); padding: 2px 6px; }
.note { color: var(--dim); margin: 2px 6px 6px; font-size: 11px; line-height: 1.5; }

.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 22px;
  padding: 0 8px;
  background: var(--header);
  color: var(--dim);
  border-top: 1px solid var(--outline);
  font-variant-numeric: tabular-nums;
}
.statusbar .right { margin-left: auto; }

body.dragover .viewport { outline: 2px dashed var(--accent-hi); outline-offset: -6px; }

.panel-head .tab { background: transparent; color: var(--dim); height: 22px; }
.panel-head .tab.on { background: var(--widget); color: var(--text); }

.maps {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: 1px;
  background: var(--outline);
  overflow: hidden;
}
.cands { background: var(--editor); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.cands-head {
  display: flex;
  align-items: center;
  padding: 6px 8px 2px;
  color: var(--dim);
  flex: none;
}
.cands-head .count { margin-left: auto; font-variant-numeric: tabular-nums; }
.cand-list { overflow-y: auto; flex: 1; min-height: 0; padding: 4px 5px; display: flex; flex-direction: column; gap: 3px; }
.cand {
  text-align: left;
  height: auto;
  display: grid;
  gap: 1px;
  background: var(--box);
  padding: 4px 7px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
}
.cand .top { color: var(--accent-hi); }
.cand .vals { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand[aria-selected="true"] { background: #4772b355; box-shadow: 0 0 0 2px var(--accent-hi); }
.cand[aria-selected="true"] .top { color: #fff; }
.cands .note { margin: 2px 6px 6px; }
.mapedit { background: #202020; display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.ed-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 10px 2px;
  flex: none;
}
.ed-grid label { display: grid; gap: 2px; color: var(--dim); font-size: 10px; }
.ed-grid input, .ed-grid select, .ed-row input {
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  min-width: 0;
}
.ed-grid input { font-variant-numeric: tabular-nums; }
.ed-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  flex: none;
  flex-wrap: wrap;
}
.ed-row .sep { width: 1px; height: 18px; background: #ffffff1a; margin: 0 4px; }
.ed-row .meta { margin-left: auto; color: var(--dim); font-variant-numeric: tabular-nums; }
.ed-row .lbl { color: var(--dim); }
.ed-row select, .ed-row textarea {
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.ed-row textarea { height: 22px; width: 130px; resize: none; font-family: ui-monospace, Menlo, monospace; font-size: 11px; }
.ed-row input.short { width: 64px; }
.ed-row input:disabled { opacity: 0.4; }
.axes { flex: none; margin: 0 10px 4px; background: var(--box); border-radius: var(--radius); }
.axes summary { cursor: pointer; padding: 4px 8px; color: var(--dim); font-size: 11px; }
.axis-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 2px 8px 8px; }
.axis { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.axis .on { grid-column: 1 / -1; color: var(--text); display: flex; gap: 6px; align-items: center; }
.axis .on input { accent-color: var(--accent-hi); }
.axis label { display: grid; gap: 2px; color: var(--dim); font-size: 10px; }
.axis input, .axis select {
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}
table.grid td.oor { color: #e3a45a; }
.ed-row input#mapName { width: 180px; }
.grid-wrap { flex: 1; min-height: 120px; overflow: auto; padding: 0 10px; }
table.grid { border-collapse: collapse; font: 11px ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
table.grid td, table.grid th {
  border: 1px solid #ffffff14;
  padding: 2px 8px;
  text-align: right;
  white-space: nowrap;
}
table.grid th { color: var(--accent-hi); font-weight: normal; background: #ffffff06; }
table.grid td.rh { color: var(--accent-hi); background: #ffffff06; }
.mapviz-wrap { flex: 1; min-height: 160px; display: flex; flex-direction: column; padding: 0 10px; }
.mapviz { flex: 1; min-height: 0; cursor: grab; touch-action: none; user-select: none; }
.mapviz.dragging { cursor: grabbing; }
.mapviz-svg { width: 100%; height: 100%; display: block; }
.mapviz-hint { flex: none; padding: 2px 0 6px; color: var(--dim); font-size: 10px; text-align: center; }
.mv-floor path { stroke: #ffffff18; fill: none; }
.mv-surf path { stroke: #00000055; stroke-width: 0.5; }
.mv-dot { fill: var(--accent-hi); }
.mv-tick { fill: var(--accent-hi); font: 9px ui-monospace, Menlo, monospace; }
.mv-ax { fill: var(--dim); font: 10px system-ui, sans-serif; }
.mv-range, .mv-note { fill: var(--dim); font: 10px ui-monospace, Menlo, monospace; }
.pack-list { flex: none; max-height: 132px; overflow-y: auto; padding: 0 10px 10px; display: flex; flex-direction: column; gap: 3px; }
.pack-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--box);
  border-radius: var(--radius);
  padding: 3px 8px;
}
.pack-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pack-item .kind {
  flex: none;
  min-width: 42px;
  text-align: center;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: help;
  border: 1px solid;
}
.pack-item .kind-map { color: #ee7c26; border-color: #ee7c2688; background: #ee7c2618; }
.pack-item .kind-curve { color: #6fb3e0; border-color: #6fb3e088; background: #6fb3e018; }
.pack-item .kind-scalar { color: #9fc48a; border-color: #9fc48a88; background: #9fc48a18; }
.pack-item .kind-switch { color: #d7a0e8; border-color: #d7a0e888; background: #d7a0e818; }
.pack-item .dims { color: var(--dim); font-size: 10px; font-variant-numeric: tabular-nums; margin-left: auto; white-space: nowrap; }
.pack-item button { height: 20px; }

.engviz { padding: 6px 6px 0; }
.engviz-svg { width: 100%; height: auto; display: block; }
.eng-fire { animation: engFire 1.8s linear infinite; }
.eng-piston { animation: engPiston 1.8s ease-in-out infinite; }
.eng-spin { animation: engSpin 2.4s linear infinite; }
.eng-belt { animation: engBelt 0.9s linear infinite; }
@keyframes engFire {
  0%, 100% { opacity: 0.35; }
  6% { opacity: 1; }
  26% { opacity: 0.35; }
}
@keyframes engPiston {
  0%, 50%, 100% { transform: none; }
  25%, 75% { transform: translate(calc(var(--px, 0) * 1px), calc(var(--py, 1) * 1px)); }
}
@keyframes engSpin { to { transform: rotate(360deg); } }
@keyframes engBelt { to { stroke-dashoffset: calc(var(--eng-dash, 12) * -1px); } }
@media (prefers-reduced-motion: reduce) {
  .eng-fire, .eng-spin, .eng-belt, .eng-piston { animation: none; }
  .eng-fire { opacity: 0.85; }
}
