/* Telemetry console.
 *
 * The design brief here is narrow: one person, checking their own games,
 * usually on a phone, usually to answer "did anything change". So the page is
 * built as an instrument panel rather than a card kit — figures separated by
 * hairlines, tabular numerals everywhere, one accent colour reserved for the
 * data itself, and no decoration that isn't carrying a number.
 */

:root {
    --paper: #eef0ec;
    --surface: #fbfcfa;
    --ink: #1b2a2e;
    --muted: #63747a;
    --faint: #8b979b;
    --rule: #d3d9d2;
    --accent: #0f5f52;
    --accent-soft: #9fc9be;
    --alt: #3e5c8a;
    --alert: #a8412a;
    --good: #2f6b3a;

    --h0: #e9ece8;
    --h1: #cfe0d8;
    --h2: #a6ccbe;
    --h3: #6faa96;
    --h4: #2f7f6a;

    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

    --gap: 1.5rem;
    --pad: 1.125rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #101a1c;
        --surface: #162225;
        --ink: #e4ebe7;
        --muted: #93a4a6;
        --faint: #6d8083;
        --rule: #26383b;
        --accent: #63c3ac;
        --accent-soft: #2c5f55;
        --alt: #7d9ed0;
        --alert: #e08a72;
        --good: #74c088;

        --h0: #1a2628;
        --h1: #1f3b37;
        --h2: #235049;
        --h3: #2c6d5f;
        --h4: #3f9a83;
    }
}

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

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ---------------------------------------------------------------- header */

.masthead {
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
    position: sticky;
    top: 0;
    z-index: 10;
}

.masthead-row {
    max-width: 1320px;
    margin: 0 auto;
    padding: 0.75rem var(--pad);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.wordmark {
    font-weight: 650;
    letter-spacing: -0.015em;
    font-size: 1.0625rem;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.wordmark small {
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--faint);
}

.masthead-spacer {
    flex: 1;
}

.picker {
    font: inherit;
    font-size: 0.875rem;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 0.3rem 0.5rem;
    max-width: 15rem;
}

.window-switch {
    display: flex;
    border: 1px solid var(--rule);
    border-radius: 3px;
    overflow: hidden;
}

.window-switch a {
    padding: 0.3rem 0.6rem;
    font-size: 0.8125rem;
    color: var(--muted);
    border-right: 1px solid var(--rule);
    background: var(--paper);
}

.window-switch a:last-child {
    border-right: 0;
}

.window-switch a:hover {
    text-decoration: none;
    color: var(--ink);
}

.window-switch a.on {
    background: var(--accent);
    color: var(--surface);
}

.signout {
    background: none;
    border: 0;
    font: inherit;
    font-size: 0.8125rem;
    color: var(--muted);
    cursor: pointer;
    padding: 0.3rem;
}

.signout:hover {
    color: var(--alert);
}

.tabs {
    max-width: 1320px;
    margin: 0 auto;
    padding: 0 var(--pad);
    display: flex;
    gap: 1.25rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tabs a {
    padding: 0.5rem 0 0.6rem;
    font-size: 0.9375rem;
    color: var(--muted);
    white-space: nowrap;
    border-bottom: 2px solid transparent;
}

.tabs a:hover {
    text-decoration: none;
    color: var(--ink);
}

.tabs a.on {
    color: var(--ink);
    border-bottom-color: var(--accent);
    font-weight: 550;
}

/* ------------------------------------------------------------------ page */

main {
    max-width: 1320px;
    margin: 0 auto;
    padding: var(--gap) var(--pad) 4rem;
}

h1 {
    font-size: 1.375rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin: 0 0 1rem;
}

h2 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
    letter-spacing: -0.005em;
}

.hint {
    color: var(--muted);
    font-size: 0.8125rem;
    margin: 0.35rem 0 0;
    max-width: 62ch;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 4px;
    padding: var(--pad);
    margin-bottom: var(--gap);
}

.panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.panel-head h2 {
    margin: 0;
}

.panel-head .meta {
    font-size: 0.8125rem;
    color: var(--faint);
}

/* ------------------------------------------------------------------ rail */

/* The header figures. Not cards: one continuous strip divided by hairlines,
 * so the eye reads across the row instead of stopping at every border. */
.rail {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 4px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    margin-bottom: var(--gap);
}

.readout {
    padding: 0.9rem var(--pad);
    border-right: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
    min-width: 0;
}

.readout:last-child {
    border-right: 0;
}

.readout .label {
    font-size: 0.75rem;
    color: var(--muted);
    display: block;
    margin-bottom: 0.15rem;
}

.readout .value {
    font-size: 1.75rem;
    font-weight: 550;
    letter-spacing: -0.03em;
    line-height: 1.1;
    display: block;
}

.readout .value .unit {
    font-size: 0.9375rem;
    font-weight: 450;
    color: var(--muted);
    letter-spacing: 0;
}

.readout .foot {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.3rem;
    min-height: 22px;
}

.chip {
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.chip.up {
    color: var(--good);
}

.chip.down {
    color: var(--alert);
}

.spark {
    width: 62px;
    height: 20px;
    overflow: visible;
}

.spark-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 1.25;
    vector-effect: non-scaling-stroke;
}

.spark-area {
    fill: var(--accent);
    opacity: 0.1;
}

.spark-dot {
    fill: var(--accent);
}

/* ----------------------------------------------------------------- chart */

.chart {
    width: 100%;
    height: 260px;
    display: block;
}

.chart-legend {
    display: flex;
    gap: 1rem;
    font-size: 0.8125rem;
    color: var(--muted);
    margin-top: 0.5rem;
}

.chart-legend span::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 2px;
    vertical-align: middle;
    margin-right: 0.35rem;
    background: currentColor;
}

