/* Guess the Hex: shared styles for every page. Arcade font + question-mark backdrop, laid out mobile-first. */

@font-face {
    font-family: leadFont;
    src: url("/fonts/arcade.woff2") format("woff2"), url("/fonts/arcade.woff") format("woff");
    unicode-range: U+000-5FF;
    /* The font is preloaded and cached, so wait for it instead of flashing a fallback font between pages */
    font-display: block;
}

:root {
    --ink: #000;
    --muted: #555;
    --line: #e2e2e2;
    --panel: rgba(255, 255, 255, 0.92);
    --link: #0000ee;
    --good: green;
    --ok: orange;
    --bad: red;
    --pixel: leadFont, "Courier New", monospace;
    --text: Avenir, "Avenir Next", "Segoe UI", Arial, sans-serif;
    --gutter: 16px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: #fff url("/newBackg.png") center top;
    font-family: var(--text);
    line-height: 1.5;
}

a { color: var(--link); }

.pixel, h1, h2, h3, .btn, label, .menu, .site-header, .stat-list, .rank-list, .kpis, .pixel-table th, .home-player {
    font-family: var(--pixel);
    font-weight: normal;
    letter-spacing: 0.02em;
}

/* ---------- Header ---------- */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 20px;
    padding: 14px var(--gutter);
}

.site-header .brand {
    font-size: clamp(20px, 5vw, 32px);
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
}

.site-header nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    font-size: clamp(13px, 3.4vw, 18px);
}

.site-header nav a { color: var(--ink); text-decoration: none; }
.site-header nav a:hover { color: var(--link); }

/* ---------- Page body ---------- */

.page {
    max-width: 880px;
    margin: 0 auto;
    padding: 0 var(--gutter) 56px;
}

.page-title {
    text-align: center;
    font-size: clamp(30px, 8vw, 50px);
    line-height: 1.15;
    margin: 12px 0 28px;
    overflow-wrap: anywhere;
}

.page-title small {
    display: block;
    font-size: 0.5em;
    margin-top: 6px;
}

.page-wide { max-width: 1180px; }

.section-title {
    font-size: 18px;
    line-height: 1.3;
    margin: 36px 0 14px;
}

.section-title small {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.panel-note {
    font-size: 14px;
    color: var(--muted);
    margin: 8px 0 0;
}

.panel-note.centered { text-align: center; margin: -16px 0 24px; }
.stat-list .one-line { white-space: nowrap; }

.panel {
    background: var(--panel);
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
    padding: 20px clamp(16px, 4vw, 28px);
    margin: 0 0 28px;
}

.panel > :first-child { margin-top: 0; }

.grid-2, .grid-3 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 32px;
    align-items: start;
}

.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* minmax(0, 1fr), not 1fr: a plain 1fr column won't shrink below a chart canvas's width, so phones overflowed */
@media (max-width: 1000px) { .grid-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.panel { min-width: 0; }
.chart canvas { max-width: 100%; }

/* Panels that sit side by side line up: same height per row */
.grid-2 > .panel, .grid-3 > .panel { align-self: stretch; }

/* ---------- Headline numbers ---------- */

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 96px), 1fr));
    gap: 16px;
    margin: 0 0 28px;
}

@media (max-width: 560px) {
    .kpis { gap: 10px; }
    .kpis div { padding: 12px 4px; box-shadow: 4px 4px 0 var(--ink); }
    .kpis dt { font-size: 10px; }
    .stat-list { font-size: 13px; }
}

.kpis div {
    display: flex;
    flex-direction: column-reverse; /* number above its label */
    align-items: center;
    gap: 6px;
    padding: 16px 8px;
    background: var(--panel);
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
    text-align: center;
}

.kpis dd { margin: 0; font-size: clamp(22px, 4vw, 32px); line-height: 1; }
.kpis dt { font-size: 12px; color: var(--muted); }

