:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --page: #f8f8f8;
  --surface: #ffffff;
  --text: #404040;
  --heading: #292832;
  --muted: #6d6d76;
  --line: #e7e7e7;
  --line-strong: #d4d3db;
  --input: #ffffff;
  --switch: #e9e9ed;
  --accent: #6051f5;
  --accent-hover: #5143d9;
  --accent-soft: #f1efff;
  --focus: #8d83ff;
  --error: #a92b22;
  --error-bg: #fff4f2;
  --error-line: #efc7c2;
  --glow: rgba(96, 81, 245, 0.075);
  --shadow: 0 1px 2px rgba(31, 27, 54, 0.03), 0 20px 60px rgba(46, 39, 94, 0.07);
  --gutter: clamp(20px, 4vw, 56px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #17181d;
  --surface: #202127;
  --text: #e8e8eb;
  --heading: #f4f3f8;
  --muted: #a0a1aa;
  --line: #353640;
  --line-strong: #4a4b55;
  --input: #232429;
  --switch: #303139;
  --accent: #6051f5;
  --accent-hover: #766af7;
  --accent-soft: #2b2940;
  --focus: #a49aff;
  --error: #ffb4ab;
  --error-bg: #3a2528;
  --error-line: #63383b;
  --glow: rgba(96, 81, 245, 0.1);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.16), 0 20px 60px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

body {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  isolation: isolate;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 42%, var(--glow), transparent 62%), var(--page);
}

button, input { font: inherit; }
button { cursor: pointer; }
button, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.icon,
.input-icon {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.masthead {
  position: relative;
  z-index: 2;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(20px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 0
    max(var(--gutter), env(safe-area-inset-left));
}

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

.brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  flex: none;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
  font-size: 14px;
  font-weight: 750;
  line-height: 1;
}

.brand-name {
  color: #20244b;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.3px;
}

:root[data-theme="dark"] .brand-name { color: var(--heading); }

.theme-switch {
  display: flex;
  flex: none;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: var(--switch);
}

.theme-button {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 550;
  transition: color 160ms var(--ease-out), background-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.theme-button .icon { width: 14px; height: 14px; }
.theme-button:hover { color: var(--text); }
.theme-button:active { transform: scale(0.96); }
.theme-button[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(26, 24, 44, 0.12);
}

.stage {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 0;
  place-items: center;
  padding: 32px max(var(--gutter), env(safe-area-inset-right))
    max(48px, env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

.login-stack {
  position: relative;
  z-index: 1;
  width: min(100%, 440px);
}

.auth {
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-header { margin-bottom: 32px; }

.auth-kicker {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.auth h1 {
  margin: 0;
  color: var(--heading);
  font-size: 30px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.04em;
}

.field { margin-bottom: 20px; }

.field label {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.input-wrap {
  display: flex;
  min-height: 48px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  transition: border-color 180ms var(--ease-out), background-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
}

.input-wrap:hover { border-color: var(--line-strong); }

.input-wrap:focus-within {
  border-color: var(--focus);
  background: var(--input);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.input-icon {
  width: 17px;
  height: 17px;
  margin-left: 14px;
  color: var(--muted);
}

.input-wrap input {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 0 12px;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  caret-color: var(--accent);
  font-size: 14px;
}

.input-wrap input:focus-visible { outline: none; }
.input-wrap input::placeholder { color: var(--muted); opacity: 1; }

.eye {
  display: grid;
  width: 44px;
  height: 44px;
  flex: none;
  margin-right: 1px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  transition: color 160ms var(--ease-out), background-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.eye .icon { width: 18px; height: 18px; }
.eye:hover { color: var(--accent); background: var(--accent-soft); }
.eye:active { transform: scale(0.92); }
.eye .icon-eye-off { display: none; }
.eye[data-visible="true"] .icon-eye { display: none; }
.eye[data-visible="true"] .icon-eye-off { display: block; }

.error {
  margin: -4px 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--error-line);
  border-radius: 8px;
  color: var(--error);
  background: var(--error-bg);
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.primary {
  display: inline-flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 4px 12px rgba(96, 81, 245, 0.16);
  font-size: 15px;
  font-weight: 650;
  transition: background-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out), transform 160ms var(--ease-out), opacity 180ms var(--ease-out);
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 6px 16px rgba(96, 81, 245, 0.22);
}

.primary:active:not(:disabled) { transform: scale(0.985); }
.primary:disabled { opacity: 0.68; cursor: wait; }

.button-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.36);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.primary.is-loading .button-spinner { display: block; }

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

@media (max-width: 760px) {
  .masthead {
    min-height: 64px;
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .stage {
    padding: 24px max(20px, env(safe-area-inset-right))
      max(32px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  }

  .auth { padding: 28px; }
}

@media (max-width: 480px) {
  :root { --gutter: 16px; }

  .masthead {
    min-height: 60px;
    gap: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .brand-mark { width: 26px; height: 26px; border-radius: 7px; font-size: 13px; }
  .brand-name { font-size: 15px; }
  .theme-button { min-height: 44px; padding: 0 10px; }

  .stage {
    padding: 20px max(16px, env(safe-area-inset-right))
      max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .auth { padding: 24px 20px; }
  .auth-header { margin-bottom: 24px; }
  .auth-kicker { margin-bottom: 8px; }
  .auth h1 { font-size: 26px; }
  .field { margin-bottom: 16px; }
  .field label { font-size: 14px; }
  .input-wrap { min-height: 50px; }
  .input-wrap input { height: 48px; font-size: 16px; }
  .input-icon { margin-left: 12px; }
  .eye { height: 46px; }
  .primary { min-height: 48px; font-size: 16px; }
}

@media (max-height: 700px) and (min-width: 761px) {
  .stage { padding-top: 16px; padding-bottom: 24px; }
  .auth { padding: 28px 32px; }
  .auth-header { margin-bottom: 24px; }
}

@media (pointer: coarse) {
  .theme-button { min-height: 44px; }
  .eye { min-width: 44px; min-height: 44px; }
}

@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;
  }
}
