:root {
  --bg: #0b101b;
  --bg-soft: #111a2a;
  --panel: rgba(15, 22, 36, 0.82);
  --panel-solid: #131d30;
  --border: rgba(126, 151, 190, 0.22);
  --text: #eaf1ff;
  --muted: #93a2bd;
  --accent: #ff5a3d;
  --accent-soft: rgba(255, 90, 61, 0.14);
  --gold: #ffc46a;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body,
#app,
#viewport,
#canvas-container {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #1b2740 0%, var(--bg) 62%);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui,
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 76px;
  padding: 14px 22px;
  background: linear-gradient(180deg, rgba(13, 19, 31, 0.96), rgba(13, 19, 31, 0.72));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 260px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), #b72a17);
  color: #fff;
  font-weight: 800;
  letter-spacing: 1px;
  box-shadow: 0 10px 28px rgba(255, 90, 61, 0.32);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.tool-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.tool-button:hover,
.tool-button:focus-visible {
  border-color: rgba(255, 90, 61, 0.7);
  background: rgba(255, 90, 61, 0.12);
  outline: none;
}

.tool-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 22px rgba(255, 90, 61, 0.24);
}

.icon-button {
  width: 38px;
  padding-left: 0;
  padding-right: 0;
}

#viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
}

#canvas-container {
  position: absolute;
  inset: 0;
}

#canvas-container canvas {
  display: block;
  touch-action: none;
}

