:root {
    --medal-bronze:   #BF9000;
    --medal-silver:   #CCC;
    --medal-gold:     #FFE599;
    --medal-author:   #6AA84F;
    --medal-warrior:  #4A86E8;
    --medal-champion: #E06666;
    --border:         #E0E0E0;
    --page-max:       1850px;
    --radius:         6px;
    --trend-up:       #16A34A;
    --trend-down:     #DC2626;
}

@font-face {
    font-family: "Open Sans";
    src: url("fonts/open-sans-400.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Open Sans";
    src: url("fonts/open-sans-400-italic.woff2") format("woff2");
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: "Open Sans";
    src: url("fonts/open-sans-700.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: #FAF9F7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body, input, button {
    font-family: "Open Sans", system-ui, sans-serif;
    font-size: 14px;
    line-height: 24px;
}

a {
    color: blue;
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

h1, h2, p, ul, table {
    margin: 16px 0;
}
ul {
    margin-left: 24px;
}

h1 {
    font-size: 24px;
}

h2 {
    font-size: 20px;
    margin-top: 32px;
}

h3 {
    font-size: 16px;
}

h1, h2, h3 {
    text-align: center;
}

table {
    border-collapse: collapse;
}
tr:hover {
    background: #EEE;
}
th, td {
    padding: 4px 16px;
}
th {
    background: #EEE;
}
td {
    border-top: 1px solid #CCC;
}
td.value {
    text-align: center;
}

.autocomplete-wrap input,
.edit-twitch input[type=text] {
    padding: 5px 10px;
    border: 1px solid #CCC;
    border-radius: var(--radius);
}

button {
    padding: 5px 10px;
    background: #4A5EC0;
    color: #FFF;
    border: 1px solid #4A5EC0;
    border-radius: var(--radius);
    cursor: pointer;
}

button:hover {
    background: #3A4DA6;
}

.description {
    text-align: center;
}

header {
    background: #FEFEFE;
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 14px 28px;
    display: flex;
    align-items: center;
    gap: 28px;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    font-weight: bold;
}
.site-logo:hover {
    text-decoration: none;
}

.logo-bars {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    height: 34px;
}

.logo-bar {
    width: 9px;
    border-radius: 1px 1px 0 0;
}
.logo-bar-bronze { height: 20px; background: var(--medal-bronze); }
.logo-bar-gold   { height: 34px; background: var(--medal-gold);   }
.logo-bar-silver { height: 26px; background: var(--medal-silver); }

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo-eyebrow {
    color: #777;
    text-transform: uppercase;
}

.logo-title {
    font-size: 25px;
    color: #222;
}

header form {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 0 auto;
}

header input[type=search] {
    background: #F5F5F5;
    color: #222;
}

.autocomplete-wrap {
    position: relative;
}

.search-autocomplete-wrap {
    width: 400px;
}

.search-autocomplete-wrap input[type=search] {
    width: 100%;
}

.autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #FFF;
    border: 1px solid #CCC;
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    z-index: 10;
}

.autocomplete-suggestions:empty {
    display: none;
}

.autocomplete-suggestions a {
    display: block;
    padding: 4px 8px;
    color: inherit;
}

.autocomplete-suggestions a:hover,
.autocomplete-suggestions a.active {
    background: #EEE;
    text-decoration: none;
}

.search-see-all {
    font-style: italic;
    color: #999;
}

nav {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 0 28px 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

nav a,
.nav-logout button {
    font-weight: bold;
    padding: 9px 14px;
    border-radius: var(--radius);
}

.nav-logout {
    display: contents;
}

.nav-logout button {
    background: none;
    border: none;
    color: blue;
    font-size: inherit;
    cursor: pointer;
}

nav a.nav-active {
    background: #F0F0F0;
}

nav a:hover,
.nav-logout button:hover {
    background: var(--border);
    text-decoration: none;
}

footer {
    padding: 22px 28px;
    text-align: center;
    background: #FEFEFE;
    border-top: 1px solid var(--border);
}

main {
    flex: 1;
    width: 100%;
    max-width: var(--page-max);
    margin: 32px auto;
    padding: 16px;
    background: #FFF;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.twitch-link img {
    display: block;
    width: 24px;
    height: 24px;
}

/* A fixed box, not the image's own width: country flags are 10:7 and the World and
   continent ones square, and a name column must not shift from row to row. */
.flag {
    height: 16px;
    aspect-ratio: 23 / 16;
    object-fit: contain;
    margin-right: 4px;
    vertical-align: -3px;
}

.player-heading .flag {
    height: 24px;
    margin-right: 0;
}

/* The flag opening each entry is what separates one player from the next, so the gap
   carries the job a separator character used to do. */
.player-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 20px;
    margin: 16px 0;
}

.player-heading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.player-ranks {
    margin-top: 0;
    text-align: center;
    font-style: italic;
}

/* ── Homepage leaderboards ───────────────────────────────────────────────── */

.home-boards {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.home-board {
    flex: 1;
    min-width: 260px;
}

.home-board table {
    width: 100%;
}

.home-board-link {
    text-align: center;
}

/* ── World Records page ──────────────────────────────────────────────────── */

.wr-podium {
    display: flex;
    gap: 14px;
    padding: 26px 32px 22px;
    border-bottom: 1px solid var(--border);
    align-items: flex-end;
}

.wr-podium-col {
    flex: 1;
    text-align: center;
}

.wr-podium-avatar,
.wr-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #FFF;
}

.wr-podium-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    margin: 0 auto 8px;
    font-size: 18px;
    text-shadow: -1px -1px 0 #666, 1px -1px 0 #666, -1px 1px 0 #666, 1px 1px 0 #666;
}

.wr-podium-bar {
    border-radius: 5px 5px 0 0;
    margin-top: 8px;
}

.wr-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 13px 32px;
    border-bottom: 1px solid var(--border);
}

