:root {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: rgba(255, 255, 255, 0.97);
  --line: rgba(92, 108, 128, 0.18);
  --text: #1d2836;
  --muted: #5f7084;
  --accent: #2e73d6;
  --accent-deep: #1c4f97;
  --shadow: 0 20px 48px rgba(28, 49, 82, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(215, 79, 42, 0.18), transparent 28%),
    radial-gradient(circle at left 20%, rgba(232, 190, 90, 0.24), transparent 24%),
    linear-gradient(160deg, #f7f2ea 0%, #f0ebe1 45%, #ece5da 100%);
}

body {
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at top right, rgba(69, 121, 214, 0.12), transparent 24%),
    radial-gradient(circle at left 15%, rgba(196, 218, 245, 0.45), transparent 28%),
    linear-gradient(180deg, #f7fafe 0%, #edf2f7 48%, #e8eef5 100%);
}

button,
input,
label,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) 1fr;
  height: 100vh;
}

.sidebar {
  height: 100vh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.hero-panel { background: linear-gradient(135deg, rgba(245, 249, 255, 0.98), rgba(255, 255, 255, 0.94)); }

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-deep);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 2.5vw, 2.5rem);
  line-height: 1.05;
  margin-bottom: 14px;
}

h2 {
  font-size: 1rem;
}

.lead {
  color: var(--muted);
  line-height: 1.6;
}

code {
  background: rgba(61, 88, 123, 0.1);
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
}

.upload-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  border: 2px dashed rgba(46, 115, 214, 0.3);
  border-radius: 20px;
  padding: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(243, 248, 255, 0.92));
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.upload-card:hover {
  transform: translateY(-1px);
  border-color: rgba(46, 115, 214, 0.52);
  box-shadow: 0 12px 28px rgba(46, 115, 214, 0.12);
}

.upload-card input {
  display: none;
}

.upload-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.upload-copy,
.hint-list,
.status-box,
#stepSummary {
  color: var(--muted);
  line-height: 1.55;
}

