/* ============================================================
   Quick sign-in / sign-up dialog (fragments/auth-modal.html)
   ------------------------------------------------------------
   Mobile-first: a full-height sheet that rises from the bottom;
   from 640px a centred card that settles in. Colours only from
   theme.css tokens, so light/dark follow html.dark. Form controls
   reuse the jm-* components in site.css.
   ============================================================ */

.am[hidden], .am [hidden] { display: none !important; }

.am {
    position: fixed; inset: 0; z-index: 1500;
    display: flex; align-items: flex-end; justify-content: center;
}
/* While fading out (before auth-modal.js sets [hidden]) the layer must not swallow taps meant for the page */
.am:not(.is-open) { pointer-events: none; }

.am-backdrop {
    position: absolute; inset: 0;
    background: rgba(7, 11, 23, .55);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    opacity: 0; transition: opacity .22s ease;
}

.am-card {
    position: relative; isolation: isolate;
    width: 100%; height: 100%; height: 100dvh; max-height: 100dvh;
    overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
    background: var(--bg2); color: var(--text);
    padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
    transform: translateY(40px); opacity: 0;
    transition: transform .28s cubic-bezier(.2, .8, .2, 1), opacity .2s ease;
}
.am.is-open .am-backdrop { opacity: 1; }
.am.is-open .am-card { transform: none; opacity: 1; }

/* Soft gold halo behind the header — echoes the site hero glow */
.am-glow {
    position: absolute; z-index: -1; inset-inline: 0; top: 0; height: 180px; pointer-events: none;
    background: radial-gradient(60% 100% at 50% 0%, var(--hero-glow1), transparent 70%);
}

/* ---------- top bar: segmented switch + close ---------- */
.am-top { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.am-top-spacer { flex: 1; }

.am-seg {
    position: relative; flex: 1; display: grid; grid-template-columns: 1fr 1fr;
    padding: 4px; border-radius: 14px; background: var(--card); border: 1px solid var(--border);
}
.am-seg-thumb {
    position: absolute; top: 4px; bottom: 4px; inset-inline-start: 4px; width: calc(50% - 4px);
    border-radius: 10px; background: var(--grad); box-shadow: var(--glow);
    transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
.am[data-active="signup"] .am-seg-thumb { transform: translateX(100%); }
[dir="rtl"] .am[data-active="signup"] .am-seg-thumb { transform: translateX(-100%); }
.am-seg-tab {
    position: relative; z-index: 1; border: 0; background: none; cursor: pointer; font-family: inherit;
    padding: 9px 8px; border-radius: 10px; font-size: .9rem; font-weight: 700; line-height: 1.2;
    color: var(--muted); transition: color .2s;
}
.am-seg-tab:hover { color: var(--text); }
.am-seg-tab[aria-selected="true"] { color: var(--btn-text); }
.am-seg-tab:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

.am-close {
    flex: none; display: grid; place-items: center; width: 42px; height: 42px;
    border-radius: 12px; border: 1px solid var(--border); background: var(--card);
    color: var(--muted); cursor: pointer; transition: color .18s, background .18s, border-color .18s;
}
.am-close:hover { color: var(--text); background: var(--card2); border-color: var(--faint); }
.am-close svg { width: 18px; height: 18px; }

/* ---------- heading ---------- */
.am-head { margin-bottom: 20px; }
.am-title { margin: 0 0 4px; font-size: 1.45rem; line-height: 1.3; font-weight: 700; color: var(--text); }
.am-subtitle { margin: 0; color: var(--muted); font-size: .95rem; line-height: 1.6; }

/* Contextual "why am I seeing this" line */
.am-reason {
    display: flex; align-items: center; gap: 10px; margin: -6px 0 18px; padding: 10px 14px;
    border-radius: var(--r-sm); border: 1px solid var(--border2);
    background: linear-gradient(115deg, rgba(249, 161, 27, .10), rgba(251, 191, 36, .04));
    color: var(--text); font-size: .9rem; font-weight: 600; line-height: 1.5;
}
.am-reason svg { width: 18px; height: 18px; flex: none; color: var(--accent-ink); }

.am-sr {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.am-oauth { margin-bottom: 0; }
.am-divider { margin: 18px 0; }

/* ---------- forms ---------- */
.am-form .jm-form-row { margin-bottom: 14px; gap: 5px; }
.am-form .jm-field-error { line-height: 1.4; }
.am-form .jm-help { margin: 0; line-height: 1.4; }
.am-form .jm-help:has(+ .jm-field-error:not(:empty)) { display: none; }
.am-grid { display: grid; grid-template-columns: 1fr; column-gap: 12px; }
@media (min-width: 400px) { .am-grid { grid-template-columns: 1fr 1fr; } }

.am-alert { margin-bottom: 16px; animation: am-shake .32s ease; }
.am-alert p { margin: 0; overflow-wrap: anywhere; }
.am-alert-link { display: inline-block; margin-top: 4px; color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.am-alert-link:hover { color: inherit; }

.am-row { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin: 2px 0 20px; }
.am-check { align-items: center; }
.am-check input { margin-top: 0; }
.am-link { font-size: .9rem; font-weight: 700; color: var(--accent-ink); }
.am-link:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }

.am-eye .am-eye-off { display: none; }
.am-eye[aria-pressed="true"] .am-eye-on { display: none; }
.am-eye[aria-pressed="true"] .am-eye-off { display: block; }

.am-hp {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); opacity: 0; pointer-events: none;
}

.am-submit { position: relative; }
.am-spinner {
    display: none; width: 18px; height: 18px; flex: none; border-radius: 50%;
    border: 2px solid currentColor; border-inline-end-color: transparent;
    animation: am-spin .7s linear infinite;
}
.am-submit[aria-busy="true"] .am-spinner { display: inline-block; }
.am-submit[aria-busy="true"] { cursor: progress; }
.am-submit:disabled[aria-busy="true"] { opacity: .8; }

.am-foot { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: .92rem; }
.am-foot .jm-link-btn { margin-inline-start: 4px; font-size: .92rem; }

/* Body scroll lock while open (scrollbar-gutter keeps the page from shifting) */
html.am-lock { overflow: hidden; scrollbar-gutter: stable; }

@keyframes am-spin { to { transform: rotate(360deg); } }
@keyframes am-shake {
    0%, 100% { transform: none; }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* ---------- tablet / desktop: centred card ---------- */
@media (min-width: 640px) {
    .am { align-items: center; padding: 24px; }
    .am-card {
        max-width: 460px; height: auto; max-height: calc(100dvh - 48px);
        padding: 20px 28px 28px; border-radius: 22px;
        border: 1px solid var(--border); box-shadow: var(--shadow);
        transform: translateY(12px) scale(.97);
    }
    .am-glow { border-radius: 22px 22px 0 0; }
    .am-top { margin-bottom: 24px; }
    .am-title { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
    .am-backdrop, .am-card, .am-seg-thumb, .am-seg-tab { transition: none; }
    .am-card { transform: none; }
    .am-alert { animation: none; }
    .am-spinner { animation-duration: 1.6s; }
}
html.no-animations .am-backdrop,
html.no-animations .am-card,
html.no-animations .am-seg-thumb { transition: none; }
html.no-animations .am-alert { animation: none; }
