body.modal-open {
    overflow: hidden;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--backdrop);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity var(--transition-base);
    padding: 20px;
}

.modal-overlay.visible {
    opacity: 1;
}

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0;
    max-width: 440px;
    width: 100%;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-card);
    position: relative;
    animation: modalAppear var(--transition-base) cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.modal-box--bare {
    background: transparent;
    border: none;
    box-shadow: none;
    max-width: 95vw;
}

.modal-box--bare .modal-title {
    display: none;
}

.modal-box--bare .modal-body {
    padding: 0;
    align-items: center;
    gap: 12px;
}

.modal-box--bare .modal-html-wrap {
    align-items: center;
    gap: 12px;
}

.modal-bare-img {
    display: block;
    max-width: 100%;
    max-height: 85vh;
    border-radius: 8px;
}

.modal-bare-caption {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-on-accent);
    text-shadow: 0 1px 4px var(--photo-shade);
    text-align: center;
}

.img-gallery {
    --gallery-nav: 112px;
    --gallery-gap: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.img-gallery-row {
    display: grid;
    grid-template-columns: var(--gallery-nav) auto var(--gallery-nav);
    gap: var(--gallery-gap);
}

.img-gallery-img {
    display: block;
    max-width: calc(95vw - 2 * (var(--gallery-nav) + var(--gallery-gap)));
    max-height: calc(100vh - 100px);
    border-radius: 8px;
    transition: opacity var(--transition-fast);
}

.img-gallery-img.is-loading {
    opacity: 0.3;
}

.img-gallery-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.img-gallery-nav:hover {
    background: color-mix(in srgb, var(--text-on-accent) 8%, transparent);
}

.img-gallery-nav:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.img-gallery-nav-icon,
.img-gallery-count {
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
    color: var(--text-primary);
}

.img-gallery-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.img-gallery-nav:hover .img-gallery-nav-icon {
    border-color: var(--accent);
    color: var(--accent);
}

.img-gallery-caption {
    display: flex;
    align-items: center;
    gap: 10px;
}

.img-gallery-count {
    padding: 3px 10px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
    text-shadow: none;
}

@keyframes modalAppear {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);   }
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    padding: 24px 24px 12px;
    flex-shrink: 0;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    padding: 24px;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.modal-html-wrap {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-html-wrap > .notice-banner {
    margin-bottom: 0;
}

.modal-title + .modal-body {
    padding-top: 0;
}

.modal-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.modal-footer-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
}

.modal-close {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 10001;
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
}

.modal-box.modal-multi-box {
    background: transparent;
    border: none;
    box-shadow: none;
    max-width: 860px;
    overflow: visible;
}

.modal-multi-panels {
    flex: 1;
    min-height: 0;
    display: flex;
    gap: 14px;
    overflow: visible;
}

.modal-multi-panels--column {
    flex-direction: column;
}

.modal-multi-panels--grid {
    display: grid;
}

.modal-multi-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-card);
    overflow: hidden;
    max-height: calc(100vh - 80px);
    animation: modalAppear var(--transition-base) cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-box--danger,
.modal-multi-panel--danger {
    border-top: 4px solid var(--danger);
    box-shadow: var(--shadow-card), 0 0 16px var(--danger-glow);
}
.modal-box--warning,
.modal-multi-panel--warning {
    border-top: 4px solid var(--warning);
    box-shadow: var(--shadow-card), 0 0 16px var(--warning-border);
}
.modal-box--success,
.modal-multi-panel--success {
    border-top: 4px solid var(--success);
    box-shadow: var(--shadow-card), 0 0 16px var(--success-border);
}
.modal-box--accent,
.modal-multi-panel--accent {
    border-top: 4px solid var(--accent);
    box-shadow: var(--shadow-card), 0 0 16px var(--accent-glow);
}

.modal-multi-panels--grid .modal-multi-panel {
    max-height: 100%;
}

.modal-multi-panel--plain > .modal-multi-panel-body:first-child {
    padding-top: 20px;
}

.modal-multi-panel-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    padding: 20px 24px 0;
    flex-shrink: 0;
}

.modal-multi-panel-body {
    flex: 1;
    min-height: 0;
    padding: 16px 24px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    transform: translateZ(0);
    -webkit-overflow-scrolling: touch;
}

.modal-multi-panel-body > .modal-html-wrap {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-multi-panel-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.modal-multi-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
    margin-top: 14px;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-card);
    animation: modalAppear var(--transition-base) cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-multi-box--footer .modal-multi-panel {
    max-height: calc(100vh - 160px);
}

.modal-edit-footer {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 16px;
}

.modal-edit-status {
    min-width: 0;
    font-size: 13px;
    color: var(--text-muted);
}

.modal-edit-status--dirty {
    font-weight: 600;
    color: var(--warning-text);
}