.legend-primary {
    color: var(--accent);
}

.legend-secondary {
    color: var(--alt);
}

.tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--ink);
    color: var(--paper);
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem;
    border-radius: 3px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.08s;
    z-index: 20;
}

/* ----------------------------------------------------------------- grids */

.split {
    display: grid;
    gap: var(--gap);
    grid-template-columns: 1fr;
}

@media (min-width: 900px) {
    .split.two {
        grid-template-columns: 1.35fr 1fr;
    }

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

@media (min-width: 620px) and (max-width: 899px) {
    .split.three {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --------------------------------------------------------------- listing */

.listing {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.listing th {
    text-align: left;
    font-weight: 550;
    color: var(--muted);
    font-size: 0.8125rem;
    padding: 0 0.5rem 0.45rem 0;
    border-bottom: 1px solid var(--rule);
    white-space: nowrap;
}

.listing td {
    padding: 0.4rem 0.5rem 0.4rem 0;
    border-bottom: 1px solid var(--rule);
    vertical-align: baseline;
}

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

.listing .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.listing th.num {
    text-align: right;
}

.listing .dim {
    color: var(--muted);
}

.listing .name {
    font-weight: 500;
}

.listing tbody tr:hover {
    background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.mono {
    font-family: var(--mono);
    font-size: 0.8125rem;
}

/* A share bar drawn behind the row, so a breakdown reads as a shape before
 * it reads as numbers. */
.bar-cell {
    position: relative;
    min-width: 60px;
}

.bar-cell .bar {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 6px;
    background: var(--accent);
    opacity: 0.22;
    border-radius: 1px;
}

/* -------------------------------------------------------------- cohorts */

.cohorts {
    overflow-x: auto;
}

.cohort-grid {
    border-collapse: separate;
    border-spacing: 2px;
    font-size: 0.75rem;
}

.cohort-grid th {
    font-weight: 500;
    color: var(--muted);
    padding: 0 0.25rem;
    text-align: center;
    white-space: nowrap;
}

.cohort-grid th.row-head,
.cohort-grid td.row-head {
    text-align: left;
    padding-right: 0.6rem;
    white-space: nowrap;
    color: var(--muted);
}

.cohort-grid td.row-head b {
    color: var(--ink);
    font-weight: 550;
}

.cell {
    width: 34px;
    height: 26px;
    text-align: center;
    border-radius: 2px;
    color: var(--ink);
}

.cell.empty {
    background: transparent;
}

.cell.h0 {
    background: var(--h0);
    color: var(--faint);
}

.cell.h1 {
    background: var(--h1);
}

.cell.h2 {
    background: var(--h2);
}

.cell.h3 {
    background: var(--h3);
}

.cell.h4 {
    background: var(--h4);
    color: var(--surface);
}

/* -------------------------------------------------------------- details */

.spec-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 0 var(--gap);
}

.spec {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--rule);
    font-size: 0.875rem;
}

.spec dt {
    color: var(--muted);
    margin: 0;
}

.spec dd {
    margin: 0;
    text-align: right;
    word-break: break-word;
}

.flags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.flag {
    font-size: 0.75rem;
    padding: 0.15rem 0.45rem;
    border: 1px solid var(--rule);
    border-radius: 999px;
    color: var(--muted);
}

.flag.on {
    border-color: var(--accent-soft);
    color: var(--accent);
}

pre.stack {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 0.75rem;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.75rem;
    line-height: 1.6;
    margin: 0;
}

.severity {
    color: var(--alert);
    font-weight: 550;
}

/* ---------------------------------------------------------------- forms */

.toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"] {
    font: inherit;
    font-size: 0.875rem;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--rule);
    border-radius: 3px;
    background: var(--surface);
    color: var(--ink);
    min-width: 0;
}

.btn {
    font: inherit;
    font-size: 0.875rem;
    padding: 0.4rem 0.85rem;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--surface);
    border-radius: 3px;
    cursor: pointer;
}

