/* =============================================================================
   MODAL COMPONENTS - Unified Modal System
   =============================================================================

   Uses semantic tokens from themes.css for automatic theme support.
   All modals across the application use these base styles.

   USAGE:
   - Always use CSS variables from themes.css
   - Extend these base styles for specialized modals (e.g., card details modal)
   - Dark theme support is automatic through CSS variables

   ============================================================================= */

/* ========================================
   BASE MODAL STYLES
   ======================================== */

/* Modal Overlay */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-overlay);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Modal Content Container — Newtype v2 HUD shell: dark fill, neon
   border + neon-glow shadow, angular corners. Specialised modals
   (card detail, profile, etc.) opt out via their own .cardModal- /
   .profile-modal classes and aren't affected. */
.modal-content {
    background: var(--bg-2);
    border-radius: 0;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 0 16px var(--neon-glow);
    border: 1px solid var(--neon);
}

/* ========================================
   MODAL SIZE VARIANTS
   ======================================== */

/* Small Modal */
.small-modal {
    max-width: 400px;
    width: 90%;
}

/* Large Modal - For modals with more content (forms, lists) */
.modal-large {
    max-width: 800px;
    width: 90%;
}

/* Deck Modal - Wider for card lists */
.deck-modal-content {
    max-width: 1000px;
    width: 95%;
    max-height: 90vh;
    background: var(--modal-bg);
}

.deck-modal-content .modal-body {
    display: flex;
    gap: var(--spacing-2xl);
    padding: 0 var(--spacing-lg) var(--spacing-lg);
}

.deck-info-section {
    flex: 0 0 350px;
    border-bottom: none;
    border-right: 1px solid var(--border-primary);
    padding-right: var(--spacing-2xl);
    padding-bottom: var(--spacing-lg);
    margin-bottom: 0;
}

.deck-cards-section {
    flex: 1;
    min-width: 0;
}

/* ========================================
   MODAL HEADER
   ======================================== */

/* Modal header — Newtype v2 HUD strip. Title in JetBrains Mono uppercase,
   close button as a HUD square (matches the deck modal nav buttons). */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--spacing-lg);
    background: rgba(6, 8, 5, 0.4);
}

.modal-header h3 {
    margin: 0;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

/* Headers using h2 (legacy MSA / GDSim / TTS modals) get the same
   treatment so all modals match without per-file edits. */
.modal-header h2 {
    margin: 0;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

/* Close button — HUD-square icon button. Both <span class="close">×</span>
   and <button class="close">×</button> render the same. */
.close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    line-height: 1;
    cursor: pointer;
    transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.close:hover {
    border-color: var(--neon);
    color: var(--neon);
    background: var(--hover-bg);
    box-shadow: 0 0 8px var(--neon-glow);
}

/* `.modal-close` — alias used by tournament-management, tournament-results
   and other pages that ship their own close button class. Mirrors `.close`
   so those modals pick up the v2 HUD chrome without per-page rules. */
.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    line-height: 1;
    cursor: pointer;
    transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}
.modal-close:hover {
    border-color: var(--neon);
    color: var(--neon);
    background: var(--hover-bg);
    box-shadow: 0 0 8px var(--neon-glow);
}

/* Card Modal - Special header styling */
#cardModal .modal-header {
    padding: var(--spacing-lg) var(--spacing-xl);
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: var(--text-inverse);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
}

#cardModal .modal-header h3 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--text-inverse);
}

#cardModal .modal-header .close {
    color: var(--text-inverse);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity var(--transition-fast);
}

#cardModal .modal-header .close:hover {
    opacity: 1;
    background-color: var(--overlay-light);
    border-radius: var(--radius-md);
}

/* Creator Modal - Enhanced close button */
#creatorModal .modal-header {
    position: relative;
    padding-right: 50px;
}

#creatorModal .modal-header .close {
    position: absolute;
    right: var(--spacing-lg);
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    color: var(--text-tertiary);
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
}

#creatorModal .modal-header .close:hover {
    color: var(--text-primary);
    background-color: var(--interactive-hover);
}

/* ========================================
   MODAL BODY & FOOTER
   ======================================== */

.modal-body {
    padding: 0 var(--spacing-lg) var(--spacing-lg);
}

.modal-footer {
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border);
    margin-top: var(--spacing-lg);
    background: rgba(6, 8, 5, 0.4);
}

/* Action buttons inside a modal (footer or .form-actions row) get the
   v2 HUD treatment — angular border, mono uppercase label, neon-glow on
   the primary. This overrides the rounded-pill defaults from
   components/buttons.css inside the modal scope without changing them
   elsewhere. Same vocabulary as the Export modal's GENERATE IMAGE /
   CANCEL action buttons. */
