:root {
    color-scheme: dark;
    --bg: #04080d;
    --panel: rgba(8, 20, 30, 0.94);
    --panel-soft: rgba(11, 28, 41, 0.76);
    --line: rgba(111, 203, 232, 0.2);
    --line-strong: rgba(111, 203, 232, 0.46);
    --text: #eaf8ff;
    --muted: #7f9eaa;
    --accent: #65dcff;
    --accent-strong: #a7efff;
    --danger: #ff7786;
    --gold: #ffd66b;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.44);
    --radius: 14px;
    font-family: "Segoe UI", "Noto Sans JP", system-ui, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 15% -10%, rgba(34, 151, 196, 0.22), transparent 34rem),
        radial-gradient(circle at 100% 30%, rgba(116, 49, 155, 0.13), transparent 28rem),
        linear-gradient(160deg, #07111a 0%, #03070b 70%);
}

body::before {
    position: fixed;
    inset: 0;
    z-index: -1;
    content: "";
    pointer-events: none;
    opacity: 0.18;
    background-image:
        linear-gradient(rgba(119, 212, 241, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(119, 212, 241, 0.08) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: linear-gradient(to bottom, black, transparent 78%);
}

button {
    font: inherit;
}

.page-shell {
    width: min(1080px, calc(100% - 32px));
    margin: 0 auto;
    padding: 42px 0 28px;
}

.site-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 26px;
}

.eyebrow,
.board-kicker,
.control-label,
.site-footer,
.connection-badge {
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 0.7rem;
}

h1 {
    margin: 0;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: clamp(2.25rem, 7vw, 4.7rem);
    font-weight: 800;
    letter-spacing: 0.02em;
    line-height: 0.9;
    text-shadow: 0 0 28px rgba(101, 220, 255, 0.22);
}

.header-subtitle {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: clamp(0.78rem, 2vw, 1rem);
    font-weight: 700;
    letter-spacing: 0.31em;
}

.connection-badge {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: rgba(3, 11, 17, 0.66);
    font-family: Consolas, monospace;
    font-size: 0.66rem;
    white-space: nowrap;
}

.connection-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #65e7a5;
    box-shadow: 0 0 10px rgba(101, 231, 165, 0.7);
}

.control-panel,
.ranking-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
}

.control-panel {
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 22px;
    margin-bottom: 16px;
    padding: 18px;
}

.control-label {
    margin: 0 0 8px 3px;
    color: var(--muted);
    font-family: Consolas, monospace;
    font-size: 0.65rem;
}

.segmented-control {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.26);
}

.segment-button,
.refresh-button,
.page-arrow,
.page-number {
    border: 1px solid transparent;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
    transition:
        color 170ms ease,
        border-color 170ms ease,
        background-color 170ms ease,
        transform 170ms ease,
        box-shadow 170ms ease;
}

.segment-button {
    min-height: 44px;
    padding: 8px 13px;
    border-radius: 7px;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.segment-button:hover,
.segment-button:focus-visible,
.refresh-button:hover,
.refresh-button:focus-visible,
.page-arrow:hover:not(:disabled),
.page-arrow:focus-visible,
.page-number:hover,
.page-number:focus-visible {
    color: var(--accent-strong);
    border-color: var(--line-strong);
    outline: none;
}

.segment-button.is-active {
    border-color: rgba(101, 220, 255, 0.48);
    color: #041018;
    background: linear-gradient(135deg, #9beaff, #58cbed);
    box-shadow: 0 0 22px rgba(101, 220, 255, 0.16);
}

.player-button {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
}

.player-button small {
    font-size: 0.59rem;
    opacity: 0.72;
}

.ranking-panel {
    overflow: hidden;
}

.ranking-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 22px 24px 19px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(90deg, rgba(57, 152, 186, 0.1), transparent 58%);
}

.board-kicker {
    margin: 0 0 5px;
    color: var(--accent);
    font-family: Consolas, monospace;
    font-size: 0.64rem;
}

h2 {
    margin: 0;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: clamp(1rem, 3vw, 1.42rem);
    letter-spacing: 0.035em;
}

h2 span {
    color: var(--gold);
}

.refresh-button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-family: Consolas, monospace;
    font-size: 0.67rem;
    letter-spacing: 0.08em;
}

