:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --blue: #007aff;
  --red: #d92d20;
  --text: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #a1a1a6;
  --line: #d8d8dc;
  --page: #f2f2f7;
  --panel: #ffffff;
  background: var(--page);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page);
}

button {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
}

.header-inner,
.page-shell {
  width: min(100% - 32px, 820px);
  margin-inline: auto;
}

.header-inner {
  display: flex;
  align-items: center;
  min-height: 68px;
  gap: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: 0;
}

.page-shell {
  display: grid;
  gap: 15px;
  padding-block: 18px 40px;
}

.panel {
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.045);
}

.status-panel,
.connect-panel {
  padding: 16px;
}

.status-row,
.panel-header,
.step-row,
.result-values {
  display: flex;
  align-items: center;
}

.status-row,
.panel-header {
  justify-content: space-between;
  gap: 16px;
}

.status-label {
  display: flex;
  align-items: center;
  min-width: 0;
  color: var(--blue);
  font-weight: 600;
}

.device-name {
  margin-top: 12px;
  color: var(--secondary);
  font-size: 20px;
  line-height: 1.3;
}

.device-name.connected {
  color: var(--text);
  font-weight: 700;
}

.panel-header {
  min-height: 54px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfd;
}

.process-content {
  min-height: 190px;
  padding: 24px;
}

.button {
  min-height: 38px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0;
  transition: background-color 120ms ease, opacity 120ms ease, transform 120ms ease;
}

.button:hover:not(:disabled) {
  filter: brightness(0.96);
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 3px solid rgba(0, 122, 255, 0.28);
  outline-offset: 2px;
}

.button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.button-primary {
  background: var(--blue);
  color: #ffffff;
}

.button-danger {
  border-color: rgba(217, 45, 32, 0.35);
  background: #ffffff;
  color: var(--red);
}

.button-small {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 14px;
}

.connect-panel {
  display: grid;
  justify-items: start;
  gap: 16px;
}

.connect-hint {
  width: 100%;
  padding-block: 8px;
  text-align: center;
  color: var(--secondary);
}

.idle-state {
  display: grid;
  min-height: 142px;
  place-content: center;
  justify-items: center;
  gap: 10px;
  text-align: center;
}

.state-title {
  font-size: 17px;
  font-weight: 650;
}

.state-detail,
.step-detail {
  color: var(--secondary);
  font-size: 14px;
}

.steps {
  max-width: 460px;
}

.step-row {
  gap: 12px;
}

.step-marker {
  display: grid;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 2px solid var(--blue);
  border-radius: 50%;
  color: var(--blue);
  font-size: 14px;
  font-weight: 700;
}

.step-marker.complete {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.step-marker.pending {
  border-color: rgba(110, 110, 115, 0.25);
  color: var(--secondary);
}

.step-marker.loading::after {
  width: 11px;
  height: 11px;
  content: "";
  border: 2px solid rgba(0, 122, 255, 0.25);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.step-title {
  line-height: 1.35;
  font-weight: 600;
}

.step-detail {
  margin-top: 3px;
}

.step-line {
  width: 2px;
  height: 24px;
  margin: 4px 0 4px 15px;
  background: rgba(110, 110, 115, 0.2);
}

.step-line.active {
  background: var(--blue);
}

.result-state {
  text-align: center;
}

.result-delta {
  color: var(--blue);
  font-size: 44px;
  line-height: 1.1;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.result-divider {
  height: 1px;
  margin: 22px 0 18px;
  background: var(--line);
}

.result-values {
  justify-content: center;
}

.result-value {
  flex: 1 1 50%;
  padding: 0 16px;
}

.result-value + .result-value {
  border-left: 1px solid var(--line);
}

.result-value dt {
  color: var(--secondary);
  font-size: 13px;
}

.result-value dd {
  margin: 5px 0 0;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.error-dialog {
  width: min(100% - 40px, 420px);
  padding: 22px;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
}

.error-dialog::backdrop {
  background: rgba(0, 0, 0, 0.32);
}

.error-dialog p {
  margin: 12px 0 20px;
  color: var(--secondary);
  line-height: 1.55;
}

.error-dialog form {
  display: flex;
  justify-content: flex-end;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

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

@media (max-width: 560px) {
  .header-inner,
  .page-shell {
    width: min(100% - 20px, 820px);
  }

  .process-content {
    padding: 20px 16px;
  }

  .result-delta {
    font-size: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