.stage-rail {
  position: absolute;
  top: 22px;
  left: 22px;
  z-index: 5;
  width: 150px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.stage-rail h2 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stage-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.stage-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.stage-item.active {
  border-color: rgba(255, 90, 61, 0.55);
  background: var(--accent-soft);
}

.stage-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.stage-item.active .stage-dot {
  background: var(--accent);
  box-shadow: 0 0 0 5px var(--accent-soft);
}

.stage-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-panel {
  position: absolute;
  left: 22px;
  bottom: 84px;
  z-index: 5;
  width: min(390px, calc(100vw - 44px));
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.info-empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.info-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.info-tag {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.info-heading h2 {
  margin: 0;
  font-size: 21px;
}

#info-description {
  margin: 0 0 14px;
  color: #c7d2e5;
  font-size: 14px;
  line-height: 1.72;
}

.spec-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 14px;
  margin: 0;
}

.spec-list div {
  min-width: 0;
}

.spec-list dt {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.spec-list dd {
  margin: 3px 0 0;
  font-size: 14px;
  color: var(--gold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.explode-panel {
  position: absolute;
  left: 50%;
  bottom: 24px;
  z-index: 6;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.explode-panel label {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

#explode-slider {
  width: min(340px, 40vw);
  accent-color: var(--accent);
  cursor: pointer;
}

#explode-value {
  width: 42px;
  color: var(--gold);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.timeline {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 5;
  width: 240px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.timeline-header {
  display: flex;
  align-items: center;
  gap: 11px;
}

.play-button {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 9px 22px rgba(255, 90, 61, 0.28);
}

.play-button:hover {
  transform: scale(1.04);
}

.timeline-header h2 {
  margin: 0;
  font-size: 16px;
}

.timeline-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  height: 5px;
  margin: 15px 0 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

#timeline-progress {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width 0.12s linear;
}

.step-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.step-item {
  position: relative;
  padding: 8px 0 8px 24px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.step-item::before {
  position: absolute;
  left: 5px;
  top: 12px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  content: "";
  background: transparent;
}

.step-item.active {
  color: var(--text);
  font-weight: 600;
}

.step-item.active::before {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 5px var(--accent-soft);
}

.step-item.done {
  color: #b8c5db;
}

.step-item.done::before {
  border-color: var(--gold);
  background: var(--gold);
}

.view-hint {
  position: absolute;
  right: 22px;
  bottom: 24px;
  z-index: 4;
  color: rgba(192, 205, 229, 0.72);
  font-size: 12px;
  pointer-events: none;
}

.part-label {
  padding: 5px 9px;
  border: 1px solid rgba(255, 90, 61, 0.48);
  border-radius: 999px;
  background: rgba(17, 26, 42, 0.86);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  letter-spacing: 0.02em;
  box-shadow: 0 7px 20px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 16, 0.68);
  backdrop-filter: blur(5px);
}

.help-modal[hidden] {
  display: none;
}

.help-card {
  position: relative;
  width: min(560px, calc(100vw - 40px));
  padding: 26px 30px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

.help-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}

.help-card h2 {
  margin: 0 0 16px;
  font-size: 22px;
}

.help-card ul {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-card li {
  color: #c7d2e5;
  font-size: 14px;
  line-height: 1.65;
}

.help-card strong {
  color: var(--text);
}

.help-note {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: var(--bg);
  transition: opacity 0.6s ease;
}

.loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-inner {
  text-align: center;
  color: var(--muted);
}

.spinner {
  width: 46px;
  height: 46px;
  margin: 0 auto 16px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  .brand p {
    display: none;
  }

  .stage-rail {
    width: 128px;
  }

  .timeline {
    width: 205px;
  }

  .info-panel {
    width: min(320px, calc(100vw - 44px));
  }
}

@media (max-width: 680px) {
  .topbar {
    min-height: 58px;
    gap: 10px;
    padding: 9px 10px;
  }

  .brand {
    min-width: 0;
    flex: 0 0 auto;
    gap: 9px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 12px;
  }

  .brand h1 {
    font-size: 15px;
    white-space: nowrap;
  }

  .toolbar {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .toolbar::-webkit-scrollbar {
    display: none;
  }

  .tool-button {
    flex: 0 0 auto;
    padding: 7px 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .icon-button {
    width: 32px;
    height: 32px;
    padding: 0;
  }

  /* 结构导航：横向滑动条 */
  .stage-rail {
    top: 64px;
    left: 10px;
    right: 10px;
    bottom: auto;
    width: auto;
    max-width: none;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px;
    border-radius: 16px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .stage-rail::-webkit-scrollbar {
    display: none;
  }

  .stage-rail h2 {
    display: none;
  }

  .stage-item {
    flex: 0 0 auto;
    width: auto;
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 999px;
  }

  .stage-name {
    font-size: 12px;
  }

  /* 信息卡：底部可滚动卡片 */
  .info-panel {
    left: 10px;
    right: 10px;
    bottom: 170px;
    width: auto;
    max-height: 32vh;
    overflow-y: auto;
    padding: 14px 16px;
    border-radius: 16px;
    -webkit-overflow-scrolling: touch;
  }

  .info-heading h2 {
    font-size: 18px;
  }

  #info-description {
    font-size: 13px;
    line-height: 1.58;
  }

  .spec-list {
    gap: 7px 12px;
  }

  .spec-list dt {
    font-size: 10px;
  }

  .spec-list dd {
    font-size: 12px;
  }

  /* 拆解滑块：底部第二层 */
  .explode-panel {
    left: 10px;
    right: 10px;
    bottom: 122px;
    transform: none;
    width: auto;
    justify-content: center;
    padding: 9px 12px;
  }

  .explode-panel label {
    font-size: 11px;
  }

  #explode-slider {
    width: min(48vw, 220px);
  }

  /* 时间轴：底部横向流程 */
  .timeline {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 12px;
    width: auto;
    padding: 8px 10px;
    border-radius: 16px;
  }

  .play-button {
    width: 34px;
    height: 34px;
    font-size: 15px;
  }

  .timeline-header {
    gap: 8px;
  }

  .timeline-header h2 {
    font-size: 13px;
  }

  .timeline-header p {
    font-size: 10px;
  }

  .progress-track {
    margin: 8px 0;
  }

  .step-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .step-list::-webkit-scrollbar {
    display: none;
  }

  .step-item {
    flex: 0 0 auto;
    padding: 5px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  .step-item::before {
    display: none;
  }

  body[data-mode="demo"] .stage-rail,
  body[data-mode="demo"] .explode-panel,
  body[data-mode="demo"] .info-panel {
    display: none;
  }

  body[data-mode="demo"] .timeline {
    bottom: 12px;
  }

  .view-hint {
    display: none;
  }

  .help-card {
    width: calc(100vw - 28px);
    max-height: 76vh;
    overflow-y: auto;
    padding: 22px 20px;
    border-radius: 20px;
  }

  .help-card h2 {
    font-size: 19px;
  }

  .help-card li {
    font-size: 13px;
  }
}

@media (max-width: 900px) and (max-height: 520px) {
  .topbar {
    min-height: 50px;
    padding: 6px 10px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .brand h1 {
    font-size: 13px;
  }

  .tool-button {
    padding: 6px 9px;
    font-size: 11px;
  }

  .stage-rail {
    top: 54px;
    left: 10px;
    right: 225px;
    bottom: auto;
    width: auto;
    max-width: none;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px;
    border-radius: 16px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .stage-rail::-webkit-scrollbar {
    display: none;
  }

  .stage-rail h2 {
    display: none;
  }

  .stage-item {
    flex: 0 0 auto;
    width: auto;
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 999px;
  }

  .stage-name {
    font-size: 12px;
  }

  .info-panel {
    bottom: 120px;
    max-height: 24vh;
  }

  .explode-panel {
    bottom: 80px;
    padding: 7px 10px;
  }

  .timeline {
    bottom: 8px;
  }

  body[data-mode="demo"] .stage-rail,
  body[data-mode="demo"] .explode-panel,
  body[data-mode="demo"] .info-panel {
    display: none;
  }
}
