*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #1a1a2e; --panel: #16213e; --accent: #0f3460;
  --red: #e94560; --text: #e0e0e0; --muted: #8892a4;
  --halfA: #4da3ff; --halfB: #ffa24d;
}
body { background: var(--bg); color: var(--text); font-family: system-ui, sans-serif;
       font-size: 14px; height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
nav { background: var(--panel); border-bottom: 1px solid var(--accent); padding: 0 16px;
      height: 44px; display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
nav a { color: var(--red); text-decoration: none; font-weight: 600; font-size: 14px; }
nav a:hover { text-decoration: underline; }
.nav-title { font-weight: 700; font-size: 16px; }
.nav-status { margin-left: auto; font-size: 11px; color: var(--muted); }
.main { display: flex; flex: 1; overflow: hidden; }
.sidebar { width: 290px; background: var(--panel); border-right: 1px solid var(--accent);
           overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; flex-shrink: 0; }
.canvas-area { flex: 1; position: relative; overflow: hidden; }
h3 { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 6px; }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
select { width: 100%; padding: 7px 10px; border: 1px solid var(--accent); border-radius: 6px;
         background: var(--bg); color: var(--text); font-size: 14px; outline: none; transition: border-color 0.2s; }
select:focus { border-color: var(--red); }
select option { background: var(--bg); color: var(--text); }

/* Sliders */
.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row input[type="range"] {
  flex: 1; -webkit-appearance: none; height: 4px; border-radius: 2px;
  background: #0f3460; outline: none; cursor: pointer;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--red); cursor: pointer;
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; border: none;
  background: var(--red); cursor: pointer;
}
.slider-val { min-width: 44px; text-align: right; color: var(--red); font-size: 13px; font-weight: 600; cursor: text; }
.slider-val-input {
  width: 54px; background: rgba(233,69,96,0.1); border: none; border-radius: 4px;
  color: var(--red); font-size: 13px; font-weight: 600; text-align: right;
  outline: none; padding: 1px 4px; font-family: inherit; -moz-appearance: textfield;
}
.slider-val-input::-webkit-inner-spin-button,
.slider-val-input::-webkit-outer-spin-button { display: none; }

/* STL drop zone */
.drop-zone {
  border: 2px dashed var(--accent); border-radius: 8px; padding: 22px 14px;
  text-align: center; cursor: pointer; transition: all 0.2s;
  color: var(--muted); font-size: 12px; line-height: 1.5;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--red); color: var(--red); }
.drop-zone.has-file { border-color: var(--red); border-style: solid; color: var(--text); }
.drop-zone-icon { font-size: 22px; display: block; margin-bottom: 6px; }
#stlInput { display: none; }

/* Model info */
.model-stats { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.model-stats .row { display: flex; justify-content: space-between; gap: 8px; }
.model-stats .row b { color: var(--text); font-weight: 600; }

/* Radio / segmented groups */
.radio-group { display: flex; gap: 4px; flex-wrap: wrap; }
.radio-group label {
  flex: 1; min-width: 56px; text-align: center; padding: 6px 6px; border: 1px solid var(--accent);
  border-radius: 6px; cursor: pointer; font-size: 11px; font-weight: 500;
  text-transform: none; color: var(--muted); transition: all 0.2s; margin-bottom: 0;
}
.radio-group input[type="radio"] { display: none; }
.radio-group input[type="radio"]:checked + label {
  background: var(--red); border-color: var(--red); color: #fff;
}

.toggle-row { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.toggle-row input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--red); cursor: pointer; }
.toggle-row label { margin: 0; cursor: pointer; color: var(--text); }

/* Buttons */
.btn { display: block; width: 100%; padding: 10px; border: none; border-radius: 8px;
       cursor: pointer; font-size: 13px; font-weight: 600; transition: all 0.15s; font-family: inherit; }
.btn + .btn { margin-top: 6px; }

/* Two buttons on one line. The adjacency rule above cannot see past the
   wrapper, so spacing around the row has to be declared here. */
.btn-row { display: flex; gap: 6px; margin-top: 6px; }
.btn-row > .btn { margin-top: 0; }
.btn-row + .btn,
.btn + .btn-row { margin-top: 6px; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: #ff5a73; }
.btn-secondary { background: var(--accent); color: var(--text); }
.btn-secondary:hover { background: #1a4a80; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Export block stays reachable: the sidebar is taller than most windows. */
.action-bar {
  position: sticky; bottom: -16px; margin-top: auto;
  padding: 12px 0 16px; background: var(--panel);
  border-top: 1px solid var(--accent); z-index: 2;
}
.separator { height: 1px; background: var(--accent); }
.notice { font-size: 10px; color: var(--muted); line-height: 1.5; }
.author-link { color: #8892a4; text-decoration: underline; transition: color 0.15s; }
.author-link:hover { color: #e94560; }

/* FDM report */
.fdm-report {
  margin-top: 10px; display: flex; flex-direction: column; gap: 3px;
  font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--accent); padding-top: 8px;
}
.fdm-report .row { display: flex; justify-content: space-between; gap: 8px; }
.fdm-report .row b { color: var(--text); font-weight: 600; }
.fdm-report .row b.ok { color: #4ec98a; }
.fdm-report .row b.bad { color: #f0c14b; }

/* Warning block (undercuts etc.) */
.warn {
  border: 1px solid rgba(184,137,10,0.5); background: rgba(184,137,10,0.12);
  color: #f0c14b; border-radius: 6px; padding: 8px 10px; font-size: 11px; line-height: 1.5;
  display: none;
}
.warn.visible { display: block; }

/* Half colour legend */
.legend { display: flex; gap: 10px; font-size: 11px; color: var(--muted); }
.legend .item { display: flex; align-items: center; gap: 5px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; }

/* Language toggle */
.lang-toggle { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.lang-toggle span {
  font-size: 12px; color: #556; cursor: pointer; padding: 2px 6px;
  border-radius: 4px; transition: all 0.2s; user-select: none;
}
.lang-toggle span.active { color: var(--red); font-weight: 700; }
.lang-toggle span:hover { color: var(--red); }

/* View tools */
#view-tools {
  position: absolute; top: 14px; right: 14px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 5; user-select: none;
}
.view-btn {
  border: 1px solid #0f3460; background: rgba(18,33,62,0.88); color: #c8d4e6;
  border-radius: 8px; height: 30px; min-width: 40px; padding: 0 10px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.4px; cursor: pointer; transition: all 0.2s;
  font-family: inherit;
}
.view-btn:hover { border-color: #e94560; color: #fff; }
.view-btn.active { border-color: #e94560; background: rgba(233,69,96,0.18); color: #e94560; }
#viewGrid { display: grid; grid-template-columns: repeat(3, 40px); gap: 6px; justify-content: end; }
#viewGrid [data-view="bottom"] { grid-column: 2; }
#fitViewBtn { width: 132px; }
#screenshotBtn { min-width: 40px; font-size: 14px; }

/* Gizmo hint */
#gizmo-hint {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  background: rgba(18,33,62,0.88); border: 1px solid var(--accent);
  border-radius: 8px; padding: 7px 11px; font-size: 11px; color: var(--muted);
  line-height: 1.5; max-width: 260px; pointer-events: none;
}
#gizmo-hint b { color: var(--text); }
#seam-readout { color: var(--red); font-weight: 600; }

/* Overlays */
#loading-overlay {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; background: rgba(26,26,46,0.75); z-index: 12;
  pointer-events: none; color: var(--red); font-size: 13px; text-align: center;
}
#loading-overlay.visible { display: flex; }
#loading-overlay::before {
  content: ''; width: 32px; height: 32px;
  border: 3px solid rgba(233,69,96,0.3); border-top-color: var(--red);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
#regen-overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(26,26,46,0.45); z-index: 11; pointer-events: none;
}
#regen-overlay.active { display: flex; }
#regen-overlay::after {
  content: ''; width: 28px; height: 28px;
  border: 3px solid rgba(233,69,96,0.3); border-top-color: var(--red);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#error-msg {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #c73e54; color: #fff; padding: 8px 16px; border-radius: 6px;
  font-size: 13px; display: none; z-index: 20; max-width: 80%; text-align: center;
}
#export-notice {
  position: absolute; bottom: 56px; left: 50%; transform: translateX(-50%);
  background: #b8890a; color: #fff; padding: 8px 32px 8px 14px; border-radius: 6px;
  font-size: 12px; max-width: 360px; text-align: center; z-index: 20;
  white-space: normal; line-height: 1.4;
}
#export-notice-close {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0;
}

/* Slicer settings card (shown after export) */
#slicer-card {
  position: absolute; bottom: 20px; right: 20px; z-index: 21;
  background: var(--panel); border: 1px solid var(--accent);
  border-radius: 10px; padding: 12px 32px 12px 14px;
  font-size: 12px; color: var(--text); min-width: 230px;
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
}
#slicer-card > b { display: block; margin-bottom: 8px; font-size: 12px; }
#slicer-card .sc-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 3px 0; color: var(--muted);
}
#slicer-card .sc-row b { color: var(--text); font-weight: 600; }
#slicer-card .sc-hint {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--accent);
  font-size: 10px; color: var(--muted); line-height: 1.5;
}
.sc-close {
  position: absolute; right: 8px; top: 8px;
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0;
}
.sc-close:hover { color: var(--red); }

/* Empty state in viewport */
#empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  color: var(--muted); font-size: 13px; text-align: center; pointer-events: none;
  padding: 24px;
}
#empty-state .big { font-size: 40px; opacity: 0.5; }
#empty-state.hidden { display: none; }
