/**
 * Auth modal — dark theme, matches the SnowPro 50-day editorial palette.
 *
 * Same token strategy as gate-block.css: prefer the theme's --sf-* tokens
 * with hex fallbacks so the plugin still looks polished on themes that
 * don't define them.
 *
 * Layout strategy:
 *   - Fixed-position host covers the viewport.
 *   - Backdrop is a sibling, not a parent (cleaner stacking + click handling).
 *   - The modal panel is centred via flex on the host.
 *   - On narrow viewports the panel becomes a full-screen sheet with a
 *     scrollable body (modals on phones with on-screen keyboards otherwise
 *     get clipped at the bottom).
 */

:root {
  --tcg-accent: #29B5E8;
}

/* ─────────────────────────────────────────────────────────
   Host + backdrop
   ───────────────────────────────────────────────────────── */
.tcg-modal-host {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;

  /* Hidden default. JS sets aria-hidden="false" + removes [hidden]. */
  /* We also fade in via opacity once the open class lands. */
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.tcg-modal-host.tcg-modal-host--open {
  opacity: 1;
  pointer-events: auto;
}

.tcg-modal-host[hidden] {
  display: none;
}

.tcg-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 9, 14, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* ─────────────────────────────────────────────────────────
   Modal panel
   ───────────────────────────────────────────────────────── */
.tcg-modal {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  padding: 2rem 1.75rem 1.75rem;
  background: var(--sf-surface, #141923);
  border: 1px solid var(--sf-border, #232A38);
  border-radius: 14px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);

  /* Subtle slide-up on open. Disabled under reduced-motion below. */
  transform: translateY(8px);
  transition: transform 0.22s cubic-bezier(.2, .8, .2, 1);

  font-family: var(--sf-font, 'Figtree', system-ui, sans-serif);
}

.tcg-modal-host--open .tcg-modal {
  transform: translateY(0);
}

/* Cyan left-edge accent — visually ties it to the gate block. */
.tcg-modal::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--tcg-accent);
  border-radius: 14px 0 0 14px;
}

.tcg-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--sf-muted, #8B93A4);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  padding: 0;
}

