:root {
    --color-green-tag: #3fb950;
    --color-midnight-ink: #181825;
    --color-graphite: #484758;
    --color-deep-slate: #242433;
    --color-carbon: #000000;
    --color-stone: #636363;
    --color-pebble: #949494;
    --color-ash: #8b8b8b;
    --color-fog: #f7f7f7;
    --color-snow: #ffffff;
    --shadow-subtle: rgba(24, 24, 37, 0.12) 0 2px 3px -2px;
    --shadow-button: rgba(0, 0, 0, 0.04) 0 1px 2px, rgba(0, 0, 0, 0.02) 0 2px 4px, rgba(0, 0, 0, 0.02) 0 4px 8px;
    --font-heading: "DM Sans", "Inter", sans-serif;
    --font-body: "Inter", sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    background: var(--color-fog);
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: var(--font-body);
    color: var(--color-midnight-ink);
    background: var(--color-fog);
    letter-spacing: -0.01em;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-height: 30px;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1,
h2 {
    font-family: var(--font-heading);
    font-weight: 300;
    letter-spacing: 0;
    color: var(--color-carbon);
}

h1 {
    max-width: 780px;
    margin-bottom: 16px;
    font-size: 70px;
    line-height: 1.08;
}

h2 {
    margin-bottom: 18px;
    font-size: 32px;
    line-height: 1.2;
}

h2 a {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

h3 {
    margin-bottom: 16px;
    color: var(--color-carbon);
    font-size: 18px;
    font-weight: 500;
    letter-spacing: -0.02em;
}

button {
    min-height: 44px;
    border: 0;
    border-radius: 28px;
    padding: 12px 24px;
    color: var(--color-carbon);
    background: var(--color-green-tag);
    box-shadow: var(--shadow-button);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.02em;
    transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

button:hover {
    transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--color-midnight-ink);
    outline-offset: 3px;
}

.container {
    width: min(1200px, calc(100% - 40px));
    margin: 0 auto;
    padding: 32px 0 80px;
}

.hero {
    display: grid;
    justify-items: center;
    padding: 96px 20px 56px;
    text-align: center;
}

.hero p,
.username-input-form p {
    max-width: 620px;
    margin-bottom: 0;
    color: var(--color-stone);
    font-size: 18px;
    line-height: 1.5;
}

.section-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    margin-bottom: 18px;
    border-radius: 100px;
    padding: 7px 13px;
    color: var(--color-graphite);
    background: var(--color-snow);
    box-shadow: var(--shadow-subtle);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: -0.02em;
}

.panel,
.username-tags-container,
.stats,
.empty-state-content,
.username-input-form,
.modal-content {
    border-radius: 24px;
    background: var(--color-snow);
    box-shadow: var(--shadow-subtle);
}

.panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
    padding: 20px 24px;
}

.date-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.date-controls button,
button.leaderboard,
.cancel-btn {
    color: var(--color-graphite);
    background: var(--color-fog);
    box-shadow: none;
}

.date-controls button.active,
button.leaderboard.active,
.username-submit-btn,
.add-btn {
    color: var(--color-carbon);
    background: var(--color-green-tag);
    box-shadow: var(--shadow-button);
}

.username-tags-container {
    margin-bottom: 24px;
    padding: 20px 24px;
}

.username-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.username-tag,
.player-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 100px;
    padding: 7px 12px;
    color: var(--color-graphite);
    background: var(--color-fog);
    font-size: 13px;
    font-weight: 500;
}

.tag-close {
    cursor: pointer;
    color: var(--color-ash);
    font-size: 17px;
    line-height: 1;
}

.tag-close:hover {
    color: var(--color-carbon);
}

.add-user-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    height: 34px;
    min-height: 34px;
    padding: 0 14px;
}

.plus-icon {
    line-height: 1;
}

.stats {
    position: relative;
    padding: 24px;
    overflow: hidden;
}

.stats::before {
    content: "";
    position: absolute;
    top: 0;
    left: 24px;
    right: 24px;
    height: 3px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(45, 164, 78, 0.95), rgba(126, 231, 135, 0.78));
}

.stats + .stats {
    margin-top: 24px;
}

table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    color: var(--color-midnight-ink);
    font-size: 14px;
}

.stats h2 + table,
.leaderboard-section h3 + table {
    margin-top: 12px;
}

th,
td {
    padding: 13px 12px;
    border-bottom: 1px solid rgba(24, 24, 37, 0.08);
    text-align: center;
    vertical-align: middle;
}

th {
    color: var(--color-stone);
    background: transparent;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: -0.02em;
    text-transform: uppercase;
}

tbody tr {
    transition: background-color 160ms ease;
}

tbody tr:hover {
    background: var(--color-fog);
}

tbody tr:last-child td {
    border-bottom: 0;
}

.totals td {
    background: var(--color-fog);
    font-weight: 500;
}

td.percentage {
    color: var(--color-pebble);
    font-size: 12px;
    font-style: italic;
    text-align: left;
    padding-left: 2px;
}

td.score {
    text-align: right;
    padding-right: 2px;
}

td.time {
    white-space: nowrap;
}

.rating-before {
    color: var(--color-pebble);
    font-size: 11px;
}

.rating-climb {
    color: #3fb950;
    font-weight: 500;
}

.rating-fall {
    color: #e5534b;
}

.green,
.blue {
    color: var(--color-midnight-ink);
    font-weight: 500;
}

.red,
.yellow {
    color: var(--color-stone);
}

.player-noname {
    opacity: 0.5;
}

@font-face {
    font-family: "Chess V3";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url(chessglyph-v3.woff2) format("woff2");
}

