:root {
  --setup-page-bg: #fff;
  --setup-overlay-bg: #fff;
  --setup-surface: #fff;
  --setup-surface-muted: rgba(26, 30, 28, 0.04);
  --setup-border: rgba(26, 30, 28, 0.08);
  --setup-border-strong: rgba(26, 30, 28, 0.14);
  --setup-text: #1a1e1c;
  --setup-text-muted: rgba(26, 30, 28, 0.72);
  --setup-text-soft: rgba(26, 30, 28, 0.55);
  --setup-text-faint: rgba(26, 30, 28, 0.5);
  --setup-accent: #2c7be5;
  --setup-accent-soft: rgba(44, 123, 229, 0.08);
  --setup-accent-text: #1a5bb8;
  --setup-shadow: 0 16px 48px rgba(26, 30, 28, 0.08);
  --setup-busy-bg: rgba(255, 255, 255, 0.82);
  --setup-info-bg: rgba(44, 123, 229, 0.08);
  --setup-info-text: rgba(26, 30, 28, 0.78);
  --setup-warn-bg: #fff7e6;
  --setup-warn-border: #ffd591;
  --setup-warn-text: #874d00;
  --setup-error: #b42318;
  --setup-ok: #067647;
  --setup-loader-bg: #fff;
}

html[data-theme="dark"] {
  --setup-page-bg: #0f1114;
  --setup-overlay-bg: #0f1114;
  --setup-surface: #181b20;
  --setup-surface-muted: rgba(255, 255, 255, 0.05);
  --setup-border: rgba(255, 255, 255, 0.1);
  --setup-border-strong: rgba(255, 255, 255, 0.16);
  --setup-text: #eef0f3;
  --setup-text-muted: rgba(238, 240, 243, 0.78);
  --setup-text-soft: rgba(238, 240, 243, 0.58);
  --setup-text-faint: rgba(238, 240, 243, 0.45);
  --setup-accent: #4d93ef;
  --setup-accent-soft: rgba(77, 147, 239, 0.14);
  --setup-accent-text: #8eb8ff;
  --setup-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --setup-busy-bg: rgba(24, 27, 32, 0.88);
  --setup-info-bg: rgba(77, 147, 239, 0.12);
  --setup-info-text: rgba(238, 240, 243, 0.86);
  --setup-warn-bg: rgba(255, 169, 64, 0.12);
  --setup-warn-border: rgba(255, 169, 64, 0.35);
  --setup-warn-text: #ffd591;
  --setup-error: #ff8a80;
  --setup-ok: #6ee7a8;
  --setup-loader-bg: #181b20;
}

html,
body {
  margin: 0;
  background: var(--setup-page-bg);
  color: var(--setup-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wesp-setup {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--setup-overlay-bg);
}

.wesp-setup__intro {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 10001;
  width: min(520px, calc(100vw - 32px));
  height: min(240px, 36vh);
  background: transparent;
  transition: opacity 0.45s ease, visibility 0.45s;
}

.wesp-setup__intro--done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.wesp-setup__intro .wesp-logo-loader,
.wesp-setup__intro .wesp-logo-loader--embedded,
.wesp-setup__intro .wesp-logo-loader--plain {
  background: transparent !important;
}

.wesp-setup__panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 10002;
  display: flex;
  flex-direction: column;
  width: min(520px, calc(100vw - 32px));
  max-height: min(85vh, 620px);
  overflow: hidden;
  padding: 0;
  border-radius: 16px;
  background: var(--setup-surface);
  border: 1px solid var(--setup-border);
  box-shadow: var(--setup-shadow);
  color: var(--setup-text);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease 0.08s, visibility 0.35s ease 0.08s, background 0.2s ease, color 0.2s ease;
  isolation: isolate;
}

.wesp-setup__header {
  flex: 0 0 auto;
  padding: 22px 24px 0;
}

.wesp-setup__content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 24px 8px;
  overscroll-behavior: contain;
}

.wesp-setup__footer {
  flex: 0 0 auto;
  padding: 12px 24px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--setup-border);
  background: var(--setup-surface);
}

.wesp-setup__panel--busy {
  pointer-events: none;
}

.wesp-setup__busy {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 16px;
  background: var(--setup-busy-bg);
  backdrop-filter: blur(2px);
}

.wesp-setup__spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--setup-border-strong);
  border-top-color: var(--setup-accent);
  border-radius: 50%;
  animation: wesp-setup-spin 0.75s linear infinite;
}

.wesp-setup__busy-label {
  font-size: 13px;
  color: var(--setup-text-muted);
}

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

.wesp-setup__panel--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.wesp-setup__title {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--setup-text);
}

.wesp-setup__lead {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--setup-text-muted);
}