.hint-list {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.toolbar.secondary {
  grid-template-columns: repeat(2, 1fr);
  margin-top: 12px;
}

button {
  appearance: none;
  border: none;
  border-radius: 16px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #4385e0, #2d6fd1);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
  box-shadow: 0 12px 24px rgba(45, 111, 209, 0.22);
}

button:hover {
  transform: translateY(-1px);
  filter: saturate(1.05);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.slider-group,
.speed-group {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.settings-group {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.settings-label {
  color: var(--muted);
  font-size: 0.84rem;
}

.settings-select {
  appearance: none;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid rgba(97, 110, 128, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.settings-color {
  width: 100%;
  height: 42px;
  padding: 4px;
  border: 1px solid rgba(97, 110, 128, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
  cursor: pointer;
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 0.84rem;
}

.settings-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.light-grid {
  display: grid;
  gap: 10px;
}

.light-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(97, 110, 128, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.light-card strong {
  font-size: 0.84rem;
  color: var(--text);
}

.light-axis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.light-axis {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.light-axis input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid rgba(97, 110, 128, 0.16);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
}

.slider-header,
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 12px;
}

.stats-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.84rem;
}

.parts-list {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  color: var(--muted);
}

.parts-list li {
  line-height: 1.45;
}

.part-card {
  position: relative;
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(97, 110, 128, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 18px rgba(34, 48, 68, 0.06);
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}

.part-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(34, 48, 68, 0.1);
}

.part-card.is-selected {
  border-color: rgba(77, 120, 183, 0.52);
  box-shadow: 0 0 0 2px rgba(77, 120, 183, 0.15), 0 12px 24px rgba(34, 48, 68, 0.14);
}

.part-card--submodel {
  background: linear-gradient(180deg, rgba(244, 248, 255, 0.98), rgba(233, 240, 251, 0.92));
  border-color: rgba(88, 122, 168, 0.24);
}

.part-card__preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: linear-gradient(180deg, #f6f8fb, #e9eef4);
  border: 1px solid rgba(97, 110, 128, 0.1);
  user-select: none;
  -webkit-user-drag: none;
}

.part-card__preview--interactive {
  display: block;
  touch-action: none;
  cursor: grab;
}

.part-card__preview--interactive:active {
  cursor: grabbing;
}

.part-card__preview--instruction {
  display: block;
  background: linear-gradient(180deg, #f8fbff, #edf3f9);
}

.part-card__preview--activatable {
  cursor: zoom-in;
}

.part-card__meta {
  display: grid;
  gap: 2px;
}

.part-card__code {
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
  word-break: break-word;
}

.part-card__count {
  color: var(--muted);
  font-size: 0.63rem;
}

.part-card__color {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  border: 1px solid rgba(111, 91, 62, 0.08);
}

.part-card__badge {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(49, 73, 105, 0.92);
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  box-shadow: 0 8px 16px rgba(35, 47, 68, 0.18);
}

.status-box {
  min-height: 72px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 16px;
  border: 1px solid rgba(111, 91, 62, 0.1);
}

.viewer-panel {
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.viewer-tools {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 3;
  display: grid;
  gap: 12px;
  justify-items: end;
}

.viewer-badge {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 3;
  display: grid;
  gap: 10px;
  width: min(500px, calc(100% - 210px));
  max-height: calc(100% - 36px);
  padding: 10px;
  border: 1px solid rgba(97, 110, 128, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  color: #324255;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.35;
  box-shadow: 0 10px 24px rgba(34, 48, 68, 0.1);
  backdrop-filter: blur(8px);
}

.viewer-badge__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.viewer-badge__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.viewer-badge__header span:first-child {
  color: #36506f;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.viewer-badge__button {
  padding: 6px 9px;
  border-radius: 10px;
  font-size: 0.68rem;
  box-shadow: 0 8px 18px rgba(45, 111, 209, 0.16);
}

.hidden {
  display: none !important;
}

.parts-list--overlay {
  margin: 0;
  grid-template-columns: repeat(auto-fill, minmax(102px, 1fr));
  overflow: auto;
  padding-right: 2px;
  gap: 6px;
}

.parts-list--bom {
  grid-template-columns: 1fr;
  max-height: 260px;
  overflow: auto;
}

.parts-list--bom-grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  margin: 0;
}

.bom-launch {
  width: 100%;
}

.dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
}

.dialog__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 34, 48, 0.28);
  backdrop-filter: blur(6px);
}

.dialog__panel {
  position: relative;
  z-index: 1;
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(97, 110, 128, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 20px 48px rgba(28, 49, 82, 0.2);
}

.dialog__panel--wide {
  width: min(1100px, calc(100vw - 32px));
}

.dialog__header,
.dialog__toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.dialog__meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.84rem;
}

.dialog__close {
  padding: 8px 12px;
  border-radius: 12px;
}

.dialog__toggles {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.dialog__body {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.dialog__empty {
  padding: 24px;
  border: 1px dashed rgba(97, 110, 128, 0.2);
  border-radius: 14px;
  color: var(--muted);
  background: rgba(244, 248, 252, 0.9);
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(233, 239, 247, 0.95);
}

.segmented-control__button {
  padding: 8px 12px;
  border-radius: 10px;
  background: transparent;
  color: var(--accent-deep);
  box-shadow: none;
}

.segmented-control__button.is-active {
  background: linear-gradient(180deg, #4385e0, #2d6fd1);
  color: #fff;
  box-shadow: 0 8px 20px rgba(45, 111, 209, 0.2);
}

.bom-table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  overflow: hidden;
}

.bom-table th,
.bom-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(97, 110, 128, 0.12);
  text-align: left;
  vertical-align: middle;
}

.bom-table tbody tr {
  cursor: pointer;
  transition: background 150ms ease;
}

.bom-table tbody tr:hover {
  background: rgba(235, 242, 251, 0.72);
}

.bom-table tbody tr.is-selected {
  background: rgba(220, 233, 250, 0.85);
}

.bom-table__preview {
  width: 72px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(97, 110, 128, 0.1);
  background: linear-gradient(180deg, #f6f8fb, #e9eef4);
}

.bom-table__color {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border-radius: 999px;
  border: 1px solid rgba(97, 110, 128, 0.18);
  vertical-align: middle;
}

.orientation-panel {
  width: 188px;
  padding: 12px;
  border: 1px solid rgba(97, 110, 128, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 28px rgba(34, 48, 68, 0.12);
  backdrop-filter: blur(10px);
}

.orientation-header {
  margin-bottom: 8px;
  color: #36506f;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.orientation-cube {
  display: grid;
  place-items: center;
  height: 126px;
  cursor: grab;
  perspective: 500px;
  user-select: none;
}

.orientation-cube.is-clicked {
  animation: cubePulse 240ms ease;
}

.orientation-cube:active {
  cursor: grabbing;
}

.orientation-cube__inner {
  position: relative;
  width: 64px;
  height: 64px;
  transform-style: preserve-3d;
  transition: transform 160ms ease;
}

.orientation-cube__face {
  position: absolute;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border: 1px solid rgba(97, 110, 128, 0.22);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(232, 239, 248, 0.9));
  color: #324255;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.68);
}

.orientation-cube__face span {
  pointer-events: none;
}

@keyframes cubePulse {
  0% { scale: 1; }
  45% { scale: 1.08; }
  100% { scale: 1; }
}

.orientation-cube__face--front { transform: translateZ(32px); }
.orientation-cube__face--back { transform: rotateY(180deg) translateZ(32px); }
.orientation-cube__face--right { transform: rotateY(90deg) translateZ(32px); }
.orientation-cube__face--left { transform: rotateY(-90deg) translateZ(32px); }
.orientation-cube__face--top { transform: rotateX(90deg) translateZ(32px); }
.orientation-cube__face--bottom { transform: rotateX(-90deg) translateZ(32px); }

.light-stage {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.light-presets {
  margin-top: 0;
}

.light-stage__header {
  color: var(--muted);
  font-size: 0.72rem;
}

.light-orbit {
  position: relative;
  height: 120px;
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.95), rgba(232,239,248,0.9)),
    linear-gradient(180deg, rgba(255,255,255,0.75), rgba(225,233,243,0.9));
  border: 1px solid rgba(97, 110, 128, 0.16);
  overflow: hidden;
}

.light-orbit__grid {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(109,127,147,0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(109,127,147,0.09) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(circle at center, black 56%, transparent 100%);
}

.light-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  box-shadow: 0 8px 18px rgba(34, 48, 68, 0.18);
  cursor: grab;
}

.light-handle:active {
  cursor: grabbing;
}

.light-handle--hemi {
  background: radial-gradient(circle at 35% 35%, #fffdf3, #ffd15c);
}

.light-handle--key {
  background: radial-gradient(circle at 35% 35%, #ffffff, #8eb6ff);
}

.light-handle--rim {
  background: radial-gradient(circle at 35% 35%, #ffffff, #8fd8d0);
}

.view-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.view-presets__button {
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 0.76rem;
}

.viewer-size {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.viewer-layout {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.viewer-size__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.76rem;
}

.viewer-size__fit {
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 0.74rem;
}

.loading-overlay {
  width: 220px;
  padding: 12px;
  border: 1px solid rgba(97, 110, 128, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 28px rgba(34, 48, 68, 0.12);
  backdrop-filter: blur(10px);
}

.loading-overlay.hidden {
  display: none;
}

.loading-overlay__title {
  margin-bottom: 8px;
  color: #324255;
  font-size: 0.88rem;
  font-weight: 700;
}

.loading-overlay__bar {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: rgba(111, 91, 62, 0.12);
}

.loading-overlay__fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4b8ff0, #2d6fd1);
  transition: width 180ms ease;
}

.loading-overlay__label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

#sceneCanvas {
  display: block;
  width: 100%;
  height: 100vh;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(32, 24, 21, 0.16);
  backdrop-filter: blur(3px);
  z-index: 2;
}

.drop-overlay.hidden {
  display: none;
}

.drop-card {
  display: grid;
  gap: 6px;
  padding: 24px 32px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(46, 115, 214, 0.16);
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar {
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .viewer-panel {
    min-height: 60vh;
    height: 60vh;
  }

  .viewer-tools {
    top: 12px;
    right: 12px;
  }

  .orientation-panel,
  .loading-overlay {
    width: 160px;
  }

  .light-orbit {
    height: 104px;
  }
}
