/* ---------- vimplant2 web — dark theme ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
  --bg:       #000000;
  --surface:  #0e0e10;
  --surface2: #18181c;
  --border:   #2a2a30;
  --text:     #e0e0e4;
  --text2:    #888890;
  --accent:   #4a9eff;
  --radius:   6px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

/* ---------- Layout ---------- */
#app   { display: flex; flex-direction: column; height: 100vh; }
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: baseline; gap: 12px; }
.header-right { text-align: right; display: flex; flex-direction: column; gap: 2px; }
#header h1  { font-size: 16px; font-weight: 600; letter-spacing: -0.3px; }
.subtitle   { font-size: 12px; color: var(--text2); }
.credit     { font-size: 11px; color: var(--text2); }
.credit a   { color: var(--text); text-decoration: none; }
.credit a:hover { color: var(--accent); }
.credit-sub { font-size: 10px; color: var(--text2); }
.credit-sub a { color: var(--text); text-decoration: none; }
.credit-sub a:hover { color: var(--accent); }

#main {
  display: flex; flex: 1; min-height: 0;
}

/* ---------- Controls panel ---------- */
#controls {
  width: 360px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
}
.ctrl-section     { margin-bottom: 16px; }
.ctrl-section h3  {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text2); margin-bottom: 8px;
}
.ctrl-section label {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px; cursor: pointer;
}
.ctrl-section label span:first-child {
  min-width: 60px; font-size: 12px; color: var(--text2);
}
.ctrl-section select {
  flex: 1; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 6px; font-size: 12px; outline: none;
}
.ctrl-section input[type="number"] {
  flex: 1; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 6px; font-size: 12px; outline: none;
  min-width: 0;
}
.ctrl-section select:focus { border-color: var(--accent); }
.ctrl-section input[type="number"]:focus { border-color: var(--accent); }

/* range input */
.ctrl-section input[type="range"] {
  flex: 1; height: 4px; -webkit-appearance: none; appearance: none;
  background: var(--surface2); border-radius: 2px; outline: none;
}
.ctrl-section input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}
.ctrl-section output {
  min-width: 28px; font-size: 11px; text-align: right; color: var(--text2);
}

.implant-config-panel {
  margin: 8px 0 10px;
  padding: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.implant-config-panel[hidden] {
  display: none !important;
}

.ctrl-note {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text2);
}

.number-stepper {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22px;
  align-items: stretch;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.number-stepper:focus-within {
  border-color: var(--accent);
}

.number-stepper input[type="number"] {
  border: 0;
  border-radius: 0;
  appearance: textfield;
  min-width: 0;
}

.number-stepper input[type="number"]::-webkit-outer-spin-button,
.number-stepper input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stepper-buttons {
  display: grid;
  grid-template-rows: 1fr 1fr;
  background: #000000;
  border-left: 1px solid var(--border);
}

.stepper-btn {
  appearance: none;
  border: 0;
  background: #000000;
  color: var(--accent);
  cursor: pointer;
  font-size: 9px;
  line-height: 1;
  padding: 0;
}

.stepper-btn + .stepper-btn {
  border-top: 1px solid var(--border);
}

.stepper-btn:hover {
  background: #08172a;
}

.stepper-btn:active {
  background: #0d2240;
}

/* area checkboxes */
.area-toggle { display: flex; align-items: center; gap: 6px; }
.swatch {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 2px; flex-shrink: 0;
}
.area-toggle input[type="checkbox"] {
  accent-color: var(--accent);
}

.stats-section #stats {
  font-size: 11px; line-height: 1.6; color: #ffffff;
  white-space: pre-line;
}
#infoMeta {
  margin-top: 10px;
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--text2);
}
#infoMeta a {
  color: var(--text);
  text-decoration: none;
}
#infoMeta a:hover {
  color: var(--accent);
}
#pickedInfo {
  font-size: 11px; line-height: 1.6; color: var(--text2);
  white-space: pre-line;
  min-height: 64px;
}

#implantListStatus,
#implantListHint {
  font-size: 11px;
  color: var(--text2);
  margin-top: 8px;
}

#implantList {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.implant-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.implant-row.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(74, 158, 255, 0.2);
}

.implant-row.hidden {
  opacity: 0.65;
}

.implant-select,
.implant-vis {
  background: transparent;
  color: var(--text);
  border: 0;
  cursor: pointer;
  font-size: 11px;
}

.implant-select {
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.implant-vis {
  color: var(--text2);
}

.implant-select:hover,
.implant-vis:hover {
  color: var(--accent);
}

.implant-meta {
  font-size: 10px;
  color: var(--text2);
  white-space: nowrap;
}

/* buttons */
.btn-row { margin-top: 8px; }
.btn-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.ctrl-btn {
  width: 100%; padding: 6px;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-size: 11px;
}
.ctrl-btn:hover { border-color: var(--accent); color: var(--accent); }
.ctrl-btn-label {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
  margin-bottom: 0;
}
.ctrl-btn:disabled {
  opacity: 0.45;
  cursor: default;
  color: var(--text2);
}
.hidden-input {
  position: absolute;
  width: 0; height: 0;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* ---------- 3D Viewport ---------- */
#viewport {
  flex: 1; position: relative; min-width: 0;
  background: var(--bg);
}
#canvas3d { width: 100%; height: 100%; display: block; }

/* colorbar */
#colorbar {
  position: absolute; bottom: 16px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.55); border-radius: 20px;
  padding: 6px 16px;
  font-size: 11px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
#colorbar.visible { opacity: 1; }
#colorbar .bar {
  width: 180px; height: 8px; border-radius: 4px;
}
#colorbar .label { color: var(--text2); }

/* loading overlay */
#loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  background: var(--bg);
  z-index: 10;
  transition: opacity 0.4s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading span { font-size: 12px; color: var(--text2); }

/* ---------- Polar panel ---------- */
#polar-panel {
  width: 484px; flex-shrink: 0;
  background: #000000;
  border-left: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
  overflow: hidden;
}
#polarCanvas {
  width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  display: block;
  image-rendering: auto;
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  #main { flex-direction: column; }
  #controls {
    width: 100%; height: auto;
    border-right: none; border-bottom: 1px solid var(--border);
    display: flex; flex-wrap: wrap; gap: 8px;
    padding: 8px 12px;
  }
  .ctrl-section { margin-bottom: 0; }
  #polar-panel {
    width: 100%; height: 330px;
    border-left: none; border-top: 1px solid var(--border);
  }
}
