:root {
  --bg: #0f1418;
  --bg-2: #161c22;
  --bg-3: #1e252c;
  --line: #2a333c;
  --line-2: #3a4753;
  --text: #d8e0e8;
  --text-dim: #8d99a5;
  --text-faint: #5d6772;
  --accent: #f8a948;
  --accent-2: #4ec9d0;
  --danger: #ff6b6b;
  --good: #6acb6e;
  --panel-w: 320px;
}

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

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button, input, select { font: inherit; color: inherit; }

/* topbar */
.topbar {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  font-size: 22px;
  color: var(--accent);
  font-weight: 700;
  line-height: 1;
  transform: translateY(2px);
}
.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
}
.brand-ver {
  font-size: 11px;
  color: var(--accent);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  padding: 2px 7px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: rgba(248, 169, 72, 0.08);
  letter-spacing: 0.3px;
  align-self: center;
}
.status {
  font-size: 12px;
  color: var(--text-dim);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* layout */
.layout {
  display: flex;
  height: calc(100vh - 44px);
  height: calc(100dvh - 44px);
}

.panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.viewer {
  flex: 1;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}
.viewer canvas { display: block; width: 100%; height: 100%; }
.viewer-overlay {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-faint);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: rgba(15, 20, 24, 0.7);
  backdrop-filter: blur(6px);
  padding: 6px 12px;
  border-radius: 4px;
  pointer-events: none;
}

/* blocks */
.block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.block-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  font-weight: 600;
}

/* inputs */
input[type="number"], input[type="text"], select {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text);
  width: 100%;
  outline: none;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
  border-color: var(--accent);
}
select { cursor: pointer; }

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  outline: none;
  border: 1px solid var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.xyz-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.xyz-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.xyz-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.row-inline { display: flex; gap: 8px; align-items: flex-end; }
.row-inline > .grow { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--text-dim); }
.rangeval {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text);
  text-align: right;
  margin-top: 2px;
}

/* buttons */
.btn, .btn-sm {
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
}
.btn-sm { padding: 6px 10px; font-size: 11px; }
.btn:hover, .btn-sm:hover { background: var(--line); border-color: var(--accent); }
.btn:disabled, .btn-sm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--bg-3);
  border-color: var(--line);
}
.btn.primary {
  background: var(--accent);
  color: #1a1208;
  border-color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.5px;
}
.btn.primary:hover:not(:disabled) { background: #ffb95a; }
.btn.primary:disabled { background: var(--bg-3); color: var(--text-faint); border-color: var(--line); }
.full { width: 100%; }

.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  font-size: inherit;
}

/* file drop */
.filedrop {
  border: 1px dashed var(--line-2);
  border-radius: 6px;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  background: var(--bg-3);
}
.filedrop:hover { border-color: var(--accent); }
.filedrop.drag { border-color: var(--accent); background: rgba(248, 169, 72, 0.08); }
.filedrop-icon { font-size: 22px; color: var(--text-faint); margin-bottom: 4px; }
.filedrop-text { font-size: 12px; color: var(--text-dim); }

.model-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  padding: 8px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.model-info > div { display: flex; justify-content: space-between; }
.model-info span:first-child { color: var(--text-dim); }

/* notes */
.note {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.4;
  font-style: italic;
}

/* progress */
[hidden] { display: none !important; }
.progress { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.progress-bar {
  height: 6px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s;
}
.progress-text {
  font-size: 11px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text-dim);
  text-align: center;
}

/* results */
.results-info {
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
  padding: 8px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  line-height: 1.5;
}

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
.toast.err { border-color: var(--danger); color: var(--danger); }
.toast.ok { border-color: var(--good); }

/* mobile */
@media (max-width: 720px) {
  :root { --panel-w: 100%; }
  .layout { flex-direction: column; }
  .panel {
    width: 100%;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .viewer { min-height: 50vh; }
  .status { display: none; }
}

/* version pill clickable affordance */
.brand-ver {
  cursor: pointer;
  transition: background 0.12s, transform 0.12s;
}
.brand-ver:hover { background: rgba(248, 169, 72, 0.18); }
.brand-ver:active { transform: scale(0.96); }
.brand-ver:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* update banner */
.update-banner {
  position: fixed;
  top: 44px;
  left: 0;
  right: 0;
  z-index: 90;
  background: var(--accent);
  color: #1a1208;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  animation: bannerSlide 0.25s ease-out;
}
@keyframes bannerSlide {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}
.update-banner-text { flex: 1; }
.update-banner-text strong { font-weight: 700; }
.update-banner-btn {
  background: #1a1208;
  color: var(--accent);
  border: none;
  padding: 5px 12px;
  border-radius: 3px;
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.4px;
}
.update-banner-btn:hover { background: #2a1f10; }
.update-banner-dismiss {
  background: transparent;
  border: none;
  color: #1a1208;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  opacity: 0.7;
}
.update-banner-dismiss:hover { opacity: 1; }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  width: min(560px, calc(100% - 32px));
  max-height: calc(100vh - 60px);
  max-height: calc(100dvh - 60px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.5);
  animation: modalIn 0.18s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text);
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 3px;
}
.modal-close:hover { color: var(--text); background: var(--bg-3); }
.modal-body {
  overflow-y: auto;
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* changelog entries */
.cl-entry {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.cl-entry:last-child { border-bottom: none; padding-bottom: 0; }
.cl-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.cl-version {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.cl-date {
  font-size: 11px;
  color: var(--text-faint);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.cl-new-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  background: var(--accent);
  color: #1a1208;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}
.cl-notes {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cl-notes li {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
  padding-left: 14px;
  position: relative;
}
.cl-notes li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: var(--accent);
  font-weight: 700;
}

/* mesh status indicator */
.mesh-status {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.mesh-status.ok { color: var(--good); }
.mesh-status.warn { color: var(--accent); }

/* repair button warn state */
#repairBtn.warn {
  border-color: var(--accent);
  color: var(--accent);
}
#repairBtn.warn:hover {
  background: rgba(248, 169, 72, 0.1);
}

/* repair modal */
.repair-intro {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg-3);
  border-left: 2px solid var(--accent-2);
  border-radius: 3px;
}
.repair-status {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  padding: 8px 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 3px;
}
.repair-status.ok { border-color: var(--good); color: var(--good); }
.repair-status.warn { border-color: var(--accent); color: var(--accent); }

.repair-estimate {
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  padding-top: 4px;
}
.repair-estimate span { color: var(--text); font-weight: 600; }

.repair-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--bg-3);
  border: 1px solid var(--good);
  border-radius: 4px;
}
.repair-result-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.repair-result-text > div {
  display: flex;
  justify-content: space-between;
}
.repair-result-text > div > span:first-child { color: var(--text-dim); }

.repair-actions {
  margin-top: 4px;
}
