/* Fonts (self-hosted; see fonts/OFL-*.txt for their licenses). Only the Latin subset is
   included; any other characters fall back to the system font. */

/* IBM Plex Sans: body text. A variable font, covering the regular and semibold weights. */
@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url("../fonts/ibm-plex-sans.woff2") format("woff2");
}

@font-face {
    font-family: "IBM Plex Sans";
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/ibm-plex-sans-italic.woff2") format("woff2");
}

/* Space Grotesk: titles and section labels. */
@font-face {
    font-family: "Space Grotesk";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/space-grotesk.woff2") format("woff2");
}

:root {
    --bg: #1f2124;
    --panel: #2a2e39;
    --panel-overlay: #171b23;
    /* The panel's background: very faint diagonal lines over --panel-overlay. */
    --panel-background:
        repeating-linear-gradient(135deg, rgb(255 255 255 / 0.035) 0 1px, transparent 1px 6px),
        var(--panel-overlay);
    --border: #262c3a;
    --text: #e6e8ee;
    --muted: #95abe7;
    --accent: #7490dc;
    --error: #ff6b6b;
    --gutter: 16px;
    --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-heading: "Space Grotesk", var(--font-body);

    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    overflow: hidden;
    background: #000;
    color: var(--text);
    font: 14px/1.4 var(--font-body);
}

/* View: fills the window. The rendered image is scaled to fit (see the quality levels in main.js). */

#view {
    position: fixed;
    inset: 0;
    display: block;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    cursor: grab;
    touch-action: none; /* We handle drag and pinch ourselves. */
}

#view:active {
    cursor: grabbing;
}

#view:focus {
    outline: none;
}

.status {
    position: fixed;
    inset: 0;
    margin: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    text-align: center;
    color: var(--muted);
    pointer-events: none;
}

.status[hidden] {
    display: none;
}

.status.error {
    color: var(--error);
    white-space: pre-wrap;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
}

/* Panel: floats over the view, and collapses to its title. */

.panel {
    position: fixed;
    top: var(--gutter);
    right: var(--gutter);
    width: min(320px, calc(100vw - 2 * var(--gutter)));
    max-height: calc(100dvh - 2 * var(--gutter));
    overflow-y: auto;
    background: var(--panel-background);
    border: 1px solid var(--border);
}

/* When collapsed, shrink to fit the title. */
.panel:not([open]) {
    width: auto;
}

.panel summary {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    list-style: none;
    cursor: pointer;
    user-select: none;
    /* Opaque, since the panel's content scrolls underneath. The pattern lines up with the
       panel's, since the title bar sits at the panel's top-left corner. */
    background: var(--panel-background);
}

.panel summary::-webkit-details-marker {
    display: none;
}

/* Chevron: points down when collapsed, up when open. */
.panel summary::after {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    margin-top: -4px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform 0.15s;
}

.panel[open] summary::after {
    margin-top: 4px;
    transform: rotate(-135deg);
}

.panel summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.panel h1 {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 600;
    white-space: nowrap;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 16px 16px;
}

.controls header p {
    margin: 0;
}

.hint {
    margin: 4px 0 0;
    color: var(--muted);
}

kbd {
    padding: 0 4px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font: 12px ui-monospace, Consolas, monospace;
}

.stats {
    margin: 0;
    padding: 0 4px;
    min-height: 2.8em; /* Reserve both lines before the first frame, so the layout doesn't shift. */
    white-space: pre-line;
    color: var(--muted);
    font: 12px ui-monospace, Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

.credit {
    margin: 0;
    padding: 0 4px;
    color: var(--muted);
    font-size: 16px;
}

a {
    color: var(--accent);
}

/* "What's this?" dialog */

.about {
    width: min(560px, calc(100vw - 2 * var(--gutter)));
    max-height: calc(100dvh - 4 * var(--gutter));
    padding: 0;
    overflow-y: auto;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
}

.about::backdrop {
    background: rgb(0 0 0 / 0.6);
    backdrop-filter: blur(2px);
}

/* The padding is on this inner element, so that a click on the dialog element itself
   is always a click outside the content (see main.js). */
.about-content {
    padding: 20px 24px;
}

.about h2 {
    margin: 0 0 8px;
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 600;
}

/* The title only takes focus so that the dialog opens scrolled to the top. */
.about h2:focus {
    outline: none;
}

.about h3 {
    margin: 16px 0 6px;
    color: var(--muted);
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.about ul {
    margin: 0;
    padding-left: 20px;
}

.about li + li {
    margin-top: 6px;
}

.about form {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

fieldset {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--border);
}

legend {
    padding: 0 4px;
    color: var(--muted);
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

label {
    display: flex;
    justify-content: space-between;
}

label.check {
    justify-content: flex-start;
    gap: 8px;
    cursor: pointer;
}

output {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

input[type=range] {
    width: 100%;
    margin: 0 0 6px;
    accent-color: var(--accent);
}

input[type=checkbox] {
    accent-color: var(--accent);
}

select,
button {
    padding: 6px 8px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
}

select {
    margin-bottom: 6px;
}

button {
    margin-top: 6px;
    cursor: pointer;
}

button:hover {
    border-color: var(--accent);
}
