/* ── Utility ── */
.no-spin::-webkit-inner-spin-button,
.no-spin::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Segoe UI, Arial, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f0f2f5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  background: #0078d4;
  color: #fff;
  padding: 10px 24px;
  flex-shrink: 0;
}
.header-inner        { display: flex; align-items: center; gap: 16px; }
.logo                { height: 28px; width: auto; display: block; }
.header-title-block  { display: flex; flex-direction: column; gap: 1px; }
.header-title        { font-size: 14px; opacity: 0.88; }
.header-version      { font-size: 10px; opacity: 0.60; letter-spacing: 0.3px; }

/* ── Main layout ── */
main {
  display: flex;
  flex: 1;
  gap: 0;
  overflow: hidden;
  min-height: 0;
}

/* ── Controls panel ── */
.controls-panel {
  width: 280px;
  min-width: 240px;
  background: #fff;
  border-right: 1px solid #dde3ea;
  overflow-y: auto;
  padding: 12px;
  flex-shrink: 0;
}

.card {
  background: #f7f9fc;
  border: 1px solid #dde3ea;
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.card h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #0078d4;
  margin-bottom: 10px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #444;
  margin-top: 8px;
  margin-bottom: 3px;
}

select, input[type="number"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #c8d0db;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  color: #1a1a1a;
  appearance: none;
}
select:focus, input[type="number"]:focus {
  outline: none;
  border-color: #0078d4;
  box-shadow: 0 0 0 2px rgba(0,120,212,0.15);
}

.info-row {
  font-size: 11px;
  color: #666;
  margin-top: 6px;
}

.preset-info {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
  height: 14px;
}

.toggle-row {
  margin-top: 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.toggle-row input { width: auto; }

.hidden { display: none !important; }

/* Download card */
.download-card { text-align: center; }

.btn-download {
  width: 100%;
  padding: 9px;
  background: #0078d4;
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: background 0.15s;
}
.btn-download:hover { background: #005fa3; }
.btn-download-p2 {
  width: 100%;
  padding: 9px;
  background: #761516;
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: background 0.15s;
}
.btn-download-p2:hover { background: #5a0f10; }

/* ── Download popup menu ── */
.dl-wrap {
  position: relative;
  margin-bottom: 6px;
}
.dl-wrap:last-child { margin-bottom: 0; }

.dl-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #c8d0db;
  border-radius: 5px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.13);
  z-index: 200;
  overflow: hidden;
}

.dl-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  background: none;
  border: none;
  border-bottom: 1px solid #f0f2f5;
  cursor: pointer;
  color: #1a1a1a;
  text-align: left;
}
.dl-item:last-child { border-bottom: none; }
.dl-item:hover:not(.dl-item-soon) { background: #eef3f9; color: #0078d4; }

.dl-item-soon {
  color: #aaa;
  cursor: default;
}

.dl-soon-tag {
  font-size: 10px;
  background: #f3f4f6;
  color: #9ca3af;
  padding: 1px 6px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  font-weight: 400;
}

/* ── Preview panel ── */
.preview-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 8px;
  border-bottom: 1px solid #dde3ea;
  background: #f7f9fc;
  font-size: 13px;
  font-weight: 600;
  color: #333;
  flex-shrink: 0;
}

.preview-tab {
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #c8d0db;
  border-radius: 4px;
  background: #f0f2f5;
  color: #555;
  cursor: pointer;
}
.preview-tab.active {
  background: #0078d4;
  color: #fff;
  border-color: #0078d4;
}
.preview-tab:hover:not(.active) { background: #e2e8f0; }

.preview-box {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
  padding: 12px;
  background: #fafbfc;
  position: relative;
}

#preview-img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  display: block;
}

.preview-box-3d {
  padding: 0 !important;
}

#three-canvas {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  align-self: stretch;
  display: block;
  touch-action: none;
}

.preview-box svg {
  max-width: 100%;
  max-height: 100%;
}

.preview-placeholder {
  color: #bbb;
  font-size: 14px;
}

.preview-footer {
  padding: 6px 16px;
  font-size: 11px;
  color: #888;
  border-top: 1px solid #eee;
  background: #f7f9fc;
  flex-shrink: 0;
  height: 28px;
}

/* ── Footer ── */
footer {
  background: #1a1a2e;
  color: #aaa;
  font-size: 11px;
  text-align: center;
  padding: 8px;
  flex-shrink: 0;
  height: 36px;
}
footer a { color: #6ab3e8; text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Drive bar ── */
.drive-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 6px 16px;
  background: #eef3f9;
  border-bottom: 1px solid #d0dae6;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.drive-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  cursor: pointer;
}
.drive-toggle input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
  accent-color: #0078d4;
}

.drive-spacing {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #444;
}
.drive-spacing label {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  color: #444;
  white-space: nowrap;
}
.drive-spacing input[type="number"] {
  width: 90px;
  padding: 4px 6px;
  font-size: 12px;
}
#gear_ratio { width: 75px; }

.belt-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #b0bec5;
  border-radius: 6px;
  padding: 4px 10px;
}

