:root {
  --bg: #15161a; --panel: #1d1f24; --line: #2c2f36; --text: #e6e6e6; --muted: #9aa0a8;
  --accent: #d4a24c; --link: #8ab4f8;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: grid; grid-template-columns: 240px 1fr 380px; height: 100vh;
  background: var(--bg); color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
#sidebar, #panel { background: var(--panel); overflow: hidden; display: flex; flex-direction: column; }
#sidebar { border-right: 1px solid var(--line); }
#panel { border-left: 1px solid var(--line); }
h1 { font-size: 15px; letter-spacing: .2em; margin: 14px 14px 8px; color: var(--accent); }
.search { padding: 0 10px 8px; }
.search input, select {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; font: inherit;
}
#mapList { list-style: none; margin: 0; padding: 0 6px 10px; overflow-y: auto; flex: 1; }
#mapList li {
  padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px;
}
#mapList li:hover { background: #262930; }
#mapList li.active { background: #33302a; color: var(--accent); }
#mapList small { font-size: 11px; }
.k { color: var(--muted); }
#mapList .num { color: var(--muted); font-variant-numeric: tabular-nums; }
main { display: flex; flex-direction: column; min-width: 0; }
#toolbar {
  display: flex; align-items: center; gap: 14px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex-wrap: wrap;
}
#mapTitle { font-weight: 600; min-width: 160px; }
#mapTitle small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.toggles { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.toggles label {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border: 1px solid var(--line);
  border-radius: 999px; cursor: pointer; user-select: none; color: var(--muted);
}
.toggles input { display: none; }
.toggles label.on { color: var(--text); border-color: #4a4e57; background: #262930; }
.toggles .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.toggles .n { color: var(--muted); font-size: 11px; }
.zoom { display: flex; align-items: center; gap: 4px; }
.zoom button {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  width: 28px; height: 26px; cursor: pointer; font-size: 15px;
}
#zoomLabel { width: 46px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
#stage { position: relative; flex: 1; overflow: hidden; cursor: grab; background: #0c0d0f; }
#stage.dragging { cursor: grabbing; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
#hover {
  position: absolute; left: 10px; bottom: 10px; background: rgba(20, 21, 25, .9); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 9px; pointer-events: none; font-variant-numeric: tabular-nums; max-width: 60%;
}
#hover:empty { display: none; }
#details { padding: 12px 14px; border-bottom: 1px solid var(--line); overflow-y: auto; max-height: 75%; }
#details h2 { font-size: 13px; margin: 0 0 8px; color: var(--accent); }
#details .ent { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
#details .ent h3 { margin: 0 0 4px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
#details .ent .k { color: var(--muted); }
#details .text { white-space: pre-wrap; background: var(--bg); border-radius: 6px; padding: 6px 8px; margin-top: 6px; }
.hint { color: var(--muted); }
a, .link { color: var(--link); cursor: pointer; text-decoration: none; }
a:hover, .link:hover { text-decoration: underline; }
.items { list-style: none; padding: 0; margin: 4px 0 0; }
.items li { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.spr {
  width: 32px; height: 32px; flex: none; background-image: url(items.png);
  image-rendering: pixelated; border-radius: 4px; background-color: #2a2d33;
}
.badge { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: #33363d; color: var(--text); }
.badge.red { background: #6b2626; } .badge.purple { background: #4f2a63; } .badge.green { background: #29502c; }
#listing { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.listhead { display: flex; gap: 8px; align-items: center; padding: 10px 14px 6px; }
.listhead select { flex: 1; }
#listCount { color: var(--muted); }
#entityList { list-style: none; margin: 0; padding: 0 8px 10px; overflow-y: auto; flex: 1; }
#entityList li { padding: 4px 6px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#entityList li:hover { background: #262930; }
#entityList .xy { color: var(--muted); font-variant-numeric: tabular-nums; width: 62px; flex: none; }
.dlg { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
.dlg li { padding: 2px 0; border-bottom: 1px solid var(--line); }
details summary { cursor: pointer; }
.wt { display: block; margin: 0 14px 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--accent); text-decoration: none; }
.wt:hover { background: #262930; text-decoration: none; }
#itemHits { list-style: none; margin: 0; padding: 0 10px; max-height: 30%; overflow-y: auto; }
#itemHits li { padding: 3px 4px; border-bottom: 1px solid var(--line); }
#itemHits li ul { list-style: none; padding-left: 8px; margin: 2px 0; }
.icon { width: 32px; height: 32px; flex: none; background-image: url(items.png); image-rendering: pixelated;
  border-radius: 4px; background-color: #2a2d33; display: inline-block; vertical-align: middle; }
.portrait { width: 68px; height: 74px; flex: none; background-image: url(portraits.png); image-rendering: pixelated;
  border-radius: 4px; float: right; margin-left: 8px; }
.evs { list-style: none; padding: 0; margin: 6px 0 0; font-size: 12px; }
.evs li { padding: 2px 0 2px calc(var(--d, 0) * 14px); border-top: 1px dotted var(--line); }
.evs .n { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
.evs .x { margin: 3px 0 2px; }
.trig { font-size: 11px; color: var(--muted); }
.mapinfo td { padding: 1px 8px 1px 0; vertical-align: top; }
.opts { list-style: none; padding: 0 0 0 6px; margin: 4px 0; }
.opts li { margin: 2px 0; }
.opt { color: #e8d39a; }
details.lazy > summary, details.conv > summary { cursor: pointer; padding: 2px 0; }
details.lazy .sub { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 6px; }
details.conv { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 4px; }
#mapTitle { min-width: 0; flex: 0 1 auto; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toggles { min-width: 300px; }

/* conversation graph overlay */
#gOverlay { position: fixed; inset: 0; background: #0e0f12; z-index: 20; display: flex; flex-direction: column; }
#gOverlay[hidden] { display: none; }
.gbar { display: flex; gap: 14px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.gbar #gHint { flex: 1; font-size: 12px; }
.gbar button { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; width: 30px; height: 28px; cursor: pointer; }
.legend i { display: inline-block; width: 22px; height: 0; border-top: 2px solid; vertical-align: middle; margin: 0 4px 0 10px; }
.legend .lo { border-color: #e8d39a; } .legend .lw { border-color: #ce93d8; border-top-style: dashed; } .legend .le { border-color: #8a8f99; }
#gBody { flex: 1; display: flex; min-height: 0; }
#gStage { flex: 1; overflow: hidden; cursor: grab; }
#gStage.dragging { cursor: grabbing; }
#gSvg { width: 100%; height: 100%; display: block; }
#gInfo { width: 420px; border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 12px 14px; }
.gn rect { fill: #23262c; stroke: #3a3e47; rx: 6; }
.gn.entry rect { fill: #2b2a22; stroke: #6b5d33; rx: 14; }
.gn.entry.shared rect { fill: #24232b; stroke: #4f4a66; }
.gn.sel rect { stroke: #ffd54f; stroke-width: 2.5; }
.gn.dim { opacity: .35; } .ge.dim { opacity: .12; }
.gn text { fill: #e6e6e6; font: 12px system-ui, "Segoe UI", sans-serif; }
.gn text.b { fill: #9aa0a8; font-size: 11px; }
.gn text.h { fill: #d4a24c; font-size: 11px; font-weight: 600; }
.gn { cursor: pointer; }
.ge path { fill: none; stroke-width: 1.6; }
.ge.option path { stroke: #e8d39a; } .ge.word path { stroke: #ce93d8; stroke-dasharray: 5 4; } .ge.word { opacity: .3; } .ge.word.hi { opacity: 1; } .ge.entry path { stroke: #8a8f99; }
.ge text { font: 11px system-ui, sans-serif; fill: #e8d39a; paint-order: stroke; stroke: #0b0c0e; stroke-width: 4px; }
.ge.word text { fill: #ce93d8; }
.ge.hi path { stroke-width: 3; } .ge.hi text { font-weight: 600; }
.gbtn { margin-left: 6px; font-size: 12px; }
.gn rect.hdr { fill: #3a3424; stroke: #6b5d33; } .gn rect.hdr.shared { fill: #2c2a38; stroke: #4f4a66; }
.timectl { display: flex; align-items: center; gap: 6px; }
.timectl input[type=range] { width: 140px; accent-color: var(--accent); }
.timectl input[type=range]:disabled { opacity: .35; }
#timeLabel { width: 40px; font-variant-numeric: tabular-nums; }
.timectl button { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; width: 28px; height: 26px; cursor: pointer; }
.timectl button:disabled { opacity: .35; }
.timectl label { color: var(--muted); display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
/* second toolbar row: time, animation, sound, zoom always visible */
#toolbar { row-gap: 6px; }
.timectl { flex-wrap: wrap; order: 3; width: 100%; }
.zoom { order: 2; }
.timectl button.sound { width: auto; padding: 0 8px; }
.timectl button.sound:disabled { opacity: .5; }
.v3d { position: absolute; inset: 0; z-index: 8; background: #000; }
.v3d canvas { width: 100%; height: 100%; display: block; cursor: grab; }
.v3dbar { position: absolute; left: 0; right: 0; top: 0; display: flex; gap: 12px; align-items: center; padding: 6px 10px;
  background: rgba(20,21,25,.85); font-size: 12px; }
.v3dbar .v3dinfo { margin-left: auto; font-variant-numeric: tabular-nums; }
.v3dbar button { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; width: 28px; height: 24px; cursor: pointer; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { background: var(--bg); color: var(--muted); border: 0; border-radius: 0; width: auto; height: 26px; padding: 0 10px; cursor: pointer; font-weight: 600; }
.seg button.on { background: #3a3424; color: var(--accent); }
.v3d { transition: none; }
#clockCtl { display: inline-flex; align-items: center; gap: 6px; margin-left: 6px; }
#clockCtl input { width: 150px; accent-color: #8ab4f8; }
#clockLabel { width: 40px; font-variant-numeric: tabular-nums; }
/* toolbar: row 1 title + zoom, row 2 category chips, row 3 time/animation/3D/sound; every row wraps,
   and the whole bar scrolls if it still does not fit */
#toolbar { flex-wrap: wrap; row-gap: 6px; max-height: 45vh; overflow-y: auto; }
#mapTitle { order: 0; flex: 1 1 200px; max-width: none; }
.zoom { order: 1; flex: 0 0 auto; }
.toggles { order: 2; flex: 1 1 100%; min-width: 0; }
.timectl { order: 3; flex: 1 1 100%; flex-wrap: wrap; row-gap: 6px; }
@media (max-width: 1400px) { body { grid-template-columns: 200px 1fr 320px; } }
@media (max-width: 1100px) { body { grid-template-columns: 170px 1fr 270px; } }
.timectl button.sound.onx { background: #3a3424; color: var(--accent); }
.timectl input.vol { width: 70px; accent-color: #9aa0a8; }
#evlog, #statePanel { position: absolute; left: 10px; bottom: 40px; width: 460px; max-height: 45%; overflow-y: auto; z-index: 6;
  background: rgba(20,21,25,.94); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
#statePanel { left: auto; right: 10px; width: 360px; }
#evlog[hidden], #statePanel[hidden] { display: none; }
.evhead { display: flex; gap: 8px; align-items: center; position: sticky; top: -6px; background: rgba(20,21,25,.98); padding: 2px 0; }
.evhead b { flex: 1; color: var(--accent); }
.evhead button, #statePanel button { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 5px; cursor: pointer; }
#evlog ol { list-style: none; margin: 4px 0 0; padding: 0; }
#evlog li { padding: 2px 0; border-top: 1px dotted var(--line); }
#evlog .t { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px; }
#evlog .kd { display: inline-block; min-width: 54px; color: #ce93d8; }
#stSwitches { display: flex; flex-wrap: wrap; gap: 4px 10px; }
#stSwitches label { color: var(--muted); cursor: pointer; } #stSwitches label.on { color: var(--accent); }
.runbtn { margin-left: 6px; font-size: 11px; background: #2b2a22; color: var(--accent); border: 1px solid #6b5d33; border-radius: 5px; cursor: pointer; }
#fadeLayer { position: absolute; inset: 0; pointer-events: none; background: #000; opacity: 0; z-index: 5; transition: none; }
#subtitle { position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%); max-width: 70%; z-index: 7; cursor: pointer;
  background: rgba(15,16,20,.92); border: 1px solid #6b5d33; border-radius: 8px; padding: 10px 14px; font-size: 14px; white-space: pre-wrap; }
#subtitle[hidden] { display: none; }
#subtitle .who { color: var(--accent); font-size: 12px; margin-bottom: 4px; } #subtitle .who:empty { display: none; }
#scriptBar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 7; display: flex; gap: 8px; align-items: center;
  background: rgba(20,21,25,.94); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-size: 12px; }
#scriptBar[hidden] { display: none; }
#scriptBar button { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 5px; cursor: pointer; }
.gn.unique rect { stroke: #d4a24c; stroke-width: 1.6; } .gn.shared rect { fill: #1e2026; stroke: #3a3e47; } .gn.shared text { opacity: .85; }
.gn.unique text.b:last-of-type { fill: #d4a24c; }
.gexp rect { fill: #3a3424; stroke: #d4a24c; cursor: pointer; } .gexp text { fill: #d4a24c; font: 600 11px system-ui; cursor: pointer; }
