:root {
  --bg: #eef1f4; --surface: rgba(255,255,255,.94); --surface-solid: #fff; --text: #1d2329; --muted: #5f6b76;
  --border: #d5dbe1; --accent: #d9661f; --accent-ink: #fff; --btn: #f3f5f7; --btn-hover: #e6eaee;
  --dim: #1565c0; --dim-bg: rgba(255,255,255,.88); --shadow: 0 6px 24px rgba(20,30,40,.14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191d; --surface: rgba(28,33,38,.94); --surface-solid: #1c2126; --text: #e6eaee; --muted: #9aa6b1;
    --border: #333c45; --btn: #262d34; --btn-hover: #313a43; --dim: #7fb5ff; --dim-bg: rgba(20,24,28,.85);
    --shadow: 0 6px 24px rgba(0,0,0,.45); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; touch-action: none; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; display: flex; align-items: center; gap: 14px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 10; backdrop-filter: blur(6px);
}
#topbar h1 { font-size: 16px; margin: 0; white-space: nowrap; }
.keyfigs { display: flex; gap: 16px; overflow-x: auto; scrollbar-width: none; color: var(--muted); font-size: 13px; }
.keyfigs b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.keyfigs span { white-space: nowrap; }
.icon { display: none; }

#panel {
  position: fixed; top: 64px; left: 12px; bottom: 12px; width: 280px; overflow-y: auto; z-index: 9;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px 14px 14px;
  box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
#panel section { border-bottom: 1px solid var(--border); padding: 10px 0; }
#panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.btngrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
button, select {
  font: inherit; color: var(--text); background: var(--btn); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; cursor: pointer;
}
button:hover { background: var(--btn-hover); }
button.active { outline: 2px solid var(--accent); outline-offset: -2px; }
button.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.wide { width: 100%; margin-top: 8px; }
.row { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.row select { margin-left: auto; }
#clipPos, #buildStep { width: 100%; margin-top: 6px; accent-color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border); flex: none; }

#info, #detail {
  position: fixed; right: 12px; z-index: 9; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 14px 16px; backdrop-filter: blur(6px);
}
#info { bottom: 12px; width: 320px; }
#detail { top: 64px; width: 400px; max-height: calc(100% - 76px); overflow-y: auto; }
#info h3, #detail h3 { margin: 0 24px 6px 0; font-size: 15px; }
#info dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0 0; }
#info dt { color: var(--muted); }
#info dd { margin: 0; font-variant-numeric: tabular-nums; }
#detail ol { padding-left: 20px; margin: 8px 0; }
#detail li { margin-bottom: 6px; }
.close { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; font-size: 20px; line-height: 1; padding: 4px 8px; }

dialog#modal {
  width: min(960px, calc(100% - 32px)); max-height: calc(100% - 48px); border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface-solid); color: var(--text); padding: 20px 22px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10,15,20,.45); }
#modalBody h2 { margin: 0 0 10px; font-size: 18px; }
#modalBody h3 { margin: 18px 0 6px; font-size: 15px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num { text-align: right; white-space: nowrap; }
.formula { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--btn); border-radius: 6px; padding: 8px 10px; margin: 6px 0; overflow-x: auto; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: zoom-in; }
.gallery figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.warn { border-left: 3px solid var(--accent); padding: 6px 10px; background: var(--btn); border-radius: 0 6px 6px 0; margin: 10px 0; }

/* etiketter i 3D */
.dim, .note {
  font: 600 12px/1 system-ui, sans-serif; color: var(--dim); background: var(--dim-bg); padding: 3px 6px;
  border-radius: 5px; border: 1px solid color-mix(in srgb, var(--dim) 35%, transparent); white-space: nowrap; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.dim.small { font-size: 11px; font-weight: 500; }
.note { color: var(--text); border-color: var(--border); font-weight: 500; }
.note.accent { color: #fff; background: var(--accent); border-color: var(--accent); }
.note.angle { color: var(--dim); }
.note.boundary { color: #fff; background: #d32f2f; border-color: #d32f2f; }
.note.north { color: #fff; background: #c62828; border-color: #c62828; font-size: 14px; }

@media (max-width: 760px) {
  .icon { display: inline-block; }
  #topbar { gap: 10px; }
  #topbar h1 { font-size: 15px; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh; border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform .2s; }
  body.menu-open #panel { transform: none; }
  #info { left: 12px; right: 12px; width: auto; }
  #detail { left: 12px; right: 12px; width: auto; top: auto; bottom: 12px; max-height: 50vh; }
}