.modal .btn-primary,
.modal .btn-secondary,
.modal .form-actions .btn-primary,
.modal .form-actions .btn-secondary {
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: 0;
    font-family: var(--font-mono);
    font-size: 11px; /* HUD micro */
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.modal .btn-primary {
    background: var(--neon);
    color: var(--bg-body);
    border: 1px solid var(--neon);
}
.modal .btn-primary:hover {
    background: var(--color-primary-light);
    transform: none;
    box-shadow: 0 0 12px var(--neon-glow);
}

.modal .btn-secondary {
    background: transparent;
    color: var(--text-2);
    border: 1px solid var(--border);
}
.modal .btn-secondary:hover {
    border-color: var(--neon);
    color: var(--neon);
    background: var(--hover-bg);
    transform: none;
    box-shadow: 0 0 6px var(--neon-glow);
}

/* Danger variant — destructive actions like Discard / Delete inherit
   the same HUD chrome but in --color-error red. */
.modal .btn-danger {
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: 0;
    border: 1px solid var(--color-error);
    background: transparent;
    color: var(--color-error);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}
.modal .btn-danger:hover {
    background: var(--color-error-bg);
    color: var(--color-error-light);
    box-shadow: 0 0 8px rgba(255, 59, 59, 0.3);
    transform: none;
}

/* .form-actions inside the modal body — same right-aligned row of HUD
   buttons. Many of the menu modals use this instead of .modal-footer. */
.modal .form-actions {
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
    margin-top: var(--spacing-lg);
}

/* `.modal-actions` — alias used by tournament-management's form modals
   (Save / Cancel row). Same right-aligned HUD row as .form-actions /
   .modal-footer. Border separator keeps the button row visually grouped
   under the form body. */
.modal .modal-actions {
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--border);
}

/* Tournament-management modals open via `.show` (instead of removing
   `.hidden`). The base `.show` utility in display.css is `display: block`,
   which would break the modal flex layout. Restore `display: flex` for
   the open state so the tournament modals center correctly. */
.modal.show {
    display: flex !important;
}

.modal-footer-left,
.modal-footer-right {
    display: flex;
    gap: var(--spacing-md);
}

/* ========================================
   MODAL TABS
   ======================================== */

.cards-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: var(--spacing-lg);
}

.tab-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tab-btn:hover:not(.active) {
    color: var(--text-primary);
    background: var(--interactive-hover);
}

.cards-list {
    display: none;
}

.cards-list.active {
    display: block;
}

/* ========================================
   CARD LISTS IN MODALS
   ======================================== */

.card-group {
    margin-bottom: var(--spacing-lg);
}

.card-group-header {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-primary);
    font-size: var(--font-size-base);
}

.card-list-item {
    display: flex;
    align-items: center;
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-secondary);
}

.card-quantity {
    font-weight: 600;
    color: var(--color-primary);
    min-width: 30px;
    margin-right: var(--spacing-md);
    text-align: center;
}

.card-name {
    flex: 1;
    color: var(--text-primary);
}

/* ========================================
   TRADING SECTIONS (Creator Modal)
   ======================================== */

.creator-trading-section {
    margin-top: var(--spacing-2xl);
    padding: var(--spacing-lg);
    background: var(--surface-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
}

.creator-trading-section h3 {
    margin: 0 0 var(--spacing-md) 0;
    color: var(--text-primary);
    font-size: var(--font-size-xl);
    font-weight: 600;
}

/* Trading Cards Grid */
.trading-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--spacing-md);
    max-height: 500px;
    overflow-y: auto;
    padding: var(--spacing-sm);
}

/* Custom scrollbar for trading grid */
.trading-cards-grid::-webkit-scrollbar {
    width: 8px;
}

.trading-cards-grid::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: var(--radius-md);
}

.trading-cards-grid::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--radius-md);
}

.trading-cards-grid::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Trading Card Thumbnail */
.trading-card-thumbnail {
    cursor: pointer;
    transition: all var(--transition-base);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.trading-card-thumbnail:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

/* Image Wrapper with Quantity Badge */
.trading-card-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 5/7;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--surface-tertiary);
}

.trading-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Quantity Badge */
.trading-card-quantity-badge {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    background: var(--overlay-heavy);
    color: var(--text-inverse);
    padding: calc(var(--spacing-xs) / 2) var(--spacing-sm);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 700;
    box-shadow: var(--shadow-md);
    z-index: 2;
}

/* Card Info */
.trading-card-info {
    padding: var(--spacing-sm) var(--spacing-xs) var(--spacing-xs);
    text-align: center;
}

