/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Kaisei Opti', serif;
    background: #fff5f7;
    color: #4a3040;
    min-height: 100vh;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(232, 109, 149, .06) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(255, 183, 120, .06) 0%, transparent 50%);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #fff0f3;
}

::-webkit-scrollbar-thumb {
    background: #e86d95;
    border-radius: 30px;
}

::-webkit-scrollbar-thumb:hover {
    background: #d4567e;
}

/* ===== Header ===== */
header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 10px 16px;
    border-bottom: 2px solid rgba(232, 109, 149, .2);
    box-shadow: 0 2px 20px rgba(232, 109, 149, .08);
}

/* ===== Controls ===== */
.controls {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.controls-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.count {
    font-size: .75rem;
    color: #c0849a;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: .03em;
}

/* ===== Mode buttons ===== */
.mode-buttons {
    display: flex;
    gap: 5px;
}

.mode-btn {
    padding: 5px 16px;
    border: 2px solid rgba(232, 109, 149, .25);
    border-radius: 20px;
    background: transparent;
    color: #c0849a;
    font-family: inherit;
    font-size: .72rem;
    cursor: pointer;
    transition: all .25s ease;
    letter-spacing: .04em;
    font-weight: 600;
}

.mode-btn.active {
    background: #e86d95;
    border-color: #e86d95;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 3px 12px rgba(232, 109, 149, .35);
}

.mode-btn:hover:not(.active) {
    background: rgba(232, 109, 149, .08);
    border-color: rgba(232, 109, 149, .4);
    color: #e86d95;
}

/* ===== Filter chips ===== */
.filter-chips,
.collect-chips {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.chip {
    padding: 4px 14px;
    border: 2px solid rgba(232, 109, 149, .18);
    border-radius: 20px;
    background: transparent;
    color: #c0849a;
    font-family: inherit;
    font-size: .72rem;
    cursor: pointer;
    transition: all .25s ease;
    letter-spacing: .03em;
    font-weight: 600;
}

.chip.active {
    background: linear-gradient(135deg, #e86d95, #f2a1b8);
    border-color: transparent;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 2px 10px rgba(232, 109, 149, .3);
}

.chip:hover:not(.active) {
    background: rgba(232, 109, 149, .07);
    border-color: rgba(232, 109, 149, .35);
    color: #e86d95;
}

/* ===== Edit Panel ===== */
.edit-panel {
    max-width: 900px;
    margin: 0 auto;
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding-top: 8px;
}

.edit-panel.visible {
    display: flex;
}

.edit-panel select,
.edit-panel button {
    padding: 5px 14px;
    border: 2px solid rgba(232, 109, 149, .25);
    border-radius: 20px;
    font-family: inherit;
    font-size: .75rem;
    cursor: pointer;
    transition: .25s;
}

.edit-panel select {
    background: #fff;
    color: #6a4a5a;
    border-color: rgba(232, 109, 149, .25);
}

.edit-panel button {
    background: #e86d95;
    color: #fff;
    font-weight: 700;
    border-color: #e86d95;
    box-shadow: 0 2px 8px rgba(232, 109, 149, .25);
}

.edit-panel button:hover {
    background: #d4567e;
    box-shadow: 0 3px 12px rgba(232, 109, 149, .35);
}

.sel-count {
    font-size: .72rem;
    color: #c0849a;
    font-weight: 700;
}

/* ===== Main content ===== */
main {
    padding: 16px;
    padding-top: 76px;
}

/* ===== Grid ===== */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    max-width: 1400px;
    margin: 0 auto;
}

.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: #c0849a;
    font-size: .95rem;
}

/* ===== Card ===== */
.card {
    position: relative;
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    cursor: pointer;
    transition: transform .25s ease, box-shadow .25s ease;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 2px 8px rgba(232, 109, 149, .1);
    border: 2px solid transparent;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(232, 109, 149, .18);
}

.card.selected {
    border-color: #e86d95;
    box-shadow: 0 4px 16px rgba(232, 109, 149, .3);
}

.card .thumb {
    width: 100%;
    aspect-ratio: 7 / 6;
    overflow: hidden;
    background: #fff0f3;
}

.card .thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .3s ease;
}

.card:hover .thumb img {
    transform: scale(1.05);
}

/* ===== Checkbox (管理モード) ===== */
.card-checkbox-wrap {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 5;
    display: none;
}

.edit-mode .card-checkbox-wrap {
    display: block;
}

.card-checkbox-wrap input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #e86d95;
    cursor: pointer;
    border-radius: 50%;
}

/* ===== Collect badge ===== */
.collect-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: linear-gradient(135deg, #e86d95, #f2a1b8);
    color: #fff;
    font-size: .65rem;
    font-weight: 700;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 14px 0 10px;
    box-shadow: 0 2px 6px rgba(232, 109, 149, .3);
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(80, 40, 55, .6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 0;
    max-width: 520px;
    width: 94%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 16px 48px rgba(232, 109, 149, .2);
    border: 2px solid rgba(232, 109, 149, .15);
}

.modal-content img {
    width: 100%;
    display: block;
    border-radius: 0;
}

.modal-details {
    padding: 16px 20px;
}

.modal-details .modal-name {
    font-size: .95rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #4a3040;
    letter-spacing: .02em;
}

.modal-details .modal-meta {
    display: flex;
    gap: 8px;
    font-size: .8rem;
    color: #b07090;
}

.modal-details .modal-meta span {
    background: rgba(232, 109, 149, .08);
    padding: 4px 12px;
    border: 1px solid rgba(232, 109, 149, .15);
    border-radius: 12px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: rgba(255, 255, 255, .85);
    color: #e86d95;
    border: 2px solid rgba(232, 109, 149, .2);
    font-size: 1.2rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 210;
    transition: .25s;
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: #e86d95;
    color: #fff;
    border-color: #e86d95;
    box-shadow: 0 3px 12px rgba(232, 109, 149, .35);
}

/* ===== Edit modal fields ===== */
.modal-edit {
    padding: 0 20px 20px;
    display: none;
}

.modal-edit.visible {
    display: block;
}

.modal-edit label {
    font-size: .75rem;
    font-weight: 700;
    color: #c0849a;
    display: block;
    margin-bottom: 4px;
    letter-spacing: .04em;
}

.modal-edit select {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid rgba(232, 109, 149, .2);
    border-radius: 12px;
    background: #fff;
    color: #6a4a5a;
    font-family: inherit;
    font-size: .85rem;
    margin-bottom: 14px;
    transition: border-color .25s;
}

.modal-edit select:focus {
    outline: none;
    border-color: #e86d95;
}

.modal-edit .save-btn {
    display: block;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #e86d95, #f2a1b8);
    color: #fff;
    font-family: inherit;
    font-size: .85rem;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: .05em;
    transition: .25s;
    box-shadow: 0 4px 16px rgba(232, 109, 149, .3);
}

.modal-edit .save-btn:hover {
    background: linear-gradient(135deg, #d4567e, #e86d95);
    box-shadow: 0 6px 20px rgba(232, 109, 149, .4);
    transform: translateY(-1px);
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 6px;
    }

    main {
        padding: 8px;
        padding-top: 76px;
    }

    .card {
        border-radius: 10px;
    }

    .collect-badge {
        border-radius: 0 10px 0 8px;
    }
}

@media (min-width: 768px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (min-width: 1200px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}