.ratio-arrows {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ratio-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 16px;
  padding: 0;
  font-size: 9px;
  line-height: 1;
  background: #e8edf3;
  border: 1px solid #c8d0db;
  border-radius: 3px;
  cursor: pointer;
  color: #444;
}
.ratio-btn:hover { background: #d0daea; border-color: #0078d4; color: #0078d4; }
.lock-ratio-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #475569;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.min-dist-btn {
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  background: #f1f3f5;
  border: 1px solid #c8d0db;
  border-radius: 4px;
  cursor: pointer;
  color: #555;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.min-dist-btn:hover { background: #e2e8f0; border-color: #0078d4; color: #0078d4; }
.min-dist-btn.min-dist-warn {
  background: #fee2e2;
  border-color: #f87171;
  color: #b91c1c;
}
.min-dist-btn.min-dist-warn:hover {
  background: #fecaca;
}

.reset-btn {
  padding: 3px 10px;
  font-size: 12px;
  background: #f1f3f5;
  border: 1px solid #c8d0db;
  border-radius: 4px;
  cursor: pointer;
  color: #555;
  white-space: nowrap;
}
.reset-btn:hover { background: #fee2e2; border-color: #f87171; color: #b91c1c; }
.import-btn {
  padding: 3px 10px;
  font-size: 12px;
  background: #eff6ff;
  border: 1px solid #93c5fd;
  border-radius: 4px;
  cursor: pointer;
  color: #1d4ed8;
  white-space: nowrap;
}
.import-btn:hover { background: #dbeafe; border-color: #3b82f6; }
.drive-info-btn {
  padding: 3px 10px;
  font-size: 12px;
  background: #eef5fc;
  border: 1px solid #90b8db;
  border-radius: 4px;
  cursor: pointer;
  color: #0078d4;
  white-space: nowrap;
}
.drive-info-btn:hover { background: #0078d4; border-color: #0078d4; color: #fff; }
.drive-bar-right {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
}
.drive-note {
  font-size: 11px;
  color: #888;
  white-space: nowrap;
}

/* ── Panel title ── */
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: #0078d4;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 2px 10px;
  border-bottom: 2px solid #0078d4;
  margin-bottom: 10px;
}

/* ── Belt lock info card ── */
.belt-lock-info {
  font-size: 12px;
  color: #333;
  padding: 8px 12px;
  background: #eef3f9;
  border-color: #c2d4e8;
}

/* ── Dual layout: main becomes 3-column ── */
main.dual {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
}
main.dual .controls-panel {
  border-right: 1px solid #dde3ea;
}
main.dual #panel2 {
  border-left: 1px solid #dde3ea;
  border-right: none;
}

/* ── Pulley 2 accent colour (amber/orange) ── */
.panel-title-p2 {
  color: #761516 !important;
  border-bottom-color: #761516 !important;
}

/* ── Snap buttons container (inside preview-header) ── */
.view-snap-bar {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
}
.view-snap-btn {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255,255,255,0.82);
  border: 1px solid #bbb;
  border-radius: 4px;
  cursor: pointer;
  color: #333;
  white-space: nowrap;
  backdrop-filter: blur(2px);
  transition: background 0.12s;
}
.view-snap-btn:hover {
  background: rgba(0,120,212,0.15);
  border-color: #0078d4;
  color: #0078d4;
}

/* ── Help button ── */
.help-btn-row {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  padding: 6px 2px 2px;
  background: linear-gradient(to bottom, transparent, #fff 40%);
}

.btn-help {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid #c8d0db;
  background: #f0f4f9;
  color: #0078d4;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.btn-help:hover {
  background: #0078d4;
  border-color: #0078d4;
  color: #fff;
}
/* Out-of-range number input highlight */
input.input-out-of-range {
  outline: 2px solid #dc2626 !important;
  background: #fff0f0 !important;
}

/* Help icon in drive bar */
.drive-help {
  display: flex;
  align-items: center;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  main { flex-direction: column; height: auto; }
  main.dual { grid-template-columns: 1fr; }
  .controls-panel { width: 100%; border-right: none; border-bottom: 1px solid #dde3ea; }
  .preview-panel { min-height: 360px; }
  .drive-bar { gap: 10px; }
}

/* ── Feature Build mode visibility ── */
body.feature-build .fb-2d { display: none !important; }
body:not(.feature-build) .fb-3d { display: none !important; }

/* ── Hub section collapsible ── */
.hub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #0078d4;
  margin-bottom: 0;
}
.hub-header:hover { color: #005fa3; }
.hub-arrow {
  font-size: 10px;
  transition: transform 0.2s;
  color: #0078d4;
}
.hub-arrow.open { transform: rotate(180deg); }
.hub-body {
  display: none;
  margin-top: 10px;
}
.hub-body.open { display: block; }
.hub-info {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}
.hub-warn {
  font-size: 11px;
  color: #b91c1c;
  background: #fee2e2;
  border-radius: 4px;
  padding: 4px 8px;
  margin-top: 6px;
}

/* Loading Overlay Spinner */
#loading-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(3px);
  z-index: 9999;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 500;
}
.spinner {
  width: 64px;
  height: 64px;
  border: 6px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 20px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Bug report button (preview header) ─────────────────────────────────── */
.btn-bug-report {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid #e6b84a;
  background: #fffbeb;
  color: #b45309;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-bug-report:hover {
  background: #f59e0b;
  border-color: #d97706;
  color: #fff;
}

/* ── Bug report modal ────────────────────────────────────────────────────── */
#bug-report-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1100;
  align-items: center;
  justify-content: center;
}
#bug-report-box {
  background: #fff;
  border-radius: 8px;
  width: min(520px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
  overflow: hidden;
}
.bug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 12px;
  border-bottom: 1px solid #dde3ea;
  background: #fffbeb;
  flex-shrink: 0;
}
.bug-title {
  font-size: 18px;
  font-weight: 700;
  color: #92400e;
}
.bug-feature-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  cursor: pointer;
  margin-left: auto;
  margin-right: 10px;
  user-select: none;
}
.bug-feature-toggle input[type="checkbox"] {
  cursor: pointer;
  accent-color: #2563eb;
  width: 14px;
  height: 14px;
}
.bug-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #555;
  line-height: 1;
  padding: 0 4px;
}
.bug-close:hover { color: #000; }
.bug-body {
  overflow-y: auto;
  padding: 18px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bug-label {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  display: block;
}
.bug-optional {
  font-weight: 400;
  color: #888;
  font-size: 12px;
}
.bug-textarea {
  width: 100%;
  border: 1px solid #c8d6e2;
  border-radius: 4px;
  padding: 7px 9px;
  font-size: 13px;
  resize: vertical;
  font-family: inherit;
  box-sizing: border-box;
  color: #1a1a1a;
}
.bug-textarea:focus { outline: none; border-color: #0078d4; }
.bug-input {
  width: 100%;
  border: 1px solid #c8d6e2;
  border-radius: 4px;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
  color: #1a1a1a;
}
.bug-input:focus { outline: none; border-color: #0078d4; }
.bug-status {
  font-size: 12px;
  min-height: 18px;
  color: #555;
}
.bug-status-ok    { color: #16a34a; font-weight: 600; }
.bug-status-error { color: #dc2626; font-weight: 600; }
.bug-status-warn  { color: #b45309; font-weight: 600; white-space: pre-line; }
.bug-philosophy {
  font-size: 12px;
  color: #666;
  background: #f8fafc;
  border-top: 1px solid #dde3ea;
  padding: 10px 20px;
  line-height: 1.5;
}
.bug-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid #dde3ea;
  flex-shrink: 0;
}
.bug-btn {
  padding: 6px 20px;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  border: 1.5px solid transparent;
  font-weight: 600;
}
.bug-btn-cancel {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #475569;
}
.bug-btn-cancel:hover { background: #e2e8f0; }
.bug-btn-submit {
  background: #0078d4;
  border-color: #0078d4;
  color: #fff;
}
.bug-btn-submit:hover:not(:disabled) { background: #005fa3; border-color: #005fa3; }
.bug-btn-submit:disabled { opacity: 0.55; cursor: default; }

/* ── Import design modal ─────────────────────────────────────────────────── */
#import-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1100;
  align-items: center;
  justify-content: center;
}
#import-box {
  background: #fff;
  border-radius: 8px;
  width: min(480px, 96vw);
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
  overflow: hidden;
}
.import-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 12px;
  border-bottom: 1px solid #dde3ea;
  background: #eff6ff;
  flex-shrink: 0;
}
.import-title {
  font-size: 17px;
  font-weight: 700;
  color: #1e3a5f;
}
.import-info {
  padding: 16px 20px 12px;
  border-bottom: 1px solid #e8edf3;
  background: #f8fafc;
}
.import-info p {
  font-size: 13px;
  color: #374151;
  line-height: 1.55;
  margin: 0;
}
.import-body {
  padding: 16px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.import-file-input {
  width: 100%;
  font-size: 13px;
  font-family: inherit;
  padding: 6px 4px;
  border: 1px solid #c8d6e2;
  border-radius: 4px;
  background: #fff;
  box-sizing: border-box;
  cursor: pointer;
}
.import-file-input:focus { outline: none; border-color: #0078d4; }

/* ── Bug report info button & panel ─────────────────────────────────────── */
.bug-info-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid #c8d0db;
  background: #f0f4f9;
  color: #0078d4;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
  margin-left: auto;
  margin-right: 6px;
}
.bug-info-btn:hover {
  background: #0078d4;
  border-color: #0078d4;
  color: #fff;
}
.bug-info-panel {
  background: #eef5fc;
  border-left: 3px solid #0078d4;
  border-radius: 0 4px 4px 0;
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 13px;
  color: #1a3a5c;
  line-height: 1.5;
}
.bug-info-panel ul {
  margin: 6px 0 4px 18px;
}
.bug-info-panel li {
  margin-bottom: 3px;
}
.bug-info-panel p {
  margin-top: 6px;
  font-style: italic;
  color: #4a6080;
}

/* ── Footer build info ───────────────────────────────────────────────────── */
.footer-build { color: #666; }