.tcg-modal-close:hover,
.tcg-modal-close:focus-visible {
  background: var(--sf-surface-hover, #1A2030);
  color: var(--sf-text-bright, #F4F6FA);
  border-color: var(--sf-border, #232A38);
  outline: none;
}

/* ─────────────────────────────────────────────────────────
   Header
   ───────────────────────────────────────────────────────── */
.tcg-modal-header {
  margin-bottom: 1.25rem;
  padding-right: 2rem; /* leave room for the close button */
}

.tcg-modal-title {
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--sf-text-bright, #F4F6FA);
  letter-spacing: -0.01em;
}

.tcg-modal-sub {
  margin: 0;
  color: var(--sf-muted, #8B93A4);
  font-size: 0.92rem;
  line-height: 1.5;
}

/* Mode-aware title/sub: hide the inactive mode's text. */
.tcg-modal-host[data-tcg-mode="signup"] .tcg-modal-title--login,
.tcg-modal-host[data-tcg-mode="signup"] .tcg-modal-sub--login,
.tcg-modal-host[data-tcg-mode="login"]  .tcg-modal-title--signup,
.tcg-modal-host[data-tcg-mode="login"]  .tcg-modal-sub--signup {
  display: none;
}

/* Mode-aware form visibility — JS just toggles [hidden] but this rule
   exists as a safety net in case CSS races the JS on first render. */
.tcg-modal-host[data-tcg-mode="signup"] .tcg-modal-form--login,
.tcg-modal-host[data-tcg-mode="login"]  .tcg-modal-form--signup {
  display: none;
}

/* When the success pane is showing, hide both forms. */
.tcg-modal-host[data-tcg-state="success"] .tcg-modal-form,
.tcg-modal-host[data-tcg-state="success"] .tcg-modal-header {
  display: none;
}

/* ─────────────────────────────────────────────────────────
   Form-level alert
   ───────────────────────────────────────────────────────── */
.tcg-modal-alert {
  margin-bottom: 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--sf-text-bright, #F4F6FA);
  font-size: 0.875rem;
  line-height: 1.45;
}

.tcg-modal-alert[hidden] {
  display: none;
}

/* ─────────────────────────────────────────────────────────
   Field primitives — input, label, error, hint
   ───────────────────────────────────────────────────────── */
.tcg-field {
  margin-bottom: 0.95rem;
}

.tcg-field:last-of-type {
  margin-bottom: 0;
}

.tcg-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--sf-text, #E4E7EE);
  letter-spacing: 0.01em;
}

.tcg-input,
.tcg-select {
  display: block;
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 0.95rem;
  line-height: 1.4;
  font-family: inherit;
  color: var(--sf-text-bright, #F4F6FA);
  background: var(--sf-bg, #0E1218);
  border: 1px solid var(--sf-border, #232A38);
  border-radius: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.tcg-input:hover,
.tcg-select:hover {
  border-color: var(--sf-border-light, #2E3648);
}

.tcg-input:focus,
.tcg-select:focus {
  outline: none;
  border-color: var(--tcg-accent);
  box-shadow: 0 0 0 3px rgba(41, 181, 232, 0.18);
}

/* Native <select> down-arrow — colored to match the muted text. */
.tcg-select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%238B93A4' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 10px 6px;
  padding-right: 2.25rem;
}

.tcg-field-hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--sf-muted, #8B93A4);
}

.tcg-field-error {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: #F87171;
}

.tcg-field-error[hidden] {
  display: none;
}

/* When a field is in error, paint the input red. JS sets .tcg-field--error
   on the parent — single style hook for input + label + error message. */
.tcg-field--error .tcg-input,
.tcg-field--error .tcg-select {
  border-color: rgba(239, 68, 68, 0.55);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.14);
}

/* ─────────────────────────────────────────────────────────
   Country combobox
   - Search input + multiline <select> sized at 6 rows.
   - JS filters options as user types and selects the highlighted item
     on Enter.
   ───────────────────────────────────────────────────────── */
.tcg-country {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tcg-country-search {
  /* same shape as .tcg-input, slightly tighter */
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  line-height: 1.4;
  font-family: inherit;
  color: var(--sf-text-bright, #F4F6FA);
  background: var(--sf-bg, #0E1218);
  border: 1px solid var(--sf-border, #232A38);
  border-radius: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tcg-country-search:focus {
  outline: none;
  border-color: var(--tcg-accent);
  box-shadow: 0 0 0 3px rgba(41, 181, 232, 0.18);
}

.tcg-country-select {
  /* Multi-row select — looks more like a listbox than a dropdown. */
  height: auto;
  padding: 0.4rem 0.5rem;
  background-image: none;       /* no chevron when size > 1 */
  font-size: 0.92rem;
}

.tcg-country-select option {
  padding: 0.35rem 0.4rem;
  color: var(--sf-text-bright, #F4F6FA);
  background: var(--sf-bg, #0E1218);
}

/* optgroups (the "Suggested" + "All countries" groupings) */
.tcg-country-select optgroup {
  font-style: normal;
  font-weight: 700;
  color: var(--sf-muted, #8B93A4);
  background: var(--sf-surface, #141923);
}

/* ─────────────────────────────────────────────────────────
   Checkbox rows
   ───────────────────────────────────────────────────────── */
.tcg-field--checkbox {
  margin-top: 1.05rem;
}

.tcg-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--sf-muted, #8B93A4);
  cursor: pointer;
}

.tcg-checkbox-label a {
  color: var(--tcg-accent);
  text-decoration: none;
}
.tcg-checkbox-label a:hover {
  text-decoration: underline;
}

.tcg-checkbox {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0.18rem 0 0; /* nudge to align with first text line */
  accent-color: var(--tcg-accent);
  cursor: pointer;
}

/* ─────────────────────────────────────────────────────────
   Turnstile slot
   - Cloudflare's widget renders inside this container at fixed
     dimensions (~300x65). We just give it some breathing room.
   ───────────────────────────────────────────────────────── */
.tcg-field--turnstile {
  margin-top: 1.05rem;
  min-height: 65px;
}

.tcg-turnstile {
  /* Cloudflare injects an iframe; nothing to style on this div directly. */
}

/* ─────────────────────────────────────────────────────────
   Submit button + spinner
   ───────────────────────────────────────────────────────── */
.tcg-form-actions {
  margin-top: 1.25rem;
}

.tcg-submit {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.85rem 1.25rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  background: var(--tcg-accent);
  color: #0E1218;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.tcg-submit:hover,
.tcg-submit:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(41, 181, 232, 0.32);
  outline: none;
}

.tcg-submit:active {
  transform: translateY(0);
}

.tcg-submit:disabled,
.tcg-submit[aria-busy="true"] {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.tcg-submit-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: 0.55rem;
  border: 2px solid rgba(14, 18, 24, 0.35);
  border-top-color: #0E1218;
  border-radius: 50%;
  animation: tcg-spin 0.7s linear infinite;
}
.tcg-submit-spinner[hidden] {
  display: none;
}

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

/* Ghost variant for the success pane "Close" button. */
.tcg-submit--ghost {
  background: transparent;
  color: var(--sf-text, #E4E7EE);
  border-color: var(--sf-border-light, #2E3648);
}

.tcg-submit--ghost:hover,
.tcg-submit--ghost:focus-visible {
  background: var(--sf-surface-hover, #1A2030);
  border-color: var(--tcg-accent);
  color: var(--sf-text-bright, #F4F6FA);
  box-shadow: none;
}

/* ─────────────────────────────────────────────────────────
   Mode switch link row
   ───────────────────────────────────────────────────────── */
.tcg-modal-switch {
  margin: 1rem 0 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--sf-muted, #8B93A4);
}

.tcg-link-btn {
  display: inline;
  padding: 0;
  margin-left: 0.25rem;
  font: inherit;
  color: var(--tcg-accent);
  background: transparent;
  border: none;
  cursor: pointer;
}

.tcg-link-btn:hover,
.tcg-link-btn:focus-visible {
  text-decoration: underline;
  outline: none;
}

/* ─────────────────────────────────────────────────────────
   Success pane
   ───────────────────────────────────────────────────────── */
.tcg-modal-success {
  text-align: center;
  padding: 1rem 0 0;
}

.tcg-modal-success[hidden] {
  display: none;
}

.tcg-success-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  background: rgba(41, 181, 232, 0.12);
  color: var(--tcg-accent);
  border-radius: 50%;
}

.tcg-success-title {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--sf-text-bright, #F4F6FA);
}

.tcg-success-text {
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--sf-muted, #8B93A4);
}

/* ─────────────────────────────────────────────────────────
   Body lock — JS adds .tcg-modal-open to <html> while open.
   Locks scroll without triggering the iOS scroll-bounce that
   `position:fixed` workarounds cause. overflow:hidden on <html>
   is the simplest answer that holds up across browsers.
   ───────────────────────────────────────────────────────── */
html.tcg-modal-open {
  overflow: hidden;
}

/* ─────────────────────────────────────────────────────────
   Mobile — fullscreen-ish sheet for narrow viewports
   ───────────────────────────────────────────────────────── */
@media (max-width: 540px) {
  .tcg-modal-host {
    padding: 0;
    align-items: stretch;
  }
  .tcg-modal {
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    padding: 1.5rem 1.25rem 1.25rem;
  }
  .tcg-modal::before {
    border-radius: 0;
  }
  .tcg-modal-title {
    font-size: 1.25rem;
  }
}

/* ─────────────────────────────────────────────────────────
   Reduced motion
   ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .tcg-modal-host,
  .tcg-modal,
  .tcg-submit,
  .tcg-submit-spinner {
    transition: none;
    animation: none;
  }
  .tcg-modal {
    transform: none;
  }
}
