/**
 * Surreal's login system (auth/*.php), on the public pages' shared base
 * (surreal-public.css, loaded first): same palette, buttons and motion
 * as the landing page. A cast member peeks over each card and says
 * something; the card rises in once. prefers-reduced-motion: no motion.
 */

/* The names the setup pages' inline styles still use */
:root {
    --color-primary: var(--primary);
    --color-text: var(--text);
    --color-text-muted: var(--text-2);
    --color-border: var(--border);
    --color-bg: var(--bg);
    --text-muted: var(--text-2);
    --success: #22c55e;
    --danger: #ef4444;
}

.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100svh;
    padding: 108px 20px 56px;
}

/* Login pages: the landing page's bold headline beside the card */
.auth-wrapper--split {
    display: grid;
    align-items: center;
    gap: 72px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 440px);
    max-width: var(--max);
    margin: 0 auto;
    padding: 150px var(--gutter) 64px;
}

.auth-hero > * {
    animation: rise-in 0.7s cubic-bezier(.2, .7, .2, 1) both;
}

/* From /join: how joining works (lib/trial-path.php, css/trial-path.css)
   under the greeting, the form beside both */
.auth-wrapper--trial {
    grid-template-rows: auto auto;
    row-gap: 40px;
}

.auth-wrapper--trial .auth-hero {
    align-self: end;
}

.auth-wrapper--trial > .auth-card {
    grid-row: 1 / span 2;
    grid-column: 2;
}

.auth-trial {
    --trial-path-surface: var(--bg);
    grid-column: 1;
    align-self: start;
    max-width: 520px;
    animation: rise-in 0.7s cubic-bezier(.2, .7, .2, 1) 0.16s both;
}

