/*
 The page's colours, made of one: the theme's background (the user's,
 --base-light / --base-dark, set by theme.js). OKLCH: lightness as the
 eye sees it, so the same steps read the same at every hue. The
 background's lightness is held in a band (the text on it always
 readable whatever colour is picked), its chroma held low (never
 garish); the text is the background's hue at a fixed lightness; muted
 text a mix of the text and the block, not transparency.
*/
:root,
:root.light {
    color-scheme: light;
    --background: oklch(from var(--base-light, #cccccc) clamp(0.78, l, 0.96) min(c, 0.08) h);
    --blockBackground: oklch(from var(--background) calc(l + 0.05) c h);
    --color: oklch(from var(--background) 0.2 min(c, 0.03) h);
    --muted: color-mix(in oklch, var(--color) 54%, var(--blockBackground));
    --link: oklch(from var(--background) 0.45 0.15 250);
}

:root.dark {
    color-scheme: dark;
    --background: oklch(from var(--base-dark, #18191a) clamp(0.14, l, 0.32) min(c, 0.06) h);
    --blockBackground: oklch(from var(--background) calc(l + 0.06) c h);
    --color: oklch(from var(--background) 0.93 min(c, 0.02) h);
    --muted: color-mix(in oklch, var(--color) 62%, var(--blockBackground));
    --link: oklch(from var(--background) 0.78 0.12 250);
}

:root {
    --gap: 16px;
    --width: 960px;
    --radius: 6px;
    font-family: system-ui, sans-serif;
    line-height: 1.5;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
}

a {
    color: var(--link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.block {
    background-color: var(--blockBackground);
    border-radius: var(--radius);
}

.text-muted {
    color: var(--muted);
}

/* The top: the logo, the sections, the theme and the sign-in; on a
   phone two rows (the logo and the rest, then the sections' icons). */
.top {
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: 8px var(--gap);
    background-color: var(--blockBackground);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--color);
}

.nav {
    display: flex;
    gap: 4px;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius);
    color: var(--muted);
}

.nav a:hover {
    text-decoration: none;
    color: var(--color);
    background-color: var(--background);
}

.nav a[aria-current] {
    color: var(--color);
    background-color: var(--background);
}

.top-right {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* Icons (icons.mjs): the text's colour and size. */
.icon {
    width: 1.15em;
    height: 1.15em;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* A button that's only its icon (its name its tooltip). */
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: var(--radius);
    background: none;
    color: var(--muted);
}

.icon-button:hover {
    text-decoration: none;
    color: var(--color);
    background-color: var(--background);
}

/* The theme's switch: three buttons together, the one in use pressed. */
theme-switch {
    display: inline-flex;
    justify-self: start;
    padding: 2px;
    gap: 2px;
    border: 1px solid var(--muted);
    border-radius: var(--radius);
    background-color: var(--background);
}

theme-switch button {
    width: 30px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--muted);
}

theme-switch button:hover {
    color: var(--color);
}

theme-switch button[aria-pressed="true"] {
    color: var(--color);
    background-color: var(--blockBackground);
    box-shadow: 0 1px 2px oklch(0 0 0 / 0.25);
}

/* The tooltip (icons.mjs). */
.tip {
    position: fixed;
    z-index: 20;
    max-width: min(280px, calc(100vw - 8px));
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--background);
    background-color: var(--color);
    pointer-events: none;
}

button {
    font: inherit;
    color: inherit;
    background-color: var(--background);
    border: 1px solid var(--muted);
    border-radius: var(--radius);
    padding: 4px 12px;
    cursor: pointer;
}

button:disabled {
    color: var(--muted);
    cursor: default;
}

#page {
    max-width: var(--width);
    margin: 0 auto;
    padding: var(--gap);
}

.games {
    display: grid;
    gap: 8px;
}

.game {
    padding: 10px var(--gap);
}

.theme-form {
    display: grid;
    gap: 8px;
    padding: var(--gap);
    max-width: 320px;
}

.theme-form fieldset {
    border: none;
    padding: 0;
    display: grid;
    gap: 4px;
}

.account {
    display: flex;
    align-items: center;
    gap: 4px;
}

.account .name {
    margin: 0 4px;
}

.avatar {
    border-radius: 50%;
}

.button {
    color: inherit;
    border: 1px solid var(--muted);
    border-radius: var(--radius);
    padding: 4px 12px;
}

.button:hover {
    text-decoration: none;
    background-color: var(--background);
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
}

.cards {
    display: grid;
    gap: 8px;
    margin-bottom: var(--gap);
}

.card,
.post {
    padding: 10px var(--gap);
}

.card-title {
    font-weight: 600;
    color: var(--color);
    overflow-wrap: anywhere;
}

.meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.9em;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.actions {
    display: flex;
    gap: 8px;
    margin-top: var(--gap);
}

.post-form {
    display: grid;
    gap: 12px;
    padding: var(--gap);
}

.post-form label {
    display: grid;
    gap: 4px;
}

input,
textarea {
    font: inherit;
    color: inherit;
    background-color: var(--background);
    border: 1px solid var(--muted);
    border-radius: var(--radius);
    padding: 6px 8px;
}

button.tag {
    border: none;
    background: none;
    padding: 0;
    color: var(--link, inherit);
    cursor: pointer;
    font: inherit;
}

.narrow {
    margin-bottom: var(--gap);
}

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px var(--gap);
    margin-bottom: 8px;
}

.grow {
    flex: 1;
}

.tag-edit {
    display: grid;
    gap: 8px;
    padding: var(--gap);
    margin-bottom: 8px;
}

.tag-edit label {
    display: grid;
    grid-template-columns: 9em 1fr;
    align-items: center;
}

.meter {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
}

.meter-bar {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background-color: var(--background);
    border: 1px solid var(--muted);
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    background-color: var(--link);
}

.thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: var(--radius);
}

