:root {
  --bg: #1d1f22;
  --panel: #26292d;
  --line: #3a3e44;
  --text: #e8e8e6;
  --muted: #9aa0a6;
  --accent: #2f9bff;
  --warn: #f0b429;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, sans-serif;
  display: flex; flex-direction: column;
}
button, input, select {
  font: inherit; color: var(--text); background: #33373c;
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px;
}
input:disabled { opacity: 0.5; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.on { border-color: var(--accent); background: #243447; }
button.primary { background: #1f6fc4; border-color: #2f86e0; color: #fff; }
button.primary:hover { background: #2a7fd8; }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* spinner arrows crowd the small number boxes; typing and arrow keys still work */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { white-space: nowrap; }
.group { display: flex; gap: 4px; align-items: center; }
.group button { padding: 5px 8px; font-size: 13px; }
.group > label { white-space: nowrap; }
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; padding: 3px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: #33373c; font-size: 16px; line-height: 1.4; user-select: none;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover, .menu[open] summary { border-color: var(--accent); }
.menu-items {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 2000; min-width: 190px;
  display: flex; flex-direction: column; padding: 4px; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.menu-items button { text-align: left; border-color: transparent; background: none; }
.menu-items button:hover { background: #33373c; }
.menu-items button.danger { color: #ff8a80; }
#search { position: relative; display: flex; gap: 6px; flex: 1; min-width: 260px; max-width: 520px; }
#q { flex: 1; min-width: 0; }
#results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 2000;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
}
#results li { padding: 6px 8px; border-radius: 4px; cursor: pointer; }
#results li:hover, #results li.active { background: #33373c; }
#results li.muted { cursor: default; }
.units { color: var(--muted); display: flex; gap: 6px; align-items: center; }
#panelToggle { margin-left: auto; }
#panelToggle[aria-pressed="false"] { border-color: var(--line); color: var(--muted); }
body.no-panel #panel { display: none; }

main { flex: 1; display: flex; min-height: 0; }
#tools {
  width: 168px; overflow-y: auto; padding: 8px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-content: start;
  border-right: 1px solid var(--line); background: var(--panel);
}
#tools .tool-group { grid-column: 1 / -1; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 8px 0 0; }
#tools button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; min-height: 52px;
}
#tools button[data-tool="select"] { grid-column: 1 / -1; flex-direction: row; justify-content: center; min-height: 38px; gap: 8px; }
#tools button[data-tool="select"] span { font-size: 13px; }
#tools .key {
  position: absolute; top: 2px; right: 3px; font-size: 9px; line-height: 1; padding: 2px 3px;
  color: var(--muted); background: none; border: 0; opacity: .8;
}
#tools button span { font-size: 11px; color: #b4b9bf; text-align: center; line-height: 1.15; }
#tools button.active { border-color: var(--accent); background: #243447; }
#tools button.active span { color: var(--text); }

#stage { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: #2b2d30; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 500; overflow: hidden; }
#overlay.hidden { visibility: hidden; }
#overlay g[data-id] * { pointer-events: visiblePainted; cursor: move; }
#overlay.placing g[data-id] *, #overlay.adjusting g[data-id] * { pointer-events: none; }
#overlay:not(.placing):not(.adjusting) #els g[data-id]:hover { filter: drop-shadow(0 0 2px #2f9bff) drop-shadow(0 0 1px #2f9bff); }
#overlay .handle { pointer-events: all; cursor: grab; }
#overlay .port { pointer-events: none; }
#overlay.adjusting [data-bd] { pointer-events: all; cursor: move; }
#welcome {
  position: absolute; z-index: 600; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 32px)); padding: 20px 22px; border-radius: 10px;
  background: rgba(30, 32, 36, .94); border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
#welcome h1 { font-size: 18px; margin: 0 0 8px; }
#welcome p { margin: 0 0 10px; }
#hint, #toast {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 600;
  background: rgba(20, 22, 25, .9); padding: 6px 12px; border-radius: 6px; pointer-events: none;
  max-width: 80%; text-align: center;
}
#hint { bottom: 24px; }
#imgStatus {
  position: absolute; top: 12px; right: 12px; z-index: 600; pointer-events: none;
  background: rgba(20, 22, 25, .9); padding: 4px 10px; border-radius: 12px; font-size: 12px; color: var(--muted);
}
#imgStatus.error { color: var(--warn); border: 1px solid var(--warn); }
.iconbtn { line-height: 0; padding: 5px 7px !important; }
.iconbtn svg { width: 16px; height: 16px; }
#hint:empty { display: none; }
#toast { top: 16px; border: 1px solid var(--accent); display: flex; gap: 12px; align-items: center; pointer-events: auto; }
#toast[hidden] { display: none; }
#toast button { padding: 2px 10px; }