.refresh-button.is-loading .refresh-icon {
    animation: rotate 750ms linear infinite;
}

.ranking-stage {
    position: relative;
    min-height: 506px;
}

.ranking-stage.is-exiting-left {
    animation: exit-left 130ms ease forwards;
}

.ranking-stage.is-exiting-right {
    animation: exit-right 130ms ease forwards;
}

.ranking-stage.is-entering-left {
    animation: enter-left 210ms cubic-bezier(0.22, 0.8, 0.25, 1) both;
}

.ranking-stage.is-entering-right {
    animation: enter-right 210ms cubic-bezier(0.22, 0.8, 0.25, 1) both;
}

.status-message {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 2;
    place-items: center;
    padding: 24px;
    color: var(--muted);
    background: rgba(5, 14, 21, 0.83);
    font-family: Consolas, monospace;
    font-size: 0.78rem;
    letter-spacing: 0.1em;
    text-align: center;
}

.status-message.is-visible {
    display: grid;
}

.status-message.is-error {
    color: var(--danger);
}

.table-wrap {
    width: 100%;
    overflow: hidden;
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-family: Consolas, "SFMono-Regular", monospace;
}

.ranking-table th {
    height: 42px;
    padding: 0 16px;
    color: var(--muted);
    background: rgba(0, 0, 0, 0.18);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.13em;
    text-align: left;
}

.ranking-table th:first-child,
.ranking-table td:first-child {
    width: 14%;
    padding-left: 24px;
}

.ranking-table th:nth-child(2),
.ranking-table td:nth-child(2) {
    width: 27%;
    text-align: right;
}

.ranking-table th:nth-child(3),
.ranking-table td:nth-child(3) {
    width: 15%;
    text-align: center;
}

.ranking-table th:nth-child(4),
.ranking-table td:nth-child(4) {
    width: 18%;
    text-align: center;
}

.ranking-table th:nth-child(5),
.ranking-table td:nth-child(5) {
    width: 26%;
    padding-right: 24px;
    text-align: right;
}

.ranking-table td {
    height: 46px;
    padding: 0 16px;
    border-top: 1px solid rgba(111, 203, 232, 0.08);
    color: #d9edf4;
    font-size: clamp(0.73rem, 1.8vw, 0.88rem);
    letter-spacing: 0.045em;
    white-space: nowrap;
}

.ranking-table tr:first-child td {
    border-top: 1px solid rgba(111, 203, 232, 0.14);
}

.ranking-table tr:hover td {
    background: rgba(101, 220, 255, 0.04);
}

.ranking-table .rank-cell {
    color: var(--accent);
    font-weight: 700;
}

.ranking-table tr.is-top-rank .rank-cell {
    color: var(--gold);
}

.ranking-table .score-cell {
    color: var(--text);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.ranking-table .name-cell {
    color: var(--accent-strong);
    font-weight: 700;
    letter-spacing: 0.13em;
}

.ranking-table .date-cell {
    color: var(--muted);
}

.ranking-table tr.is-empty td {
    color: rgba(127, 158, 170, 0.32);
}

.ranking-table tr.is-skeleton td::after {
    display: block;
    width: 72%;
    height: 9px;
    margin-left: auto;
    border-radius: 999px;
    content: "";
    background: linear-gradient(90deg, rgba(112, 172, 193, 0.07), rgba(112, 172, 193, 0.2), rgba(112, 172, 193, 0.07));
    background-size: 220% 100%;
    animation: shimmer 1.15s linear infinite;
}

.ranking-table tr.is-skeleton td:first-child::after,
.ranking-table tr.is-skeleton td:nth-child(3)::after,
.ranking-table tr.is-skeleton td:nth-child(4)::after {
    margin-right: auto;
}

.pagination {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
    min-height: 68px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.16);
}

.page-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 82px;
    min-height: 36px;
    padding: 6px 10px;
    border-radius: 7px;
    font-family: Consolas, monospace;
    font-size: 0.67rem;
    letter-spacing: 0.08em;
}

.page-arrow:disabled {
    cursor: default;
    opacity: 0.25;
}