.good { color: var(--good); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.match { color: purple; }

/* ---------- Label / value lists ---------- */

.stat-list {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px 16px;
    margin: 0;
    font-size: 15px;
}

.stat-list dt, .stat-list dd { margin: 0; }
.stat-list dd { text-align: right; white-space: nowrap; }
.stat-list .gap { grid-column: 1 / -1; height: 4px; }

/* ---------- Leaderboard ---------- */

.rank-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 15px;
}

.rank-list li {
    display: grid;
    grid-template-columns: 3ch minmax(0, 1fr) auto;
    gap: 12px;
    padding: 6px 0;
}

.rank-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .you { border-top: 2px dashed var(--line); margin-top: 8px; padding-top: 12px; color: var(--ink); }

/* ---------- Per-colour breakdown: one bar per group, best first ---------- */

.group-intro { margin: -4px 0 16px; }

.group-bars {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 14px;
}

.group-bars li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 6px 16px;
}

.group-bars .label {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
    font-family: var(--pixel);
    font-size: 14px;
}

.group-bars .name { display: inline-flex; align-items: center; gap: 10px; }
.group-bars .label small { font-family: var(--text); font-size: 13px; color: var(--muted); }
.group-bars .value { font-family: var(--pixel); font-size: 16px; text-align: right; }
.group-bars .bar { grid-column: 1 / -1; height: 14px; border: 2px solid var(--ink); background: #fff; }
.group-bars .bar i { display: block; height: 100%; }
.group-bars .few { opacity: 0.45; }
.swatch { flex: none; width: 14px; height: 14px; border: 2px solid var(--ink); }

/* ---------- Charts ---------- */

.chart {
    position: relative;
    height: clamp(300px, 55vw, 380px);
    margin: 0;
}

.chart-tall { height: clamp(380px, 70vw, 480px); }

/* ---------- Tables (how to play, admin) ---------- */

.table-wrap { overflow-x: auto; margin: 16px 0 24px; }

.pixel-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
    margin-bottom: 6px; /* room for the shadow inside .table-wrap */
    font-size: 15px;
}

.pixel-table th, .pixel-table td {
    padding: 10px 14px;
    border: 1px solid var(--line);
    text-align: center;
    vertical-align: middle;
}

