/* "How it works" page. Builds on the tokens of app.css; diagrams are inline SVG styled from here. */

/* The sky gradient is sized by the root box, so the root grows with the page instead of repeating per screen. */
html:has(.how),
body:has(.how) {
    height: auto;
    min-height: 100%;
}

/* Not auto: a scrolling body would become the scroll container of the sticky tab bar and never let it stick. Clip, not
   hidden, for the same reason: it cuts the full-width tab bar at the scrollbar without becoming a scroll container. */
body:has(.how) {
    overflow: visible;
    overflow-x: clip;
}

.how {
    --d-bg: #130b27;
    --d-ink: var(--text);
    --d-muted: rgba(246, 231, 208, 0.66);
    --d-line: rgba(246, 231, 208, 0.72);
    --d-faint: rgba(246, 231, 208, 0.22);
    --d-panel: rgba(255, 255, 255, 0.035);
    --d-rr: var(--accent);
    --d-cf: #b98cff;
    --d-obs: var(--ok);
    --d-php: #7cc4ff;
    --d-kv: #ff7a8a;
    --d-edge: rgba(246, 231, 208, 0.6);
    --d-bad: var(--bad);
    --d-ok: var(--ok);
    --code-bg: rgba(0, 0, 0, 0.32);

    max-width: 1040px;
    margin: 0 auto;
    padding: 24px 16px 64px;
    font-size: 16px;
    line-height: 1.6;
}

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

.how h1 {
    margin: 8px 0 12px;
    font-size: clamp(28px, 5vw, 40px);
    line-height: 1.2;
}

.how h2 {
    margin: 0 0 12px;
    font-size: 24px;
    line-height: 1.3;
}

.how h3 {
    margin: 28px 0 10px;
    font-size: 19px;
    line-height: 1.3;
}

.how p,
.how ul,
.how ol {
    margin: 0 0 12px;
    max-width: 72ch;
}

.how code {
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--code-bg);
    font: 0.88em/1.4 ui-monospace, 'Cascadia Code', Consolas, monospace;
    overflow-wrap: anywhere;
}

.how pre {
    margin: 0 0 16px;
    padding: 12px 14px;
    overflow-x: auto;
    border-radius: 8px;
    background: var(--code-bg);
}

.how pre code {
    padding: 0;
    background: none;
    overflow-wrap: normal;
}

.how__nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
}

/* The way back on the left; Grafana and the language switch together on the right. */
.how__nav > :first-child {
    margin-right: auto;
}

.how__lead {
    color: var(--d-muted);
}

.how__section {
    margin-top: 48px;
    scroll-margin-top: 84px;
}

.how__terms {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 16px;
    margin: 0 0 12px;
}

.how__terms dt {
    font-weight: 600;
}

.how__terms dd {
    margin: 0;
    color: var(--d-muted);
}

@media (max-width: 560px) {
    .how__terms {
        grid-template-columns: 1fr;
    }

    .how__terms dd {
        margin-bottom: 8px;
    }
}

/* Section tabs. The bar sticks to the top so the tabs stay reachable in long panels; without JS it is a plain table of contents.
   It spans the whole window, out of the text column, so the tabs wrap only when the window is full. */

.tabs {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 28px calc(50% - 50vw) 0;
    padding: 8px 16px;
    border-bottom: 1px solid var(--d-faint);
    background: rgba(11, 8, 32, 0.9);
    backdrop-filter: blur(8px);
}