#panel { width: 310px; overflow-y: auto; border-left: 1px solid var(--line); background: var(--panel); }
#panel section, #panel details.sec { padding: 12px; border-bottom: 1px solid var(--line); }
#panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; margin: 0 0 8px; color: var(--muted); }
#panel details.sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; user-select: none; }
#panel details.sec > summary::-webkit-details-marker { display: none; }
#panel details.sec > summary::before {
  content: ''; width: 6px; height: 6px; margin: 0 2px 8px 1px; flex: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s;
}
#panel details.sec[open] > summary::before { transform: rotate(45deg); }
#panel details.sec:not([open]) > summary h2 { margin-bottom: 0; }
#panel details.sec:not([open]) > summary::before { margin-bottom: 0; }
#panel details.sec > summary:hover h2 { color: var(--text); }
.props-head { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.props-head h2 { flex: 1; margin: 0 !important; font-size: 15px !important; text-transform: none !important; letter-spacing: 0 !important; color: var(--text) !important; }
.props-head button { padding: 3px 6px; line-height: 0; }
.props-head button svg { width: 16px; height: 16px; }
.props-help { margin: 0 0 12px; }
.ellist { list-style: none; margin: 0 0 10px; padding: 0; max-height: 260px; overflow-y: auto; }
.ellist li button {
  width: 100%; display: flex; gap: 8px; align-items: center; text-align: left;
  background: none; border-color: transparent; padding: 4px 6px; font-size: 13px;
}
.ellist li button:hover { background: #33373c; }
.ellist li button svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
#ask { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 16px; width: min(360px, 90vw); }
#ask::backdrop { background: rgba(0,0,0,.45); }
#ask form { display: flex; flex-direction: column; gap: 10px; }
#ask .row { display: flex; flex-direction: row-reverse; gap: 8px; justify-content: flex-start; }
#panel h3 { font-size: 13px; margin: 14px 0 6px; }
#panel label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; }
#panel label.check { flex-direction: row; align-items: center; gap: 6px; }
#panel .row { display: flex; gap: 6px; margin-bottom: 8px; }
#panel .row button { flex: 1; }
#panel select { max-width: 100%; }
.field { display: flex; gap: 6px; align-items: center; }
.field input[type=range] { flex: 1; padding: 0; min-width: 0; }
.field input[type=number] { width: 72px; }

.legrow { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; padding: 8px; margin-bottom: 6px; background: #2d3035; border-radius: 6px; }
.legrow strong { grid-column: 1 / -1; font-size: 12px; }
.legrow label { margin: 0 !important; }
.legrow input[type=number] { width: 100%; }
.lanes-head { display: flex; align-items: center; gap: 4px; margin: 4px 0 6px; }
.lanes-head h3 { flex: 1; margin: 0 !important; }
.lanes-head button { padding: 2px 8px; font-size: 12px; }
.lanetotal { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.lanetotal strong { color: var(--text); font-weight: 600; }
.lanecaption { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-bottom: 3px; }
.lanestrip {
  position: relative; display: flex; height: 84px; padding: 3px; gap: 0;
  background: #17191b; border-radius: 6px; touch-action: none; user-select: none;
}
.lanestrip.resizing, .lanestrip.resizing * { cursor: col-resize !important; }
.lb {
  position: relative; flex: 1 1 0; min-width: 14px; padding: 4px 0 3px; border: 0; border-radius: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 2px;
  font-size: 10.5px; line-height: 1; cursor: grab; overflow: visible;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35);
}
.lb:first-child { border-radius: 4px 0 0 4px; }
.lb:last-child { border-radius: 0 4px 4px 0; }
.lb:hover { filter: brightness(1.12); }
.lb.sel { box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 1px var(--accent); z-index: 1; }
.lb:focus-visible { outline: 2px solid #fff; outline-offset: -3px; z-index: 2; }
.lb.zero { opacity: .55; background-image: repeating-linear-gradient(45deg, transparent 0 3px, rgba(0,0,0,.35) 3px 5px) !important; }
.lb.dragging { opacity: .85; z-index: 3; cursor: grabbing; box-shadow: 0 4px 14px rgba(0,0,0,.6); }
.lb .ll { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; overflow: hidden; flex: 1; min-height: 0; font-weight: 500; }
.lb .la { font-size: 12px; font-weight: 700; }
.lb .lw { font-size: 10px; opacity: .9; white-space: nowrap; }
.lb .grip { position: absolute; top: 0; bottom: 0; right: -5px; width: 10px; z-index: 4; cursor: col-resize; }
.lb .grip::after { content: ''; position: absolute; top: 30%; bottom: 30%; left: 4px; width: 2px; border-radius: 1px; background: rgba(255,255,255,.0); }
.lb .grip:hover::after, .lanestrip.resizing .grip::after { background: #fff; }
.lanemark { position: absolute; top: -2px; bottom: -2px; width: 4px; border-radius: 2px; background: var(--accent); pointer-events: none; z-index: 5; }
.striphelp { margin: 5px 0 8px; }
.lanehint { margin: 0 0 8px; }
.lanecard { padding: 8px; margin-bottom: 8px; background: #2d3035; border-radius: 6px; border: 1px solid var(--accent); }
.lanecard-top { display: flex; gap: 4px; align-items: center; }
.lanecard-top select { flex: 1; min-width: 0; padding: 3px 4px; font-size: 12.5px; }
.lanecard-top button { padding: 3px 6px; font-size: 11px; min-width: 24px; line-height: 1; }
.lanecard-top button svg { width: 14px; height: 14px; }
.lanecard-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 8px; }
#panel label.lanenum { margin: 0; font-size: 11.5px; color: var(--muted); gap: 2px; }
.lanenum span { color: var(--text); font-size: 12px; white-space: nowrap; }
.lanenum input { width: 56px; padding: 3px 5px; font-size: 12.5px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 4px 8px; font-size: 12px; background: #33373c; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: #243447; color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.seg.wide { display: flex; margin-bottom: 6px; }
.seg.wide button { flex: 1; }
.lane-add select { flex: 1; min-width: 0; font-size: 12.5px; padding: 4px 6px; }
.xsd { margin: 4px 0 6px; font-size: 12.5px; }
.xsd summary { cursor: pointer; color: var(--muted); margin-bottom: 6px; }
.xsd summary:hover { color: var(--text); }
.swatch { width: 10px; height: 22px; border-radius: 2px; flex: none; border: 1px solid #000; }
.linkfix { font-size: 12px; color: var(--warn); display: flex; gap: 6px; align-items: center; margin: -2px 0 8px; }
.linkfix button { padding: 2px 6px; font-size: 12px; white-space: nowrap; }
#xs svg { display: block; max-width: 100%; height: auto; margin-bottom: 6px; border-radius: 4px; }
.linkrow { font-size: 12px; display: flex; gap: 6px; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.linkrow button { padding: 2px 6px; font-size: 12px; }
.linkrow { padding: 3px 4px; border-radius: 4px; }
.linkrow:hover { background: #2d3035; }
.linkbtns { display: flex; gap: 4px; flex: none; }
.linksub { margin: 8px 0 2px; }
.linkfix { padding: 6px 8px; border: 1px solid var(--warn); border-radius: 6px; flex-direction: column; align-items: stretch !important; margin: 2px 0 8px !important; }
.linkfix button { align-self: flex-start; }
.lanes-head button.on { border-color: var(--accent); background: #243447; }

.warn { border: 1px solid var(--warn); border-radius: 6px; padding: 8px; margin: 10px 0; font-size: 12.5px; color: var(--text); }
.warn strong { color: var(--warn); }
.warn ul { margin: 4px 0; padding-left: 18px; }
p.warn { color: var(--warn); }

table.qty { width: 100%; border-collapse: collapse; font-size: 12px; }
table.qty th { text-align: left; color: var(--muted); font-weight: normal; }
table.qty td { padding: 3px 2px; vertical-align: middle; }
table.qty input { width: 58px; padding: 2px 4px; font-size: 12px; }
table.qty .total td { border-top: 1px solid var(--line); font-weight: 600; padding-top: 6px; }

.muted { color: var(--muted); }

/* smaller windows: tighter header and narrower side columns */
@media (max-width: 1180px) {
  header { gap: 8px; }
  #search { min-width: 160px; }
  .group > label, .units > span { display: none; }
  #panel { width: 280px; }
}
@media (max-width: 960px) {
  .brand { display: none; }
  #tools { width: 116px; grid-template-columns: 1fr 1fr; padding: 6px; }
  #tools button { min-height: 40px; padding: 6px 0; }
  #tools button span, #tools .key, #tools .tool-group { display: none; }
  #tools .tool-group { display: block; grid-column: 1 / -1; height: 1px; background: var(--line); margin: 4px 0; font-size: 0; }
  #panel { width: 260px; }
}
.small { font-size: 12px; }
kbd { background: #33373c; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; font-size: 11px; }
button.danger:hover { border-color: #e0574f; }
#overlay.splitting #els g[data-id] * { cursor: crosshair; }