.pixel-table th { font-size: 13px; font-weight: normal; background: var(--ink); color: #fff; border-color: var(--ink); }
.pixel-table tbody tr:nth-child(even) td:not(.swatch-cell) { background: #f4f4f4; }
.pixel-table td:first-child { font-weight: 600; }
.pixel-table .swatch-cell { font-family: var(--pixel); font-size: 13px; min-width: 8.5em; height: 48px; border-color: #fff; }
.pixel-table .good td { color: var(--good); }
.pixel-table .ok td { color: #c77700; }
.pixel-table .bad td { color: var(--bad); }
.pixel-table .match td { color: purple; }
.ladder .swatch-cell { height: 34px; min-width: 6em; }

.data-table { font-size: 14px; }
.data-table th, .data-table td { padding: 8px 10px; white-space: nowrap; }
.data-table td:first-child { font-weight: normal; text-align: left; }
.data-table td.name { font-family: var(--pixel); font-size: 13px; }

/* #D9FE32 broken into its components */
.hex-example { display: grid; gap: 0; max-width: 560px; margin: 16px auto 0; }
.hex-whole {
    font-family: var(--pixel);
    font-size: clamp(28px, 7vw, 44px);
    text-align: center;
    padding: 18px;
    border: 3px solid var(--ink);
    border-bottom: 0;
}
.hex-example .table-wrap { margin-top: 0; }

.hex-digits {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
    max-width: 560px;
    margin: 16px auto 24px !important;
    padding: 0 !important;
}

.hex-digits li {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
    border: 3px solid var(--ink);
    background: var(--panel);
}

.hex-digits b { font-family: var(--pixel); font-weight: normal; font-size: 22px; line-height: 1.2; }
.hex-digits span { font-size: 13px; color: var(--muted); }

.credit { font-size: 13px; color: var(--muted); margin-top: 0; }

/* ---------- Colour groups page ---------- */

.group-list { list-style: none; padding: 0 !important; margin: 28px 0; display: grid; gap: 22px; }
.group-list h2 { font-size: 18px; margin: 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.group-list h2 small { font-size: 14px; color: var(--muted); }
.group-list p { margin: 4px 0 8px; font-size: 14px; color: var(--muted); }
.swatch-row { display: grid; grid-template-columns: repeat(14, 1fr); border: 3px solid var(--ink); }
.swatch-row span { aspect-ratio: 1; }

/* ---------- Prose pages (about, how to play, data) ---------- */

.prose { font-size: 16px; }
.prose p, .prose li { text-align: left; }
.prose img { display: block; max-width: 100%; height: auto; margin: 20px auto; }
.prose h2 { margin-top: 36px; }
.prose ul { padding-left: 1.2em; }

/* ---------- Forms ---------- */

.form {
    max-width: 420px;
    margin: 0 auto;
}

.form label {
    display: block;
    font-size: 15px;
    margin: 18px 0 6px;
}

.form input[type=text], .form input[type=password], .form input[type=email] {
    width: 100%;
    padding: 12px 16px;
    font: 16px var(--text); /* 16px stops iOS zooming into the field */
    border: 2px solid var(--ink);
    border-radius: 0;
    background: #fff;
}

.form input:focus { outline: 3px solid var(--link); outline-offset: 1px; }

.btn {
    display: block;
    width: 100%;
    margin-top: 24px;
    padding: 12px;
    font-size: clamp(20px, 6vw, 28px);
    color: #fff;
    background: var(--ink);
    border: 3px solid var(--ink);
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}

.btn:hover, .btn:focus-visible { background: #fff; color: var(--ink); }

.form-error {
    font-family: var(--pixel);
    color: var(--bad);
    text-align: center;
    margin: 0 0 8px;
}

.form-links { text-align: center; margin-top: 20px; font-family: var(--pixel); font-size: 14px; }

/* ---------- Home ---------- */

.home {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.home .site-header { justify-content: flex-end; }

.home-title {
    text-align: center;
    font-size: clamp(36px, 10vw, 64px);
    line-height: 1.1;
    margin: clamp(8px, 4vh, 40px) var(--gutter) 12px;
}

.home-player {
    text-align: center;
    font-size: clamp(13px, 3.4vw, 16px);
    margin: 0 var(--gutter) clamp(20px, 5vh, 44px);
}

.home-player a { text-decoration: none; }

.menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(14px, 3.2vh, 28px);
    font-size: clamp(24px, 7vw, 35px);
    flex: 1;
}

.menu a { text-decoration: none; transition: color 0.1s ease-in-out; }
.menu a:hover, .menu a:focus-visible { color: var(--ink); }
.menu .new { color: blue; }
.menu .resume { color: red; }
.menu .leaderboard { color: green; }
.menu .personal { color: purple; }
.menu .how { color: orange; }

.site-footer {
    font-family: var(--pixel);
    font-size: 12px;
    padding: 24px var(--gutter);
    text-align: center;
}

.site-footer a { text-decoration: none; }

/* ---------- Single-message pages ---------- */

.notice {
    text-align: center;
    font-size: clamp(22px, 5vw, 36px);
    line-height: 1.3;
    margin: 12vh auto 32px;
    max-width: 760px;
}

.notice-link {
    display: block;
    text-align: center;
    font-family: var(--pixel);
    font-size: clamp(18px, 4vw, 26px);
    text-decoration: none;
}

/* ---------- Segmented switch (leaderboard chart) ---------- */

.switch { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }

.switch button {
    font: 13px var(--pixel);
    padding: 8px 12px;
    color: var(--ink);
    background: #fff;
    border: 3px solid var(--ink);
    border-radius: 0;
    cursor: pointer;
}

.switch button[aria-pressed="true"] { color: #fff; background: var(--ink); }
.switch button:hover:not([aria-pressed="true"]) { color: var(--link); }