/* Wraps into more rows instead of scrolling: every tab stays in sight, on a phone too. Not the text column's 72ch. */
.how .tabs__list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    max-width: none;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tabs__list a {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 8px;
    color: var(--d-muted);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.tabs__list a:hover {
    color: var(--text);
    background: var(--d-panel);
}

.tabs__list a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.tabs--ready .tabs__list [aria-selected="true"] {
    color: var(--text);
    background: rgba(255, 138, 31, 0.14);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.tabs--ready ~ .how__section {
    margin-top: 28px;
}

.callout {
    margin: 0 0 16px;
    padding: 10px 14px;
    max-width: 72ch;
    border-left: 3px solid var(--accent);
    border-radius: 0 8px 8px 0;
    background: var(--d-panel);
}

/* Diagrams */

/* The page keeps a readable text column; diagrams break out of it, but only up to a size where labels stay ~1.3x of the viewBox. */
html {
    overflow-x: clip;
}

.diagram {
    --diagram-width: min(100vw - 32px, 1360px);

    width: var(--diagram-width);
    margin: 16px 0 20px calc(50% - var(--diagram-width) / 2);
    padding: 16px;
    border: 1px solid var(--d-faint);
    border-radius: 10px;
    background: var(--d-bg);
    box-sizing: border-box;
}

/* On narrow screens the drawing keeps a readable size and scrolls inside its frame, not the page. */
.diagram__scroll {
    overflow-x: auto;
}

.diagram__svg {
    display: block;
    width: 100%;
    height: auto;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.diagram figcaption {
    margin-top: 8px;
    color: var(--d-muted);
    font-size: 14px;
}

.diagram__svg text {
    fill: var(--d-ink);
    stroke: none;
    font-size: 11px;
}

.diagram__svg .d-t {
    font-size: 12px;
    font-weight: 600;
}

.diagram__svg .d-h {
    font-size: 13px;
    font-weight: 600;
}

.diagram__svg .d-s,
.diagram__svg .d-n {
    fill: var(--d-muted);
}

.diagram__svg .d-m,
.diagram__svg .d-l {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
}

.diagram__svg .d-phase {
    fill: var(--accent);
}

.diagram__svg .d-bad {
    fill: var(--d-bad);
}

.diagram__svg .d-ok {
    fill: var(--d-ok);
}

.d-box {
    fill: var(--d-panel);
    stroke: var(--d-edge);
    stroke-width: 1.2;
}

.d-box.g-rr {
    stroke: var(--d-rr);
}

.d-box.g-cf {
    stroke: var(--d-cf);
}

.d-box.g-obs {
    stroke: var(--d-obs);
}

.d-box.g-php {
    stroke: var(--d-php);
}

.d-box.g-kv {
    stroke: var(--d-kv);
}

.d-group {
    fill: rgba(255, 138, 31, 0.05);
    stroke: var(--d-rr);
    stroke-width: 1;
    stroke-dasharray: 6 4;
}

.d-e {
    fill: none;
    stroke: var(--d-line);
    stroke-width: 1.4;
}

.d-e--ret {
    stroke-dasharray: 5 4;
}

.d-e--acc {
    stroke: var(--d-cf);
}

.d-e--ok {
    stroke: var(--d-obs);
}

.d-e--kv {
    stroke: var(--d-kv);
}

.d-mk path {
    fill: var(--d-line);
}

.d-mk--acc path {
    fill: var(--d-cf);
}

.d-mk--ok path {
    fill: var(--d-obs);
}

.d-mk--kv path {
    fill: var(--d-kv);
}

.d-life,
.d-sep {
    fill: none;
    stroke: var(--d-faint);
    stroke-width: 1;
    stroke-dasharray: 3 4;
}

.d-sep {
    stroke-dasharray: none;
}

.d-crit {
    fill: rgba(255, 138, 31, 0.35);
    stroke: var(--d-rr);
    stroke-width: 1;
}

.d-wait {
    fill: rgba(246, 231, 208, 0.08);
    stroke: var(--d-muted);
    stroke-width: 1;
    stroke-dasharray: 3 3;
}

/* The window between the idempotency marker and the effect: a crash there loses the transition. */
.d-risk {
    stroke: var(--d-bad);
}

/* Scenes diagram: stage axis, the stageMax staircase and pumpkins. */
.d-axis {
    fill: none;
    stroke: var(--d-muted);
    stroke-width: 1;
}

.d-cap {
    fill: none;
    stroke: var(--d-rr);
    stroke-width: 2.5;
}

.d-pk {
    fill: var(--d-rr);
    fill-opacity: 0.75;
}

.d-pk--done {
    fill-opacity: 1;
}

.d-note {
    fill: var(--d-panel);
    stroke: var(--d-faint);
}

.d-note--bad {
    stroke: var(--d-bad);
}

.d-note--ok {
    stroke: var(--d-ok);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 14px;
    color: var(--d-muted);
}

.legend__swatch {
    display: inline-block;
    width: 18px;
    height: 0;
    margin-right: 6px;
    vertical-align: middle;
    border-top: 2px solid var(--swatch);
}

/* Stages strip: how a pumpkin climbs inside a scene, HELLOWIN_CLICKS_PER_STAGE clicks per stage. */

.stages {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
    max-width: 72ch;
}

.stages__item {
    flex: 1 1 96px;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--d-panel);
    border-top: 3px solid var(--accent);
    font-size: 14px;
}

.stages__item b {
    display: block;
    font-size: 18px;
}

.data-table {
    width: 100%;
    margin: 0 0 16px;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th,
.data-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--d-faint);
    text-align: left;
    vertical-align: top;
}

.table-scroll {
    overflow-x: auto;
}
