/* ============================================================
   MiraculousTO — Auth theme (login + 2FA)
   Ladybug spinner: ported from secret/player.php
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

:root {
  --mto-red: #e62b2b;
  --mto-red-bright: #ff1744;
  --mto-red-deep: #c62828;
  --mto-purple: #380099;
  --mto-green: #97c459;
  --mto-noir: #17171c;
  --mto-card: #1f1f26;
  --mto-card-border: rgba(255, 255, 255, 0.09);
  --mto-text: #ffffff;
  --mto-text-dim: rgba(255, 255, 255, 0.65);
  --mto-text-faint: rgba(255, 255, 255, 0.45);
  --mto-input-bg: rgba(255, 255, 255, 0.06);
  --mto-input-border: rgba(255, 255, 255, 0.14);
  --mto-focus-ring: rgba(230, 43, 43, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  letter-spacing: 0.01em;
  color: var(--mto-text);
  background-color: var(--mto-noir);
  background-image: radial-gradient(circle, rgba(230, 43, 43, 0.12) 7px, transparent 8px);
  background-size: 72px 72px;
  animation: mtoDotsDrift 60s linear infinite;
}

@keyframes mtoDotsDrift {
  from { background-position: 0 0; }
  to   { background-position: 144px 72px; }
}

/* ---------- Layout ---------- */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--mto-card);
  border: 1px solid var(--mto-card-border);
  border-radius: 16px;
  padding: 32px 28px;
  margin: 0;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}

body.document-loaded .auth-card {
  opacity: 1;
  transform: none;
}

body.has-error .auth-card {
  animation: mtoShake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) 0.5s both;
}

@keyframes mtoShake {
  10%, 90%      { transform: translateX(-1px); }
  20%, 80%      { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60%      { transform: translateX(4px); }
}

/* ---------- Page loader (full-screen, ladybug) ---------- */
.auth-loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--mto-noir);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

body.document-loaded .auth-loader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---------- Ladybug icon (ported from player.php) ---------- */
.ladybug-container {
  position: relative;
  width: 90px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ladybug-icon {
  --size: 64px;
  width: var(--size);
  height: var(--size);
  position: relative;
  border-radius: 50%;
  background: radial-gradient(circle, #d50000 0, #b71c1c 70%);
  border: 3px solid #000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  flex-shrink: 0;
}

.ladybug-icon .dot {
  --dot: calc(var(--size) * 0.25);
  position: absolute;
  width: var(--dot);
  height: var(--dot);
  background: #000;
  border-radius: 50%;
}

.ladybug-icon .dot.center {
  --dot: calc(var(--size) * 0.30);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.ladybug-icon .dot.tl { top: 12%;    left: 12%;  }
.ladybug-icon .dot.tr { top: 12%;    right: 12%; }
.ladybug-icon .dot.bl { bottom: 12%; left: 12%;  }
.ladybug-icon .dot.br { bottom: 12%; right: 12%; }

.loading-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 5px solid transparent;
  border-top: 5px solid var(--mto-red-bright);
  border-right: 5px solid var(--mto-red-deep);
  border-radius: 50%;
  animation: ladybugRingRotate 1.2s linear infinite;
}

.auth-loader .ladybug-icon .dot:not(.center) { animation: dotWave 2s ease-in-out infinite; }
.auth-loader .ladybug-icon .dot.tl { animation-delay: 0s; }
.auth-loader .ladybug-icon .dot.tr { animation-delay: 0.15s; }
.auth-loader .ladybug-icon .dot.bl { animation-delay: 0.25s; }
.auth-loader .ladybug-icon .dot.br { animation-delay: 0.35s; }

@keyframes ladybugRingRotate {
  0%   { transform: rotate(0); }
  100% { transform: rotate(360deg); }
}

@keyframes dotWave {
  0%, 25%, 100% { transform: scale(1); }
  12%           { transform: scale(1.35); }
}

@keyframes dotWaveCenter {
  0%, 25%, 100% { transform: translate(-50%, -50%) scale(1); }
  12%           { transform: translate(-50%, -50%) scale(1.25); }
}

/* ---------- Brand header ---------- */
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 22px;
  text-align: center;
}

.auth-brand .ladybug-icon {
  --size: 56px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.auth-brand .ladybug-icon:hover { transform: rotate(-8deg) scale(1.06); }

.auth-brand .ladybug-icon:hover .dot:not(.center) { animation: dotWave 1.2s ease-in-out infinite; }
.auth-brand .ladybug-icon:hover .dot.center       { animation: dotWaveCenter 1.2s ease-in-out infinite; }
.auth-brand .ladybug-icon:hover .dot.tl { animation-delay: 0s; }
.auth-brand .ladybug-icon:hover .dot.tr { animation-delay: 0.15s; }
.auth-brand .ladybug-icon:hover .dot.bl { animation-delay: 0.25s; }
.auth-brand .ladybug-icon:hover .dot.br { animation-delay: 0.35s; }

.auth-brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--mto-text);
}

.auth-brand .auth-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--mto-text-dim);
}

