.sort-page {
    --ink: #153e42;
    --line: #ccdbd8;
    --accent: #12645b;
    width: min(850px, calc(100% - 28px));
    margin: 0 auto;
    padding-block: clamp(32px, 6vw, 80px);
    color: var(--ink);
    font-family: "Noto Sans JP", system-ui, sans-serif;
}
.sort-page [hidden] { display: none !important; }
.sort-intro { margin-bottom: 1rem; }
.sort-page .panel {
    --panel-padding: clamp(16px, 4vw, 36px);
    background: #fffefa;
    padding: var(--panel-padding);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 12px 38px #123e3d12;
}
.sort-page h2 { margin: 0 0 12px; font-weight: 750; font-size: 1.12rem; }
.sort-page button:where(:not(.common-share-icon)) {
    font: inherit;
    border: 1px solid var(--line);
    background: white;
    color: var(--ink);
    padding: .65em 1em;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
}
.sort-page button:where(:not(.common-share-icon)):disabled { opacity: .5; cursor: default; }
.sort-page button:where(:not(.common-share-icon)):hover:enabled,
.sort-page button[aria-pressed="true"] {
    background: #ecf7f2;
    border-color: var(--accent);
}
.sort-page .primary, .sort-page .primary:hover:enabled { background: var(--accent); color: white; }
.games, .choice-grid { display: grid; gap: 10px; }
.games { gap: 6px; }
#games { grid-template-columns: repeat(6, minmax(0, 1fr)); }
#series { grid-template-columns: repeat(7, minmax(0, 1fr)); }
#series[data-game="acacia"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.games a {
    box-sizing: border-box;
    display: grid;
    place-items: center;
    min-width: 0;
    color: var(--ink);
    text-decoration: none;
    font-size: .72rem;
    line-height: 1.2;
}
#games a,
.series-logo {
    min-height: 48px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}
