:root {
  --bg: #14171c;
  --panel: #1e232b;
  --panel2: #262c36;
  --line: #39414e;
  --text: #dde3ec;
  --dim: #8a94a6;
  --accent: #4da3ff;
  --accent2: #63d68a;
  --danger: #ff6b6b;
  --tap: 52px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100dvh; }

#topbar, #toolbar {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); padding: 6px 10px; z-index: 5;
  overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
#topbar::-webkit-scrollbar, #toolbar::-webkit-scrollbar { display: none; }
#topbar > *, #toolbar > * { flex-shrink: 0; }
#topbar { padding-top: calc(6px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
#toolbar { padding-bottom: calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); justify-content: center; justify-content: safe center; }
.spacer { flex: 1; }
.divider { width: 1px; height: 30px; background: var(--line); margin: 0 4px; }

#doc-name { color: var(--dim); font-weight: 600; max-width: 30vw; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

button {
  color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; font-size: 17px; cursor: pointer;
  min-width: 44px; min-height: 44px; touch-action: manipulation;
}
button:active { background: #313a47; }
button.hidden { display: none; }
.tb { min-width: 44px; }
.tb.danger, button.danger { color: var(--danger); }
.tb.accent, button.accent { color: #0b1420; background: var(--accent); border-color: var(--accent); font-weight: 700; }

#mode-switch { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg { border: 0; border-radius: 0; min-width: 64px; background: var(--panel); color: var(--dim); }
.seg.active { background: var(--accent); color: #0b1420; font-weight: 700; }

#toolbar .tool { min-width: var(--tap); min-height: var(--tap); font-size: 20px; }
#toolbar .tool.active { border-color: var(--accent); color: var(--accent); background: #20304a; }
#toolbar .tool.accent { font-size: 15px; }
#toolbar .tool.toggle.on { border-color: var(--accent2); color: var(--accent2); background: #1e3a2a; }
#btn-arcseg, #btn-done, #btn-fit { font-size: 14px !important; }

#stage { position: relative; flex: 1; overflow: hidden; background: var(--bg); }
#c2d, #c3d { position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; display: block; }
#c3d.hidden, #c2d.hidden { display: none; }

#chips { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.chip {
  position: absolute; transform: translate(-50%, -50%);
  background: rgba(30, 41, 56, 0.92); border: 1px solid var(--accent);
  color: var(--accent); border-radius: 14px; padding: 6px 12px;
  font-size: 14px; font-weight: 600; pointer-events: auto; cursor: pointer;
  white-space: nowrap;
}
.chip.pad { border-color: var(--accent2); color: var(--accent2); }

#hint {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 25, 33, 0.85); color: var(--dim); border-radius: 8px;
  padding: 5px 12px; font-size: 13px; pointer-events: none; white-space: nowrap;
}
#hint:empty { display: none; }

#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 8; }
#sheet-backdrop.hidden { display: none; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  max-height: 70dvh; display: flex; flex-direction: column; gap: 10px;
}
.sheet.hidden { display: none; }
.sheet-head { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.sheet-foot { display: flex; gap: 8px; }
.sheet-foot .tb { flex: 1; font-size: 14px; }

#np-value { margin-left: auto; font-size: 22px; color: var(--accent); min-width: 90px; text-align: right; }
#np-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#np-grid button { min-height: 56px; font-size: 20px; }
#np-grid .wide { grid-column: span 2; }

#design-list, #ops-list { list-style: none; overflow-y: auto; flex: 1; }
#design-list li, #ops-list li {
  padding: 12px 10px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; gap: 10px; align-items: baseline;
}
#design-list li.sel, #ops-list li.sel { background: #20304a; border-radius: 8px; }
#design-list li .when, #ops-list li .kind { color: var(--dim); font-size: 12px; margin-left: auto; }
#ops-list li .active-mark { color: var(--accent2); font-weight: 700; }

#btn-face-sketch {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #0b1420; border-color: var(--accent);
  font-weight: 700; font-size: 15px; padding: 0 18px; z-index: 4;
}
#btn-fit-3d {
  position: absolute; bottom: 18px; right: 14px; z-index: 4;
  font-size: 15px; padding: 0 16px;
}

#toast {
  position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); z-index: 20;
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  transition: opacity 0.25s; white-space: nowrap;
}
#toast.hidden { opacity: 0; pointer-events: none; }
