/* ============================================
   MODALS
   Auth modal, settings, import modal, popups
   ============================================ */

/* ============================================
   BASE MODAL — the app-wide dialog shell
   (ui/components/base_modal.rs). The frame every dialog modal shares:
   pinned to a fixed top anchor (title bar never moves as content changes),
   width fills the viewport up to a per-modal cap, height fits content up to
   the viewport with the BODY scrolling while header/footer stay put.
   ============================================ */

/* A profile opened from inside another modal — a player named in a Pod Stats
   drill-down, say — must land on top of the modal that offered the link. Both
   are the same shell, so without this the later-portaled one wins and the
   profile opens underneath. */
.base-modal-overlay:has(> .user-profile-modal) {
    z-index: calc(var(--z-modal-stacked) + 100);
}

.base-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    /* Pin to a top anchor and grow downward — vertical centering makes the
       title bar and buttons shift as content height changes. */
    align-items: flex-start;
    justify-content: center;
    padding: 4vh 16px;
    z-index: var(--z-modal);
    animation: fadeIn 0.2s ease;
    cursor: pointer;
}

/* An overlay rendered inline inside a `.stagger-reveal` block (the pod
   overview's confirm dialogs) is one of that block's children, and the
   `:nth-child` stagger rules outrank `.base-modal-overlay` for the delay. The
   fade then started 100-500ms late: the overlay showed at full opacity, cut
   to nothing, and faded back in. A dialog is never part of the reveal. */
.stagger-reveal > .base-modal-overlay {
    animation-delay: 0s;
}

.base-modal {
    display: flex;
    flex-direction: column;
    /* Fill the viewport width by default; the width variants only cap it. */
    width: 100%;
    /* The overlay's padding is the viewport margin; never grow past it. */
    max-height: 100%;
    background: var(--popup-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-2xl);
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: baseModalPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: default;
}

@keyframes baseModalPop {
    from {
        opacity: 0;
        transform: scale(0.97) translateY(12px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.base-modal--sm { max-width: 440px; }
.base-modal--md { max-width: 600px; }
.base-modal--lg { max-width: 800px; }
.base-modal--xl { max-width: 1100px; }

.base-modal-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2-5);
    padding: var(--space-3) var(--space-5);
    /* The Card Detail Modal's header height, so the title bar reads the same
       across every modal. */
    min-height: 72px;
    border-bottom: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--text-color) 2%, transparent);
}

.base-modal-header-icon {
    display: inline-flex;
    align-items: center;
    color: var(--text-color);
}

/* The title and its optional subtitle. A title is kept short (the detail
   goes in the subtitle), and one that still runs long wraps onto a second
   line rather than being cut off mid-word. */
.base-modal-heading {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-0-5);
}

.base-modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--text-color);
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

.base-modal-subtitle {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

/* The Card Detail Modal's close button, verbatim — one × for the whole app. */
.base-modal-close {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-round);
    background: var(--button-bg);
    border: none;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
    font-size: 24px;
    margin-left: auto;
}

.base-modal-close svg {
    width: 24px;
    height: 24px;
    stroke-width: 2.5px;
    flex-shrink: 0;
}

.base-modal-close:hover {
    background: var(--entry-hover-bg);
}

/* Tab strip that replaces the title on the title bar's left side. Only the
   dimensions live here — every visual state (track, segments, active, hover,
   soft-disabled) comes from the shared button contract in buttons.css, the
   same way the panel/search/legal segmented controls get theirs. The close
   button's own margin-left: auto pushes the strip left. */
.base-modal-tabs {
    flex: 0 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1);
    border-radius: var(--radius-lg);
    overflow-x: auto;
}

.base-modal-tab {
    padding: 7px 16px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

/* The one part that scrolls — vertically only. `min-height: 0` lets it
   actually shrink inside the flex column instead of pushing the footer
   off-screen; `overflow-x: hidden` because setting overflow-y alone computes
   overflow-x to auto, and a modal must never scroll sideways. */
.base-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 20px;
}

.base-modal-footer {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3-5) var(--space-5);
    border-top: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--text-color) 2%, transparent);
}

/* An action's label stays on one line: actions that do not fit side by side
   wrap onto the next row rather than squeezing their words into a column. */
.base-modal-footer > button {
    white-space: nowrap;
}

/* Three or more actions in a small dialog stack, full width, Cancel last. */
.base-modal--sm .base-modal-footer:has(> :nth-child(3)) {
    flex-direction: column;
    align-items: stretch;
}

.base-modal--sm .base-modal-footer:has(> :nth-child(3)) > .modal-action-secondary {
    order: 1;
}

/* Shared button styles for the action bar, so every modal's actions read the
   same. Primary = the accent gradient; secondary = quiet outline. */
