:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #65738a;
  --line: #d9e2ef;
  --panel: rgba(255, 255, 255, 0.92);
  --accent: #0f766e;
  --accent-2: #f59e0b;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 24px 60px rgba(30, 41, 59, 0.14);
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 12%, rgba(20, 184, 166, 0.18), transparent 32%),
    radial-gradient(circle at 88% 4%, rgba(245, 158, 11, 0.18), transparent 30%),
    linear-gradient(135deg, #f8fafc 0%, #e8eef7 100%);
}

.shell {
  width: min(1320px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(217, 226, 239, 0.9);
  border-radius: 26px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  padding: 24px;
  backdrop-filter: blur(14px);
}

.hero {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: end;
}

.eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.16em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.version-badge {
  background: rgba(15, 118, 110, 0.12);
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 999px;
  display: inline-block;
  letter-spacing: 0;
  margin-left: 10px;
  padding: 4px 9px;
  text-transform: none;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  font-size: clamp(32px, 5vw, 58px);
  line-height: 0.98;
  letter-spacing: -0.06em;
  margin-bottom: 16px;
}

h2 {
  font-size: 20px;
}

.subhead {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
  margin-bottom: 0;
}

.safety-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 20px;
  display: grid;
  gap: 8px;
  padding: 18px;
}

.safety-box strong {
  color: #9a3412;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.status-card, .angle-card {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 18px;
  display: grid;
  gap: 7px;
  padding: 16px;
}

.status-card span, .angle-card span, label {
  color: var(--muted);
  font-size: 14px;
}

