:root {
  color-scheme: light;
  --page: #f4f7fb;
  --card: rgba(255, 255, 255, 0.94);
  --text: #182235;
  --muted: #667085;
  --soft: #eef3f9;
  --line: #e2e8f0;
  --primary: #3767d6;
  --primary-hover: #2d58ba;
  --primary-soft: #eaf0ff;
  --success: #21836c;
  --success-soft: #e8f7f1;
  --danger: #c33f55;
  --shadow: 0 20px 60px rgba(32, 54, 88, 0.09), 0 2px 8px rgba(32, 54, 88, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 15%, rgba(191, 214, 255, 0.32), transparent 32rem),
    radial-gradient(circle at 85% 85%, rgba(196, 235, 224, 0.25), transparent 30rem),
    var(--page);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 34px 24px 22px;
}

.brand {
  width: min(100%, 1120px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--primary);
  border: 1px solid rgba(55, 103, 214, 0.12);
  border-radius: 10px;
  background: var(--primary-soft);
}

.brand-mark svg {
  width: 20px;
  height: 20px;
}

.auth-main {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 46px 0;
}

.auth-card {
  width: min(100%, 440px);
  padding: 40px;
  border: 1px solid rgba(218, 226, 237, 0.9);
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.view h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.view-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  color: var(--primary);
  border-radius: 15px;
  background: var(--primary-soft);
}

.view-icon svg {
  width: 26px;
  height: 26px;
}

.success-icon {
  color: var(--success);
  background: var(--success-soft);
}

.neutral-icon {
  color: #66758c;
  background: var(--soft);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.lead {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.75;
}

.destination {
  margin: 20px 0 0;
  padding: 11px 14px;
  color: #365385;
  border: 1px solid #dce6fa;
  border-radius: 10px;
  background: var(--primary-soft);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.auth-form {
  margin-top: 28px;
}

.field-label {
  display: block;
  margin-bottom: 9px;
  font-size: 14px;
  font-weight: 600;
}

.code-input {
  width: 100%;
  height: 58px;
  padding: 0 16px;
  color: var(--text);
  caret-color: var(--primary);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: var(--card);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: 0.35em;
  text-align: center;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.code-input::placeholder {
  color: #a7b0bf;
  font-weight: 400;
}

.code-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(55, 103, 214, 0.12);
}

.remember-option {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-top: 20px;
  cursor: pointer;
}

.remember-option input {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin: 2px 0 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.remember-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.remember-copy strong {
  font-size: 13px;
  font-weight: 550;
  line-height: 1.5;
}

.remember-copy small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.form-error {
  min-height: 21px;
  margin: 14px 0 8px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.button {
  width: 100%;
  min-height: 46px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.button:focus-visible {
  outline: 3px solid rgba(55, 103, 214, 0.28);
  outline-offset: 3px;
}

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

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

.button-primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 6px 16px rgba(55, 103, 214, 0.2);
}

.button-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.button-secondary {
  color: var(--text);
  border-color: var(--line);
  background: var(--soft);
}

.button-secondary:hover:not(:disabled) {
  border-color: #c8d2e0;
}

#authenticated-view .button,
#unconfigured-view .button,
#invalid-link-view .button,
#error-view .button {
  margin-top: 8px;
}

.session-note {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 26px 0 4px;
  padding: 13px 14px;
  color: var(--muted);
  border-radius: 11px;
  background: var(--soft);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(33, 131, 108, 0.1);
}

.loading-view,
#error-view,
#unconfigured-view,
#invalid-link-view {
  text-align: center;
}

.loading-view h1 {
  margin-top: 22px;
  font-size: 20px;
}

.loading-view p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

#error-view .view-icon,
#unconfigured-view .view-icon,
#invalid-link-view .view-icon {
  margin-right: auto;
  margin-left: auto;
}

.spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.setup-heading {
  text-align: left;
}

.setup-loading {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--muted);
  font-size: 14px;
}

.qr-frame {
  width: 220px;
  height: 220px;
  display: grid;
  place-items: center;
  margin: 26px auto 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.qr-frame img {
  display: block;
  width: 192px;
  height: 192px;
}

.manual-secret {
  padding: 13px 15px;
  border-radius: 11px;
  background: var(--soft);
  text-align: center;
}

.manual-secret span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.manual-secret code {
  display: block;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.08em;
  line-height: 1.6;
  overflow-wrap: anywhere;
  user-select: all;
}

.setup-view .auth-form {
  margin-top: 22px;
}

.setup-view .form-error {
  margin-bottom: 0;
  text-align: center;
}

#setup-retry {
  margin-top: 10px;
}

.page-footer {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  letter-spacing: 0.04em;
}

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

@media (max-width: 520px) {
  .page-shell {
    padding: 22px 16px 18px;
  }

  .auth-main {
    padding: 34px 0;
  }

  .auth-card {
    padding: 30px 24px;
    border-radius: 20px;
  }

  .view h1 {
    font-size: 25px;
  }

  .view-icon {
    margin-bottom: 20px;
  }

  .code-input {
    height: 56px;
    font-size: 23px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #111722;
    --card: rgba(25, 33, 46, 0.95);
    --text: #edf2fa;
    --muted: #a0acbd;
    --soft: #222c3b;
    --line: #354154;
    --primary: #83a7ff;
    --primary-hover: #9ab7ff;
    --primary-soft: #243451;
    --success: #72d4b8;
    --success-soft: #193a35;
    --danger: #ff93a4;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  }

  body {
    background:
      radial-gradient(circle at 15% 15%, rgba(55, 84, 135, 0.2), transparent 32rem),
      var(--page);
  }

  .auth-card {
    border-color: #2b3647;
  }

  .brand-mark {
    border-color: #354663;
  }

  .destination {
    color: #b7ccff;
    border-color: #354a71;
  }

  .button-primary {
    color: #132142;
  }

  .button-secondary:hover:not(:disabled) {
    border-color: #526078;
  }

  .code-input::placeholder {
    color: #647187;
  }

  .neutral-icon {
    color: #b0bdce;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }

  .spinner {
    animation-duration: 1600ms;
  }
}