.wesp-setup__step-indicator {
  margin-bottom: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--setup-text-faint);
}

.wesp-setup__field {
  margin-bottom: 12px;
}

.wesp-setup__label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--setup-text);
}

.wesp-setup__input,
.wesp-setup__select {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  border: 1px solid var(--setup-border-strong);
  border-radius: 10px;
  font-size: 16px;
  background: var(--setup-surface);
  color: var(--setup-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.wesp-setup__input:focus,
.wesp-setup__select:focus {
  outline: none;
  border-color: var(--setup-accent);
  box-shadow: 0 0 0 3px var(--setup-accent-soft);
}

.wesp-setup__input:-webkit-autofill,
.wesp-setup__input:-webkit-autofill:hover,
.wesp-setup__input:-webkit-autofill:focus,
.wesp-setup__input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--setup-surface) inset !important;
  box-shadow: 0 0 0 1000px var(--setup-surface) inset !important;
  -webkit-text-fill-color: var(--setup-text) !important;
  caret-color: var(--setup-text);
  transition: background-color 600000s ease-in-out 0s;
}

.wesp-setup__input:autofill {
  box-shadow: 0 0 0 1000px var(--setup-surface) inset !important;
  -webkit-text-fill-color: var(--setup-text) !important;
  caret-color: var(--setup-text);
}

.wesp-setup__input--readonly {
  background: var(--setup-surface-muted);
  color: var(--setup-text-muted);
  cursor: default;
}

.wesp-setup__input-group {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.wesp-setup__input-group .wesp-setup__input {
  flex: 1 1 auto;
  min-width: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.wesp-setup__input-suffix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--setup-border-strong);
  border-left: none;
  border-radius: 0 8px 8px 0;
  background: var(--setup-surface-muted);
  color: var(--setup-text-soft);
  font-size: 14px;
  white-space: nowrap;
  user-select: none;
}

.wesp-setup__checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}

.wesp-setup__role-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 4px;
}

.wesp-setup__role-grid--cards {
  gap: 12px;
}

.wesp-setup__role-btn {
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--setup-border-strong);
  background: var(--setup-surface);
  color: var(--setup-text);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.wesp-setup__role-btn:hover {
  border-color: var(--setup-accent);
}

.wesp-setup__role-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--setup-accent-soft);
}

.wesp-setup__role-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 84px;
  padding: 20px 18px;
  border-radius: 12px;
  text-align: center;
}

.wesp-setup__theme-grid .wesp-setup__theme-card {
  position: relative;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  min-height: 0;
  padding: 12px 14px 12px 62px;
  text-align: left;
  background: var(--setup-surface-muted);
  border-color: var(--setup-border);
  color: var(--setup-text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.wesp-setup__theme-grid .wesp-setup__theme-card::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 32px;
  height: 32px;
  margin-top: -16px;
  border-radius: 8px;
  border: 1px solid var(--setup-border-strong);
  box-sizing: border-box;
}

.wesp-setup__theme-card--light::before {
  background: linear-gradient(145deg, #ffffff 0%, #d8dee8 100%);
}

.wesp-setup__theme-card--dark::before {
  background: linear-gradient(145deg, #505662 0%, #171b21 100%);
}

.wesp-setup__theme-card span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 400;
  color: var(--setup-text-soft);
}

.wesp-setup__role-btn strong {
  display: block;
  margin-bottom: 4px;
}

.wesp-setup__role-card strong {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--setup-text);
}

.wesp-setup__theme-card strong {
  margin-bottom: 0;
  font-size: 15px;
}

.wesp-setup__role-btn.is-selected:not(.wesp-setup__theme-card) {
  border-color: var(--setup-accent);
  background: var(--setup-accent-soft);
  box-shadow: 0 0 0 1px rgba(44, 123, 229, 0.18);
}

.wesp-setup__theme-card.is-selected {
  border-color: var(--setup-accent);
  background: var(--setup-accent-soft);
  box-shadow: none;
}

.wesp-setup__role-card.is-selected:not(.wesp-setup__theme-card) strong {
  color: var(--setup-accent-text);
}

.wesp-setup__theme-grid .wesp-setup__theme-card strong {
  color: var(--setup-text);
}

.wesp-setup__theme-grid .wesp-setup__theme-card.is-selected strong {
  color: var(--setup-accent-text);
}

.wesp-setup__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.wesp-setup__actions-fill {
  flex: 1 1 12px;
  min-width: 8px;
}

.wesp-setup__btn {
  appearance: none;
  border: 1px solid var(--setup-border-strong);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 42px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  background: var(--setup-surface);
  color: var(--setup-text);
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.wesp-setup__btn:hover:not(:disabled) {
  border-color: var(--setup-accent);
}

.wesp-setup__btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--setup-accent-soft);
}

