/* ============================================
   CSS Variables / Design Tokens
   ============================================ */
:root {
  --color-primary: #e02424;
  --color-primary-dark: #b91c1c;
  --color-primary-light: #fef2f2;
  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-secondary: #6b7280;
  --color-text-tertiary: #9ca3af;
  --color-border: #e5e7eb;
  --color-border-focus: #e02424;
  --color-error: #ef4444;
  --color-error-light: #fef2f2;
  --color-success: #10b981;
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;
  --radius-xl: 0;
  /* 8px grid spacing scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  /* Type scale */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-display: 28px;
  /* Elevation */
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 8px 32px rgba(0,0,0,0.06);
  --shadow-card-hover: 0 2px 6px rgba(0,0,0,0.06), 0 12px 48px rgba(0,0,0,0.08);
  --shadow-btn: 0 2px 8px rgba(224, 36, 36, 0.25);
  --shadow-btn-hover: 0 4px 16px rgba(224, 36, 36, 0.35);
  --shadow-input-focus: 0 0 0 3px rgba(224, 36, 36, 0.12);
  --shadow-input-error: 0 0 0 3px rgba(239, 68, 68, 0.1);
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

/* ============================================
   Reset & Base
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Subtle, refined background — barely visible radial washes */
  background-image:
    radial-gradient(ellipse at 25% 0%, rgba(224,36,36,0.03) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 100%, rgba(224,36,36,0.02) 0%, transparent 55%);
}

/* ============================================
   Page Container
   ============================================ */
.page-wrapper {
  width: 100%;
  max-width: 420px;
  animation: fadeInUp 0.5s var(--transition-normal) both;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Brand Header
   ============================================ */
.brand {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-md);
}

.brand-logo img {
  width: 120px;
  height: auto;
  display: block;
}

.brand-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  letter-spacing: 0.02em;
}

/* ============================================
   Card Title
   ============================================ */
.card-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-lg);
  letter-spacing: -0.01em;
}

/* ============================================
   Form Groups
   ============================================ */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-sm);
  letter-spacing: 0.01em;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  width: 20px;
  height: 20px;
  pointer-events: none;
  z-index: 1;
  color: var(--color-text-tertiary);
  transition: color var(--transition-fast);
}

.input-wrapper:focus-within .input-icon {
  color: var(--color-primary);
}

.input-wrapper.error .input-icon {
  color: var(--color-error);
}

.form-input {
  width: 100%;
  height: 48px;
  padding: 0 44px 0 44px;
  font-size: 16px;
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

.form-input::placeholder {
  color: var(--color-text-tertiary);
  opacity: 1;
}

.form-input:focus {
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-input-focus);
}

/* Toggle button inside password input */
.input-toggle {
  position: absolute;
  right: 4px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-tertiary);
  border-radius: 0;
  transition: color var(--transition-fast), background var(--transition-fast);
  z-index: 1;
  padding: 0;
}

.input-toggle:hover {
  color: var(--color-text-secondary);
  background: rgba(0, 0, 0, 0.04);
}

.input-toggle:active {
  transform: scale(0.92);
}

.input-toggle svg {
  width: 20px;
  height: 20px;
  transition: opacity var(--transition-fast);
}

/* ============================================
   Validation States
   ============================================ */
.form-input.error {
  border-color: var(--color-error);
  box-shadow: var(--shadow-input-error);
}

.form-input.success {
  border-color: var(--color-success);
}

.error-message {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--color-error);
  margin-top: var(--space-xs);
  animation: fadeIn 0.2s ease;
}

.error-message.show {
  display: flex;
}

.error-message svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
   Extras Row (Remember + Forgot)
   ============================================ */
.form-extras {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.remember-me {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.remember-me input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--color-border);
  border-radius: 0;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all var(--transition-fast);
  background: var(--color-surface);
}

.remember-me input[type="checkbox"]:checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.remember-me input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: 2px solid white;
  border-top: none;
  border-right: none;
  transform: rotate(-45deg);
}

.remember-me .remember-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.forgot-link {
  font-size: var(--text-sm);
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--transition-fast), opacity var(--transition-fast);
}

.forgot-link:hover {
  color: var(--color-primary-dark);
  opacity: 0.85;
}

/* ============================================
   Submit Button
   ============================================ */