.auth-trial__title {
    margin: 0 0 16px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

.auth-hero > :nth-child(2) {
    animation-delay: 0.08s;
}

.auth-hero__title {
    margin-bottom: 18px;
    font-size: clamp(40px, 6vw, 66px);
    font-weight: 800;
    line-height: 1.04;
    letter-spacing: -0.01em;
}

.auth-hero__title span {
    color: var(--primary);
}

.auth-hero__lead {
    max-width: 460px;
    font-size: 19px;
    color: var(--text-2);
}

.auth-wrapper > .setup-card {
    animation: rise-in 0.7s cubic-bezier(.2, .7, .2, 1) 0.12s both;
}

/* The card. No z-index or transform of its own, so the peeking cast
   member (z-index -1) sits behind it until they pop up. */
.auth-card,
.setup-card {
    position: relative;
    width: 100%;
    max-width: 440px;
    padding: 36px 32px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.setup-card {
    max-width: 760px;
}

/* The wordmark: the old landing's 3D "S", kept as Surreal's own mark */
.auth-logo {
    margin-bottom: 18px;
    text-align: center;
}

.s-logo {
    display: inline-block;
}

.s-text {
    font-size: 56px;
    font-weight: 900;
    line-height: 1;
    text-shadow: 2px 0 0 #1e3a5f, 3px 1px 0 #1e3a5f, 4px 2px 0 #1e3a5f;
    color: var(--primary);
    user-select: none;
}

.auth-title {
    margin-bottom: 8px;
    font-size: 26px;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
}

.auth-subtitle {
    margin-bottom: 26px;
    font-size: 15px;
    text-align: center;
    color: var(--text-2);
}

.auth-card h2 {
    margin-bottom: 20px;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
}

.auth-card .subtitle {
    margin-bottom: 22px;
    font-size: 14px;
    text-align: center;
    color: var(--text-2);
}

.auth-card .hint,
.auth-card .small-text {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-2);
}

/* A guest sent here from /join */
.auth-context {
    margin-bottom: 22px;
    padding: 16px;
    text-align: center;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.auth-context__text {
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-2);
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

.auth-divider::before,
.auth-divider::after {
    flex: 1;
    height: 1px;
    background: var(--border);
    content: "";
}

/* ===== Forms ===== */
.auth-card .form-group,
.setup-card .form-group {
    margin-bottom: 18px;
}

.auth-card .form-group label,
.setup-card .form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.auth-card .form-group input[type="text"],
.auth-card .form-group input[type="email"],
.auth-card .form-group input[type="password"],
.setup-card .form-group input {
    width: 100%;
    padding: 13px 14px;
    font: inherit;
    font-size: 16px; /* under 16px, iOS zooms the page in on focus */
    color: var(--text);
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-card .form-group input:focus,
.setup-card .form-group input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgb(61 142 248 / 22%);
}

.auth-card .form-group input::placeholder {
    color: var(--text-3);
}

.auth-card .form-group small {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-2);
}

.auth-card .form-check {
    display: flex;
    align-items: center;
    margin: -10px 0 12px;
}

.auth-card .form-check input[type="checkbox"] {
    display: inline-grid;
    flex-shrink: 0;
    place-content: center;
    width: 18px;
    height: 18px;
    margin: 0 10px 0 0;
    background: var(--bg-deep);
    border: 2px solid var(--border-strong);
    border-radius: 4px;
    cursor: pointer;
    appearance: none;
}

.auth-card .form-check input[type="checkbox"]::before {
    width: 10px;
    height: 10px;
    background: #ffffff;
    transform: scale(0);
    transition: transform 0.15s ease;
    content: "";
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.auth-card .form-check input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.auth-card .form-check input[type="checkbox"]:checked::before {
    transform: scale(1);
}

.auth-card .form-check input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.auth-card .form-check label {
    padding: 10px 0;
    font-size: 14px;
    color: var(--text-2);
    cursor: pointer;
}

/* The old markup's button names, on the shared buttons */
.btn-primary {
    color: #ffffff;
    background: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    color: var(--text);
    background: var(--bg-card);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
}

.auth-card form .btn-primary,
.auth-card form .btn-secondary,
.auth-card .auth-passkey .btn,
.auth-card .auth-context .btn {
    justify-content: center;
    width: 100%;
}

/* Passkeys: below the form, or above it for someone who has one on this browser */
.auth-card .auth-passkey .btn {
    gap: 8px;
}

.auth-passkey .auth-divider {
    margin: 18px 0;
}

/* Turnstile stays invisible unless Cloudflare wants a click; then it
   spans the form. As a plain empty block its margin collapses into the
   checkbox row's, so the hidden widget leaves no gap. */
.auth-card .turnstile-wrapper {
    margin-bottom: 12px;
}

.auth-card .alert {
    margin-bottom: 22px;
    padding: 13px 15px;
    font-size: 14px;
    border-radius: var(--radius);
}

.auth-card .alert-danger {
    color: #fca5a5;
    background: rgb(239 68 68 / 12%);
    border: 1px solid rgb(239 68 68 / 35%);
}

.auth-card .alert-success {
    color: #86efac;
    background: rgb(34 197 94 / 12%);
    border: 1px solid rgb(34 197 94 / 35%);
}

.auth-card a:not(.btn) {
    font-weight: 500;
    text-decoration: none;
    color: var(--primary);
}

.auth-card a:not(.btn):hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.forgot-password {
    margin-top: 8px;
    text-align: right;
}

/* Padded out to a thumb-sized target without moving the text */
.forgot-password a {
    display: inline-block;
    margin: -8px 0;
    padding: 8px 0 8px 12px;
    font-size: 13px;
}

.auth-footer {
    margin-top: 26px;
    font-size: 14px;
    text-align: center;
    color: var(--text-2);
}

.auth-footer .back-link {
    display: inline-block;
    margin-top: 12px;
}

.auth-card .auth-footer .back-link {
    color: var(--text-2);
}

.password-requirements {
    margin-top: 10px;
    padding: 12px 14px;
    font-size: 12px;
    color: var(--text-2);
    background: var(--bg-deep);
    border-radius: var(--radius);
}

.password-requirements strong {
    font-weight: 600;
    color: var(--text);
}

.password-requirements ul {
    margin: 6px 0 0 16px;
}

.password-requirements li {
    margin: 3px 0;
}

.invite-required,
.registration-success {
    padding: 12px 0;
    text-align: center;
}

.invite-required h3 {
    margin-bottom: 10px;
    font-size: 20px;
    color: var(--primary);
}

.invite-required p,
.registration-success p {
    margin-bottom: 8px;
    color: var(--text-2);
}

.gnome-child {
    width: 90px;
    height: auto;
    margin-bottom: 14px;
}

.registration-success .success-icon {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    font-size: 28px;
    color: #ffffff;
    background: #16a34a;
    border-radius: 50%;
}

.registration-success h2 {
    margin-bottom: 8px;
    font-size: 22px;
}

.registration-success .redirect-notice {
    margin-bottom: 18px;
    font-size: 13px;
    color: var(--text-3);
}

/* ===== The cast, peeking over the card ===== */
.peek {
    position: absolute;
    top: -62px;
    right: 30px;
    z-index: -1;
    animation: peek-up 0.7s cubic-bezier(.3, 1.5, .5, 1) 0.45s both;
}

.peek img {
    display: block;
    width: 80px;
    height: 80px;
    transform: rotate(-6deg);
    filter: drop-shadow(1px 0 0 #ffffff) drop-shadow(-1px 0 0 #ffffff) drop-shadow(0 1px 0 #ffffff) drop-shadow(0 -1px 0 #ffffff);
    object-fit: contain;
}

/* What they say: a speech bubble, drawn the cheap way on purpose */
.peek__say {
    position: absolute;
    right: 84px;
    bottom: 44px;
    width: max-content;
    max-width: min(280px, calc(100vw - 130px));
    padding: 6px 10px;
    font-family: "Comic Sans MS", "Comic Sans", "Chalkboard SE", cursive;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
    text-wrap: balance;
    color: #111111;
    background: #ffffff;
    border: 2px solid #111111;
    border-radius: 14px;
    animation: peek-say 0.35s ease 1.15s both;
}

.peek__say::after {
    position: absolute;
    right: -9px;
    bottom: 8px;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 9px solid #111111;
    content: "";
}

/* ===== Logging in: checking, in, or not quite ===== */
.auth-card.is-pending input,
.auth-card.is-pending .form-check,
.auth-card.is-pending .forgot-password {
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.auth-card button[aria-disabled="true"] {
    pointer-events: none;
}

.auth-dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 6px;
}

.auth-dots i {
    width: 5px;
    height: 5px;
    background: currentColor;
    border-radius: 50%;
    animation: auth-dot 0.9s ease-in-out infinite;
}

.auth-dots i:nth-child(2) {
    animation-delay: 0.15s;
}

.auth-dots i:nth-child(3) {
    animation-delay: 0.3s;
}

.auth-card.is-in .peek {
    animation: peek-cheer 0.5s cubic-bezier(.3, 1.6, .5, 1) both;
}

.auth-card .peek__say--again {
    animation: peek-say 0.3s ease both;
}

/* The card's contents shake, not the card: moving the card would lift
   the peeking cast member in front of it */
.auth-card.is-shake > :not(.peek) {
    animation: auth-shake 0.4s ease;
}

/* The page lifts away into Surreal */
.auth-wrapper.is-leaving {
    opacity: 0;
    transform: translateY(-16px) scale(0.98);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

@keyframes auth-dot {
    0%,
    80%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

@keyframes peek-cheer {
    0% {
        transform: translateY(0);
    }

    45% {
        transform: translateY(-26px) rotate(4deg);
    }

    100% {
        transform: translateY(-12px);
    }
}

@keyframes auth-shake {
    20%,
    60% {
        transform: translateX(-8px);
    }

    40%,
    80% {
        transform: translateX(8px);
    }
}

@keyframes peek-up {
    from {
        transform: translateY(58px);
    }
}

@keyframes peek-say {
    from {
        opacity: 0;
        transform: scale(0.6);
    }
}

@media (prefers-reduced-motion: reduce) {
    .auth-hero > *,
    .auth-trial,
    .auth-wrapper > .setup-card,
    .peek,
    .peek__say,
    .auth-card.is-in .peek,
    .auth-card .peek__say--again,
    .auth-dots i {
        animation: none;
    }
}

@media (width <= 900px) {
    .auth-wrapper--split {
        gap: 72px;
        grid-template-columns: minmax(0, 1fr);
        padding-top: 110px;
        justify-items: center;
    }

    .auth-hero {
        width: 100%;
        max-width: 440px;
    }

    .auth-wrapper--trial > .auth-card {
        grid-row: auto;
        grid-column: auto;
    }

    .auth-trial {
        width: 100%;
        max-width: 440px;
        grid-column: auto;
    }

    .auth-hero__title {
        font-size: clamp(34px, 9vw, 48px);
    }

    .auth-hero__lead {
        font-size: 16px;
    }
}

/* Phones: the headline shrinks to a greeting so the form, not the
   pitch, fills the first screen */
@media (width <= 600px) {
    /* The card becomes a sheet: edge to edge, filling the rest of the
       screen, its fields lined up with the greeting above */
    .auth-wrapper--split {
        place-items: stretch stretch;
        gap: 64px;
        grid-template-rows: auto 1fr;
        padding: 92px 0 0;
    }

    .auth-wrapper--split .auth-hero {
        max-width: none;
        padding: 0 var(--gutter);
    }

    .auth-wrapper--split > .auth-card {
        max-width: none;
        padding: 28px var(--gutter) calc(40px + env(safe-area-inset-bottom));
        border-width: 1px 0 0;
        border-radius: 0;
    }

    /* The sheet carries on under the form */
    .auth-wrapper--trial {
        row-gap: 0;
    }

    .auth-wrapper--trial > .auth-card {
        padding-bottom: 32px;
    }

    .auth-trial {
        --trial-path-surface: var(--bg-card);
        max-width: none;
        padding: 0 var(--gutter) calc(40px + env(safe-area-inset-bottom));
        background: var(--bg-card);
    }

    /* The greeting already says these */
    .auth-subtitle,
    .auth-title--echo {
        display: none;
    }

    .auth-card .subtitle {
        text-align: left;
    }

    .auth-hero__title {
        margin-bottom: 0;
        font-size: 30px;
    }

    .auth-hero__lead,
    .peek--desktop-only {
        display: none;
    }
}

@media (width <= 480px) {
    .auth-card,
    .setup-card {
        padding: 30px 20px;
    }

    .auth-title {
        font-size: 22px;
    }

    .peek {
        right: 16px;
    }

    .peek__say {
        font-size: 12px;
    }
}