.wesp-setup__btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--setup-text-muted);
}

.wesp-setup__btn--ghost:hover:not(:disabled) {
  background: var(--setup-surface-muted);
  border-color: var(--setup-border);
  color: var(--setup-text);
}

.wesp-setup__btn--primary {
  background: var(--setup-accent);
  border-color: var(--setup-accent);
  color: #fff;
  padding-inline: 20px;
}

.wesp-setup__btn--primary:hover:not(:disabled) {
  filter: brightness(1.06);
  border-color: var(--setup-accent);
}

.wesp-setup__btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.wesp-setup__msg {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.5;
  min-height: 1.4em;
}

.wesp-setup__msg--error {
  color: var(--setup-error);
}

.wesp-setup__msg--ok {
  color: var(--setup-ok);
}

.wesp-setup__hint {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--setup-text-soft);
}

.wesp-setup__info {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--setup-info-bg);
  font-size: 13px;
  line-height: 1.5;
  color: var(--setup-info-text);
}

.wesp-setup__info--warn {
  background: var(--setup-warn-bg);
  border: 1px solid var(--setup-warn-border);
  color: var(--setup-warn-text);
}

.wesp-setup__section-title {
  margin: 18px 0 10px;
  font-size: 15px;
  font-weight: 600;
}

.wesp-setup__qr-wrap {
  display: flex;
  justify-content: center;
  margin: 8px 0 10px;
  padding: 14px;
  border-radius: 12px;
  background: var(--setup-surface-muted);
  border: 1px solid var(--setup-border);
}

.wesp-setup__qr {
  display: block;
  width: min(200px, 100%);
  height: auto;
  margin: 0;
}

.wesp-setup__url {
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
  color: var(--setup-text-muted);
}

.wesp-setup__progress-bar {
  height: 6px;
  background: var(--setup-surface-muted);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.wesp-setup__progress-fill {
  height: 100%;
  width: 0;
  background: var(--setup-accent);
  transition: width 0.2s linear;
}

.wesp-setup__summary-list {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.6;
}

.wesp-setup__input--touch {
  cursor: text;
  caret-color: var(--setup-accent);
}

.wesp-setup__keyboard {
  flex: 0 0 auto;
  display: none;
  padding: 10px 16px 4px;
  border-top: 1px solid var(--setup-border);
  background: var(--setup-surface);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.wesp-setup__keyboard.is-visible {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.wesp-setup__keyboard-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
  max-width: 100%;
  margin: 0 auto;
}

.wesp-setup__keyboard-key {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 4px;
  border: 1px solid var(--setup-border-strong);
  border-radius: 8px;
  background: var(--setup-surface-muted);
  color: var(--setup-text);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.wesp-setup__keyboard-key:active {
  transform: scale(0.96);
  background: var(--setup-accent-soft);
  border-color: var(--setup-accent);
}

.wesp-setup__keyboard-key--wide {
  font-size: 18px;
}

.wesp-setup__keyboard-key--action {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

@media (max-width: 520px) {
  .wesp-setup__intro {
    height: min(200px, 32vh);
  }

  .wesp-setup__panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 720px);
    border-radius: 18px 18px 0 0;
    border-bottom: none;
  }

  .wesp-setup__header {
    padding: 18px 18px 0;
  }

  .wesp-setup__content {
    padding: 14px 18px 6px;
  }

  .wesp-setup__footer {
    padding: 10px 18px calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .wesp-setup__title {
    font-size: 20px;
  }

  .wesp-setup__role-card {
    min-height: 72px;
    padding: 16px 14px;
  }

  .wesp-setup__theme-grid .wesp-setup__theme-card {
    padding: 11px 12px 11px 56px;
  }

  .wesp-setup__theme-grid .wesp-setup__theme-card::before {
    left: 12px;
    width: 28px;
    height: 28px;
    margin-top: -14px;
  }

  .wesp-setup__btn {
    min-height: 44px;
  }

  .wesp-setup__actions {
    gap: 6px;
  }

  .wesp-setup__actions-fill {
    flex-basis: 100%;
    height: 0;
    min-width: 0;
  }

  .wesp-setup__btn--primary {
    flex: 1 1 auto;
    min-width: calc(50% - 4px);
  }

  .wesp-setup__keyboard {
    padding: 8px 14px 2px;
  }

  .wesp-setup__keyboard-grid {
    gap: 5px;
  }

  .wesp-setup__keyboard-key {
    min-height: 44px;
    font-size: 14px;
  }

  .wesp-setup__keyboard-key--action {
    font-size: 11px;
  }
}