.wr-row:last-child {
    border-bottom: none;
}

.wr-badge {
    width: 44px;
    height: 44px;
    border-radius: 11px;
    font-size: 17px;
    flex-shrink: 0;
}

.wr-row-label {
    flex-shrink: 0;
    width: 150px;
}

.wr-row-label-players {
    color: #6B6B68;
}

.wr-dot {
    color: #BBB;
}

/* ── Medal dot ─────────────────────────────────────────────────────────────── */

.medal-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 4px;
    vertical-align: -1px;
    border-radius: 50%;
}

/* ── Medal grid (player page) ────────────────────────────────────────────── */
.table-center {
    position: relative;
    width: fit-content;
    margin: 16px auto;
}

.medal-grid {
    line-height: 20px;
}

.medal-grid col.year-col   { width: 90px; }
.medal-grid col.season-col { width: 90px; }
.medal-grid col.data-col   { width: 40px; }

.medal-grid tr:hover {
    background: none;
}

.medal-grid th,
.medal-grid td {
    border: 1px solid #BBB;
    padding: 2px 4px;
    text-align: center;
}

.medal-grid thead th {
    position: sticky;
    top: 0;
    border-bottom: 1px solid #000;
}

.map-header.map-white,  td.map-white  { background: #FFF;    }
.map-header.map-green,  td.map-green  { background: #86EFAC; }
.map-header.map-blue,   td.map-blue   { background: #93C5FD; }
.map-header.map-red,    td.map-red    { background: #FCA5A5; }
.map-header.map-black,  td.map-black  { background: #374151; color: #FFF; }

.medal-none,     td.summary.medal-none     { background: #FFF; }
.medal-nr,       td.summary.medal-nr       { background: repeating-linear-gradient(-45deg, #D0D0D0, #D0D0D0 3px, #F0F0F0 3px, #F0F0F0 9px); }
.medal-pending,  td.summary.medal-pending  { background: repeating-linear-gradient(45deg, #D0D0D0, #D0D0D0 3px, #F0F0F0 3px, #F0F0F0 9px); }
.medal-bronze,   td.summary.medal-bronze   { background: var(--medal-bronze); }
.medal-silver,   td.summary.medal-silver   { background: var(--medal-silver); }
.medal-gold,     td.summary.medal-gold     { background: var(--medal-gold); }
.medal-author,   td.summary.medal-author   { background: var(--medal-author); }
.medal-warrior,  td.summary.medal-warrior  { background: var(--medal-warrior); }
.medal-champion, td.summary.medal-champion { background: var(--medal-champion); }

.wr-label { font-size: 11px; color: #FFF; }

.medal-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px 14px;
    margin: 16px 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.medal-swatch {
    display: inline-block;
    width: 38px;
    height: 22px;
    border: 1px solid #BBB;
    flex-shrink: 0;
}

td.summary {
    font-weight: bold;
}

td.count {
    font-weight: normal;
}

td.time {
    font-weight: normal;
}

td.year-cell,
td.col-season {
    font-weight: bold;
}

tfoot tr.averages td.summary {
    font-weight: normal;
}

tfoot tr.totals td {
    font-weight: bold;
}

tfoot tr.averages td {
    font-size: 11px;
}

.medal-grid .block-start {
    border-left: 1px solid #000;
}

.medal-grid .block-end {
    border-right: 1px solid #000;
}

.medal-grid .col-season,
.medal-grid tfoot tr > :first-child {
    border-right: 1px solid #000;
}

tr.year-start td {
    border-top: 1px solid #000;
}

tr.year-end td {
    border-bottom: 1px solid #000;
}

td.year-cell {
    border-bottom: 1px solid #000;
}

.medal-grid tfoot tr:first-child td,
.medal-grid tfoot tr:first-child th {
    border-top: 1px solid #000;
}

/* ── Grid hovercards ───────────────────────────────────────────────────────── */

.hovercard {
    position: absolute;
    display: none;
    z-index: 20;
    max-width: 320px;
    padding: 8px 10px;
    background: #FFF;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px #0003;
    font-size: 13px;
    line-height: 18px;
    text-align: left;
    pointer-events: none;
}

.hovercard-title {
    font-weight: bold;
}

.hovercard-medals {
    margin: 6px 0 0;
}

.hovercard-medals td {
    padding: 0 8px 0 0;
    border-top: none;
}

.hovercard-medals td:last-child {
    padding-right: 0;
    text-align: right;
    white-space: nowrap;
}

.hovercard-medals tr.record {
    font-weight: bold;
}

.hovercard-medals + div {
    margin-top: 6px;
}

/* ── Update records ────────────────────────────────────────────────────────── */

.update-check {
    display: none;
}

.medal-grid.update-mode .col-season,
.medal-grid.update-mode tfoot tr > :first-child {
    border-right: none;
}

.medal-grid.update-mode .update-check {
    display: table-cell;
    text-align: center;
    padding: 0 4px;
    border-right: 1px solid #000;
}

.update-cell-active { background: #FFE0B2; }

.medal-grid.update-mode .update-check label {
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
    text-align: center;
}

.update-controls {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 16px;
    display: flex;
    gap: 8px;
}

.update-submit {
    display: none;
}

/* ── Compare autocomplete (player page) ───────────────────────────────────── */

.compare-autocomplete {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 16px 0;
}

.compare-autocomplete input[type=text] {
    width: 400px;
}

/* ── Latest records / Next medals (player page) ───────────────────────────── */

.player-tables {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    column-gap: 64px;
}

/* ── Compare page ─────────────────────────────────────────────────────────── */

.compare-stats {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px 32px;
    margin: 16px 0;
    text-align: center;
}

.compare-stats .stat-value {
    font-weight: bold;
    display: block;
}

.compare-extra {
    text-align: center;
}

/* ── Compare grid (compare page) ───────────────────────────────────────────── */

.gap-a5 { background: #2E9E55; }
.gap-a4 { background: #63C182; }
.gap-a3 { background: #98D9AA; }
.gap-a2 { background: #C6EBCF; }
.gap-a1 { background: #E9F7EC; }
.gap-draw { background: #FFF; }
.gap-b1 { background: #FDECEC; }
.gap-b2 { background: #F8D2D2; }
.gap-b3 { background: #F0A6A6; }
.gap-b4 { background: #E27777; }
.gap-b5 { background: #C94444; }

.gap-scale {
    display: flex;
}

.gap-scale .medal-swatch + .medal-swatch {
    margin-left: -1px;
}

/* ── Season pages ──────────────────────────────────────────────────────────── */

.season-table tr:hover {
    background: none;
}

.season-nav {
    text-align: center;
}

.season-chart {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 8px;
    margin: 16px auto;
}

.season-chart-col {
    width: 44px;
    text-align: center;
}

.season-chart-bar {
    margin-top: 4px;
    background: var(--medal-gold);
    border-radius: 5px 5px 0 0;
}

/* ── Trend arrows ──────────────────────────────────────────────────────────── */

.trend-up {
    color: var(--trend-up);
}

.trend-down {
    color: var(--trend-down);
}

/* ── Edit Twitch channel ───────────────────────────────────────────────────── */

.edit-twitch {
    margin: 24px auto;
    width: fit-content;
}

.edit-twitch form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.edit-twitch input[type=text] {
    width: 200px;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .header-inner {
        padding: 14px 16px;
        gap: 16px;
    }

    header form {
        width: 400px;
    }

    .search-autocomplete-wrap {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    nav {
        padding: 0 16px 12px;
    }

    main {
        margin: 16px auto;
    }

    footer {
        padding: 22px 16px;
    }

    /* Player page */

    .update-controls {
        position: static;
    }
}

@media (max-width: 640px) {
    .header-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px;
    }

    header form {
        width: 100%;
        margin: 0;
    }

    header input[type=search] {
        font-size: 16px;
    }

    nav {
        padding: 0 12px 10px;
    }

    main {
        margin: 0 0 16px;
        padding: 12px 8px;
        border: none;
        border-radius: 0;
    }

    th, td {
        padding: 4px 8px;
    }

    footer {
        padding: 16px 12px;
    }

    /* World Records page */

    .wr-podium {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 20px 12px 16px;
    }

    .wr-podium-col {
        display: grid;
        grid-template-columns: auto 1fr;
        column-gap: 16px;
        align-items: center;
        text-align: left;
    }

    .wr-podium-avatar {
        grid-row: span 2;
        margin: 0;
    }

    .wr-podium-bar {
        display: none;
    }

    .wr-row {
        flex-wrap: wrap;
        gap: 8px 16px;
        padding: 13px 12px;
    }

    .wr-row-label {
        width: auto;
    }

    .wr-row-players {
        flex-basis: 100%;
        min-width: 0;
        overflow-wrap: anywhere;
    }

    /* Player page */

    .compare-autocomplete-wrap {
        flex: 0 1 400px;
        min-width: 0;
    }

    .compare-autocomplete input[type=text] {
        width: 100%;
        font-size: 16px;
    }
}