.base-modal-footer .modal-action-primary,
.modal-action-primary {
    padding: var(--space-2-5) var(--space-5);
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    color: var(--button-primary-text);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--accent-glow);
    transition: all 0.2s;
}

.modal-action-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.modal-action-danger {
    padding: var(--space-2-5) var(--space-5);
    border: none;
    border-radius: var(--radius-md);
    background: var(--danger-color);
    color: white;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-action-secondary {
    padding: var(--space-2-5) var(--space-5);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-action-secondary:hover {
    color: var(--text-color);
    border-color: var(--text-muted);
}

@media (max-width: 640px) {
    .base-modal-overlay {
        padding: 2vh 8px;
    }

    .base-modal-header,
    .base-modal-body,
    .base-modal-footer {
        padding-left: var(--space-3-5);
        padding-right: var(--space-3-5);
    }

    .base-modal-title {
        font-size: 1.1rem;
    }

    /* On a phone the actions fill their row, and three or more stack, full
       width, with Cancel last, rather than squeezing side by side. */
    .base-modal-footer > * {
        flex: 1 1 auto;
    }

    .base-modal-footer:has(> :nth-child(3)) {
        flex-direction: column;
        align-items: stretch;
    }

    .base-modal-footer:has(> :nth-child(3)) > .modal-action-secondary {
        order: 1;
    }

    .base-modal-footer:has(> :nth-child(3)) .modal-action-left {
        margin-right: 0;
    }
}

/* Per-modal hooks on the BaseModal shell (kept out of the base section above).
   A left-aligned slot in the action bar, for a footer action that is not part
   of the Cancel/confirm pair (e.g. Manage Tags' "Suggest Tags"). */
.base-modal-footer .modal-action-left {
    margin-right: auto;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    animation: fadeIn 0.2s ease;
    cursor: pointer;
}

/* Modal Content */
.modal-content {
    background: var(--popup-bg);
    border-radius: var(--radius-2xl);
    padding: var(--space-6);
    width: 90%;
    max-width: 500px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    position: relative;
    cursor: default;
}

.modal-content h3 {
    margin: 0 0 var(--space-2) 0;
    color: var(--accent-color);
}

.modal-hint {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-bottom: var(--space-4);
}

/* Import Modal */

/* The collapsed failure list sits between the status line and the buttons. */
.import-failed-details {
    margin: -4px 0 12px;
}

.import-textarea {
    width: 100%;
    height: 200px;
    padding: var(--space-3) var(--space-3-5) var(--space-3) var(--space-3);
    border-radius: var(--radius-lg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-color);
    font-family: monospace;
    font-size: 0.9em;
    resize: vertical;
    box-sizing: border-box;
}

.import-textarea:focus {
    outline: none;
    border-color: var(--accent-color);
}

.import-status {
    color: var(--accent-color);
    font-size: 0.85em;
    min-height: 20px;
    margin: var(--space-2) 0;
}

.import-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    margin-bottom: var(--space-3);
}

.import-mode .filter-toggle-hint {
    margin-top: 0;
    text-align: center;
}

.import-replace-warning {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin: 0 0 15px 0;
    padding: var(--space-2-5) var(--space-3);
    font-size: 0.85em;
    line-height: 1.4;
    color: var(--warning-color);
    background: var(--warning-bg);
    border: 1px solid var(--warning-color);
    border-radius: var(--radius-md);
}

/* Import sources that no longer work through a URL. Informational rather than a
   warning: nothing the user did is wrong, the upstream site blocks automated
   access, so this states the fact and points at the export-and-paste route. */
.modal-hint--warning {
    margin: -8px 0 16px 0;
    padding: var(--space-2-5) var(--space-3);
    color: var(--text-primary);
    background: var(--info-bg);
    border-left: 3px solid var(--accent-color);
    border-radius: var(--radius-sm);
}

/* --- Public profile banner ---

   The art runs the full height of the profile header rather than sitting above it: the avatar,
   name and badges are laid over the image, and it dissolves into the modal background just
   before the "My Color Identity" / "My Signature Card" cards begin. Anchored `center top`
   because card art frames its subject near the top, and with no visible bottom edge there is
   nothing for a user to align -- which is what let the per-user position control go away. */
.profile-banner {
    position: relative;
    width: 100%;
    height: 480px;
    background-image: var(--profile-banner-art, none);
    background-size: cover;
    background-position: center top;
    background-repeat: no-repeat;
}

/* Sits over the art. Nearly clear at the top so the image keeps its color, then accelerating
   so the last third is indistinguishable from the modal itself. */
.profile-banner-fade {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0) 34%,
        color-mix(in srgb, var(--popup-bg) 30%, transparent) 55%,
        color-mix(in srgb, var(--popup-bg) 70%, transparent) 76%,
        color-mix(in srgb, var(--popup-bg) 92%, transparent) 90%,
        var(--popup-bg) 100%
    );
}

