:root {
    --surface-gap: 18px;
    --stack-gap: 18px;
    --stack-gap-compact: 10px;
}

/* A stack is a vertical flow. Horizontal action groups use .actions instead. */
.stack {
    display: grid;
    gap: var(--stack-gap);
    align-items: start;
}

.stack.compact {
    gap: var(--stack-gap-compact);
}

.stack > * {
    min-width: 0;
}

/* Keep a predictable page rhythm without adding spacing inside grids/details. */
main > .card + .card,
main > .card + .stack,
main > .card + .detail,
main > .stack + .card,
main > .stack + .stack,
main > .stack + .detail,
main > .detail + .card,
main > .detail + .stack,
main > .detail + .detail {
    margin-top: var(--surface-gap);
}

/* Dark surfaces need a restrained edge so adjacent layers remain perceptible. */
html[data-theme="dark"] .card {
    border-color: color-mix(in srgb, var(--border) 84%, var(--text) 16%);
}

/* Destructive actions use shape, border and an explicit marker in addition to colour. */
.button.danger {
    border: 1px solid var(--danger-border);
    background: var(--danger-bg);
    color: var(--danger-text);
}

.button.danger:hover {
    border-color: var(--danger-text);
    background: color-mix(in srgb, var(--danger-bg) 82%, var(--danger-text) 18%);
}

.button.danger .button-icon {
    width: 1.35em;
    height: 1.35em;
    display: inline-grid;
    place-items: center;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: .82em;
    font-weight: 900;
    line-height: 1;
}

/* Keyboard focus should be as clear and consistent as pointer hover. */
.button:focus-visible,
nav a:focus-visible,
.link-button:focus-visible,
.header-link:focus-visible,
.theme-toggle:focus-visible,
.list-item:focus-visible,
.metric-card:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent);
    outline-offset: 2px;
}

.button:disabled,
.button[aria-disabled="true"] {
    opacity: .55;
    cursor: not-allowed;
    filter: saturate(.65);
}

@media (max-width: 520px) {
    :root {
        --surface-gap: 14px;
        --stack-gap: 14px;
    }
}