.images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.images img {
    max-width: 100%;
    max-height: 320px;
    border-radius: var(--radius);
}

.files {
    display: grid;
    gap: 8px;
    margin-bottom: var(--gap);
}

/* Markdown: a post's text (md-dom.mjs's render). */

.md {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: var(--gap) 0;
}

.md :is(h3, h4, h5) {
    margin: 0.4em 0 0.2em;
}

.md small {
    display: block;
    color: var(--muted);
}

.md blockquote {
    margin: 0.2em 0;
    padding-left: 12px;
    border-left: 4px solid var(--muted);
}

.md :is(ul, ol) {
    margin: 0.2em 0;
    padding-left: 1.5em;
}

.md pre,
.md code,
.md-editor :is(.md-code, .md-codeblock) {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    background-color: var(--background);
    border-radius: 4px;
}

.md code {
    padding: 0 4px;
}

.md pre {
    margin: 0.3em 0;
    padding: 8px 10px;
    border: 1px solid var(--muted);
    overflow-x: auto;
}

.md pre code {
    padding: 0;
    background: none;
}

.spoiler {
    background-color: var(--color);
    color: transparent;
    border-radius: 4px;
    cursor: pointer;
}

.spoiler.shown {
    background-color: var(--background);
    color: inherit;
    cursor: auto;
}

.mention,
.md-editor .md-mention,
.md-editor .md-hashtag {
    color: var(--link);
    background-color: oklch(from var(--link) l c h / 0.15);
    border-radius: 4px;
    padding: 0 2px;
}

/* The editor: the text as typed, its marks dimmed, what they mark styled. */

.md-editor {
    min-height: 8em;
    max-height: 60vh;
    overflow-y: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background-color: var(--background);
    border: 1px solid var(--muted);
    border-radius: var(--radius);
    padding: 8px 10px;
    outline: none;
    cursor: text;
}

.md-editor:focus {
    border-color: var(--link);
}

.md-editor.empty::before {
    content: attr(data-placeholder);
    color: var(--muted);
    pointer-events: none;
    position: absolute;
}

.md-editor .md-mark {
    color: var(--muted);
}

.md-editor .md-bold {
    font-weight: 700;
}

.md-editor .md-italic {
    font-style: italic;
}

.md-editor .md-underline {
    text-decoration: underline;
}

.md-editor .md-strike {
    text-decoration: line-through;
}

.md-editor .md-spoiler {
    background-color: oklch(from var(--color) l c h / 0.15);
    border-radius: 4px;
}

.md-editor :is(.md-link, .md-url) {
    color: var(--link);
}

.md-editor .md-heading {
    font-weight: 700;
}

.md-editor .md-h1 {
    font-size: 1.5em;
}

.md-editor .md-h2 {
    font-size: 1.25em;
}

.md-editor .md-h3 {
    font-size: 1.1em;
}

.md-editor .md-subtext {
    font-size: 0.85em;
    color: var(--muted);
}

.md-editor .md-quote {
    border-left: 4px solid var(--muted);
    padding-left: 8px;
}

.md-editor .md-code {
    padding: 0 2px;
}

.md-editor .md-codeblock {
    display: inline-block;
    min-width: 100%;
    box-sizing: border-box;
    padding: 2px 6px;
}

.post-form .label {
    display: grid;
    gap: 4px;
}

/* What `#` and `@` offer in the editor (Discord's list). */

.md-complete {
    position: fixed;
    z-index: 10;
    width: min(300px, calc(100vw - 16px));
    max-height: 260px;
    overflow-y: auto;
    background-color: var(--blockBackground);
    border: 1px solid var(--muted);
    border-radius: var(--radius);
    padding: 4px;
    box-shadow: 0 4px 16px oklch(0 0 0 / 0.3);
}

.md-complete-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.md-complete-item.chosen,
.md-complete-item:hover {
    background-color: var(--background);
}

.md-complete-item img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.md-complete-item .hint {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.85em;
}

/* Phones and narrow windows. */

@media (max-width: 860px) {
    .account .name,
    .top .label {
        display: none;
    }
}

@media (max-width: 600px) {
    :root {
        --gap: 12px;
    }

    .top {
        flex-wrap: wrap;
        row-gap: 4px;
        padding: 6px 8px;
    }

    .logo .label {
        display: inline;
    }

    /* The sections a row of their own, across. */
    .nav {
        order: 3;
        width: 100%;
        justify-content: space-around;
    }

    .nav a {
        padding: 8px 14px;
    }

    #page {
        padding: var(--gap) 8px;
    }

    h1 {
        font-size: 1.5em;
    }

    .card,
    .post,
    .post-form {
        padding: 10px;
    }

    .page-head {
        flex-wrap: wrap;
    }

    .row {
        flex-wrap: wrap;
    }

    .tag-edit label {
        grid-template-columns: 1fr;
    }

    .md-editor {
        max-height: 50vh;
    }

    /* Big enough to touch. */
    button,
    .button {
        min-height: 36px;
    }
}
