/* ===== Auth popup (login / signup / forgot password) => markup in base.html, behavior in auth-modal-v3.js =====
   Theme colors come from the tokens in base-v39.css; the green brand colors stay literal like the other buttons. */

/* dialog + backdrop */
.am {
    padding: 0;
    border: none;
    background: transparent;
    width: min(23.5rem, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
    overflow: visible;
    color: var(--text);
}

.am::backdrop {
    background: rgba(8, 24, 16, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.am[open] {
    animation: am-pop 380ms cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

.am[open]::backdrop {
    animation: am-fade 250ms ease both;
}

@keyframes am-pop {
    from { opacity: 0; transform: translateY(24px) scale(0.94); }
    to   { opacity: 1; transform: none; }
}

@keyframes am-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* card */
.am-card {
    position: relative;
    background: var(--surface);
    border-radius: 1.6rem;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28), 0 0 0 1px var(--border);
    overflow: hidden;
    text-align: center;
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
}

.am-shake {
    animation: am-shake 380ms ease;
}

@keyframes am-shake {
    20%, 60% { transform: translateX(-7px); }
    40%, 80% { transform: translateX(7px); }
}

/* hero band => the home page hero image (already preloaded by base.html), app logo on top */
.am-hero {
    position: relative;
    height: 8rem;
    background: url("/static/img/hero-v1.webp") center 35% / cover no-repeat, rgb(53, 171, 106);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.am-mascot { /* app logo (manifest icon) => rounded square like on a phone home screen */
    width: 5.2rem;
    height: 5.2rem;
    object-fit: cover;
    border-radius: 1.3rem;
    border: 0.25rem solid var(--surface);
    background: var(--surface);
    margin-bottom: -2.7rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
    animation: am-bob 2.8s ease-in-out infinite;
}

@keyframes am-bob {
    0%, 100% { transform: translateY(0) rotate(-3deg); }
    50%      { transform: translateY(-5px) rotate(3deg); }
}

/* close */
.am-close {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    z-index: 2;
    width: 2.1rem;
    height: 2.1rem;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35); /* dark glass => readable on the bright photo */
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: white;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color 150ms ease, transform 150ms ease;
}
.am-close:hover { background: rgba(0, 0, 0, 0.55); transform: rotate(90deg); }

/* steps */
.am-step {
    padding: 3.3rem 1.6rem 1.5rem;
}

.am-gate {
    margin: 0 auto 0.9rem;
    padding: 0.55rem 0.8rem;
    border-radius: 0.9rem;
    background: var(--mint);
    color: var(--green-deep);
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.35;
}

.am-title {
    font-size: 1.3rem;
    margin: 0.2rem 0 0.9rem;
    color: var(--text);
}

/* segmented tabs => sliding pill follows data-mode */
.am-tabs {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 0.25rem;
    margin: 0 auto 0.9rem;
    border-radius: 999px;
    background: var(--field);
}

.am-tabs::before {
    content: "";
    position: absolute;
    top: 0.25rem;
    bottom: 0.25rem;
    left: 0.25rem;
    width: calc(50% - 0.25rem);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    transition: transform 260ms cubic-bezier(0.3, 1.4, 0.5, 1);
}
.am[data-mode="login"] .am-tabs::before { transform: translateX(100%); }

.am-tab {
    position: relative;
    z-index: 1;
    border: none;
    background: transparent;
    padding: 0.5rem 0.4rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 999px;
}
.am-tab[aria-selected="true"] { color: rgb(31, 149, 84); }

/* form */
.am-form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin: 0;
}

.am-msg:empty, .am-err:empty { display: none; }

.am-msg {
    margin: 0;
    padding: 0.5rem 0.7rem;
    border-radius: 0.8rem;
    background: color-mix(in srgb, var(--error) 12%, transparent);
    color: var(--error);
    font-size: 0.92rem;
    font-weight: 600;
}

.am-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    text-align: left;
}

.am-err {
    color: var(--error);
    font-size: 0.85rem;
    font-weight: 600;
    padding-left: 0.4rem;
}

.am-pw { position: relative; }

.am-input {
    width: 100%;
    box-sizing: border-box;
    font-size: 1rem;
    padding: 0.75rem 0.95rem;
    border-radius: 0.95rem;
    border: 2px solid transparent;
    background: var(--field);
    color: var(--text);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}
.am-input::placeholder { color: var(--text-faint); }
.am-input:focus {
    outline: none;
    border-color: rgb(53, 171, 106);
    box-shadow: 0 0 0 4px rgba(53, 171, 106, 0.18);
}
.am-pw .am-input { padding-right: 2.8rem; }

.am-eye {
    position: absolute;
    right: 0.55rem;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    padding: 0.25rem;
    cursor: pointer;
    line-height: 0;
}
.am-eye img { height: 1.25rem; }

/* main button */
.am-submit {
    margin-top: 0.3rem;
    border: none;
    border-radius: 999px;
    padding: 0.8rem 1.4rem;
    font-size: 1.02rem;
    font-weight: 800;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    background-image: linear-gradient(rgb(66, 190, 121), rgb(53, 171, 106));
    box-shadow: 0 4px 0 rgb(31, 133, 76);
    cursor: pointer;
    transition: transform 90ms ease, box-shadow 90ms ease, filter 150ms ease;
}
.am-submit:hover { filter: brightness(1.06); }
.am-submit:active { transform: translateY(3px); box-shadow: 0 1px 0 rgb(31, 133, 76); }
.am-submit:disabled { cursor: progress; }
.am-submit.is-busy { color: transparent; text-shadow: none; position: relative; }
.am-submit.is-busy::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.45);
    border-top-color: white;
    animation: am-spin 700ms linear infinite;
}

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

