
/* Ensure the custom element doesn't affect page layout */
sugarcube-auth-modal {
  display: contents;
}

    #authModalOverlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.75);
      z-index: 9998;
      align-items: center;
      justify-content: center;
      padding: 1rem;
    }
    #authModal {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.75);
      z-index: 9998;
      align-items: center;
      justify-content: center;
      padding: 1rem;
    }
    .auth-modal-box {
      background: #1a1a1a;
      border: 1px solid #2a2a2a;
      border-radius: 1.25rem;
      padding: 2rem;
      width: 100%;
      max-width: 420px;
      position: relative;
      box-shadow: 0 25px 60px rgba(0,0,0,0.6);
    }
    .auth-modal-close {
      position: absolute;
      top: 1rem;
      right: 1rem;
      background: none;
      border: none;
      color: #6b7280;
      font-size: 1.25rem;
      cursor: pointer;
      line-height: 1;
      padding: 4px;
      border-radius: 4px;
      transition: color 0.2s;
    }
    .auth-modal-close:hover { color: #ffffff; }
    .auth-modal-title {
      text-align: center;
      font-size: 1.5rem;
      font-weight: 700;
      color: #ffffff;
      margin-bottom: 1.5rem;
    }
    .auth-field {
      margin-bottom: 1rem;
    }
    .auth-field label {
      display: block;
      font-size: 0.8rem;
      font-weight: 500;
      color: #9ca3af;
      margin-bottom: 0.4rem;
    }
    .auth-field input {
      width: 100%;
      background: #111;
      border: 1px solid #333;
      color: #d1d5db;
      border-radius: 0.625rem;
      padding: 0.7rem 0.9rem;
      font-size: 0.9rem;
      transition: border-color 0.2s, box-shadow 0.2s;
      box-sizing: border-box;
      font-family: inherit;
    }
    .auth-field input:focus {
      outline: none;
      border-color: #10B981;
      box-shadow: 0 0 0 3px rgba(16,185,129,0.15);
    }
    .auth-field input::placeholder { color: #4b5563; }
    .auth-submit-btn {
      width: 100%;
      background: linear-gradient(135deg, #059669, #10B981);
      color: white;
      border: none;
      border-radius: 0.625rem;
      padding: 0.75rem;
      font-size: 1rem;
      font-weight: 600;
      cursor: pointer;
      transition: opacity 0.2s, transform 0.1s;
      margin-top: 0.5rem;
    }
    .auth-submit-btn:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }
    .auth-submit-btn:disabled { opacity: 0.6; cursor: not-allowed; }
    .auth-divider {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      margin: 1.25rem 0;
      color: #4b5563;
      font-size: 0.8rem;
    }
    .auth-divider::before, .auth-divider::after {
      content: '';
      flex: 1;
      height: 1px;
      background: #2a2a2a;
    }
    .auth-google-btn {
      width: 100%;
      background: #1a1a1a;
      border: 1px solid #333;
      color: #d1d5db;
      border-radius: 0.625rem;
      padding: 0.7rem;
      font-size: 0.9rem;
      font-weight: 500;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 0.6rem;
      transition: border-color 0.2s, background 0.2s;
    }
    .auth-google-btn:hover { border-color: #10B981; background: rgba(16,185,129,0.05); }
    .auth-toggle {
      text-align: center;
      margin-top: 1.25rem;
      font-size: 0.85rem;
      color: #6b7280;
    }
    .auth-toggle a {
      color: #10B981;
      text-decoration: none;
      font-weight: 500;
      cursor: pointer;
    }
    .auth-toggle a:hover { text-decoration: underline; }
    .auth-error {
      color: #ef4444;
      font-size: 0.8rem;
      margin-bottom: 0.75rem;
      text-align: center;
      min-height: 1.2em;
    }
    .auth-field-error {
      color: #ef4444;
      font-size: 0.75rem;
      margin-top: 0.35rem;
      min-height: 1em;
      padding-left: 2px;
    }

    /* Field error state */
    .auth-field.has-error input {
      border-color: #ef4444 !important;
      box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15) !important;
    }

    /* Spinner for loading state */
    @keyframes auth-spin {
      to { transform: rotate(360deg); }
    }
    .auth-spinner {
      display: inline-block;
      width: 18px;
      height: 18px;
      border: 2.5px solid rgba(255,255,255,0.35);
      border-top-color: #fff;
      border-radius: 50%;
      animation: auth-spin 0.65s linear infinite;
      vertical-align: middle;
      margin-right: 6px;
    }

    /* Input disabled during loading */
    .auth-modal-box input:disabled {
      opacity: 0.55;
      cursor: not-allowed;
    }
    .auth-google-btn:disabled {
      opacity: 0.55;
      cursor: not-allowed;
    }

    /* ── Email Verification View ── */
    .auth-verify-icon {
      text-align: center;
      font-size: 2.5rem;
      margin-bottom: 0.75rem;
    }
    .auth-verify-desc {
      text-align: center;
      font-size: 0.9rem;
      color: #9ca3af;
      line-height: 1.6;
      margin-bottom: 1.5rem;
    }
    .auth-verify-desc strong {
      color: #ffffff;
      word-break: break-all;
    }

    /* 6-digit code input */
    .auth-code-input-row {
      display: flex;
      gap: 0.5rem;
      justify-content: center;
      margin-bottom: 0.75rem;
    }
    .auth-code-digit {
      width: 42px;
      height: 50px;
      text-align: center;
      font-size: 1.4rem;
      font-weight: 700;
      font-family: 'Courier New', monospace;
      background: #111;
      border: 1px solid #333;
      border-radius: 0.5rem;
      color: #ffffff;
      transition: border-color 0.2s, box-shadow 0.2s;
      caret-color: #10B981;
    }
    .auth-code-digit:focus {
      outline: none;
      border-color: #10B981;
      box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
    }
    .auth-code-digit.has-error {
      border-color: #ef4444;
      box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
    }

    /* Resend button */
    .auth-verify-footer {
      text-align: center;
      margin-top: 1rem;
      font-size: 0.82rem;
      color: #6b7280;
    }
    .auth-resend-btn {
      background: none;
      border: none;
      color: #10B981;
      font-size: 0.82rem;
      font-weight: 500;
      cursor: pointer;
      padding: 0;
      text-decoration: underline;
      transition: opacity 0.2s;
    }
    .auth-resend-btn:disabled {
      color: #4b5563;
      cursor: not-allowed;
      text-decoration: none;
    }
    .auth-resend-cooldown {
      color: #6b7280;
      font-size: 0.8rem;
    }

    /* Spinner for verify button */
    @keyframes auth-spin {
      to { transform: rotate(360deg); }
    }
    .auth-spinner {
      display: inline-block;
      width: 16px;
      height: 16px;
      border: 2px solid rgba(255,255,255,0.3);
      border-top-color: #fff;
      border-radius: 50%;
      animation: auth-spin 0.65s linear infinite;
      vertical-align: middle;
      margin-right: 6px;
    }