:root {
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --border: rgba(11, 11, 11, 0.12);
    --accent: #2a78d6;
    --accent-soft: rgba(42, 120, 214, 0.12);
    --stage: #e9e8e3;
    --drop: rgba(42, 120, 214, 0.14);
    --warning: #d03b3b;
    --hint-bg: rgba(11, 11, 11, 0.78);
    --hint-ink: #fff;
    /* the step numbers (tour.js): orange, apart from the controls' blue */
    --step: #d96200;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --page: #0d0d0d;
        --surface: #1a1a19;
        --ink: #f0efec;
        --ink-2: #c3c2b7;
        --muted: #898781;
        --border: rgba(255, 255, 255, 0.12);
        --accent: #3987e5;
        --accent-soft: rgba(57, 135, 229, 0.2);
        --stage: #232322;
        --drop: rgba(57, 135, 229, 0.20);
        --warning: #e66767;
        --hint-bg: rgba(240, 239, 236, 0.9);
        --hint-ink: #0b0b0b;
        --step: #e8771a;
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

/* the hidden attribute wins over the display of flex and grid containers */
[hidden] {
    display: none !important;
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
    background: var(--page);
    color: var(--ink);
    font: 14px/1.4 system-ui, -apple-system, sans-serif;
}

header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 28px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

/* the main actions take the room left, the status line giving it up first; a basis of 0 keeps a long status or
   the progress bar from pushing the rows at the right onto a line of their own, and the automatic minimum width (the
   buttons and the shortest status) still moves them under the name on a narrow screen */
.actions {
    display: flex;
    flex: 1 1 0;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 20px;
}

.actions .run {
    flex: 1 1 0;
    flex-wrap: nowrap;
}

button.big, select.big {
    flex: none;
    white-space: nowrap;
    padding: 7px 16px;
    font-size: 15px;
    font-weight: 600;
}

/* the other actions: two rows at the right edge */
.bars {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    margin-left: auto;
}

.tagline {
    margin: 0;
    font-size: 12px;
    color: var(--ink-2);
}

.bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 6px 20px;
}

h1 {
    margin: 0;
    font-size: 18px;
}

/* the name is a button that shows the steps again, drawn as the heading's text */
h1 button.title {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    cursor: pointer;
}

h1 button.title:hover {
    color: var(--accent);
}

.group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

/* the status line with the progress bar under it, up to a fixed width; its size ignores its text (contain), so the
   toolbar doesn't reflow as the text changes or the bar shows; the full text is the tooltip */
.meter {
    display: flex;
    flex: 0 1 250px;
    flex-direction: column;
    gap: 3px;
    min-width: 60px;
    contain: inline-size;
}

.status {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink-2);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.status.done {
    color: var(--ink);
}

.status.error, .status.needed {
    color: var(--warning);
}

#test-image {
    max-width: 200px;
}

/* dev mode marker beside the title */
.dev-badge {
    margin-left: 4px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
    color: var(--warning);
    border: 1px solid var(--warning);
    border-radius: 3px;
}

#about a {
    color: var(--accent);
}

#about {
    max-width: min(640px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    padding: 20px 24px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

#about::backdrop {
    background: rgba(0, 0, 0, 0.35);
}

#about h2 {
    margin: 0 0 8px;
    font-size: 18px;
}

#about h3 {
    margin: 18px 0 6px;
    font-size: 14px;
}

#about p, #about li, #about dd {
    color: var(--ink-2);
}

#about p {
    margin: 0 0 8px;
}

#about ol, #about ul {
    margin: 0;
    padding-left: 20px;
}

/* the steps numbered as on the page beside the dialog (tour.js) */
#about ol {
    padding-left: 0;
    list-style: none;
    counter-reset: step;
}

#about ol > li {
    position: relative;
    min-height: 30px;
    padding-left: 40px;
    counter-increment: step;
}

#about ol > li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: -2px;
}

/* the steps layer over the page: a full-window popover that takes no pointer events */
#tour {
    inset: 0;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
    pointer-events: none;
}

.step-badge, #about ol > li::before {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: var(--step);
    color: #fff;
    font: 700 16px/1 system-ui, -apple-system, sans-serif;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.step-badge {
    position: fixed;
}