.trading-card-uuid {
    font-family: 'Courier New', monospace;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
    /* Deck Modal - Stack sections on mobile */
    .deck-modal-content .modal-body {
        flex-direction: column;
        gap: var(--spacing-lg);
    }

    .deck-info-section {
        flex: 1;
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
        padding-right: 0;
        padding-bottom: var(--spacing-lg);
        margin-bottom: var(--spacing-lg);
    }

    .deck-modal-content {
        width: 95%;
        max-height: 95vh;
        margin: var(--spacing-sm);
    }

    /* Trading Cards - Smaller grid on mobile */
    .trading-cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: var(--spacing-sm);
    }

    .trading-card-uuid {
        font-size: var(--font-size-xs);
    }

    .trading-card-quantity-badge {
        font-size: var(--font-size-xs);
        padding: calc(var(--spacing-xs) / 2) var(--spacing-xs);
    }

    /* Modal Footer - Stack on mobile */
    .modal-footer {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    /* Keep editDeckModal buttons in a row even on mobile */
    #editDeckModal .modal-footer {
        flex-direction: row;
        gap: var(--spacing-md);
    }

    #editDeckModal .modal-footer button {
        flex: 1;
        /* Ensure consistent height between primary and secondary buttons */
        min-height: 44px;
        line-height: 1.5;
        padding: var(--spacing-sm) var(--spacing-lg);
        box-sizing: border-box;
        /* Ensure no border for both buttons */
        border: none !important;
    }

    #editDeckModal .modal-footer button:hover,
    #editDeckModal .modal-footer button:active {
        /* Prevent any border, shadow, or transform on hover/active */
        border: none !important;
        box-shadow: none !important;
        transform: none !important;
    }

    .modal-footer-left,
    .modal-footer-right {
        width: 100%;
        justify-content: stretch;
    }

    .modal-footer-left > *,
    .modal-footer-right > * {
        flex: 1;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Focus states */
.modal:focus-within {
    outline: none;
}

.close:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.tab-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .trading-card-thumbnail {
        transition: none;
    }

    .tab-btn,
    .close {
        transition: none;
    }
}

/* ========================================
   EXPORT IMAGE OPTIONS MODAL
   ======================================== */

#exportImageOptionsModal {
    z-index: 10001; /* Above deck modal (10000) */
}

#exportImageOptionsModal .modal-content {
    max-width: 400px;
}

/* Toggle Button Group - used for Group By and Design options */
.export-toggle-group {
    display: flex;
    gap: 0;
    margin-top: var(--spacing-sm);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-primary);
}

.export-toggle-btn {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    background: var(--surface-secondary);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.export-toggle-btn:not(:last-child) {
    border-right: 1px solid var(--border-primary);
}

.export-toggle-btn:hover:not(.active) {
    background: var(--surface-tertiary);
}

.export-toggle-btn.active {
    background: var(--color-primary);
    color: var(--text-inverse);
}

/* Export modal action buttons */
#exportImageOptionsModal .form-actions {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
    justify-content: center;
}

#exportImageOptionsModal .form-actions button {
    padding: var(--spacing-sm) var(--spacing-xl);
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

#exportImageOptionsModal .btn-primary {
    background: var(--color-primary);
    color: var(--text-inverse);
    border: none;
}

#exportImageOptionsModal .btn-primary:hover {
    background: var(--color-primary-dark);
}

#exportImageOptionsModal .btn-secondary {
    background: var(--surface-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}

#exportImageOptionsModal .btn-secondary:hover {
    background: var(--surface-tertiary);
    border-color: var(--surface-tertiary);
}

/* ========================================
   PROXY EXPORT MODAL
   ======================================== */

/* Proxy Export Modal - larger to accommodate card list */
.proxy-export-modal {
    max-width: 500px;
    width: 95%;
}

#proxyExportOptionsModal .modal-content {
    max-width: 500px;
}

/* Card Quantity Editor List */
.proxy-card-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    background: var(--surface-secondary);
}

.proxy-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid var(--border-primary);
    gap: var(--spacing-md);
}

.proxy-card-row:last-child {
    border-bottom: none;
}

.proxy-card-row:hover {
    background: var(--surface-tertiary);
}

.proxy-card-info {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--spacing-xs);
    flex: 1;
    min-width: 0;
}

.proxy-card-number {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.proxy-card-name {
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.proxy-card-deck-qty {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    flex-shrink: 0;
}

/* Quantity Controls */
.proxy-qty-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex-shrink: 0;
}

.proxy-qty-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    background: var(--surface-primary);
    color: var(--text-primary);
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.proxy-qty-btn:hover {
    background: var(--color-primary);
    color: var(--text-inverse);
    border-color: var(--color-primary);
}

.proxy-qty-btn:active {
    transform: scale(0.95);
}

.proxy-qty-input {
    width: 42px;
    height: 28px;
    text-align: center;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.proxy-qty-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-alpha);
}