/* text links under the form: "Forgot password?" (login) and "Back to log in" (forgot) */
.am-link {
    display: inline-block;
    margin-top: 0.9rem;
    border: none;
    background: none;
    padding: 0.2rem;
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--blue-2);
    cursor: pointer;
}
.am-link:hover { text-decoration: underline; }
.am[data-mode="signup"] .am-to-forgot { visibility: hidden; } /* keeps the card height steady between tabs */
.am-to-login, .am[data-mode="forgot"] .am-to-forgot { display: none; }
.am[data-mode="forgot"] .am-to-login { display: inline-block; }

/* forgot mode => email only, no tabs or gate line */
.am-forgot-text { display: none; margin: -0.4rem 0 0.9rem; color: var(--text-3); font-size: 0.95rem; }
.am[data-mode="forgot"] .am-forgot-text { display: block; }
.am[data-mode="forgot"] .am-tabs,
.am[data-mode="forgot"] .am-gate,
.am[data-mode="forgot"] .am-field-pw { display: none; }

/* success message (reset link sent) */
.am-msg.am-msg-ok {
    background: var(--mint);
    color: var(--green-deep);
}

/* success step */
.am-check {
    width: 4rem;
    height: 4rem;
    margin: 0 auto 0.6rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, rgb(66, 190, 121), rgb(31, 149, 84));
    box-shadow: 0 0 0 0.45rem var(--mint);
    animation: am-check-pop 520ms cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.am-check svg {
    width: 2.2rem;
    height: 2.2rem;
    fill: none;
    stroke: white;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 24;
    stroke-dashoffset: 24;
    animation: am-draw 420ms 220ms ease forwards;
}

@keyframes am-check-pop {
    from { transform: scale(0.3) rotate(-25deg); opacity: 0; }
    to   { transform: none; opacity: 1; }
}
@keyframes am-draw { to { stroke-dashoffset: 0; } }

.am-done-text {
    margin: 0 0 1rem;
    color: var(--text-3);
}
.am-step-done .am-submit { width: 100%; }

/* reduced motion => no bobbing, popping or shaking */
@media (prefers-reduced-motion: reduce) {
    .am[open], .am[open]::backdrop, .am-mascot, .am-shake, .am-check, .am-check svg, .am-tabs::before {
        animation: none;
        transition: none;
    }
    .am-check svg { stroke-dashoffset: 0; }
}
