:root {
  --bg: #f6f4f0;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b7078;
  --line: #e4e0d8;
  --accent: #2f6b55;
  --accent-ink: #ffffff;
  --chip: #f1eee8;
  --ok: #2f8f5b;
  --warn: #c98712;
  --bad: #d23f3f;
  --shadow: 0 6px 24px rgba(30, 30, 30, .12);
  --top: 56px;
  --side: 320px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  color: var(--ink); background: var(--bg); overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }

/* top bar */
.top {
  position: fixed; inset: 0 0 auto 0; height: var(--top); z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 16px; margin-right: 6px; white-space: nowrap; }
.spacer { flex: 1; }
.seg { display: flex; background: var(--chip); border-radius: 9px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); white-space: nowrap;
}
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.toggles { display: flex; gap: 4px; }
.toggles button {
  border: 1px solid var(--line); background: var(--panel); padding: 5px 9px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 13px;
}
.toggles button.on { background: #e7f1ec; border-color: #b9d6c8; color: var(--accent); font-weight: 600; }
select#preset { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 8px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); padding: 6px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:hover, .toggles button:hover { border-color: #cfc9be; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; margin-top: 10px; }
.icon { border: 0; background: transparent; cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 6px; color: var(--muted); }
.icon:hover { background: var(--chip); }
.menu { display: none; }

/* sidebar */
.side {
  position: fixed; top: var(--top); left: 0; bottom: 0; width: var(--side); overflow-y: auto; z-index: 10;
  background: var(--panel); border-right: 1px solid var(--line); padding: 4px 0 30px;
}
.panel { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel h3 { margin: 0 0 6px; font-size: 15px; }
.panel h3.fold { cursor: pointer; display: flex; align-items: center; gap: 6px; user-select: none; margin: 0; }
.panel h3.fold::after { content: "▾"; margin-left: auto; color: var(--muted); font-size: 12px; transition: transform .15s; }
.panel.closed h3.fold::after { transform: rotate(-90deg); }
.panel h3.fold + .body { margin-top: 10px; }
.panel.closed .body { display: none; }
.count { background: var(--chip); color: var(--muted); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
p { margin: 6px 0; }
kbd { background: var(--chip); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12px; }
.facts { width: 100%; border-collapse: collapse; margin-top: 8px; }
.facts td { padding: 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
.facts td:first-child { color: var(--muted); padding-right: 10px; width: 55%; }
.notes { padding-left: 18px; margin: 10px 0 0; }
.notes li { margin-bottom: 10px; }
.notes li::marker { color: var(--accent); font-weight: 700; }
.notes p { color: var(--muted); margin: 2px 0 0; font-size: 13px; }
.btnrow { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.btnrow .btn { flex: 1; }
.cat h4 { margin: 10px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.cat:first-child h4 { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: 1px solid var(--line); background: var(--chip); border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 12.5px; }
.chip:hover { background: #e9e4da; }
.presets { margin-bottom: 12px; }
.fin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.fin-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.fin-grid input[type=color] { width: 100%; height: 28px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: var(--panel); }
.fin-grid select { border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: var(--panel); }
#objList { list-style: none; padding: 0; margin: 10px 0 0; max-height: 340px; overflow: auto; }
#objList li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
#objList li span { color: var(--muted); }
#objList li:hover { background: var(--chip); }
#objList li.sel { background: #fdf0d8; }
.btn:disabled { opacity: .5; cursor: default; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin-left: 4px; }
.badge.ok { background: #e3f3ea; color: var(--ok); }
.badge.warn { background: #fbf0dc; color: var(--warn); }
.vsave { display: flex; gap: 6px; margin-top: 8px; }
.vsave input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; background: #fff; }
.vlist { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow: auto; }
.vlist li { display: flex; gap: 9px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 9px; }
.vlist li.cur { border-color: #b9d6c8; background: #f2f8f5; }
.vlist li.empty { border: 0; padding: 0; }
.vlist img, .vlist .nothumb { width: 84px; height: 47px; object-fit: cover; border-radius: 6px; cursor: pointer; flex: none; background: var(--chip); }
.vmeta { display: flex; flex-direction: column; min-width: 0; }
.vmeta b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vact { display: flex; gap: 10px; margin-top: 1px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: 12px; font-weight: 600; }
.link.danger { color: var(--bad); }
#triangle .row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }
#triangle .total { font-weight: 600; border-bottom: 0; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }

/* viewport */
#viewport { position: fixed; top: var(--top); left: var(--side); right: 0; bottom: 0; }
#viewport canvas { display: block; touch-action: none; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.tag { font-size: 11.5px; padding: 2px 6px; border-radius: 5px; white-space: nowrap; pointer-events: none; }
.tag.name { background: rgba(255,255,255,.88); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.tag.dim { background: #fff; font-weight: 700; border: 1.5px solid currentColor; }
.tag.dim.ok { color: var(--ok); } .tag.dim.warn { color: var(--warn); } .tag.dim.bad { color: var(--bad); }
.tag.tri { color: #6246ea; border-color: #6246ea; }
.hint {
  position: absolute; left: 12px; bottom: 12px; background: rgba(255,255,255,.9); padding: 5px 10px; border-radius: 7px;
  color: var(--muted); font-size: 12px; pointer-events: none; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.warnpill { position: absolute; left: 12px; top: 12px; background: #fdecec; color: var(--bad); border: 1px solid #f3c2c2; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.toast {
  position: absolute; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0; transition: .25s;
  background: #22262b; color: #fff; padding: 8px 14px; border-radius: 9px; font-size: 13px; pointer-events: none; max-width: 90%;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* inspector */
.inspector {
  position: absolute; top: 12px; right: 12px; width: 290px; max-height: calc(100% - 24px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px;
}
.ins-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.ins-type { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ins-name { border: 0; border-bottom: 1px dashed transparent; font-weight: 600; font-size: 15px; padding: 2px 0; width: 210px; background: transparent; }
.ins-name:not(:disabled):hover, .ins-name:focus { border-bottom-color: var(--line); outline: none; }
.ins-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.ins-grid label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.unit { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 7px; padding: 0 8px 0 0; background: #fff; }
.unit input { border: 0; width: 100%; padding: 5px 8px; background: transparent; min-width: 0; outline: none; }
.unit:has(input:disabled) { background: var(--chip); }
.inline { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.ins-clear { margin-top: 12px; }
.ins-clear h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.ins-clear span { display: inline-block; margin: 0 6px 4px 0; padding: 2px 8px; border-radius: 999px; background: var(--chip); font-weight: 600; font-size: 12.5px; }

/* photos */
.modal { position: fixed; inset: 0; background: rgba(20,22,25,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.sheet { background: var(--panel); border-radius: 14px; max-width: 1100px; width: 100%; max-height: 100%; overflow: auto; padding: 16px 18px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h3 { margin: 0; }
.sheet .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 12px; }
.sheet figure { margin: 0; }
.sheet img { width: 100%; border-radius: 10px; display: block; aspect-ratio: 16/9; object-fit: cover; background: var(--chip); }
.sheet figcaption { margin-top: 6px; }

[hidden] { display: none !important; }

@media (max-width: 1280px) {
  .toggles button { padding: 5px 6px; font-size: 12px; }
  #shot { display: none; }
}
@media (max-width: 980px) {
  :root { --side: 0px; --top: 104px; }
  .top { flex-wrap: wrap; height: auto; min-height: var(--top); padding: 8px 12px; row-gap: 6px; }
  .menu { display: block; }
  .spacer { display: none; }
  .toggles { overflow-x: auto; max-width: 100%; }
  .side { width: min(340px, 88vw); transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.side-open .side { transform: none; }
  .inspector { width: auto; left: 12px; top: auto; bottom: 48px; max-height: 50%; }
}