.btn.quiet {
    background: transparent;
    color: var(--muted);
    border-color: var(--rule);
}

.btn:hover {
    text-decoration: none;
    filter: brightness(1.08);
}

.pager {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    font-size: 0.875rem;
}

/* ---------------------------------------------------------------- login */

.gate {
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: var(--pad);
}

.gate form {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 4px;
    padding: 1.75rem;
    width: min(24rem, 100%);
    display: grid;
    gap: 0.75rem;
}

.gate h1 {
    margin: 0 0 0.25rem;
    font-size: 1.125rem;
}

.gate label {
    font-size: 0.8125rem;
    color: var(--muted);
    display: grid;
    gap: 0.25rem;
}

.gate input {
    width: 100%;
}

.error {
    color: var(--alert);
    font-size: 0.8125rem;
    margin: 0;
}

/* ---------------------------------------------------------------- empty */

.empty {
    color: var(--muted);
    font-size: 0.875rem;
    padding: 1.5rem 0;
    text-align: center;
}

.empty b {
    color: var(--ink);
    display: block;
    font-weight: 550;
    margin-bottom: 0.25rem;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

@media (max-width: 620px) {
    .readout .value {
        font-size: 1.5rem;
    }

    main {
        padding-left: 0.875rem;
        padding-right: 0.875rem;
    }
}


/* ---------------------------------------------------------------- games */

/* Inputs, buttons and panels are already styled globally. What is left is
   only layout: how the fields sit next to each other, and how the per-game
   edit drawer opens under its row. */

.add-app {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    max-width: 44rem;
}

.add-app label,
.edit-panel label {
    display: grid;
    gap: 0.25rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.add-app input,
.edit-panel input {
    width: 100%;
}

.field-row {
    display: flex;
    gap: 0.85rem;
    flex-wrap: wrap;
}

.field-row > label {
    flex: 1 1 15rem;
}

/* The key is shown exactly once, so it gets the only emphasised border on
   the page. */
.key-field {
    font-family: var(--mono);
    font-size: 0.8125rem;
    letter-spacing: 0.03em;
    border-color: var(--accent) !important;
    background: var(--paper) !important;
}

/* The edit drawer lives in its own full-width row, so it is not squeezed
   into a right-aligned action cell. */
.edit-row > td {
    padding: 0;
    border-top: 0;
}

.inline-edit > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.4rem 0;
    font-size: 0.8125rem;
    color: var(--muted);
}

.inline-edit > summary::-webkit-details-marker {
    display: none;
}

.inline-edit > summary::before {
    content: "+ ";
    font-family: var(--mono);
}

.inline-edit[open] > summary {
    color: var(--accent);
}

.inline-edit[open] > summary::before {
    content: "\2212 ";
}

.inline-edit > summary:hover {
    color: var(--ink);
}

.edit-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--gap);
    padding: 0 0 1rem;
}

.edit-panel form {
    display: grid;
    gap: 0.6rem;
    flex: 1 1 18rem;
    max-width: 24rem;
}

.edit-panel .notes {
    flex: 1 1 18rem;
    margin: 0;
}

/* --------------------------------------------------------------- accounts */

.whoami {
    font-size: 0.8125rem;
    color: var(--muted);
    margin-right: 0.6rem;
}

/* Selects were never styled because nothing needed one until roles. */
select {
    font: inherit;
    font-size: 0.875rem;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--rule);
    border-radius: 3px;
    background: var(--surface);
    color: var(--ink);
    min-width: 0;
}

.add-app select,
.edit-panel select {
    width: 100%;
}

.row-actions {
    display: flex;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

/* ------------------------------------------------------------ leaderboards */

.board-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 1rem 0 0.35rem;
}

.board-switch a {
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--rule);
    border-radius: 3px;
    font-size: 0.8125rem;
    color: var(--muted);
    text-decoration: none;
}

.board-switch a:hover {
    color: var(--ink);
    border-color: var(--ink);
}

.board-switch a.on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--paper);
}

.board-switch a.on .chip {
    background: transparent;
    border-color: currentColor;
    color: inherit;
}

/* ---------------------------------------------------------------- overview */

/* The play-time grid reuses the cohort cell ramp, but its cells carry no text
   and there are 24 per row, so they are square and tight. */
.heatmap .cell {
    width: 20px;
    height: 20px;
    min-width: 20px;
}

.heatmap th {
    font-size: 0.6875rem;
    padding: 0;
}