.profile-modal-body {
    padding: 0 var(--space-8) var(--space-8) var(--space-8);
    margin-top: -40px;
    position: relative;
    z-index: 5;
}

/* Only pulled up when there is art to be pulled up over -- a profile with no banner keeps its
   original spacing rather than opening with 300px of empty modal. */
.profile-modal-body--with-banner {
    margin-top: -300px;
}

/* The profile's banner keeps its box from the start and fades the art in once the
   hidden probe image has it, rather than painting it in as it downloads. */
.user-profile-modal .profile-banner {
    opacity: 0;
    transition: opacity 0.35s ease;
}

.user-profile-modal .profile-banner.is-loaded {
    opacity: 1;
}

.profile-banner-probe {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    .user-profile-modal .profile-banner {
        transition: none;
    }
}

/* On the BaseModal shell: the banner art runs edge to edge, so the body carries
   no padding of its own — .profile-modal-body provides the content inset. */
.user-profile-modal .base-modal-body {
    padding: 0;
}

/* Legibility scrim for the header text, which now sits on top of arbitrary card art.
   Built from `--popup-bg` via color-mix so it darkens on dark themes and lightens on light
   ones automatically: profile themes are user-chosen, so a hardcoded black wash would wreck
   the light ones. The ellipse keeps the wash centred on the text and off the art's edges. */
/* Named for the public profile specifically: a plain `.profile-header` already exists further
   down for the settings modal, and it is a horizontal flex row. Reusing that name laid the
   avatar, username and badges out side by side and overflowed the page. */
.public-profile-header {
    text-align: center;
    position: relative;
}

.public-profile-header::before {
    content: "";
    position: absolute;
    inset: -24px -8% 0 -8%;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(
        ellipse 62% 58% at 50% 46%,
        color-mix(in srgb, var(--popup-bg) 78%, transparent) 0%,
        color-mix(in srgb, var(--popup-bg) 58%, transparent) 45%,
        transparent 78%
    );
}

/* The settings preview shows the same treatment at a size that fits inside the form. */
.profile-banner--preview {
    height: 150px;
    border-radius: var(--radius-2xl);
    overflow: hidden;
    border: 1px solid var(--input-border);
}

/* Phones get a shorter banner and a smaller pull-up: 480px of art would push the profile's
   actual content off the screen before the reader saw any of it. */
@media (max-width: 768px) {
    .profile-banner {
        height: 300px;
    }

    .profile-modal-body--with-banner {
        margin-top: -190px;
    }

    .public-profile-header::before {
        inset: -16px -4% 0 -4%;
    }
}

.import-file-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding: var(--space-4);
    background: var(--input-bg);
    border: 1px dashed var(--input-border);
    border-radius: var(--radius-lg);
    transition: all 0.2s;
    text-align: center;
}

.import-file-section.drag-over {
    border-color: var(--accent-color);
    background: var(--accent-bg);
    transform: scale(1.02);
    box-shadow: 0 0 15px var(--accent-glow);
}

.import-file-section:hover {
    border-color: var(--accent-color);
    background: var(--accent-bg);
}

.file-input-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    color: var(--text-color);
    font-size: 0.95em;
    cursor: pointer;
    font-weight: 500;
}

.file-input-label .ui-icon {
    color: var(--accent-color);
}

.file-input-hidden {
    display: none;
}

.modal-buttons {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

.modal-btn {
    padding: var(--space-2-5) var(--space-5);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s ease;
}

.confirm-btn {
    background: var(--accent-color);
    border: none;
    color: var(--button-primary-text);
    font-weight: bold;
}

.confirm-btn:hover {
    filter: brightness(1.1);
}

.auth-header {
    text-align: center;
    margin-bottom: var(--space-6);
}

.auth-header h2 {
    font-size: 1.8em;
    margin-bottom: var(--space-2);
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 0.95em;
    opacity: 0.9;
}

/* The logo heading the sign-in and forgot-password modals.

   These rules used to live in an inline <style> inside each of those two
   modals — two copies of the same global selectors, so whichever modal
   mounted last won and opening one could re-align the other. */
.auth-modal-logo {
    margin-bottom: var(--space-3);
    display: flex;
    justify-content: center;
    transform: scale(1.15);
    transform-origin: center;
}

/* The banner logo's "X" is absolutely positioned outside .logo-composite,
   so the box measures 180px while the artwork runs to 211px. Centring the
   box therefore leaves the visible mark sitting 20.6px right of centre.
   This margin widens the outer box to match the ink, which measures to
   within 0.2px of true centre. The number follows the text asset's aspect
   ratio, so re-measure if that artwork is ever replaced. */
.auth-modal-logo .logo-composite {
    margin-right: 41px;
}

/* Consent, which gates every way of creating an account. */
.auth-consent {
    padding: var(--space-3) var(--space-3-5);
    border: 1px solid var(--divider-border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-5);
    text-align: left;
}

.auth-consent-hint {
    display: block;
    margin: 0.4rem 0 0 22px;
    font-size: 0.8em;
    color: var(--text-muted);
}

.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: 500;
    color: var(--text-color);
}

