/* =====================================================================
 * Auth pages — shared brand-forward layout.
 *
 * All auth pages (login/join, forgot-password, reset-password,
 * verify-email, resend-verification) share this stylesheet. Page-specific
 * stylesheets either `@import` this file (forgot/reset/resend) or import
 * it and add overrides (verify-email).
 *
 * Structure (kept identical across pages for maintainability):
 *   .auth-stage             full-bleed scene with ambient aura
 *     .auth-aura            animated iridescent glow (decorative)
 *     .auth-card            transparent flex column (no frame)
 *       .auth-brand         brand mark + title + subtitle
 *       #wrapper-login      existing form (IDs preserved for JS)
 *
 * The legacy #wrapper-login rules are retained and refined — existing JS
 * still targets inputs/buttons/message elements by their original IDs.
 * ===================================================================== */

:root {
    --auth-card-max-width: 440px;
    --auth-card-radius: 22px;
    --auth-field-radius: 14px;
    --auth-field-height: 48px;
    --auth-button-height: 40px;
    --auth-gap: 12px;
    --auth-gap-lg: 18px;
}

/* ---------- Reset the shared page shell so the aura can go full-bleed ---------- */
#wrapper-contents {
    padding: 0;
    background-color: var(--global-body-background);
    justify-content: flex-start;
}

/* ---------- Stage ---------- */
.auth-stage {
    position: relative;
    width: 100%;
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(40px, 8vh, 96px) 20px clamp(40px, 6vh, 80px);
    overflow: hidden;
    isolation: isolate;
}

.auth-aura {
    position: absolute;
    inset: -20% -15% auto -15%;
    height: 120%;
    z-index: -1;
    background:
        radial-gradient(38% 48% at 22% 30%, rgba(103, 80, 216, 0.28), transparent 70%),
        radial-gradient(34% 42% at 78% 22%, rgba(199, 107, 134, 0.22), transparent 72%),
        radial-gradient(40% 46% at 62% 72%, rgba(122, 163, 154, 0.22), transparent 70%),
        radial-gradient(36% 40% at 18% 78%, rgba(201, 148, 100, 0.18), transparent 72%);
    filter: blur(80px) saturate(125%);
    opacity: 0.85;
    pointer-events: none;
    animation: auth-aura-drift 24s ease-in-out infinite alternate;
}

@keyframes auth-aura-drift {
    0%   { transform: translate3d(-3%, -2%, 0) scale(1)    rotate(0deg); }
    50%  { transform: translate3d( 2%,  1%, 0) scale(1.06) rotate(2deg); }
    100% { transform: translate3d( 3%, -1%, 0) scale(1.03) rotate(-2deg); }
}

/* ---------- Form container (no frame — form floats over the aura) ---------- */
.auth-card {
    position: relative;
    width: 100%;
    max-width: var(--auth-card-max-width);
    padding: clamp(20px, 3vw, 32px) clamp(4px, 1.5vw, 12px);
    display: flex;
    flex-direction: column;
    gap: var(--auth-gap-lg);
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    opacity: 0;
    transform: translateY(10px);
    animation: auth-fade-up 0.9s cubic-bezier(0.22, 0.61, 0.36, 1) 0.05s forwards;
}

@keyframes auth-fade-up {
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Brand header (mark + title + subtitle) ---------- */
.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
    text-align: center;
}

.auth-mark {
    width: 52px;
    aspect-ratio: 603 / 958;
    display: flex;
    align-items: center;
    justify-content: center;
    /* drop-shadow on the parent (NOT the inner SVG) — putting filter on the
     * SVG creates a separate filter buffer that re-rasterizes every frame
     * with the rotating/sweeping rects, leaking a thin gradient line above
     * or below the brand mark in dark mode. See main.css hero-mark note. */
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.18));
    isolation: isolate;
    will-change: transform, opacity;
}

.auth-mark svg {
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* No filter here — see .auth-mark note. */
}

.auth-mark-base {
    transform-origin: 50% 50%;
    transform-box: fill-box;
    animation:
        auth-mark-spin 24s linear infinite,
        auth-mark-hue  14s linear infinite;
}

.auth-mark-sheen {
    transform-origin: 50% 50%;
    transform-box: fill-box;
    transform: rotate(20deg) translateX(-40%);
    /* No mix-blend-mode — see hero-mark-sheen note in main.css. The blend
     * buffer leaks outside the SVG <g clip-path> on Blink/WebKit. */
    animation: auth-mark-sheen 8s cubic-bezier(0.6, 0, 0.4, 1) infinite;
}

