:root {
    --bg: #f6f4ef;
    --surface: #ffffff;
    --text: #1f1d1a;
    --muted: #6b665d;
    --border: #e2ddd3;
    --accent: #8a5a1c;
    --accent-text: #ffffff;
    --great: #2e7d4f;
    --good: #5a8a2e;
    --mixed: #b07d12;
    --poor: #c25a1c;
    --bad: #b3261e;
    --bar: #ece7dd;
    --insult: #c25a1c;
    --hate: #b3261e;
    --own: rgba(138, 90, 28, 0.1);
    --p1: #2f6fc0;
    --p2: #c93535;
    --p3: #23862a;
    --p4: #8a7400;
    --p5: #00828c;
    --p6: #a8399e;
    --p7: #6b6b6b;
    --p8: #c06400;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #181714;
        --surface: #22201c;
        --text: #ece8e1;
        --muted: #a39d92;
        --border: #37332c;
        --accent: #d39a4e;
        --accent-text: #1a1814;
        --great: #5cc48a;
        --good: #9ac45c;
        --mixed: #e0b043;
        --poor: #ec8a4f;
        --bad: #f0776c;
        --bar: #33302a;
        --insult: #ec8a4f;
        --hate: #f0776c;
        --own: rgba(211, 154, 78, 0.14);
        --p1: #6ea6eb;
        --p2: #ff6464;
        --p3: #00ff00;
        --p4: #ffff00;
        --p5: #00ffe1;
        --p6: #f16ce8;
        --p7: #acacac;
        --p8: #ffb415;
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
    color: inherit;
}

header.top {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 24px;
    align-items: center;
    justify-content: space-between;
    max-width: 840px;
    margin: 0 auto;
    padding: 20px 16px;
}

.brand {
    font-weight: 700;
    font-size: 18px;
    text-decoration: none;
    color: var(--accent);
}

.search {
    display: flex;
    gap: 8px;
    flex: 1 1 320px;
    max-width: 460px;
}