/* Remove number input spinners */
.proxy-qty-input::-webkit-outer-spin-button,
.proxy-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.proxy-qty-input[type=number] {
    -moz-appearance: textfield;
}

/* Empty state message */
.proxy-no-cards {
    padding: var(--spacing-lg);
    text-align: center;
    color: var(--text-tertiary);
    font-style: italic;
}

.proxy-preview-info {
    margin-top: var(--spacing-lg);
    padding: var(--spacing-md);
    background: var(--surface-tertiary);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.proxy-preview-info p {
    margin: var(--spacing-xs) 0;
}

.proxy-preview-info strong {
    color: var(--text-primary);
}

/* Proxy export modal action buttons */
#proxyExportOptionsModal .form-actions {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
    justify-content: center;
}

#proxyExportOptionsModal .form-actions button {
    padding: var(--spacing-sm) var(--spacing-xl);
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

#proxyExportOptionsModal .btn-primary {
    background: var(--color-primary);
    color: var(--text-inverse);
    border: none;
}

#proxyExportOptionsModal .btn-primary:hover {
    background: var(--color-primary-dark);
}

#proxyExportOptionsModal .btn-secondary {
    background: var(--surface-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}

#proxyExportOptionsModal .btn-secondary:hover {
    background: var(--surface-tertiary);
    border-color: var(--surface-tertiary);
}

/* ========================================
   THEME NOTES
   ========================================

   This file uses CSS variables from themes.css exclusively.
   Dark theme support is automatic - no body.dark-theme overrides needed!

   Variables used:
   - Surface: --modal-bg, --surface-secondary, --surface-tertiary
   - Text: --text-primary, --text-secondary, --text-tertiary, --text-inverse
   - Border: --border-primary, --border-secondary
   - Interactive: --interactive-hover, --overlay-light, --overlay-heavy
   - Shadows: --shadow-md, --shadow-lg, --shadow-xl
   - Colors: --color-primary, --color-primary-dark
   - Spacing: --spacing-xs through --spacing-2xl
   - Radius: --radius-sm through --radius-full
   - Scrollbar: --scrollbar-track, --scrollbar-thumb, --scrollbar-thumb-hover
   - Transitions: --transition-fast, --transition-base
   - Focus: --focus-ring

   To customize modals for a specific theme:
   1. Update the semantic tokens in themes.css
   2. All modals will update automatically
   3. No need for body.dark-theme overrides

   ======================================== */

/* =============================================================================
   MOBILE SLIDE-UP SHEET (Phase 9)

   On mobile, any .modal using the standard .modal-content pattern is rendered
   as a bottom-anchored slide-up sheet — full width, rounded top corners only,
   small grabber visual at the top edge. This catches deck details, playtest,
   share, confirmation, import/export, and any other standard modal in the
   app in a single pass.

   The card detail modal uses its own classes (.cardModal-overlay /
   .cardModal-container) and got its sheet override in phase 2 directly in
   card-modal.css.

   Modals that opt out by setting their own align-items / position on .modal
   (e.g. specialised editor surfaces) keep working — this only overrides the
   default .modal centering layout.
   ============================================================================= */
@media (max-width: 768px) {
    /* The compound selector (.modal.modal-open) is needed so we beat the
       .modal-open utility in display.css (loaded after modals.css), which
       otherwise re-centers the modal and breaks the slide-up. */
    .modal,
    .modal.modal-open {
        align-items: flex-end;
        justify-content: stretch;
        padding: 0;
    }

    .modal > .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 92vh;
        margin: 0;
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding-top: 18px;
        position: relative;
        animation: masSheetSlideUp 0.32s cubic-bezier(0.32, 0.72, 0, 1);
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.3);
    }

    /* BaseModal applies .modal-closed for ~300ms before hiding the element.
       Animate the slide-down + backdrop fade in that window so the close
       feels symmetric with the slide-up open. */
    .modal.modal-closed {
        animation: masSheetBackdropFadeOut 0.28s ease forwards;
        pointer-events: none;
    }
    .modal.modal-closed > .modal-content {
        animation: masSheetSlideDown 0.28s cubic-bezier(0.4, 0, 0.6, 1) forwards;
    }

    /* Grabber bar at the top edge */
    .modal > .modal-content::before {
        content: "";
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 5px;
        border-radius: 3px;
        background: var(--text-secondary);
        opacity: 0.4;
        pointer-events: none;
    }
}

@keyframes masSheetSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
@keyframes masSheetSlideDown {
    from { transform: translateY(0); }
    to   { transform: translateY(100%); }
}
@keyframes masSheetBackdropFadeOut {
    from { background-color: var(--modal-overlay); }
    to   { background-color: transparent; }
}