@keyframes auth-mark-spin  { to { transform: rotate(360deg); } }
@keyframes auth-mark-hue   {
    0%   { filter: hue-rotate(0deg)   saturate(1.05); }
    50%  { filter: hue-rotate(180deg) saturate(1.15); }
    100% { filter: hue-rotate(360deg) saturate(1.05); }
}
@keyframes auth-mark-sheen {
    0%   { transform: rotate(20deg) translateX(-60%); opacity: 0; }
    25%  { opacity: 0.85; }
    60%  { opacity: 0.85; }
    100% { transform: rotate(20deg) translateX( 60%); opacity: 0; }
}

.auth-title {
    margin: 6px 0 0;
    font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    font-weight: 800;
    font-size: clamp(24px, 2.6vw, 30px);
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--global-text-color);
}

body.join-mode .auth-title-login,
.auth-title-join { display: none; }
body.join-mode .auth-title-join { display: block; }

.auth-subtitle,
#wrapper-login .auth-description {
    margin: 0;
    max-width: 320px;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.55;
    letter-spacing: -0.005em;
    color: var(--global-text-muted);
    text-align: center;
}

/* ---------- Form container (legacy #wrapper-login) ---------- */
#wrapper-login {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--auth-gap);
    height: auto; /* override legacy full-height */
}

/* Hide the legacy inline <h1> — the brand header provides the title. */
#wrapper-login > h1 {
    display: none;
}

/* ---------- Inputs (BORDERLESS hairline — v2) ---------- */
/* Same recipe as profile/designIdentity §6.5 form fields. The auth-card
   itself supplies the "physical" container; the field stays open and
   quiet. */
#wrapper-login input {
    width: 100%;
    height: var(--auth-field-height);
    padding: 8px 0;
    background: transparent;
    border: 0;
    border-bottom: 1px solid rgba(var(--global-text-color-rgb), 0.18);
    border-radius: 0;
    box-sizing: border-box;
    color: var(--global-text-color);
    font-family: inherit;
    font-size: 15px;
    letter-spacing: -0.005em;
    transition: border-color 0.2s ease;
}

#wrapper-login input::placeholder {
    color: rgba(var(--global-text-color-rgb), 0.32);
}

#wrapper-login input:hover {
    border-bottom-color: rgba(var(--global-text-color-rgb), 0.32);
}

#wrapper-login input:focus {
    outline: none;
    border-bottom-color: var(--global-text-color);
}

/* Autofill — keep the themed background instead of browser yellow/blue. */
#wrapper-login input:-webkit-autofill,
#wrapper-login input:-webkit-autofill:hover,
#wrapper-login input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--global-body-background) inset;
    -webkit-text-fill-color: var(--global-text-color);
    caret-color: var(--global-text-color);
    transition: background-color 9999s ease-out 0s;
}

/* ---------- Primary button ---------- */
#wrapper-login button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: var(--auth-button-height);
    padding: 0 20px;
    margin: 2px 0 0;
    background-color: var(--global-button-background-color);
    color: var(--global-button-text-color);
    border: 1px solid transparent;
    border-radius: 999px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.005em;
    text-align: center;
    cursor: pointer;
    transition:
        background-color 0.18s cubic-bezier(0.22, 0.61, 0.36, 1),
        border-color 0.18s cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity 0.18s cubic-bezier(0.22, 0.61, 0.36, 1),
        transform 0.18s cubic-bezier(0.22, 0.61, 0.36, 1);
}

#wrapper-login button:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

#wrapper-login button:active {
    transform: translateY(0);
}

#wrapper-login button:focus-visible {
    outline: 2px solid var(--focus-outline-color);
    outline-offset: 2px;
}

#wrapper-login button:disabled {
    cursor: not-allowed;
    opacity: 0.4;
    transform: none;
}

/* ---------- OAuth buttons ---------- */
#login-oauth-buttons {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#login-oauth-buttons button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(var(--global-text-color-rgb), 0.02);
    color: var(--global-text-color);
    border: 1px solid rgba(var(--global-text-color-rgb), 0.14);
    font-weight: 500;
}

#login-oauth-buttons button:hover {
    background: rgba(var(--global-text-color-rgb), 0.06);
    border-color: rgba(var(--global-text-color-rgb), 0.28);
    opacity: 1;
    transform: none;
}

#login-oauth-buttons button svg {
    flex-shrink: 0;
}

/* Apple glyph — keep adaptive to light/dark. */
#login-apple-btn svg path {
    fill: var(--global-text-color);
}

/* ---------- Divider ---------- */
#login-divider {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 4px 0 2px;
}

#login-divider .login-divider-line {
    flex: 1;
    height: 1px;
    background-color: rgba(var(--global-text-color-rgb), 0.12);
}

#login-divider span {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(var(--global-text-color-rgb), 0.45);
}

/* ---------- Message surface (success/error) ---------- */
#login-message {
    margin: 2px 0 0;
    min-height: 1.2em;
    text-align: center;
    font-size: 13px;
    line-height: 1.45;
    color: rgba(var(--global-text-color-rgb), 0.75);
    white-space: pre-line;
}

