/* FullMoon MMO - Modal Component */

/* CombatScreen mounts modals into a dedicated root on <body>.
   This avoids stacking/compositing glitches with WebGL canvases in battle mode. */
#combat-modal-root {
    position: fixed;
    inset: 0;
    z-index: 2147483647;
    pointer-events: none;
    isolation: isolate;
    transform: translateZ(0);
    will-change: transform;
}

#combat-modal-root .modal-backdrop {
    position: absolute;
    inset: 0;
    pointer-events: auto;
}

#combat-modal-root .modal {
    position: absolute;
    pointer-events: auto;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-modal-backdrop);
    animation: fade-in 0.2s ease-out;
}

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

.modal-backdrop--closing {
    animation: fade-out 0.2s ease-in forwards;
}

@keyframes fade-out {
    to { opacity: 0; }
}

.modal {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max-width);
    max-height: 90vh;
    background: var(--theme-surface);
    border-radius: var(--border-radius-xl) var(--border-radius-xl) 0 0;
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    animation: slide-up 0.3s ease-out;
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.modal--closing {
    animation: slide-down 0.3s ease-in forwards;
}

@keyframes slide-down {
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(100%);
    }
}

.modal--fullscreen {
    top: var(--safe-area-top);
    bottom: var(--safe-area-bottom);
    max-height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom));
    border-radius: 0;
}

/* Centered modal variant */
.modal--centered {
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    max-height: 88vh;
    border-radius: var(--border-radius-xl);
    width: calc(100% - var(--spacing-lg) * 2);
    animation: modal-pop 0.3s ease-out;
}

@keyframes modal-pop {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.modal--centered.modal--closing {
    animation: modal-pop-out 0.2s ease-in forwards;
}

@keyframes modal-pop-out {
    to {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
}

.modal__handle {
    width: 40px;
    height: 4px;
    background: var(--theme-border);
    border-radius: var(--border-radius-full);
    margin: var(--spacing-sm) auto;
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    border-bottom: var(--border-width) solid var(--theme-border);
}

.modal__title {
    font-family: var(--font-family-display);
    font-size: var(--font-size-lg);
    font-weight: 700;
}

.modal__close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-full);
    color: var(--color-text-muted);
    transition: all var(--transition-fast);
}

.modal__close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text);
}

.modal__body {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    -webkit-overflow-scrolling: touch;
}

.modal__footer {
    padding: var(--spacing-md);
    border-top: var(--border-width) solid var(--theme-border);
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    justify-content: center;
}

.modal__footer--sticky {
    position: sticky;
    bottom: 0;
    background: var(--theme-surface);
}

/* Common footer layout helpers */
.modal__footer .btn--full {
    flex: 1 0 100%;
}

@media (max-width: 420px) {
    .modal--centered {
        width: calc(100% - var(--spacing-md) * 2);
        max-height: 92vh;
    }
    .modal__body {
        padding: var(--spacing-sm);
    }
    .modal__footer {
        padding: var(--spacing-sm);
    }
}

/* Confirm Modal */
.confirm-modal__message {
    text-align: center;
    margin-bottom: var(--spacing-lg);
}

.confirm-modal__actions {
    display: flex;
    gap: var(--spacing-sm);
}

.confirm-modal__actions .btn {
    flex: 1;
}