.auth-input {
    width: 100%;
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 1em;
    transition: all 0.2s;
}

.auth-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
    outline: none;
}

.auth-submit-btn {
    width: 100%;
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    background: var(--accent-gradient);
    color: var(--button-primary-text);
    font-weight: bold;
    font-size: 1.1em;
    border: none;
    cursor: pointer;
    margin-top: var(--space-4);
    transition: transform 0.1s;
}

.auth-submit-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

/* Two different reasons to be disabled, and they should not look alike. */
.auth-submit-btn:disabled {
    opacity: 0.45;
    filter: grayscale(0.6);
    cursor: not-allowed;
}

/* A disabled button still receives :hover, so the lift has to be cancelled
   or it goes on advertising itself as pressable. */
.auth-submit-btn:disabled:hover {
    filter: grayscale(0.6);
    transform: none;
}

/* Mid-request is the other kind: the press landed and the button is working,
   so it stays lit and the cursor says "wait", not "not for you". */
.auth-submit-btn.auth-submit-waiting:disabled,
.auth-submit-btn.auth-submit-waiting:disabled:hover {
    opacity: 0.7;
    filter: none;
    cursor: wait;
}

.auth-error {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger-color);
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.9em;
}

.error-icon {
    font-size: 1.2em;
}

/* Not an error: "check your inbox" after a registration (backend-api.md D4). */
.auth-notice {
    background: var(--info-bg);
    border: 1px solid var(--info-border);
    color: var(--info-color);
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
    font-size: 0.9em;
}

.form-hint {
    display: block;
    margin-top: var(--space-1);
    font-size: 0.85em;
    color: var(--text-muted);
}

/* A value the server refused, beside the field it named (a username taken or too close to
   another account's). */
.form-field-error {
    display: block;
    margin-top: var(--space-1);
    font-size: 0.85em;
    color: color-mix(in srgb, var(--danger) 80%, var(--text-primary));
}

.form-group-checkbox {
    margin-bottom: var(--space-4);
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    margin-top: var(--space-0-5);
    cursor: pointer;
}

.checkbox-label span {
    color: var(--text-color);
    font-size: 0.9em;
    line-height: 1.4;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent !important;
    border: none;
    color: var(--text-color) !important;
    padding: 0 !important;
    font-size: 2em;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-round);
    transition: all 0.2s;
    z-index: 100;
    opacity: 1;
}

.modal-close svg {
    stroke: currentColor !important;
    color: inherit !important;
}

.modal-close:hover {
    background: var(--accent-bg) !important;
    color: var(--text-color) !important;
}

.text-link {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-weight: 500;
    padding: 0;
    margin-left: var(--space-1);
    transition: all 0.2s;
}

.text-link:hover {
    filter: brightness(1.2);
}

.text-link:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.auth-footer {
    margin-top: var(--space-6);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9em;
}

/* ── The ways in ───────────────────────────────────────────────────────────
   The providers are the way in; the email form is behind a small link under
   them (and opens first only after an email registration, or for someone who
   last signed in with email on this device). A provider account is safer than
   one more password and needs no confirmation email. Password sign-in still
   matters for an account whose provider later revokes access, which is why
   the link is always there. */

/* Between the providers and the email form, in the same place either way. */
.auth-method-switch {
    display: block;
    margin: var(--space-4) auto 0;
    font-size: 0.85em;
}

.auth-oauth-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-2-5);
}

.auth-oauth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2-5);
    width: 100%;
    padding: var(--space-2-5) var(--space-3-5);
    border-radius: var(--radius-lg);
    border: 1px solid var(--ui-button-border);
    background: var(--ui-button-bg);
    color: var(--ui-button-text);
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.auth-oauth-btn:hover:not(:disabled) {
    border-color: var(--ui-button-hover-border);
}

.auth-oauth-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Sized to match the text beside it rather than a fixed pixel box, so the
   marks stay aligned when the modal font scales. */
.auth-oauth-btn svg {
    width: 1.15em;
    height: 1.15em;
    flex-shrink: 0;
}