.page-numbers {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.page-number {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 6px;
    font-family: Consolas, monospace;
    font-size: 0.7rem;
}

.page-number.is-active {
    border-color: var(--line-strong);
    color: #041018;
    background: var(--accent);
}

.page-counter {
    display: none;
    margin: 0;
    color: var(--muted);
    font-family: Consolas, monospace;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-align: center;
}

.site-footer {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 4px 0;
    color: rgba(127, 158, 170, 0.7);
    font-family: Consolas, monospace;
    font-size: 0.57rem;
}

.site-footer p {
    margin: 0;
}

.noscript-message {
    margin: 16px 0;
    padding: 13px;
    border: 1px solid rgba(255, 119, 134, 0.35);
    border-radius: 8px;
    color: var(--danger);
    text-align: center;
}

@keyframes rotate {
    to { transform: rotate(360deg); }
}

@keyframes shimmer {
    to { background-position: -220% 0; }
}

@keyframes exit-left {
    to { opacity: 0; transform: translateX(-16px); }
}

@keyframes exit-right {
    to { opacity: 0; transform: translateX(16px); }
}

@keyframes enter-left {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes enter-right {
    from { opacity: 0; transform: translateX(-16px); }
    to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 760px) {
    .page-shell {
        width: min(100% - 20px, 620px);
        padding-top: 24px;
    }

    .site-header {
        align-items: center;
        margin-bottom: 20px;
    }

    .connection-badge {
        padding: 8px;
        font-size: 0;
    }

    .control-panel {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 13px;
    }

    .ranking-heading {
        padding: 17px 15px;
    }

    .refresh-button {
        min-width: 38px;
        padding: 7px;
        font-size: 0;
    }

    .refresh-icon {
        font-size: 1rem;
    }

    .ranking-stage {
        min-height: 630px;
    }

    .ranking-table,
    .ranking-table tbody,
    .ranking-table tr,
    .ranking-table td {
        display: block;
        width: 100%;
    }

    .ranking-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .ranking-table tbody {
        padding: 8px 0;
    }

    .ranking-table tr {
        display: grid;
        grid-template-columns: 54px minmax(0, 1fr) auto;
        grid-template-areas:
            "rank name score"
            "rank stage date";
        min-height: 60px;
        padding: 9px 12px;
        border-top: 1px solid rgba(111, 203, 232, 0.1);
    }

    .ranking-table td,
    .ranking-table th:first-child,
    .ranking-table td:first-child,
    .ranking-table th:nth-child(2),
    .ranking-table td:nth-child(2),
    .ranking-table th:nth-child(3),
    .ranking-table td:nth-child(3),
    .ranking-table th:nth-child(4),
    .ranking-table td:nth-child(4),
    .ranking-table th:nth-child(5),
    .ranking-table td:nth-child(5) {
        width: auto;
        height: auto;
        padding: 0;
        border: 0;
        text-align: left;
    }

    .ranking-table .rank-cell {
        grid-area: rank;
        align-self: center;
        font-size: 0.85rem;
    }

    .ranking-table .score-cell {
        grid-area: score;
        align-self: center;
        text-align: right;
    }

    .ranking-table .name-cell {
        grid-area: name;
        align-self: end;
    }

    .ranking-table .stage-cell {
        grid-area: stage;
        align-self: start;
        margin-top: 5px;
        color: var(--muted);
        font-size: 0.66rem;
    }

    .ranking-table .date-cell {
        grid-area: date;
        align-self: start;
        margin-top: 5px;
        font-size: 0.62rem;
        text-align: right;
    }

    .ranking-table tr.is-skeleton td {
        min-height: 10px;
    }

    .pagination {
        grid-template-columns: auto 1fr auto;
        gap: 8px;
        padding: 11px 12px;
    }

    .page-numbers {
        display: none;
    }

    .page-counter {
        display: block;
    }

    .page-arrow {
        min-width: 56px;
    }

    .arrow-label {
        display: none;
    }

    .site-footer {
        display: block;
        line-height: 1.8;
        text-align: center;
    }
}

@media (max-width: 390px) {
    .segment-button {
        padding-inline: 6px;
        font-size: 0.68rem;
    }

    .player-button {
        gap: 4px;
    }

    .ranking-table tr {
        grid-template-columns: 49px minmax(0, 1fr) auto;
        padding-inline: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
    }
}