.status-card strong {
  font-size: 22px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 800;
  padding: 13px 20px;
  transition: transform 150ms ease, opacity 150ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary {
  background: var(--ink);
  color: white;
}

.ghost {
  background: #e2e8f0;
  color: var(--ink);
}

.start {
  background: var(--accent);
  color: white;
  min-width: 180px;
}

.stop {
  background: var(--danger);
  color: white;
  min-width: 120px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 18px;
}

label {
  display: grid;
  font-weight: 800;
  gap: 8px;
}

input, select {
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  font-size: 16px;
  padding: 12px 14px;
}

.debug-panel {
  border-top: 1px solid var(--line);
  margin-top: 20px;
  padding-top: 16px;
}

.debug-panel summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.tabs {
  position: sticky;
  top: 10px;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 18px;
  padding: 7px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  background: rgba(226, 232, 240, 0.94);
  box-shadow: 0 10px 28px rgba(30, 41, 59, 0.12);
}

.tabs.three-tabs { grid-template-columns: repeat(3, 1fr); }
.factory-settings { max-width: 420px; }

.tab {
  color: #64748b;
  background: transparent;
  border-radius: 14px;
}

.tab.active {
  color: white;
  background: var(--ink);
  box-shadow: 0 8px 18px rgba(23, 32, 51, 0.2);
}

.tab-view {
  display: none;
}

.tab-view.active {
  display: block;
  animation: reveal 220ms ease-out;
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading span, .reset-header p, .reset-step span {
  color: var(--muted);
}

.section-kicker {
  margin-bottom: 7px;
  color: var(--warning);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.reset-panel {
  border: 2px solid rgba(245, 158, 11, 0.45);
}

.reset-header {
  display: grid;
  grid-template-columns: 1fr 290px;
  gap: 22px;
  align-items: start;
}

.reset-header p {
  max-width: 680px;
  line-height: 1.7;
}

.danger-card {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 1px solid #fed7aa;
  border-radius: 18px;
  color: #9a3412;
  background: #fff7ed;
}

.reset-steps, .reset-status {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 22px;
}

.reset-step {
  display: grid;
  gap: 9px;
  min-height: 130px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #f8fafc;
}

.reset-step b {
  color: var(--warning);
  font-size: 13px;
}

.reset-step span {
  line-height: 1.55;
}

.reset-actions {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.origin {
  min-width: 180px;
  color: white;
  background: var(--warning);
}

.factory-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

.factory-progress-panel {
  position: sticky;
  top: 96px;
  padding: 18px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  background: #f8fafc;
  box-shadow: 0 14px 32px rgba(30, 41, 59, 0.1);
}

.factory-progress-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.factory-progress-heading h3 { margin: 0; font-size: 20px; }
.factory-progress-heading > span { max-width: 145px; color: var(--muted); font-size: 12px; line-height: 1.45; text-align: right; }
.factory-progress-list { display: grid; gap: 10px; margin: 16px 0 0; padding: 0; list-style: none; }
.factory-progress-step {
  display: grid;
  grid-template-columns: 32px 1fr 26px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}
.factory-progress-step strong { display: block; font-size: 14px; }
.factory-progress-step small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.4; }
.factory-step-number, .factory-step-state { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-weight: 900; }
.factory-step-number { color: #64748b; background: #e2e8f0; }
.factory-progress-step.is-active { border-color: #f59e0b; background: #fffbeb; transform: translateX(3px); }
.factory-progress-step.is-active .factory-step-number { color: white; background: var(--warning); }
.factory-progress-step.is-active .factory-step-state { border: 3px solid #fde68a; border-top-color: var(--warning); animation: factory-progress-spin 800ms linear infinite; }
.factory-progress-step.is-complete { border-color: #86efac; background: #f0fdf4; }
.factory-progress-step.is-complete .factory-step-number, .factory-progress-step.is-complete .factory-step-state { color: white; background: #16a34a; }
.factory-progress-step.is-failed { border-color: #fca5a5; background: #fef2f2; }
.factory-progress-step.is-failed .factory-step-number, .factory-progress-step.is-failed .factory-step-state { color: white; background: var(--danger); }

.factory-manual-power-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 15px;
  border: 2px solid #f59e0b;
  border-radius: 14px;
  color: #7c2d12;
  background: #fff7ed;
  font-size: 16px;
  line-height: 1.5;
  animation: success-pop 320ms ease-out;
}
.factory-manual-power-notice[hidden] { display: none; }
.factory-manual-power-notice > span { font-size: 28px; }

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

.factory-success-notice {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 20px;
  padding: 20px 22px;
  border: 2px solid #16a34a;
  border-radius: 18px;
  color: #14532d;
  background: linear-gradient(135deg, #dcfce7, #f0fdf4);
  box-shadow: 0 12px 28px rgba(22, 163, 74, 0.18);
  animation: success-pop 320ms ease-out;
}

.factory-success-notice[hidden] { display: none; }
.factory-success-notice strong { display: block; font-size: 24px; }
.factory-success-notice p { margin: 4px 0 0; color: #166534; font-size: 20px; font-weight: 900; }
.factory-success-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 50%;
  color: white;
  background: #16a34a;
  font-size: 30px;
  font-weight: 900;
}

@keyframes success-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.reset-success-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  padding: 14px 18px;
  border: 1px solid #86efac;
  border-radius: 12px;
  background: #f0fdf4;
  color: #166534;
  font-size: 18px;
}

.reset-success-notice[hidden] { display: none; }

.warning-note {
  margin: 16px 0 0;
  padding: 13px 15px;
  border: 1px solid #fde68a;
  border-radius: 14px;
  color: #92400e;
  background: #fffbeb;
  line-height: 1.6;
}

.confirm-dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.38);
}

.confirm-dialog::backdrop {
  background: rgba(15, 23, 42, 0.64);
}

.confirm-dialog-content { padding: 28px; }
.confirm-dialog-content h2 { margin-bottom: 12px; }
.confirm-dialog-content > p:not(.section-kicker) { color: var(--muted); line-height: 1.7; }

.confirm-check {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding: 15px;
  border: 1px solid #fed7aa;
  border-radius: 14px;
  color: #9a3412;
  background: #fff7ed;
}

.confirm-actions { justify-content: flex-end; margin-top: 22px; }
.confirm-origin { color: white; background: #c2410c; }

.angles {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}

.angle-card strong {
  color: var(--accent);
  font-size: 24px;
}

pre {
  background: #101827;
  border-radius: 18px;
  color: #dbeafe;
  min-height: 240px;
  max-height: 380px;
  overflow: auto;
  padding: 18px;
  white-space: pre-wrap;
}

@media (max-width: 1100px) and (min-width: 761px) {
  .factory-workspace { grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; }
  .factory-main .reset-header { grid-template-columns: 1fr; }
  .factory-main .danger-card { padding: 14px 16px; }
  .factory-main .status-card { padding: 13px; }
  .factory-main .status-card strong { font-size: 18px; }
}

@media (max-width: 760px) {
  .factory-workspace { grid-template-columns: 1fr; }
  .factory-progress-panel { position: static; }
}

@media (max-width: 780px) {
  .hero, .status-grid, .settings-grid, .reset-header, .reset-steps, .reset-status {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .angles {
    grid-template-columns: repeat(2, 1fr);
  }
}