#games a:hover,
#games a[aria-pressed="true"],
#series a:hover .series-logo,
#series a[aria-pressed="true"] .series-logo {
    border-color: var(--accent);
    background: #ecf7f2;
}
.games a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.games img {
    display: block;
    width: 100%;
    height: 30px;
    object-fit: contain;
}
#series a {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
    min-height: 44px;
    text-align: center;
    font-weight: 700;
}
.series-logo {
    box-sizing: border-box;
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 44px;
}
#series img { height: 24px; }
.sort-page .work-picker > h2,
.sort-page .series-picker > h2 {
    margin-bottom: 6px;
    font-size: .9rem;
}
.series-picker {
    margin-top: 12px;
}
.setup-actions {
    display: flex;
    justify-content: center;
    margin-top: 16px;
}
.setup-actions .primary {
    min-width: 150px;
    min-height: 46px;
}
.sort-page .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sort-page .actions { margin-top: 14px; }
.sort-page .comparison-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
        ". back tie"
        "leave . .";
    column-gap: 8px;
    row-gap: 4px;
}
.comparison-actions #back { grid-area: back; }
.comparison-actions #chooseTie { grid-area: tie; }
.sort-page .comparison-actions .comparison-leave {
    grid-area: leave;
    justify-self: start;
    min-height: 36px;
    padding: 4px 0;
    border: 0;
    background: transparent;
    color: #566d6b;
    font-size: .8rem;
}
.sort-page .comparison-actions .comparison-leave:hover:enabled {
    background: transparent;
    color: var(--ink);
    text-decoration: underline;
}
.play-head {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: grid;
    align-items: center;
    min-height: clamp(68px, 10vw, 86px);
    margin: calc(-1 * var(--panel-padding)) calc(-1 * var(--panel-padding)) 0;
    padding: 10px clamp(14px, 3vw, 24px);
    border-radius: 17px 17px 0 0;
    background: linear-gradient(105deg, #e5f1ed, #f1f6f4 72%, #e7f0ed);
}
.comparison-watermark {
    position: absolute;
    right: .02em;
    bottom: -.22em;
    z-index: -1;
    color: var(--accent);
    opacity: .10;
    font-size: clamp(4.5rem, 12vw, 7.5rem);
    font-weight: 900;
    line-height: 1;
    letter-spacing: -.07em;
    pointer-events: none;
    user-select: none;
}
.play-head-content {
    width: min(52%, 340px);
    min-width: 138px;
}
.play-head-content label {
    display: block;
    margin-bottom: 5px;
    font-size: .75rem;
    font-weight: 700;
}
#progress {
    --meter-fill: linear-gradient(105deg, #12645b, #279b88 70%, #4fbc9c);
    display: block;
    width: 100%;
    height: 16px;
    overflow: hidden;
    border: 0;
    border-radius: 4px;
    background: #cfdfd9;
    accent-color: var(--accent);
    appearance: none;
    mask-image: linear-gradient(to right, #000 calc(100% - 2px), transparent 0);
    mask-size: 10% 100%;
}
#progress::-webkit-progress-bar {
    background: linear-gradient(#c5d8d1, #dbe8e2);
}
#progress::-webkit-progress-value { background: var(--meter-fill); }
#progress::-moz-progress-bar { background: var(--meter-fill); }
#status { font-size: .85rem; }
.choice-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#choices {
    margin: 12px 0 20px;
    user-select: none;
    -webkit-touch-callout: none;
}
#choices button {
    --choice-color: var(--accent);
    --choice-surface: color-mix(in srgb, var(--choice-color) 55%, white);
    display: block;
    grid-column: span 2;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    overflow-wrap: anywhere;
    border-color: color-mix(in srgb, var(--choice-color) 42%, var(--line));
    background: var(--choice-surface);
}
#choices > button:nth-child(3):last-child {
    grid-column: 2 / span 2;
    grid-row: 2;
}
#choices button:hover,
#choices button:focus-visible {
    border-color: var(--choice-color);
    background: var(--choice-surface);
    box-shadow: 0 0 0 1px var(--choice-color);
}
.choice-portrait {
    position: relative;
    display: block;
    container-type: inline-size;
    aspect-ratio: 2 / 1;
    overflow: hidden;
}
.choice-art {
    position: absolute;
    inset: 0;
    z-index: 1;
    isolation: isolate;
    filter: drop-shadow(4px 5px 5px rgb(15 23 42 / .40));
}
.choice-art img {
    position: absolute;
    top: 0;
    right: 0;
    width: auto;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
    object-position: top right;
    pointer-events: none;
    -webkit-user-drag: none;
}
.choice-art > img {
    mask-image: linear-gradient(to right, transparent 3%, #000 15%);
}
.choice-art img.is-positioned {
    right: auto;
    max-width: none;
}
.choice-name {
    position: absolute;
    inset: 0 auto 0 5%;
    width: 80%;
    display: grid;
    grid-template-rows: repeat(2, minmax(0, 1fr));
    align-items: center;
    color: color-mix(in srgb, var(--choice-surface) 74%, white);
    font-family: Arial, sans-serif;
    font-weight: 900;
    line-height: .9;
    text-align: left;
}
#choices .is-pale .choice-name {
    color: color-mix(in srgb, var(--choice-surface) 87%, var(--ink));
}
.choice-name span {
    width: max-content;
    font-size: var(--name-size, 20cqw);
    transform: scaleX(var(--name-scale, 1)) translateX(var(--name-offset, 0px));
    transform-origin: left center;
    white-space: nowrap;
}
.choice-name span:only-child { grid-row: 2; }
#chart { display: block; width: 100%; height: auto; }
.result-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .65rem;
    margin-bottom: .75rem;
}
.result-heading h2 { margin: 0; }
#result:not(.is-empty) .result-heading {
    position: relative;
    isolation: isolate;
    min-height: clamp(68px, 13vw, 112px);
    align-items: flex-end;
}
#result:not(.is-empty) #resultHeading {
    position: absolute;
    z-index: -1;
    inset: auto auto 0 0;
    color: #d4e4e1;
    font-family: system-ui, sans-serif;
    font-size: clamp(3.25rem, 11vw, 7rem);
    font-weight: 950;
    line-height: .85;
    letter-spacing: -.055em;
    pointer-events: none;
}
.result-actions { display: flex; gap: .45rem; margin-left: auto; }
.result-actions button:where(:not(.common-share-icon)) {
    padding: .45em .85em;
    white-space: nowrap;
}
#resultChartNotice + .result-actions { margin-left: 0; }
#resultExport {
    border: 1px solid #aebfbd;
    background: #fff;
}
#resultExport.is-ranking {
    max-width: 610px;
    margin-inline: auto;
}
.result-editor {
    --editor-ink: #0f172a;
    margin-top: 1.25rem;
    border: 1px solid #dbe3ec;
    background: #fffcff;
    box-shadow: 0 6px 18px #0f172a0a;
}
.result-editor-tabs {
    display: flex;
    gap: .2rem;
    padding: .3rem .3rem 0;
    background: var(--editor-ink);
}
.result-editor-tabs button {
    flex: 1;
    min-width: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #d5deed;
    padding: .65rem .25rem;
}
.result-editor-tabs button:is(:hover:enabled, [aria-selected="true"]) {
    background: #fffcff;
    color: #0d3d6b;
}
.result-editor-fields {
    color: var(--editor-ink);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.15rem .75rem;
    padding: clamp(.75rem, 2.5vw, 1.25rem);
}
.result-editor-fields label {
    display: grid;
    gap: .65rem;
    justify-items: start;
    font-weight: 650;
}
.result-editor-label {
    display: inline-block;
    margin: 2px;
    padding: .35rem .75rem;
    border: 2px solid white;
    outline: 2px solid var(--editor-ink);
    background: var(--editor-ink);
    color: white;
    font-weight: 750;
}
.result-font-field {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}
.result-font-options {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    margin-top: .65rem;
}
.result-font-options button {
    padding: .4rem .65rem;
    border-radius: 6px;
}
.result-font-options button[aria-pressed="true"] {
    background: var(--editor-ink);
    border-color: var(--editor-ink);
    color: white;
}
.result-editor-fields :is(input, select) {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    padding: .7rem;
    border: 1px solid #9edfd8;
    border-radius: 8px;
    color: inherit;
    background: transparent;
    font: inherit;
}
.result-editor-wide { grid-column: 1 / -1; }
#resultEditStatus { margin: 0; font-size: .875rem; }
#resultEditStatus:empty { display: none; }
#resetResultCharacter { justify-self: start; }
.sort-test-settings {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: .75rem;
    margin: 1rem 0 0;
    padding: .75rem 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
}
.sort-test-settings label { display: grid; gap: .25rem; }
.sort-test-settings input { width: 6rem; }
.sort-test-settings :is(input, select) { font: inherit; }
#testResultSettings { margin: 0 0 1rem; }
.test-result-actions { display: flex; flex-wrap: wrap; gap: .45rem; }
#resultChartNotice { margin: 0 0 1rem; }
#saveStatus:empty { display: none; }
#result.is-empty #resultHeading {
    display: grid;
    min-height: 144px;
    place-items: center;
    text-align: center;
}
#result.is-empty .result-heading { display: block; }
#result.is-empty .result-actions { justify-content: center; }
@media (max-width: 600px) {
    #result:not(.is-empty) .result-heading {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        min-height: 0;
    }

    #result:not(.is-empty) #resultHeading {
        position: static;
        padding-top: 0.25rem;
    }

    #result:not(.is-empty) .result-heading .result-actions {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(0, 1fr);
        margin: 0;
    }

    .sort-page .result-actions button:where(:not(.common-share-icon)) {
        min-width: 0;
        min-height: 44px;
        padding: 0.4rem 0.25rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 720px) {
    #games { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    #series { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 500px) {
    .result-editor-fields { grid-template-columns: minmax(0, 1fr); }
    html:has(.sort-page) { overflow-x: hidden; }
    .choice-grid { gap: 8px; }
    #choices button { font-size: .82rem; }
    .sort-page .comparison-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas:
            "back tie"
            "leave .";
    }
    .comparison-actions :is(#back, #chooseTie) {
        justify-self: stretch;
        min-width: 0;
        min-height: 44px;
        padding: 5px 6px;
        font-size: .8rem;
        line-height: 1.2;
        white-space: nowrap;
    }
}