#login-message a {
    color: var(--global-success-color);
    text-decoration: underline;
    text-underline-offset: 2px;
}

#login-message.error  { color: var(--global-error-color); }
#login-message.success { color: var(--global-success-color); }

/* ---------- Secondary links & mode toggle ---------- */
#login-forgot-password,
.auth-back-link {
    align-self: center;
    font-size: 13px;
    color: rgba(var(--global-text-color-rgb), 0.65);
    text-decoration: none;
    transition: color 0.18s ease;
}

#login-forgot-password:hover,
.auth-back-link:hover {
    color: var(--global-text-color);
    text-decoration: underline;
    text-underline-offset: 3px;
}

#wrapper-login p {
    margin: 0;
    font-size: 13px;
    text-align: center;
    color: rgba(var(--global-text-color-rgb), 0.7);
}

#wrapper-login p span[id^="login-mode-"] {
    color: var(--global-text-color);
    font-weight: 600;
    cursor: pointer;
    margin-left: 4px;
    transition: opacity 0.18s ease;
}

#wrapper-login p span[id^="login-mode-"]:hover {
    opacity: 0.75;
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ---------- Login/Join mode toggle visibility ----------
   Inputs default to block, buttons to inline-flex (centered), <p> to block.
   Rules are per-tag so toggling never breaks text alignment. */
#wrapper-login input.mode-join,
#wrapper-login button.mode-join,
#wrapper-login p.mode-join,
#wrapper-login a.mode-join,
#wrapper-login div.mode-join { display: none; }

body.join-mode #wrapper-login input.mode-login,
body.join-mode #wrapper-login button.mode-login,
body.join-mode #wrapper-login p.mode-login,
body.join-mode #wrapper-login a.mode-login { display: none; }

body.join-mode #wrapper-login input.mode-join  { display: block; }
body.join-mode #wrapper-login button.mode-join { display: inline-flex; }
body.join-mode #wrapper-login p.mode-join      { display: block; }
body.join-mode #wrapper-login a.mode-join      { display: inline-block; }
body.join-mode #wrapper-login div.mode-join    { display: block; }

/* ---------- Closed Beta: Invite Code field ----------
   특별한 한 줄. 다른 input 들과 다르게 박스가 없고, 파도의
   기오를 닮은 언더라인만 있다. 레이블은 플로트해 올라가고,
   포커스하면 underline 이 가운데에서 양쪽으로 스르르르 퍼진다. */
#login-invite-block {
    display: none;
    flex-direction: column;
    gap: 10px;
    padding: 8px 0 0 0;
    background: transparent;
    border: 0;
}

.login-invite-field {
    position: relative;
    display: block;
    padding: 22px 2px 12px 2px;
    cursor: text;
}

#login-invite-block input#login-input-invite-code {
    display: block;
    width: 100%;
    height: auto;
    box-sizing: border-box;
    margin: 0;
    padding: 2px 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    color: var(--global-text-color);
    font-family: 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
    font-size: 17px;
    font-weight: 500;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    caret-color: var(--global-text-color);
    transition: color 0.2s ease;
}

/* placeholder 는 공백(" ") 이므로 보이지 않고, :placeholder-shown 으로
   빈 상태를 감지해 플로트 레이블을 조작한다. */
#login-invite-block input#login-input-invite-code::placeholder {
    color: transparent;
}

#login-invite-block input#login-input-invite-code:focus,
#login-invite-block input#login-input-invite-code:focus-visible {
    outline: none;
    box-shadow: none;
    border: 0;
}

/* Floating label */
.login-invite-label {
    position: absolute;
    left: 0;
    top: 22px;
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
    pointer-events: none;
    transform-origin: 0 0;
    transition:
        transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1),
        color 0.2s ease,
        opacity 0.2s ease;
    color: rgba(var(--global-text-color-rgb), 0.42);
    line-height: 1;
    white-space: nowrap;
}

.login-invite-label-tag {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: rgba(var(--global-text-color-rgb), 0.38);
    padding: 3px 7px;
    border: 1px solid rgba(var(--global-text-color-rgb), 0.12);
    border-radius: 999px;
    background: transparent;
    transition:
        color 0.2s ease,
        border-color 0.2s ease,
        background-color 0.2s ease;
}

.login-invite-label-text {
    font-size: 15px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    color: rgba(var(--global-text-color-rgb), 0.46);
    font-family: inherit;
}

/* 포커스 or 입력 중일 때 레이블이 위로 올라가며 작아진다. */
#login-invite-block input#login-input-invite-code:focus ~ .login-invite-label,
#login-invite-block input#login-input-invite-code:not(:placeholder-shown) ~ .login-invite-label {
    transform: translateY(-20px) scale(0.92);
}