.search input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.search button {
    padding: 9px 16px;
    font: inherit;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.search input:focus-visible,
.search button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

main {
    max-width: 840px;
    margin: 0 auto;
    padding: 0 16px 48px;
}

h1 {
    font-size: 28px;
    line-height: 1.2;
    margin: 8px 0;
}

h2 {
    font-size: 18px;
    margin: 32px 0 12px;
}

.status {
    color: var(--muted);
}

.status.error {
    color: var(--bad);
}

.meta {
    color: var(--muted);
    font-size: 14px;
    margin: 0;
}

.results {
    list-style: none;
    padding: 0;
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.results li + li {
    border-top: 1px solid var(--border);
}

.player {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 16px;
    justify-content: space-between;
    padding: 12px 16px;
    text-decoration: none;
}

.player:hover {
    background: var(--bar);
}

.player .name {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.player .meta {
    font-size: 14px;
    color: var(--muted);
}

.player.unrecorded .name {
    color: var(--muted);
    font-weight: 400;
}

.reputation > header {
    margin-bottom: 20px;
}

.reputation h1 {
    overflow-wrap: anywhere;
}

.score {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 6px solid var(--tone);
    border-radius: 10px;
}

.score.great { --tone: var(--great); }
.score.good { --tone: var(--good); }
.score.mixed { --tone: var(--mixed); }
.score.poor { --tone: var(--poor); }
.score.bad { --tone: var(--bad); }

.score .number {
    font-size: 48px;
    font-weight: 800;
    line-height: 1;
    color: var(--tone);
    font-variant-numeric: tabular-nums;
}

.score .verdict {
    font-size: 20px;
    font-weight: 700;
}

.score .basis {
    color: var(--muted);
    font-size: 14px;
}

.rates {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.rate {
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.rate-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.rate-title {
    font-weight: 600;
}

.rate-value {
    font-variant-numeric: tabular-nums;
}

.bar {
    position: relative;
    height: 8px;
    margin: 10px 0 8px;
    background: var(--bar);
    border-radius: 4px;
}

.bar .fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
}

.bar.bad .fill {
    background: var(--bad);
}

.bar.good .fill {
    background: var(--great);
}

.bar .average {
    position: absolute;
    top: -3px;
    width: 2px;
    height: 14px;
    margin-left: -1px;
    background: var(--text);
}

.rate-note {
    color: var(--muted);
    font-size: 13px;
}

.flagged-lines ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 10px;
}

.flagged {
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.flagged .match {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    align-items: baseline;
    justify-content: space-between;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 6px;
}

/* the player's lines the classifier read together, marked in the colour of its verdict */
.flagged .group {
    margin: 2px 0;
    padding-left: 10px;
    border-left: 3px solid var(--insult);
}

.flagged .group.hate {
    border-left-color: var(--hate);
}

/* the name, then the message flowing after it like text */
.line {
    overflow-wrap: anywhere;
}

.line .who {
    font-weight: 600;
    margin-right: 0.4em;
}

.line .who::after {
    content: ":";
}

/* when a line of a player's chat history was written, in game time */
.line .time {
    display: inline-block;
    min-width: 3.4em;
    margin-right: 0.4em;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

/* who a line was for, when not everyone: their colours; hollow when only its writer saw it */
.to {
    margin-left: 0.3em;
    white-space: nowrap;
}

.to .dot {
    display: inline-block;
    width: 0.6em;
    height: 0.6em;
    margin-left: 2px;
    vertical-align: 0.05em;
    background: currentColor;
    border: 1px solid rgba(0, 0, 0, 0.55);
    border-radius: 2px;
}

.to .dot.nobody {
    background: transparent;
    border-color: currentColor;
}

/* the moderators' review queue */
.review-items {
    list-style: none;
    padding: 0;
    margin: 16px 0;
    display: grid;
    gap: 18px;
}

.review-items > li > ul {
    list-style: none;
    padding: 0;
    margin: 4px 0;
}

.review-why {
    font-size: 13px;
    color: var(--muted);
}

.review-item.current .flagged {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--own);
}

.review-item.done {
    opacity: 0.5;
}

.review-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.review-actions button {
    padding: 4px 10px;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

/* the classifier against the moderators, on the admin page */
.quality {
    margin-top: 32px;
}

.quality-numbers {
    font-size: 18px;
    font-weight: 600;
}

.quality td {
    font-variant-numeric: tabular-nums;
}

/* a game's page */
.game .winners {
    margin: 4px 0 0;
    font-size: 14px;
    color: var(--muted);
}

/* a game's players: a table per team */
.game-players {
    margin-top: 16px;
}

.game-players table + table {
    margin-top: 12px;
}

.game-players .won {
    margin-left: 0.5em;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--great);
}

.game-players .change.up {
    color: var(--great);
}

.game-players .change.down {
    color: var(--bad);
}

/* the stats page's rankings of good behaviour, side by side where there's room */
.rankings {
    margin-top: 28px;
}

.ranking-tables {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0 24px;
}

.ranking-tables .stats-slice {
    margin-top: 8px;
}

.ranking h3 {
    margin: 0 0 4px;
    font-size: 15px;
}

.ranking td:nth-child(2) {
    text-align: left;
    overflow-wrap: anywhere;
}

/* a player's latest games */
.recent-games .note {
    margin: 2px 0 0;
    font-size: 13px;
}

.recent-games td {
    vertical-align: top;
}

.recent-games .result.won {
    color: var(--great);
}

.recent-games .result.lost {
    color: var(--bad);
}

.recent-games .mark {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    background: var(--bar);
}

.recent-games .mark.bad {
    color: var(--bad);
}

.recent-games .mark.good {
    color: var(--great);
}

/* whom a line is aimed at, muted after it */
.at {
    margin-left: 0.5em;
    font-size: 0.9em;
    opacity: 0.7;
}

/* a game's teams, under a flagged group's header or a game of a player's chat */
.teams {
    margin: -2px 0 6px;
    font-size: 13px;
    color: var(--muted);
}

/* the game's notices about a player among the chat: they resigned, were defeated, disconnected */
.line.notice {
    font-style: italic;
    color: var(--muted);
}

/* the player's own lines, in a game's chat with others */
.line.own {
    margin: 1px -6px;
    padding: 1px 6px;
    background: var(--own);
    border-radius: 4px;
}

/* names in the players' colours: on the light page darker, so they can be read; in dark mode the game's own */
.reputation .name {
    text-decoration: none;
}

.reputation a.name:hover {
    text-decoration: underline;
}

.reputation .p0 { color: inherit; }
.reputation .p1 { color: var(--p1); }
.reputation .p2 { color: var(--p2); }
.reputation .p3 { color: var(--p3); }
.reputation .p4 { color: var(--p4); }
.reputation .p5 { color: var(--p5); }
.reputation .p6 { color: var(--p6); }
.reputation .p7 { color: var(--p7); }
.reputation .p8 { color: var(--p8); }

.line.before,
.line.after {
    color: var(--muted);
}

.line.said {
    margin-top: 2px;
}

.label {
    font-size: 12px;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 999px;
    color: var(--surface);
}

/* after a line's message, a little apart */
.line .label {
    margin-left: 6px;
}

.label.insult { background: var(--insult); }
.label.hate { background: var(--hate); }

.explanation {
    margin-top: 32px;
    color: var(--muted);
    font-size: 14px;
}

.explanation summary {
    cursor: pointer;
    color: var(--text);
    font-weight: 600;
}

.explanation li + li {
    margin-top: 6px;
}

@media (max-width: 480px) {
    .score {
        gap: 14px;
        padding: 16px;
    }

    .score .number {
        font-size: 40px;
    }
}


/* The live chat, as the game shows it: each line in the writer's colour, outlined in black, floating
   over a dark map. The colours are the game's own (widgetui/UIColors.json, ColorTables.*.Text). */
.chat-page {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background: radial-gradient(ellipse at 30% 20%, #2b2f1f 0%, #171a10 55%, #0e100a 100%);
    color: #e8eeff;
    font: 700 17px/1.45 Georgia, "Times New Roman", serif;
    color-scheme: dark;
}

/* at the bottom, the newest line last; what doesn't fit goes off the top, the oldest first, fading out
   under the account corner */
.chat {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    max-height: 100%;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 48px);
    mask-image: linear-gradient(to bottom, transparent 0, #000 48px);
    list-style: none;
    max-width: 900px;
    margin: 0;
    padding: 40px 16px 28px;
    text-shadow: -1px 0 #000, 1px 0 #000, 0 -1px #000, 0 1px #000, 0 0 2px #000;
}

/* while the reader points at the chat: nothing new comes in until they move away */
.chat-paused {
    position: absolute;
    bottom: 6px;
    left: 16px;
    font: 600 13px/1.2 system-ui, sans-serif;
    color: #a8b0a0;
    text-shadow: none;
    pointer-events: none;
}

.chat-line {
    flex-shrink: 0;
    overflow-wrap: anywhere;
    animation: arrive 0.4s ease-out;
}

/* a line's last moments, like the game's chat */
.chat-line.fading {
    opacity: 0;
    transition: opacity 2s ease-in;
}

.chat a {
    color: inherit;
    text-decoration: none;
}

.chat a:hover {
    text-decoration: underline;
}

/* ".chat .pN" outranks ".chat a", so a linked name keeps its colour in the white lines of a game's start and end */
.p0, .chat-line.system, .chat .p0 { color: #e8eeff; }
.p1, .chat .p1 { color: #6ea6eb; }
.p2, .chat .p2 { color: #ff6464; }
.p3, .chat .p3 { color: #00ff00; }
.p4, .chat .p4 { color: #ffff00; }
.p5, .chat .p5 { color: #00ffe1; }
.p6, .chat .p6 { color: #f16ce8; }
.p7, .chat .p7 { color: #acacac; }
.p8, .chat .p8 { color: #ffb415; }

/* what the classifier made of a line */
.chat .tag {
    margin-left: 8px;
    padding: 2px 5px;
    font: 700 11px/1 system-ui, sans-serif;
    vertical-align: 2px;
    color: #ffd9d4;
    background: #7a1712;
    border-radius: 3px;
    text-shadow: none;
}

/* a visitor's verdict, shown on hover (or always, faintly, without one) */
.flag {
    margin-left: 8px;
    padding: 2px 6px;
    font: 600 12px/1 system-ui, sans-serif;
    vertical-align: 2px;
    color: #e8eeff;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(232, 238, 255, 0.35);
    border-radius: 3px;
    text-decoration: none;
    text-shadow: none;
    cursor: pointer;
    opacity: 0;
}

.chat-line:hover .flag,
.chat-line:focus-within .flag,
.line:hover .flag,
.line:focus-within .flag,
.flag.active {
    opacity: 1;
}

.flag.active {
    background: #7a1712;
    border-color: #c0392b;
}

/* on the player page, on a light or dark page instead of the map */
.line .flag {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
}

.line .flag.active {
    color: #fff;
    background: var(--bad);
    border-color: var(--bad);
}

@media (hover: none) {
    .flag {
        opacity: 0.5;
    }
}

.account {
    position: fixed;
    top: 10px;
    right: 16px;
    z-index: 1;
    display: flex;
    gap: 10px;
    align-items: center;
    font: 600 13px/1.4 system-ui, sans-serif;
    text-shadow: 0 0 2px #000;
}

.account form {
    margin: 0;
}

.account a,
.account button {
    padding: 0;
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    text-decoration: underline;
    cursor: pointer;
}

.account .error {
    color: #ff6464;
}

/* in the header of the other pages, on their light or dark background */
.top .account {
    position: static;
    font-size: 14px;
    text-shadow: none;
    color: var(--muted);
}

.top .account .error {
    color: var(--bad);
}

/* a player's rating on a leaderboard and how it went */
.rating-value {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.rating-graph {
    display: block;
    width: 100%;
    height: 64px;
    margin: 8px 0 6px;
    color: var(--accent);
}

/* the stats page: a table per slice, each share with a bar */
.stats .note {
    color: var(--muted);
    font-size: 14px;
}

.stats-slice {
    margin-top: 28px;
    overflow-x: auto;
}

.stats-slice h2 {
    margin-bottom: 4px;
}

/* the players' reputation scores on the stats page: a column for each band of five, the verdicts under them */
.scores .great { --tone: var(--great); }
.scores .good { --tone: var(--good); }
.scores .mixed { --tone: var(--mixed); }
.scores .poor { --tone: var(--poor); }
.scores .bad { --tone: var(--bad); }

.histogram {
    margin: 12px 0 20px;
}

.histogram .columns {
    display: flex;
    gap: 3px;
    height: 180px;
    border-bottom: 1px solid var(--border);
}

.histogram.small .columns {
    height: 90px;
}

.histogram .column {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.histogram .fill {
    background: var(--tone);
}

.histogram.small .fill {
    opacity: 0.55;
}

.histogram .axis {
    display: flex;
    gap: 3px;
    margin-top: 6px;
    font-size: 13px;
    text-align: center;
}

.histogram .axis > div {
    flex: 1;
}

.histogram .axis .verdict {
    font-weight: 600;
    color: var(--tone);
}

.histogram .axis .range {
    color: var(--muted);
}

.stats-slice table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.stats-slice th,
.stats-slice td {
    padding: 6px 8px;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.stats-slice th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.stats-slice th:first-child,
.stats-slice td:first-child {
    text-align: left;
}

.stats-slice .share {
    min-width: 72px;
}

.share-bar {
    height: 4px;
    margin-top: 3px;
    background: var(--bar);
    border-radius: 2px;
}

.share-bar div {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

.share-bar.bad div {
    background: var(--bad);
}

.share-bar.good div {
    background: var(--great);
}

/* a moderator's choice of whom a line is aimed at */
.target-picker {
    margin-left: 4px;
    padding: 1px 4px;
}

.target-picker option {
    color: #1f1d1a;
    background: #ffffff;
}

/* a moderator's label for a line, in place of the flag button */
.label-picker {
    padding: 1px 4px;
}

.label-picker option {
    color: #1f1d1a;
    background: #ffffff;
}

/* a player's whole chat, for moderators */
.history-game summary {
    cursor: pointer;
}

/* on the visitor's own page: fetching their games */
.my-games {
    margin: 0 0 16px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.my-games p {
    margin: 0 0 8px;
}

.my-games p:last-child {
    margin-bottom: 0;
}

.show-history {
    padding: 8px 14px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.label.profanity { background: var(--mixed); }
.label.ok { background: var(--good); }

/* the admin page */
.roles .note,
.roles .unknown {
    color: var(--muted);
    font-size: 14px;
}

.appoint {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0;
}

.appoint input {
    flex: 1 1 280px;
    padding: 8px 10px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.roles select,
.appoint button,
.roles .remove {
    padding: 6px 10px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.appoint button:disabled {
    opacity: 0.5;
    cursor: default;
}

.roles table {
    width: 100%;
    border-collapse: collapse;
}

.roles th,
.roles td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.roles th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

/* a player page's tabs: the chat, and the stats */
.tabs {
    display: flex;
    gap: 4px;
    margin: 24px 0 8px;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 8px 16px;
    font-weight: 600;
    text-decoration: none;
    color: var(--muted);
    border-bottom: 3px solid transparent;
}

.tab.current {
    color: var(--text);
    border-bottom-color: var(--accent);
}

/* on the signed-in visitor's own player page */
.reputation .you {
    display: inline-block;
    margin: 0 0 6px;
    padding: 1px 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: 999px;
}

@keyframes arrive {
    from {
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-line {
        animation: none;
    }

    .chat-line.fading {
        transition: none;
    }
}

@media (max-width: 480px) {
    .chat-page {
        font-size: 15px;
    }

    .chat {
        padding: 40px 12px 20px;
    }
}
