:root {
  --bg: #f4f3f0;
  --scene: #eceae6;
  --panel: #ffffffee;
  --line: #d9d6cf;
  --text: #1f1f1d;
  --muted: #6d6a63;
  --accent: #d86b12;
  --accent-bg: #fbe9d8;
  --error: #c62828;
  --warn: #a86400;
  --ok: #2e7d32;
  --radius: 8px;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --scene: #2a2a2c;
    --panel: #232325ee;
    --line: #3a3a3d;
    --text: #ececea;
    --muted: #a19e97;
    --accent: #f08a3c;
    --accent-bg: #4a2f1a;
    --error: #ff6b6b;
    --warn: #f0b24a;
    --ok: #7bc47f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }

#bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--bg); z-index: 3;
}
#bar .group { display: flex; align-items: center; gap: 4px; }
#bar .spacer { flex: 1; }

button, select, summary {
  font: inherit; color: var(--text); background: transparent;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 3px 9px; cursor: pointer; min-height: 28px;
}
button:hover, summary:hover, select:hover { border-color: var(--muted); }
button.icon { width: 28px; padding: 0; font-size: 18px; line-height: 1; }
select { max-width: 220px; }

.seg { gap: 0 !important; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.seg button.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); position: relative; z-index: 1; }

.badge { font-variant-numeric: tabular-nums; }
.badge .e { color: var(--error); font-weight: 600; }
.badge .w { color: var(--warn); font-weight: 600; }
.badge .ok { color: var(--ok); }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 200px; max-height: 60vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px;
  box-shadow: 0 6px 20px #0002; backdrop-filter: blur(6px);
}
.menu-body label { display: flex; gap: 6px; align-items: center; padding: 3px 0; white-space: nowrap; cursor: pointer; }
.menu-body hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

#viewport { position: relative; flex: 1; min-height: 0; background: var(--scene); touch-action: none; }
#viewport canvas { display: block; }

#banner, #hint, #status {
  position: absolute; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px; z-index: 2;
}
#banner { top: 12px; border-color: var(--error); color: var(--error); }
#hint { top: 40%; color: var(--muted); text-align: center; }
#status { bottom: 12px; color: var(--muted); font-size: 12px; }

.panel {
  position: absolute; z-index: 4; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 20px #0002; backdrop-filter: blur(6px); overflow: auto;
}
#info { right: 12px; bottom: 12px; width: 340px; max-height: 60vh; padding: 10px 12px; }
#issues { right: 12px; top: 12px; width: 460px; max-height: 50vh; padding: 6px 0; }

.panel h3 { margin: 0 24px 6px 0; font-size: 14px; word-break: break-all; }
.panel .close { position: absolute; right: 6px; top: 6px; border: 0; min-height: 0; padding: 2px 6px; color: var(--muted); }
.panel dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 0; }
.panel dt { color: var(--muted); }
.panel dd { margin: 0; font-variant-numeric: tabular-nums; }
.panel .sub { color: var(--muted); font-size: 12px; }

#issues .item { padding: 4px 12px; cursor: pointer; display: flex; gap: 6px; }
#issues .item:hover { background: var(--accent-bg); }
#issues .lvl-error { color: var(--error); }
#issues .lvl-warn { color: var(--warn); }
#issues .lvl-info { color: var(--muted); }

#changes-badge.has-changes { border-color: var(--accent); color: var(--accent); font-weight: 600; }
#changes { left: 12px; top: 12px; width: 440px; max-height: 55vh; padding: 8px 0 6px; }
#changes .changes-head { padding: 0 32px 6px 12px; display: grid; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
#changes .changes-head select { max-width: 280px; }
#changes .row { display: flex; align-items: center; gap: 6px; }
#changes .row .spacer { flex: 1; }
#changes button:disabled { opacity: 0.4; cursor: default; }
#changes .item { padding: 3px 12px; cursor: pointer; display: flex; gap: 6px; word-break: break-all; }
#changes .item:hover { background: var(--accent-bg); }
#changes .op { font-weight: 700; width: 12px; flex: none; }
#changes .op-added { color: #2e9e4f; }
#changes .op-changed { color: #e08a1a; }
#changes .op-removed { color: #d23b3b; }
#changes .op-renamed { color: var(--muted); }
#changes .empty { padding: 6px 12px; }

#tools button.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
#tools .icon { font-size: 14px; }

#issues .issues-head { padding: 0 32px 6px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
#issues .filters button { font-size: 12px; min-height: 24px; padding: 1px 8px; }
#issues .rule-head { padding: 6px 12px 2px; color: var(--muted); font-size: 12px; }
#issues .item.active { background: var(--accent-bg); }

#section { left: 50%; transform: translateX(-50%); bottom: 12px; width: min(520px, calc(100% - 24px)); padding: 8px 12px; display: grid; gap: 6px; }
#section .row { display: flex; align-items: center; gap: 8px; padding-right: 20px; }
#section .value { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: auto; }
#section input[type=range] { width: 100%; }

.panel button.link { border: 0; padding: 4px 0 0; min-height: 0; color: var(--accent); cursor: pointer; }

.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
.label { position: absolute; left: 0; top: 0; white-space: nowrap; font: 12px/1.25 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-variant-numeric: tabular-nums; }
.label.dim, .label.measure { background: #1f6febe6; color: #fff; border-radius: 4px; padding: 1px 5px; text-align: center; }
.label.measure small { display: block; opacity: 0.85; font-size: 10px; }
.label.snap { width: 14px; height: 14px; border-radius: 50%; background: rgba(46, 204, 113, 0.45); border: 2px solid rgba(30, 150, 80, 0.85); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6); }
.label.snap[data-kind=edge] { width: 11px; height: 11px; background: rgba(46, 204, 113, 0.3); }
.label.snap[data-kind=face] { width: 6px; height: 6px; border-width: 1px; background: rgba(46, 204, 113, 0.55); box-shadow: none; }
#issues .rule { color: var(--muted); }

@media (max-width: 640px) {
  #bar { padding: 6px 8px; gap: 6px; }
  #views button { padding: 3px 6px; }
  #info, #issues, #changes { left: 8px; right: 8px; width: auto; }
  #changes { top: auto; bottom: 8px; max-height: 50vh; }
  #info { bottom: 8px; max-height: 45vh; }
  #issues { top: auto; bottom: 8px; max-height: 45vh; }
}
