/* Keep the shared member container, navbar clearance, and compact button sizes. */
.rv-character-sorter {
    --sorter-ink: #30323a;
    --sorter-muted: #626571;
    --sorter-line: #e8e8ee;
    --sorter-red: #ce2842;
    --sorter-soft: #fff2f4;
    color: var(--sorter-ink);
}

.rv-character-sorter [hidden] { display: none !important; }
.rv-character-sorter .sorter-panel { scroll-margin-top: calc(var(--rv-member-navbar-height, 88px) + 20px); }
.rv-character-sorter :focus-visible { outline: 3px solid #ad6c0d; outline-offset: 4px; }
.rv-character-sorter :where(h1, h2, h3, p, a, label, button) { overflow-wrap: anywhere; }
.rv-character-sorter :where(h2, h3) { color: var(--sorter-ink); font-weight: 600; }
.rv-character-sorter h2 { margin: 0 0 6px; font-size: 1.2rem; line-height: 1.4; }
.rv-character-sorter h3 { margin: 0 0 10px; font-size: 1.05rem; line-height: 1.45; }
.rv-character-sorter .sorter-intro { padding: 20px 26px; }
.rv-character-sorter .sorter-intro h1 { font-size: clamp(1.45rem, 2.3vw, 1.85rem); }
.rv-character-sorter .sorter-intro p { line-height: 1.65; }
.rv-character-sorter .sorter-panel {
    min-width: 0;
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--sorter-line);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 20px rgb(40 36 49 / 3%);
}
.rv-character-sorter .sorter-section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}
.rv-character-sorter .sorter-section-heading > div { min-width: 0; }
.rv-character-sorter .sorter-section-heading p,
.rv-character-sorter .sorter-battle-heading > p:last-child {
    margin: 0;
    color: var(--sorter-muted);
    font-size: .85rem;
    line-height: 1.65;
}
.rv-character-sorter .sorter-notice,
.rv-character-sorter .sorter-resume {
    padding: 16px 20px;
    margin-bottom: 20px;
    border: 1px solid #e5c7ce;
    border-radius: 10px;
    background: var(--sorter-soft);
    color: #75243a;
    font-size: .85rem;
    line-height: 1.65;
}
.rv-character-sorter .sorter-notice.is-error { background: #fff2ec; border-color: #ebc1b0; color: #8b341a; }
.rv-character-sorter .sorter-notice.is-success { background: #eef8f1; border-color: #bddbc7; color: #28613b; }
.rv-character-sorter .sorter-resume { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.rv-character-sorter .sorter-resume h2 { font-size: 1rem; }
.rv-character-sorter .sorter-resume p { margin: 0; }
.rv-character-sorter .sorter-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.rv-character-sorter .btn-primary { background-image: var(--rv-member-gradient, linear-gradient(110deg, #ce2842, #7f080f)); color: #fff; }
.rv-character-sorter .btn-primary:hover { color: #fff; filter: brightness(.95); }
.rv-character-sorter .btn-outline-primary { color: #ae2038; border-color: #c43a50; }
.rv-character-sorter .btn-outline-primary:hover { background: var(--sorter-soft); color: #8a152a; }
.rv-character-sorter .form-label { margin-bottom: 8px; font-size: .85rem; font-weight: 500; color: var(--sorter-ink); }
.rv-character-sorter .form-control,
.rv-character-sorter .form-select { min-width: 0; font-size: .875rem; }
.rv-character-sorter .form-control:focus,
.rv-character-sorter .form-select:focus { border-color: var(--sorter-red); box-shadow: 0 0 0 .18rem rgb(206 40 66 / 12%); }
.rv-character-sorter .sorter-field { min-width: 0; }
.rv-character-sorter .sorter-story-form { display: flex; align-items: flex-end; gap: 14px; }
.rv-character-sorter .sorter-story-form .sorter-field { flex: 1; }
body.rv-member-page .rv-character-sorter .sorter-story-form .btn { align-self: flex-end; margin-bottom: 3px; flex-shrink: 0; }
.rv-character-sorter .sorter-roster-section { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--sorter-line); }
.rv-character-sorter .sorter-roster-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.rv-character-sorter .sorter-search-field { flex: 1; max-width: 440px; }
.rv-character-sorter .sorter-roster-toolbar .sorter-actions { padding-bottom: 3px; }
.rv-character-sorter .sorter-selection-meta { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 6px 20px; margin: 18px 0 12px; }
.rv-character-sorter .sorter-selection-meta p { margin: 0; color: var(--sorter-muted); font-size: .78rem; line-height: 1.6; }
.rv-character-sorter .sorter-selection-meta .sorter-selection-count { color: #9d1d33; font-weight: 600; font-size: .85rem; }
.rv-character-sorter .sorter-roster {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    max-height: 620px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 5px;
    margin: -5px;
    scrollbar-gutter: stable;
    align-items: start;
}
.rv-character-sorter .sorter-roster > p { grid-column: 1 / -1; padding: 24px 12px; margin: 0; text-align: center; color: var(--sorter-muted); }
.rv-character-sorter .sorter-roster-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    margin: 0;
    padding: 7px;
    border: 1px solid var(--sorter-line);
    border-radius: 9px;
    background: #fff;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.rv-character-sorter .sorter-roster-card:hover { border-color: #d38b99; }
.rv-character-sorter .sorter-roster-card:has(input:checked) { border-color: var(--sorter-red); background: var(--sorter-soft); box-shadow: inset 0 0 0 1px var(--sorter-red); }
.rv-character-sorter .sorter-roster-card:has(input:focus-visible) { outline: 3px solid #ad6c0d; outline-offset: 2px; }
.rv-character-sorter .sorter-roster-card:has(input:disabled) { cursor: not-allowed; opacity: .55; }
.rv-character-sorter .sorter-roster-card input[type="checkbox"] { position: absolute; top: 14px; right: 14px; z-index: 1; width: 18px; height: 18px; margin: 0; accent-color: var(--sorter-red); cursor: inherit; box-shadow: 0 0 0 3px rgb(255 255 255 / 85%); }
.rv-character-sorter .sorter-roster-visual { display: grid; place-items: center; aspect-ratio: 4 / 5; overflow: hidden; border-radius: 5px; background: #f2edf0; }
.rv-character-sorter .sorter-roster-card img { display: block; width: 100%; height: 100%; aspect-ratio: 4 / 5; object-fit: cover; object-position: center 25%; border-radius: 5px; background: #f2edf0; }
.rv-character-sorter .sorter-roster-visual.is-image-missing::after,
.rv-character-sorter .sorter-choice-art.is-image-missing::after { content: "Image Unavailable"; display: grid; place-items: center; width: 100%; height: 100%; padding: 14px; color: #85727a; font-size: .72rem; line-height: 1.6; text-align: center; }
.rv-character-sorter .sorter-roster-name { display: block; padding: 10px 4px 4px; font-size: .82rem; font-weight: 500; line-height: 1.5; color: var(--sorter-ink); overflow-wrap: anywhere; }
.rv-character-sorter .sorter-panel-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--sorter-line); }
.rv-character-sorter .sorter-help { margin: 0; color: var(--sorter-muted); font-size: .78rem; line-height: 1.7; }

/* The active comparison keeps the choice and its controls together. */
.rv-character-sorter:has(#sorter-battle:not([hidden])) .sorter-intro { display: none; }
.rv-character-sorter .sorter-battle { max-width: 940px; margin-inline: auto; padding: 20px 26px; }
.rv-character-sorter .sorter-battle-heading { text-align: center; }
.rv-character-sorter .sorter-story-name { margin: 0 0 6px; color: #a3223a; font-size: .82rem; font-weight: 500; line-height: 1.55; }
.rv-character-sorter .sorter-progress-wrap { max-width: 620px; margin: 14px auto 18px; }
.rv-character-sorter .sorter-progress-wrap label { display: block; margin-bottom: 7px; font-size: .75rem; line-height: 1.5; color: var(--sorter-muted); text-align: center; }
.rv-character-sorter progress { display: block; appearance: none; width: 100%; height: 5px; overflow: hidden; border: 0; border-radius: 10px; background: #f0e5e8; accent-color: var(--sorter-red); }
.rv-character-sorter progress::-webkit-progress-bar { background: #f0e5e8; border-radius: 10px; }
.rv-character-sorter progress::-webkit-progress-value { background: linear-gradient(90deg, #df4058, #951426); border-radius: 10px; }
.rv-character-sorter progress::-moz-progress-bar { background: linear-gradient(90deg, #df4058, #951426); border-radius: 10px; }
.rv-character-sorter .sorter-matchup { display: grid; grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr); align-items: stretch; max-width: 728px; margin-inline: auto; }
.rv-character-sorter .sorter-choice-column { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.rv-character-sorter .sorter-choice {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    flex: 1;
    padding: 0;
    border: 2px solid #e9dce0;
    border-radius: 11px;
    background: #fff;
    color: var(--sorter-ink);
    font: inherit;
    text-align: center;
    cursor: pointer;
    overflow: hidden;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.rv-character-sorter .sorter-choice:not(:disabled):hover { border-color: var(--sorter-red); box-shadow: 0 5px 18px rgb(159 25 51 / 14%); transform: translateY(-2px); }
.rv-character-sorter .sorter-choice:not(:disabled):active { transform: translateY(0); background: var(--sorter-soft); }
.rv-character-sorter .sorter-choice:disabled { cursor: wait; opacity: .65; }
.rv-character-sorter .sorter-choice-art { display: block; width: 100%; height: clamp(180px, calc(100vh - 460px), 400px); height: clamp(180px, calc(100svh - 460px), 400px); background: linear-gradient(145deg, #f3eaed, #f9f5f6); }
.rv-character-sorter .sorter-choice-art img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center; }
.rv-character-sorter .sorter-choice-name { display: flex; align-items: center; justify-content: center; flex: 1; width: 100%; min-height: 58px; padding: 11px 14px; border-top: 1px solid #f0e5e8; font-size: 1rem; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.rv-character-sorter .sorter-matchup-divider { display: flex; align-items: center; justify-content: center; padding-bottom: 58px; color: #9a6e78; font-size: .72rem; }
.rv-character-sorter .sorter-matchup-divider span { padding: 6px; border-radius: 50%; background: #faf1f3; }
.rv-character-sorter .sorter-skip { align-self: center; }
.rv-character-sorter .sorter-battle-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; max-width: 728px; margin: 20px auto 0; }
.rv-character-sorter .sorter-battle-help { max-width: 728px; margin: 14px auto 0; text-align: center; }

.rv-character-sorter .sorter-results-heading { padding-bottom: 20px; border-bottom: 1px solid var(--sorter-line); }
.rv-character-sorter .sorter-results-heading .sorter-story-name { color: #a3223a; margin-bottom: 4px; }
.rv-character-sorter .sorter-results-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); align-items: start; gap: 32px; }
.rv-character-sorter .sorter-ranking-wrap { min-width: 0; }
.rv-character-sorter .sorter-ranking { margin: 0; padding: 0; list-style: none; }
.rv-character-sorter .sorter-rank-row { display: flex; align-items: center; gap: 16px; min-width: 0; padding: 14px 0; border-bottom: 1px solid var(--sorter-line); }
.rv-character-sorter .sorter-rank-row:first-child { padding-top: 0; }
.rv-character-sorter .sorter-rank-row:last-child { border-bottom: 0; }
.rv-character-sorter .sorter-rank-number { order: 0; flex: 0 0 30px; color: #ad2038; text-align: center; font-weight: 600; font-size: 1rem; }
.rv-character-sorter .sorter-rank-image { order: 1; display: block; flex: 0 0 56px; width: 56px; height: 72px; object-fit: cover; object-position: center 25%; border-radius: 6px; background: #f2edf0; }
.rv-character-sorter .sorter-rank-row.is-image-missing::before { content: ""; order: 1; flex: 0 0 56px; width: 56px; height: 72px; border-radius: 6px; background: #f2edf0; }
.rv-character-sorter .sorter-rank-info { order: 2; min-width: 0; flex: 1; }
.rv-character-sorter .sorter-rank-name { display: inline-block; color: var(--sorter-ink); font-size: .92rem; font-weight: 500; line-height: 1.5; overflow-wrap: anywhere; }
.rv-character-sorter a.sorter-rank-name:hover { color: var(--sorter-red); text-decoration: underline; }
.rv-character-sorter .sorter-rank-tie { display: block; margin-top: 5px; color: #85666d; font-size: .72rem; line-height: 1.5; }
.rv-character-sorter .sorter-save-panel { min-width: 0; padding: 22px; border: 1px solid var(--sorter-line); border-radius: 10px; background: #faf9fb; }
.rv-character-sorter .sorter-save-panel .sorter-field { margin: 20px 0; }
.rv-character-sorter .sorter-save-panel > div > .sorter-help { margin-bottom: 18px; }
.rv-character-sorter .sorter-optional { font-size: .75rem; font-weight: 400; color: var(--sorter-muted); }
.rv-character-sorter .sorter-public-field { display: flex; align-items: flex-start; gap: 10px; margin: 22px 0; }
.rv-character-sorter .sorter-public-field input { flex: 0 0 16px; width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--sorter-red); }
.rv-character-sorter .sorter-public-field .form-check-label { font-size: .83rem; color: var(--sorter-ink); }
.rv-character-sorter .sorter-public-field .sorter-help { margin-top: 4px; }
.rv-character-sorter textarea { resize: vertical; min-height: 110px; }

@media (max-width: 991.98px) {
    .rv-character-sorter .sorter-results-layout { grid-template-columns: minmax(0, 1fr); gap: 24px; }
    .rv-character-sorter .sorter-save-panel { padding: 20px; }
    .rv-character-sorter .sorter-roster { grid-template-columns: repeat(auto-fill, minmax(125px, 1fr)); }
}
@media (max-width: 767.98px) {
    .rv-character-sorter .sorter-panel { padding: 18px; }
    .rv-character-sorter .sorter-intro { padding: 20px; }
    .rv-character-sorter .sorter-section-heading,
    .rv-character-sorter .sorter-resume { flex-direction: column; gap: 12px; }
    .rv-character-sorter .sorter-section-heading { margin-bottom: 20px; }
    .rv-character-sorter .sorter-story-form { flex-wrap: wrap; }
    .rv-character-sorter .sorter-story-form .sorter-field { flex-basis: 100%; }
    .rv-character-sorter .sorter-roster-toolbar { align-items: flex-start; flex-direction: column; gap: 12px; }
    .rv-character-sorter .sorter-search-field { width: 100%; max-width: none; }
    .rv-character-sorter .sorter-panel-footer { align-items: flex-start; }
    .rv-character-sorter .sorter-panel-footer > .btn { flex-shrink: 0; }
    .rv-character-sorter .sorter-battle { padding: 18px 16px; }
    .rv-character-sorter .sorter-matchup { grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr); }
    .rv-character-sorter .sorter-choice-name { font-size: .87rem; padding: 10px; }
    .rv-character-sorter .sorter-choice-art { height: clamp(180px, 38vh, 320px); height: clamp(180px, 38svh, 320px); }
    .rv-character-sorter .sorter-battle-heading > p:last-child { font-size: .78rem; }
    .rv-character-sorter .sorter-battle-help { text-align: left; font-size: .72rem; }
}
@media (max-width: 479.98px) {
    .rv-character-sorter .sorter-panel { padding: 16px; }
    .rv-character-sorter .sorter-roster { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-height: 500px; }
    .rv-character-sorter .sorter-selection-meta { gap: 5px; }
    .rv-character-sorter .sorter-panel-footer { align-items: flex-start; flex-direction: column; }
    .rv-character-sorter .sorter-battle { padding: 16px 12px; }
    .rv-character-sorter .sorter-battle h2 { font-size: 1.1rem; }
    .rv-character-sorter .sorter-matchup { column-gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .rv-character-sorter .sorter-matchup-divider { display: none; }
    .rv-character-sorter .sorter-choice-art { height: clamp(165px, 31vh, 250px); height: clamp(165px, 31svh, 250px); }
    .rv-character-sorter .sorter-choice-name { min-height: 64px; padding: 9px 7px; font-size: .8rem; }
    .rv-character-sorter .sorter-choice-column { gap: 10px; }
    .rv-character-sorter .sorter-battle-controls { align-items: center; gap: 12px; margin-top: 18px; }
    .rv-character-sorter .sorter-progress-wrap { margin-block: 12px 16px; }
    .rv-character-sorter .sorter-rank-row { gap: 10px; }
    .rv-character-sorter .sorter-rank-number { flex-basis: 24px; font-size: .9rem; }
    .rv-character-sorter .sorter-rank-image,
    .rv-character-sorter .sorter-rank-row.is-image-missing::before { flex-basis: 48px; width: 48px; height: 64px; }
    .rv-character-sorter .sorter-rank-name { font-size: .84rem; }
    .rv-character-sorter .sorter-save-panel { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    .rv-character-sorter .sorter-choice,
    .rv-character-sorter .sorter-roster-card { transition: none; }
    .rv-character-sorter .sorter-choice:not(:disabled):hover { transform: none; }
}