.sub {
    font-size: 0.8125rem;
    font-weight: 550;
    color: var(--muted);
    margin: 0 0 0.5rem;
}

.funnel-form {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
}

.funnel-form label {
    display: grid;
    gap: 0.25rem;
    flex: 1 1 26rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

/* --------------------------------------------------------------- sdk page */

/* The guide is prose, so it gets a measure. Everything else on the dashboard
   is tabular and wants the full width. */
.doc .panel p {
    max-width: 68ch;
    font-size: 0.9375rem;
    line-height: 1.6;
    margin: 0 0 0.75rem;
}

.doc-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--gap);
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.doc-foot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 2rem 0 1rem;
    border-top: 1px solid var(--rule);
    margin-top: var(--gap);
    text-align: center;
}

.btn.big {
    font-size: 0.9375rem;
    padding: 0.6rem 1.4rem;
    background: var(--accent);
    border-color: var(--accent);
    color: var(--paper);
    white-space: nowrap;
}

.btn.big:hover {
    filter: brightness(1.1);
}

/* Contents strip — sticky so it stays reachable through a long page. */
.toc {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 1rem;
    padding: 0.6rem 0;
    margin-bottom: var(--gap);
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    font-size: 0.8125rem;
}

.toc a {
    color: var(--muted);
    text-decoration: none;
}

.toc a:hover {
    color: var(--accent);
}

/* Token colours, taken from VS Code's default Light+ theme so the samples
   look like the editor they will be pasted into. The dark set below is
   Dark+. */
.t-cmt { color: var(--t-cmt); font-style: italic; }
.t-str { color: var(--t-str); }
.t-num { color: var(--t-num); }
.t-kw  { color: var(--t-kw); }
.t-ctl { color: var(--t-ctl); }
.t-typ { color: var(--t-typ); }
.t-fn  { color: var(--t-fn); }
.t-arg { color: var(--t-arg); }

:root {
    --t-cmt: #008000;
    --t-str: #a31515;
    --t-num: #098658;
    --t-kw:  #0000ff;
    --t-ctl: #af00db;
    --t-typ: #267f99;
    --t-fn:  #795e26;
    --t-arg: #001080;
}

.code {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-left: 2px solid var(--accent);
    border-radius: 2px;
    padding: 0.75rem 0.9rem;
    margin: 0 0 1rem;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.8125rem;
    line-height: 1.55;
    color: var(--ink);
    white-space: pre;
    tab-size: 4;
}

.steps {
    max-width: 68ch;
    margin: 0 0 0.75rem;
    padding-left: 1.2rem;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.steps li {
    margin-bottom: 0.4rem;
}

/* Anchored sections must not land under the sticky contents strip. */
.doc section[id] {
    scroll-margin-top: 3.5rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --t-cmt: #6a9955;
        --t-str: #ce9178;
        --t-num: #b5cea8;
        --t-kw:  #569cd6;
        --t-ctl: #c586c0;
        --t-typ: #4ec9b0;
        --t-fn:  #dcdcaa;
        --t-arg: #9cdcfe;
    }

    /* Dark+ sets code on a slightly deeper panel than the page. */
    .code {
        background: color-mix(in srgb, var(--ink) 6%, var(--surface));
    }
}

/* ------------------------------------------------------------- two-factor */

.gate.wide form { max-width: 34rem; }

/* Centred column: the QR is the thing you came to this page for, so it leads
   and everything else sits under it. */
.qr-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    margin: 0.75rem 0 1rem;
}

/* White background regardless of theme: a dark-mode QR with inverted colours
   is unreadable to most scanners. */
.qr {
    display: block;
    width: 220px;
    height: 220px;
    background: #fff;
    padding: 10px;
    border: 1px solid var(--rule);
    border-radius: 4px;
}

.qr-block .secret { justify-content: center; }

.manual > summary {
    list-style: none;
    cursor: pointer;
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.manual > summary::-webkit-details-marker { display: none; }
.manual > summary::before { content: "+ "; font-family: var(--mono); }
.manual[open] > summary::before { content: "\2212 "; }
.manual > summary:hover { color: var(--ink); }

/* The setup key is going to be typed by hand by someone reading it off a
   screen, so it is spaced into blocks and set large enough to be unambiguous. */
.secret {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.25rem 0 0.5rem;
}

.secret span {
    font-family: var(--mono);
    font-size: 1rem;
    letter-spacing: 0.08em;
    padding: 0.25rem 0.45rem;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 3px;
    user-select: all;
}

.uri {
    font-size: 0.75rem;
    word-break: break-all;
    color: var(--accent);
}

.code-input {
    font-size: 1.1rem;
    letter-spacing: 0.25em;
}