.step-label {
    position: fixed;
    padding: 4px 12px;
    border-radius: 14px;
    background: var(--hint-bg);
    color: var(--hint-ink);
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

#about li {
    margin-bottom: 4px;
}

#about strong {
    color: var(--ink);
}

.about-close {
    float: right;
    margin: 0 0 8px 12px;
}

.keys {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 12px;
    margin: 0;
}

.keys dt {
    color: var(--ink);
}

.keys dd {
    margin: 0;
}

kbd {
    padding: 0 4px;
    font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--page);
}

#fit-progress {
    width: 100%;
    height: 6px;
    accent-color: var(--accent);
}

.fine {
    color: var(--muted);
    font-size: 12px;
}

button, select {
    font: inherit;
    color: inherit;
    background: var(--page);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 9px;
}

button:hover:not(:disabled), select:hover:not(:disabled) {
    border-color: var(--accent);
}

button:disabled, select:disabled {
    opacity: 0.45;
    cursor: default;
}

button.primary:not(:disabled) {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

button[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

main {
    flex: 1;
    display: flex;
    min-height: 0;
}

aside {
    width: 360px;
    flex: none;
    overflow-y: auto;
    padding: 4px 16px 16px;
    border-right: 1px solid var(--border);
    background: var(--surface);
}

aside > details {
    border-bottom: 1px solid var(--border);
    padding: 8px 0 10px;
}

aside > details > summary {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-2);
    cursor: pointer;
    margin-bottom: 4px;
}

aside > details:not([open]) > summary {
    margin-bottom: 0;
}

.summary-note {
    margin-left: 6px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--muted);
}

details.sub > summary {
    font-size: 12px;
    color: var(--ink-2);
    cursor: pointer;
    margin: 8px 0 4px;
}

h3 {
    margin: 10px 0 6px;
    font-size: 13px;
    font-weight: 600;
}

dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 10px;
    margin: 0;
}

/* labels of read-only values: not the muted gray, which is a disabled field's */
dt {
    color: var(--ink-2);
}

dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.family-list {
    list-style: none;
    margin: 4px 0 8px;
    padding: 0;
}

.family-list li {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
}

.family-list li:hover {
    border-color: var(--border);
}

.family-list li.selected {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.family-list .name {
    flex: 1;
    min-width: 0;
}

.family-list .count {
    color: var(--ink-2);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.family-list .remove {
    padding: 0 6px;
    line-height: 1.2;
}

.family-list li.off .name {
    color: var(--muted);
}

.swatch {
    display: inline-block;
    width: 18px;
    height: 18px;
    flex: none;
    border: 1px solid var(--border);
    border-radius: 3px;
}

/* extrapolated or inferred: the border says so, the color stays exact (an opacity blended the panel into it, and
   dog-ages' levels 6–8 showed lighter than level 5) */
#style-c .swatch {
    width: 14px;
    height: 14px;
    margin-right: 6px;
    vertical-align: -2px;
}

.swatch.extrapolated {
    border-style: dashed;
}

/* a family whose dots vary in color: no single swatch is honest */
.swatch.varies {
    background: repeating-linear-gradient(45deg, var(--muted) 0 2px, transparent 2px 5px);
}

.levels-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.levels-row .label {
    color: var(--ink-2);
    cursor: help;
}

.levels {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.levels .level {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    color: var(--ink-2);
}

.params {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    margin-top: 8px;
}

/* the muted color is a disabled field's (below), so a label takes it only with its field disabled */
.params label {
    color: var(--ink-2);
}

.params label:has(input:disabled) {
    color: var(--muted);
}

input[type="color"]:disabled {
    opacity: 0.45;
}

/* ink, not inherited: these sit inside muted labels, and a muted value reads as a disabled field */
input[type="number"] {
    width: 68px;
    font: inherit;
    color: var(--ink);
    background: var(--page);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 4px;
}

input[type="number"]:disabled {
    color: var(--muted);
    background: transparent;
    border-style: dashed;
}

input.overridden {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

/* a value Find dots needs and the estimate couldn't give */
input.needed {
    border-color: var(--warning);
    box-shadow: 0 0 0 1px var(--warning);
}

input.needed::placeholder {
    color: var(--warning);
}

.notes p {
    margin: 6px 0 0;
    color: var(--ink-2);
    font-size: 12px;
}

#sample canvas {
    border: 1px solid var(--border);
    image-rendering: pixelated;
}

.row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.key {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin: 0 3px 0 6px;
    border-radius: 2px;
    vertical-align: -1px;
}

.check {
    display: block;
    margin-top: 6px;
}

/* under the checkbox's text */
#noise-hint {
    margin: 2px 0 6px 22px;
}

#viewer {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.viewbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.segmented {
    display: inline-flex;
    flex-wrap: wrap;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.segmented label {
    position: relative;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented span {
    display: block;
    padding: 2px 9px;
    cursor: pointer;
    border-left: 1px solid var(--border);
}

.segmented label:first-child span {
    border-left: none;
}

.segmented input:checked + span {
    background: var(--accent);
    color: #fff;
}

.segmented input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

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

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

#zoom-level {
    min-width: 48px;
    margin-left: 4px;
    font-variant-numeric: tabular-nums;
    color: var(--ink-2);
}

#stage {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--stage);
    cursor: grab;
    outline: none;
}