/* ---------- Messages ---------- */
.error-message {
  display: none;
  background: rgba(230, 43, 43, 0.14);
  border: 1px solid rgba(230, 43, 43, 0.45);
  border-left: 3px solid var(--mto-red);
  color: #ffb4b4;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}

body.has-error .error-message { display: block; }

.attempts-warning {
  background: rgba(255, 152, 0, 0.12);
  border: 1px solid rgba(255, 152, 0, 0.4);
  border-left: 3px solid #ff9800;
  color: #ffd699;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}

.attempts-info {
  color: var(--mto-text-faint);
  font-size: 12px;
  margin: 0 0 14px;
}

.code-hint {
  color: var(--mto-text-dim);
  font-size: 13px;
  margin: 0 0 16px;
}

/* ---------- Fields ---------- */
.field { margin-bottom: 14px; text-align: left; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--mto-text-dim);
  margin: 0 0 6px;
  letter-spacing: 0.03em;
  transition: color 0.2s ease;
}

.field:focus-within label { color: var(--mto-red); }

.field__wrap { position: relative; }

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--mto-text);
  background: var(--mto-input-bg);
  border: 1px solid var(--mto-input-border);
  border-radius: 8px;
  height: 44px;
  padding: 0 12px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.field input:hover { border-color: rgba(255, 255, 255, 0.25); }

.field input:focus {
  border-color: var(--mto-red);
  box-shadow: 0 0 0 3px var(--mto-focus-ring);
  background: rgba(255, 255, 255, 0.08);
}

.field--password input { padding-right: 46px; }

.password-toggle {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--mto-text-faint);
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  color: var(--mto-text);
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.password-toggle svg { width: 19px; height: 19px; }

.capslock-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: #ffd699;
}

/* 2FA code input */
.field--code input {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 14px;
  padding-left: 14px;
  height: 56px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Remember me ---------- */
.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 18px;
  font-size: 13px;
  color: var(--mto-text-dim);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.remember input {
  accent-color: var(--mto-red);
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.remember:hover { color: var(--mto-text); }

/* ---------- Buttons ---------- */
.btn {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  width: 100%;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.05em;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.25s ease, background 0.25s ease, border-color 0.25s ease;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--mto-focus-ring);
}

.btn:active { transform: scale(0.98); }

.btn--primary {
  background: var(--mto-red);
  color: #fff;
  margin-bottom: 10px;
}

.btn--primary:hover {
  background: var(--mto-red-bright);
  box-shadow: 0 6px 22px rgba(255, 23, 68, 0.35);
}

.btn--primary::after {
  content: '';
  position: absolute;
  top: 0;
  left: -80%;
  width: 50%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  transform: skewX(-20deg);
  transition: left 0.5s ease;
  pointer-events: none;
}

.btn--primary:hover::after { left: 130%; }

.btn--passkey {
  background: transparent;
  border: 1px solid var(--mto-green);
  color: var(--mto-green);
}

.btn--passkey:hover {
  background: rgba(151, 196, 89, 0.12);
  box-shadow: 0 4px 18px rgba(151, 196, 89, 0.2);
}

.btn--passkey svg { width: 18px; height: 18px; }

/* Submit spinner state */
.btn .btn__spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ladybugRingRotate 0.9s linear infinite;
}

.btn.is-submitting { pointer-events: none; opacity: 0.85; }
.btn.is-submitting .btn__spinner { display: inline-block; }
.btn.is-submitting .btn__label { opacity: 0.7; }

/* ---------- Tip ---------- */
.auth-tip {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--mto-text-faint);
  text-align: center;
}

.auth-tip em {
  color: var(--mto-text-dim);
  font-style: normal;
  font-weight: 700;
}

/* ---------- Content reveal (staggered) ---------- */
.auth-content > * {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

body.document-loaded .auth-content > * { opacity: 1; transform: none; }
body.document-loaded .auth-content > *:nth-child(1) { transition-delay: 0.05s; }
body.document-loaded .auth-content > *:nth-child(2) { transition-delay: 0.1s; }
body.document-loaded .auth-content > *:nth-child(3) { transition-delay: 0.15s; }
body.document-loaded .auth-content > *:nth-child(4) { transition-delay: 0.2s; }
body.document-loaded .auth-content > *:nth-child(5) { transition-delay: 0.25s; }
body.document-loaded .auth-content > *:nth-child(6) { transition-delay: 0.3s; }
body.document-loaded .auth-content > *:nth-child(7) { transition-delay: 0.35s; }
body.document-loaded .auth-content > *:nth-child(8) { transition-delay: 0.4s; }

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  .auth-page {
    align-items: flex-start;
    padding: max(7vh, 32px) 14px 24px;
  }

  .auth-card {
    max-width: 100%;
    padding: 26px 20px;
  }

  .auth-brand .ladybug-icon { --size: 48px; }
  .auth-brand h1 { font-size: 19px; }

  .btn { height: 48px; }

  .field--code input {
    font-size: 22px;
    letter-spacing: 10px;
    padding-left: 10px;
  }

  body { background-size: 56px 56px; }
}

@media (max-height: 620px) {
  .auth-page { align-items: flex-start; padding-top: 20px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  body { animation: none; }

  .auth-card,
  .auth-content > * {
    transition-duration: 0.01ms;
    transition-delay: 0s;
  }

  body.has-error .auth-card { animation: none; }

  .auth-brand .ladybug-icon,
  .auth-brand .ladybug-icon .dot { animation: none !important; transition: none; }
  .auth-brand .ladybug-icon:hover { transform: none; }

  .btn--primary::after { display: none; }
}
