/* Modal interaction */
.modal-open {
    overflow: hidden;
}

/* Modal buttons */
.modal-btn {
    padding: .4rem .6rem;
    border-radius: .8rem;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: linear-gradient(135deg, #3b3b3b, #8a8a8a);
    color: #f7f7f7;
    cursor: pointer;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.2;
    transition:
        transform 0.12s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease,
        background 0.2s ease;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    user-select: none;
    -webkit-user-select: none;
}

.modal-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow:
        0 14px 38px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.2);
    background: linear-gradient(135deg, #4a4a4a, #9b9b9b);
}

.modal-btn:active {
    transform: translateY(0);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
}

.modal-btn-primary {
    background: linear-gradient(135deg, #5a5a5a, #b0b0b0);
    border-color: rgba(255, 255, 255, 0.6);
    color: #fff;
}

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    touch-action: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    /* 初期は無効 */
}

.modal-backdrop.show {
    display: flex;
    /* JS側で設定する場合もあるがCSSでも担保 */
}

.modal-backdrop.in {
    opacity: 1;
    pointer-events: auto;
}

/* Modal box */
.modal-box {
    pointer-events: auto;
    background: #1a1a1a;
    border: 1px solid #2b2b2b;
    border-radius: 0.7rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    font-size: 16px;
    width: min(96vw, 1200px);
    height: 92vh;
}

@supports (height: 1dvh) {
    .modal-box {
        height: 92dvh;
    }
}

@media (min-height: 1200px) {
    .modal-box {
        height: min(92dvh, 900px);
    }
}

/* Modal header/footer */
.modal-header,
.modal-footer {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid #2b2b2b;
}

.modal-footer {
    border-top: 1px solid #2b2b2b;
    border-bottom: 0;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.modal-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    touch-action: pan-y;
}

/* Tabs */
.modal-tabs {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    border-bottom: 1px solid #2b2b2b;
    padding-bottom: 0.3rem;
    min-height: 38px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: #1a1a1a;
    z-index: 1;
    left: 0;
    isolation: isolate;
    touch-action: pan-x;
}

.modal-tabs::after,
.modal-tabs::before {
    content: "";
    position: absolute;
    top: 0;
    height: 100%;
    width: 48px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.modal-tabs::after {
    right: 0;
    background: linear-gradient(90deg, transparent, rgba(26, 26, 26, 0.95));
}

.modal-tabs::before {
    left: 0;
    background: linear-gradient(270deg, transparent, rgba(26, 26, 26, 0.95));
}

.modal-tabs.overflow-right::after {
    opacity: 1;
}

.modal-tabs.overflow-left::before {
    opacity: 1;
}

.modal-tab {
    display: inline-flex;
    align-items: center;
    height: 34px;
    background: transparent;
    color: #eee;
    border: 1px solid #2b2b2b;
    border-bottom: none;
    border-radius: 0.6rem 0.6rem 0 0;
    padding: 0 0.7rem;
    cursor: pointer;
    white-space: nowrap;
    font-size: 15px;
    user-select: none;
    -webkit-user-select: none;
}

.modal-tab.active {
    background: #222;
    border-color: #3b82f6;
}

/* Cards */
.modal-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 0.8rem;
    padding-top: 0.2rem;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: clamp(280px, 100%, 640px);
    padding-right: 0.2rem;
    min-height: 0;
    touch-action: pan-y;
}

.modal-card {
    background: #202020;
    border: 1px solid #2b2b2b;
    border-radius: 0.6rem;
    padding: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    inline-size: fit-content;
    min-inline-size: 16ch;
    max-inline-size: 36ch;
    width: auto;
    max-width: 100%;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
    user-select: none;
    -webkit-user-select: none;
}

.modal-card.active {
    border-color: #3b82f6;
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.35);
    transform: translateY(-2px);
}

.modal-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.modal-card-name {
    font-weight: 600;
    word-break: break-word;
}

.modal-card-chips {
    display: flex;
    gap: 0.2rem;
    flex-wrap: wrap;
}

.modal-card-chip {
    font-size: 0.6rem;
    background: #475569;
    color: #f8fafc;
    border: 1px solid #94a3b8;
    border-radius: 0.5rem;
    padding: 0.2rem 0.5rem;
}

.modal-card-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.modal-card-actions .modal-btn {
    padding: 0.25rem 0.5rem;
    font-size: 13px;
    border-radius: 0.6rem;
}

/* 背面クリック無効化 */
.disable-pointer {
    pointer-events: none !important;
}