#stage.dragging {
    cursor: grabbing;
}

#stage.drop-target {
    background: var(--drop);
}

#stage.picking, #stage.adding {
    cursor: crosshair;
}

#stage.removing {
    cursor: pointer;
}

#view {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#stage-message {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 16px;
    text-align: center;
    color: var(--ink-2);
    pointer-events: none;
}

/* a box, so the message reads over an image */
#stage-message .box {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

#stage-message.error {
    color: var(--warning);
}

/* a transform animation runs on the compositor, so it keeps turning while the main thread is busy */
#stage-message.busy .box::before {
    content: '';
    flex: none;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* a scan's progress: what it is, a bar, and the stage under it */
#stage-message .box.progress {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    min-width: min(320px, 100%);
}

#stage-message.busy .box.progress::before {
    display: none;
}

#stage-message .box.progress progress {
    width: 100%;
    accent-color: var(--accent);
}

#stage-message .box.progress .stage {
    min-height: 1.2em;
    font-size: 0.85em;
    color: var(--ink-2);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    #stage-message.busy .box::before {
        animation-duration: 3s;
    }
}

#mode-hint {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    padding: 4px 12px;
    border-radius: 4px;
    background: var(--hint-bg);
    color: var(--hint-ink);
    font-size: 13px;
    pointer-events: none;
    white-space: nowrap;
}

#readout {
    min-height: 44px;
    padding: 4px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

#readout p {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#readout .swatch {
    width: 11px;
    height: 11px;
    margin-right: 4px;
    vertical-align: -1px;
}

.warning {
    color: var(--warning);
    padding: 8px 16px;
}

@media (max-width: 760px) {
    main {
        flex-direction: column;
    }

    aside {
        width: auto;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}

.axis {
    margin: 8px 0;
}

.axis h3 {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 600;
}

.axis table {
    border-collapse: collapse;
    width: 100%;
}

.axis td {
    padding: 1px 4px 1px 0;
    vertical-align: middle;
}

.axis td.px {
    color: var(--ink-2);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.axis td.from {
    color: var(--ink-2);
    font-size: 12px;
    white-space: nowrap;
}

.axis td.from.warn {
    color: var(--warning);
}

.axis h3 button {
    font-size: 12px;
    font-weight: 400;
}

.axis canvas {
    display: block;
    max-width: 90px;
    height: 20px;
    image-rendering: auto;
    background: #fff;
    border: 1px solid var(--border);
}

.axis input {
    width: 72px;
}

.axis input::placeholder {
    color: var(--muted);
    font-style: italic;
}

.axis .summary {
    margin: 4px 0 0;
}

.axis .warn {
    color: var(--warning);
}

.axis td button.remove {
    padding: 0 5px;
    line-height: 1.2;
    font-size: 12px;
}

.axis p button {
    font-size: 12px;
}
