:root {
  --bg: #0e1116;
  --bg-panel: #161b22;
  --bg-elev: #1d242d;
  --bg-input: #0b0e13;
  --border: #2a323c;
  --border-soft: #222a33;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --text-faint: #6b7785;
  --accent: #4f9cff;
  --accent-hover: #6cb0ff;
  --accent-2: #34d399;
  --danger: #f87171;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --sidebar-w: 360px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
#sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0 18px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#sidebar::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.sidebar-header {
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg-panel) 78%, transparent);
  padding: 18px 0 12px;
  z-index: 5;
}
.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sidebar-header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Quiet until you look for it: faint by default, accented on hover/focus. */
.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.icon-btn svg {
  width: 17px;
  height: 17px;
  display: block;
}
.icon-btn:hover {
  color: var(--accent);
  background: var(--bg-elev);
}
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  color: var(--accent);
}
.tagline {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.panel {
  border-top: 1px solid var(--border-soft);
  padding: 16px 0;
}
.panel:first-of-type { border-top: none; }

.panel-title {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-title-row .panel-title { margin: 0; }

.hint {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-faint);
  margin: 10px 0 0;
}

/* ---------- Model picker ---------- */
.model-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.model-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px 8px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.model-card:hover { border-color: #3a4756; }
.model-card:active { transform: translateY(1px); }
.model-card.is-active {
  border-color: var(--accent);
  background: #14233a;
  box-shadow: inset 0 0 0 1px var(--accent);
}
.model-card svg { width: 34px; height: 34px; display: block; }
.model-card .stroke { stroke: var(--text-dim); }
.model-card.is-active .stroke { stroke: var(--accent-hover); }
.model-card .fill { fill: var(--bg-input); }
.model-card .label {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-dim);
  line-height: 1.1;
}
.model-card.is-active .label { color: var(--text); }

/* ---------- Sliders ---------- */
.control {
  margin-bottom: 14px;
}
.control:last-child { margin-bottom: 0; }
.control-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.control-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}
.control-value {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-hover);
  font-variant-numeric: tabular-nums;
}
.control-num {
  /* Wide enough for the longest readout the app produces — inches at 3 dp ("0.248").
     At 4.5ch the trailing decimal was clipped, which is the one digit that distinguishes
     one test-plate hole from the next. */
  width: 5.5ch;
  padding: 1px 4px;
  text-align: right;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-hover);
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 4px;
  outline: none;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, background 0.15s;
  -moz-appearance: textfield;
}
.control-num::-webkit-outer-spin-button,
.control-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.control-num:hover { border-color: var(--border); }
.control-num:focus {
  border-color: var(--accent);
  background: #0b1522;
}
.control-unit {
  font-size: 11px;
  color: var(--text-faint);
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--bg-input);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0e1116;
  box-shadow: 0 0 0 1px var(--accent);
  transition: background 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { background: var(--accent-hover); }
input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0e1116;
  box-shadow: 0 0 0 1px var(--accent);
}

/* ---------- Unit toggle ---------- */
.unit-toggle {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.unit-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
}
.unit-btn.is-active {
  background: var(--accent);
  color: #04121f;
}

/* ---------- Profile editor ---------- */
#profile-editor-wrap {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  justify-content: center;
}
#profile-canvas {
  width: 100%;
  max-width: 280px;
  height: auto;
  touch-action: none;
  cursor: crosshair;
  display: block;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  color: var(--text);
  background: var(--bg-elev);
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04121f;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-elev); }
.btn-secondary:hover { border-color: #3a4756; }
.btn-ghost {
  background: transparent;
  width: 100%;
  margin-top: 10px;
  color: var(--text-dim);
}
.btn-ghost:hover { border-color: #3a4756; color: var(--text); }
/* Bore-tester toggle, lit up while the tester is on screen. */
.btn-ghost.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.is-hidden { display: none; }

.export-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.export-wide { grid-column: 1 / -1; }

.title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Sidebar-level toolbar: sits under the tagline and stays put whichever panels are on
   screen, so nothing has to be re-parented when the bore tester takes over. */
.sidebar-header .title-actions {
  margin-top: 12px;
  justify-content: flex-end;
}
.mini-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  cursor: pointer;
}
.mini-btn:hover { color: var(--text); border-color: #3a4756; }
.size-readout, #size-readout {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.sidebar-footer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
}

.colophon {
  margin: 0;
}

/* ---------- Toggle (checkbox styled as a switch) ---------- */
/* Sitting in a section header, the switch is the only thing on its row. */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex: none;
}