span.chess-icon {
    font-family: "Chess V3";
    font-size: 24px;
}

span.chess-icon-won::before {
    color: #3fb950;
}

span.chess-icon-lost::before {
    color: #e5534b;
}

span.chess-icon-draw::before {
    color: var(--color-midnight-ink);
}

span.chess-icon-checkmated::before { content: "\1F92"; }
span.chess-icon-timeout::before { content: "\1F8A"; }
span.chess-icon-resigned::before { content: "\1F78"; }
span.chess-icon-abandoned::before { content: "\00D7"; }
span.chess-icon-agreed::before { content: "\1F88"; }
span.chess-icon-stalemate::before { content: "\222B"; }
span.chess-icon-insufficient::before { content: "\1F76"; }
span.chess-icon-50move::before { content: "\1F90"; }
span.chess-icon-timevsinsufficient::before { content: "\1F8A"; }
span.chess-icon-repetition::before { content: "\004C"; }
span.chess-icon-unknown::before { content: "\1F0D"; }

.leaderboard-section {
    margin-bottom: 32px;
}

.leaderboard-section + .leaderboard-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid rgba(24, 24, 37, 0.08);
}

.empty-state {
    margin-top: 24px;
}

.empty-state-content {
    padding: 32px;
}

.empty-state-content h3 {
    margin-bottom: 8px;
    font-size: 24px;
}

.empty-state-content p {
    color: var(--color-stone);
    line-height: 1.5;
}

.empty-state-tip {
    margin-bottom: 0;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(24, 24, 37, 0.42);
}

.modal-content {
    display: flex;
    flex-direction: column;
    width: min(860px, 100%);
    max-height: 86vh;
    overflow: hidden;
}

.modal-content tr {
    cursor: pointer;
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 24px 24px 16px;
    background: var(--color-snow);
}

.modal-header h2 {
    margin: 0;
}

.modal-body {
    flex-grow: 1;
    overflow: auto;
    padding: 0 24px 24px;
}

.close {
    float: right;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--color-stone);
    background: var(--color-fog);
    cursor: pointer;
    font-size: 26px;
    line-height: 33px;
    text-align: center;
}

.close:hover {
    color: var(--color-carbon);
}

.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    float: right;
    margin: 8px 0 0 14px;
    color: var(--color-stone);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 400;
}

.checkbox input {
    accent-color: var(--color-midnight-ink);
}

canvas#ratingChart {
    width: 100%;
    max-height: 300px;
    margin: 18px 0 20px;
}

.modal__move-count {
    padding: 0;
    color: var(--color-pebble);
    font-size: 12px;
}

.modal__player-black {
    text-align: left;
    padding: 0 5px;
}

.modal__player-white {
    text-align: right;
    padding: 0 5px;
}

.username-input-container {
    min-height: 100vh;
    padding: 1px 20px 80px;
}

.username-input-form {
    display: grid;
    justify-items: center;
    width: min(760px, 100%);
    margin: 96px auto 0;
    padding: 64px 48px;
    text-align: center;
}

.username-input-form form {
    display: flex;
    width: min(560px, 100%);
    margin-top: 32px;
    gap: 12px;
}

.username-input,
.add-user-input {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-bottom: 1px solid rgba(24, 24, 37, 0.24);
    border-radius: 0;
    padding: 12px 0;
    color: var(--color-carbon);
    background: transparent;
    font-family: var(--font-body);
    font-size: 16px;
    letter-spacing: -0.01em;
}

.username-input::placeholder,
.add-user-input::placeholder {
    color: var(--color-pebble);
}

.username-submit-btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

.add-user-modal {
    width: min(420px, 100%);
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

@media screen and (max-width: 900px) {
    h1 {
        font-size: 54px;
    }

    .panel {
        align-items: stretch;
        flex-direction: column;
    }

    .date-controls {
        justify-content: flex-start;
    }

    .leaderboard-section {
        overflow-x: auto;
    }

    .leaderboard-section table {
        min-width: 780px;
    }
}

@media screen and (max-width: 700px) {
    .desktop {
        display: none;
    }

    .container {
        width: min(100% - 24px, 1200px);
    }

    .hero {
        padding: 64px 8px 36px;
    }

    h1 {
        font-size: 42px;
        line-height: 1.12;
    }

    h2 {
        font-size: 28px;
    }

    .hero p,
    .username-input-form p {
        font-size: 16px;
    }

    .date-controls button {
        flex: 1 1 calc(50% - 8px);
        padding-inline: 14px;
    }

    .username-input-form {
        margin-top: 56px;
        padding: 40px 24px;
    }

    .username-input-form form {
        flex-direction: column;
    }

    .username-submit-btn {
        width: 100%;
    }

    .modal {
        padding: 12px;
    }

    .modal-header,
    .modal-body,
    .stats,
    .panel,
    .username-tags-container {
        padding-left: 16px;
        padding-right: 16px;
    }

    .stats::before {
        left: 16px;
        right: 16px;
    }

    .stats {
        overflow-x: hidden;
    }

    .stats table {
        min-width: 0;
        table-layout: fixed;
        font-size: 11px;
    }

    .stats col {
        width: auto !important;
    }

    .stats th,
    .stats td {
        padding: 8px 1px;
    }

    .stats th {
        font-size: 10px;
    }

    .stats td.percentage {
        font-size: 10px;
        padding-left: 2px;
    }

    .stats td.score {
        padding-right: 2px;
    }

    .stats img {
        max-height: 24px;
    }

    .stats h2 + table th:last-child,
    .stats h2 + table td:last-child {
        display: none;
    }

    .stats h2 + table col:last-child {
        visibility: collapse;
        width: 0 !important;
    }
}