.btn-submit {
  width: 100%;
  height: var(--space-2xl);
  font-size: var(--text-base);
  font-weight: 700;
  font-family: var(--font-family);
  letter-spacing: 0.05em;
  color: #ffffff;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-btn);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* Ripple on hover — a subtle lift */
.btn-submit:hover {
  background: var(--color-primary-dark);
  box-shadow: var(--shadow-btn-hover);
  transform: translateY(-2px);
}

.btn-submit:active {
  transform: scale(0.97);
  transition: transform 0.1s ease;
}

.btn-submit:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn-submit:disabled {
  background: #f4a0a0;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
  pointer-events: none;
}

/* Loading state */
.btn-submit.loading {
  color: transparent;
  pointer-events: none;
}

.btn-submit .spinner {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-submit.loading .spinner {
  display: block;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ============================================
   Bottom Link
   ============================================ */
.bottom-link {
  text-align: center;
  margin-top: var(--space-lg);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.bottom-link a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
  margin-left: var(--space-xs);
  transition: color var(--transition-fast), opacity var(--transition-fast);
}

.bottom-link a:hover {
  color: var(--color-primary-dark);
  opacity: 0.85;
}

/* ============================================
   Desktop Enhancement (>= 768px)
   ============================================ */
@media (min-width: 768px) {
  body {
    padding: 40px;
    background-image:
      radial-gradient(ellipse at 10% 10%, rgba(224, 36, 36, 0.06) 0%, transparent 50%),
      radial-gradient(ellipse at 90% 90%, rgba(224, 36, 36, 0.04) 0%, transparent 50%),
      radial-gradient(ellipse at 50% 50%, rgba(224, 36, 36, 0.02) 0%, transparent 70%);
  }

  .login-card,
  .register-card {
    padding: var(--space-2xl) var(--space-xl);
  }
}

/* ============================================
   Toast Notification
   ============================================ */
.toast {
  position: fixed;
  top: var(--space-lg);
  left: 50%;
  transform: translateX(-50%) translateY(-120px);
  background: #1a1a2e;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-left: 3px solid var(--color-success);
}

.toast.error {
  border-left: 3px solid var(--color-error);
}

.toast svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Toast dismiss hint — subtle X appears on hover */
.toast::after {
  content: '×';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.toast:hover::after {
  opacity: 0.5;
}

/* ============================================
   SMS Code Row (Register)
   ============================================ */
.sms-row {
  display: flex;
  gap: var(--space-sm);
}

.sms-row .input-wrapper {
  flex: 1;
}

.sms-row .form-input {
  padding: 0 14px 0 44px;
}

.btn-sms {
  flex-shrink: 0;
  width: 120px;
  height: var(--space-2xl);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-family);
  color: var(--color-primary);
  background: var(--color-primary-light);
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-sms:hover {
  background: #fecaca;
  border-color: var(--color-primary);
}

.btn-sms:active {
  transform: scale(0.96);
}

.btn-sms:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn-sms:disabled {
  color: var(--color-text-tertiary);
  background: #f3f4f6;
  cursor: not-allowed;
  transform: none;
}

.btn-sms.counting {
  color: var(--color-text-secondary);
  background: #f3f4f6;
}

/* ============================================
   Password Strength Indicator (Register)
   ============================================ */
.strength-bar {
  height: 4px;
  border-radius: 0;
  background: #e5e7eb;
  margin-top: var(--space-sm);
  overflow: hidden;
  transition: background var(--transition-fast);
}

.strength-bar .strength-fill {
  height: 100%;
  border-radius: 0;
  width: 0%;
  transition: width 0.3s ease, background 0.3s ease;
}

.strength-bar.weak .strength-fill {
  width: 33%;
  background: var(--color-error);
}

.strength-bar.medium .strength-fill {
  width: 66%;
  background: #f59e0b;
}

.strength-bar.strong .strength-fill {
  width: 100%;
  background: var(--color-success);
}

.strength-text {
  font-size: var(--text-xs);
  margin-top: var(--space-xs);
  color: var(--color-text-tertiary);
  transition: color var(--transition-fast);
}

.strength-text.weak { color: var(--color-error); }
.strength-text.medium { color: #f59e0b; }
.strength-text.strong { color: var(--color-success); }

/* ============================================
   Agreement Checkbox (Register)
   ============================================ */
.agreement-group {
  margin-bottom: var(--space-lg);
}

.agreement-label {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.agreement-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--color-border);
  border-radius: 0;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  margin-top: 1px;
  transition: all var(--transition-fast);
  background: var(--color-surface);
}

.agreement-label input[type="checkbox"]:checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.agreement-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: 2px solid white;
  border-top: none;
  border-right: none;
  transform: rotate(-45deg);
}

.agreement-label a {
  color: var(--color-primary);
  text-decoration: none;
}

.agreement-label a:hover {
  text-decoration: underline;
}

.agreement-error {
  display: none;
  font-size: var(--text-xs);
  color: var(--color-error);
  margin-top: var(--space-xs);
}

.agreement-error.show {
  display: block;
}

/* ============================================
   Card (shared by login & register)
   ============================================ */
.login-card,
.register-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-xl) var(--space-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(0, 0, 0, 0.04);
  /* Signature accent — a thin red line at the top, the one memorable gesture */
  border-top: 2px solid var(--color-primary);
  transition: box-shadow var(--transition-normal);
}

.login-card:hover,
.register-card:hover {
  box-shadow: var(--shadow-card-hover);
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