.control-toggle {
  margin-bottom: 14px;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}
/* The real checkbox stays focusable but invisible; .toggle-track is what you see. */
.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-track {
  position: relative;
  flex: none;
  width: 38px;
  height: 21px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.15s ease, background 0.15s ease;
}
.toggle-input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-input:checked + .toggle-track::after {
  transform: translateX(17px);
  background: #fff;
}
.toggle-input:focus-visible + .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Credits dialog ---------- */
.credits-dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 22px 24px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
.credits-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.credits-dialog h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.credits-sub {
  margin: 4px 0 16px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.credits-list {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}
.credits-list li {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
/* Name reads first; the role sits under it a step quieter. */
.credit-name {
  font-size: 13px;
  font-weight: 600;
}
.credit-role {
  font-size: 11.5px;
  color: var(--text-dim);
}
.credits-source {
  margin: 0 0 14px;
}
.credits-source a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-decoration: none;
}
.credits-source a:hover,
.credits-source a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}
.credits-source svg {
  width: 15px;
  height: 15px;
  flex: none;
}

/* The safety notice opens the legal block: quiet enough not to shout over the credits,
   a step brighter than the fine print below it because it is the part worth reading. */
.credits-disclaimer {
  margin: 0 0 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-dim);
}
.credits-disclaimer strong {
  font-weight: 600;
  color: var(--text);
}

.credits-legal {
  margin: 0 0 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 11px;
  line-height: 1.55;
  color: var(--text-faint);
}
.credits-legal a {
  color: inherit;
}
.credits-dialog .btn {
  width: 100%;
}

/* ---------- Print safety gate ---------- */
/* Wider than the credits and allowed to scroll: it carries a list, and on a phone in
   landscape the viewport is short. */
.print-dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
/* A step brighter than the credits' version of this text — here it is the point of the
   dialog, not the fine print under it. */
.print-warning {
  margin: 0 0 16px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-dim);
}
.print-warning strong {
  font-weight: 600;
  color: var(--text);
}
.print-subhead {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.print-list {
  margin: 0 0 18px;
  padding-left: 17px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-dim);
}
.print-list li { margin-bottom: 7px; }
.print-list li:last-child { margin-bottom: 0; }
.print-list strong {
  font-weight: 600;
  color: var(--text);
}
/* Any author `display` beats the UA stylesheet's [hidden] { display: none }, so a styled
   element with the hidden attribute stays on screen. Restate it once, globally, rather than
   remembering the trap at every call site. */
[hidden] { display: none !important; }

/* Side by side when both are there; the lone dismiss spans the row on its own. Overrides the
   full-width .credits-dialog .btn rule, which assumes a single Close. */
.print-actions {
  display: flex;
  gap: 8px;
}
.print-actions .btn { flex: 1; }
.print-dialog .btn { width: auto; }

/* STEP ships faceted, not analytic. Amber rather than red: it is a limitation to read before
   you rely on the file, not a safety warning like the print gate. */
.export-experimental {
  margin: 10px 0 0;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-left: 3px solid #d9a441;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-faint);
}
.export-experimental strong {
  font-weight: 600;
  color: var(--text-dim);
}

/* The standing notice under the export buttons. The modal fires once; this does not go away. */
.export-note {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-faint);
}
.linklike {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.linklike:hover { color: var(--accent-hover); }
.linklike:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- Viewport ---------- */
#viewport {
  position: relative;
  background: radial-gradient(circle at 50% 35%, #1a2230 0%, #0c0f14 70%);
  overflow: hidden;
}
#scene-canvas { display: block; width: 100%; height: 100%; }

#viewport-overlay {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
}
.chip {
  background: rgba(22, 27, 34, 0.85);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 13px;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: #3a4756; }
.chip.is-active { color: var(--accent-hover); border-color: var(--accent); }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
  pointer-events: none;
}
.loading.hidden { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 55vh;
  }
  #sidebar { order: 2; border-right: none; border-top: 1px solid var(--border); }
  #viewport { order: 1; }
}