#login-invite-block input#login-input-invite-code:focus ~ .login-invite-label .login-invite-label-text,
#login-invite-block input#login-input-invite-code:not(:placeholder-shown) ~ .login-invite-label .login-invite-label-text {
    opacity: 0;
}

#login-invite-block input#login-input-invite-code:focus ~ .login-invite-label .login-invite-label-tag {
    color: var(--global-text-color);
    border-color: rgba(var(--global-text-color-rgb), 0.32);
    background: rgba(var(--global-text-color-rgb), 0.03);
}

/* Underline: base hairline 위에 active bar 가 얹혀진다. */
.login-invite-underline {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
    background: rgba(var(--global-text-color-rgb), 0.1);
    overflow: hidden;
}

.login-invite-underline::after {
    content: "";
    position: absolute;
    left: 50%;
    right: 50%;
    top: 0;
    bottom: 0;
    background: var(--global-text-color);
    opacity: 0;
    transition:
        left 0.36s cubic-bezier(0.22, 0.61, 0.36, 1),
        right 0.36s cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity 0.2s ease;
}

#login-invite-block input#login-input-invite-code:focus ~ .login-invite-underline::after,
#login-invite-block input#login-input-invite-code:not(:placeholder-shown) ~ .login-invite-underline::after {
    left: 0;
    right: 0;
    opacity: 0.85;
}

.login-invite-hint {
    margin: 0;
    padding-left: 2px;
    font-size: 12px;
    line-height: 1.55;
    color: rgba(var(--global-text-color-rgb), 0.48);
    transition: color 0.2s ease;
}

.login-invite-field:focus-within + .login-invite-hint {
    color: rgba(var(--global-text-color-rgb), 0.62);
}

body.join-mode #wrapper-login #login-invite-block { display: flex; }

/* ===========================================================
   Legal consents (join only)
   ----------------------------------------------------------- */
/*  Visually quiet checklist that sits just above the join button.
    Uses brand-tinted custom checkboxes so it never feels like a
    legacy form. Required rows show a subtle "*" prefix; optional
    rows blend in. Hidden in login mode by default — `body.join-mode`
    promotes it back into the flow.                              */

#login-consents {
    display: none;
    flex-direction: column;
    gap: 10px;
    margin: 4px 0 6px;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(var(--global-text-color-rgb), 0.04);
    border: 1px solid rgba(var(--global-text-color-rgb), 0.08);
}
body.join-mode #wrapper-login #login-consents { display: flex; }

.login-consent-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    line-height: 1.45;
}

.login-consent-row input[type="checkbox"] {
    /* visually hidden but keyboard-focusable */
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.login-consent-check {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    margin-top: 1px;
    border-radius: 5px;
    border: 1.5px solid rgba(var(--global-text-color-rgb), 0.32);
    background: transparent;
    transition: border-color 0.15s ease, background-color 0.15s ease;
    position: relative;
}

.login-consent-check::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><polyline points='3.2 8.4 6.6 11.6 12.8 4.6'/></svg>") no-repeat center / 14px 14px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.login-consent-row input[type="checkbox"]:checked + .login-consent-check {
    background: var(--global-text-color, #111);
    border-color: var(--global-text-color, #111);
}
.login-consent-row input[type="checkbox"]:checked + .login-consent-check::after { opacity: 1; }

.login-consent-row input[type="checkbox"]:focus-visible + .login-consent-check {
    box-shadow: 0 0 0 3px rgba(var(--global-text-color-rgb), 0.18);
}

.login-consent-label {
    flex: 1;
    font-size: 12.5px;
    color: rgba(var(--global-text-color-rgb), 0.78);
}
.login-consent-label a {
    color: var(--global-text-color);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.login-consent-required .login-consent-label::before {
    content: '*';
    margin-right: 4px;
    color: var(--global-error-color, #E53935);
    font-weight: 700;
}


/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .auth-aura,
    .auth-card,
    .auth-mark-base,
    .auth-mark-sheen {
        animation: none;
    }
    .auth-card {
        opacity: 1;
        transform: none;
    }
}

/* ---------- Dark mode ---------- */
@media (prefers-color-scheme: dark) {
    .auth-aura {
        opacity: 0.6;
        filter: blur(100px) saturate(135%);
    }
    #wrapper-login input:-webkit-autofill,
    #wrapper-login input:-webkit-autofill:hover,
    #wrapper-login input:-webkit-autofill:focus {
        -webkit-box-shadow: 0 0 0 1000px #2d2d2d inset;
    }
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
    .auth-stage {
        padding: 28px 28px 32px;
        align-items: flex-start;
    }
    .auth-card {
        padding: 16px 8px;
    }
    :root {
        --auth-field-height: 46px;
    }
}

@media (max-width: 360px) {
    .auth-stage {
        padding: 24px 20px 28px;
    }
    .auth-card {
        padding: 12px 4px;
    }
}
