/* Palette: the dataviz reference instance (light and dark steps chosen separately). */
:root {
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --series-6: #008300;
    --series-7: #6250d6;
    --highlight: rgba(42, 120, 214, 0.14);
    --band: rgba(82, 81, 78, 0.16);
    --band-edge: rgba(82, 81, 78, 0.55);
    --violation: #d03b3b;
    --ok: #006300;
    /* sequential blue for |w|/c in [0, 1]: lightest = near zero, recedes into the surface */
    --seq-0: #cde2fb;
    --seq-1: #86b6ef;
    --seq-2: #3987e5;
    --seq-3: #1c5cab;
    --seq-4: #0d366b;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --page: #0d0d0d;
        --surface: #1a1a19;
        --ink: #f0efec;
        --ink-2: #c3c2b7;
        --muted: #898781;
        --grid: #2c2c2a;
        --axis: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        --series-4: #c98500;
        --series-5: #d55181;
        --series-6: #008300;
        --series-7: #9085e9;
        --highlight: rgba(57, 135, 229, 0.20);
        --band: rgba(195, 194, 183, 0.16);
        --band-edge: rgba(195, 194, 183, 0.5);
        --violation: #e66767;
        --ok: #0ca30c;
        /* reversed on dark: near zero recedes into the dark surface */
        --seq-0: #0d366b;
        --seq-1: #1c5cab;
        --seq-2: #3987e5;
        --seq-3: #86b6ef;
        --seq-4: #cde2fb;
        color-scheme: dark;
    }
}

/* One fixed color per fit method (primary or overlay), from the categorical slots; true f is series-2.
   combined uses ink: series-8 red would be confused with the residual view's violation color. */
:root {
    --fit-taut: var(--series-1);
    --fit-constant: var(--muted);
    --fit-minTV0: var(--series-3);
    --fit-minTV1: var(--series-7);
    --fit-minTV2: var(--series-6);
    --fit-minSup1: var(--series-5);
    --fit-minSup2: var(--series-4);
    --fit-combined: var(--ink);
}

* {
    box-sizing: border-box;
}

/* class rules that set display (.field, .check) would otherwise override the hidden attribute */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 1rem 1.25rem;
    background: var(--page);
    color: var(--ink);
    font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: start;
    gap: 0 1rem;
}

header h1 {
    margin: 0;
    font-size: 1.4rem;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

#toolbar-message {
    color: var(--ink-2);
    font-size: 0.8rem;
}

button {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--axis);
    border-radius: 6px;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: var(--highlight);
}

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

/* --- export menu: a <details> styled as a button with a drop-down list */
.menu {
    position: relative;
}

.menu summary {
    list-style: none;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--axis);
    border-radius: 6px;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
}

.menu summary::-webkit-details-marker {
    display: none;
}

.menu summary::after {
    content: ' ▾';
    color: var(--muted);
}

.menu summary:hover,
.menu[open] summary {
    background: var(--highlight);
}

.menu-items {
    position: absolute;
    right: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    min-width: max-content;
    margin-top: 0.25rem;
    padding: 0.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.menu-items button {
    border: none;
    text-align: left;
    padding: 0.3rem 0.6rem;
}

.menu-check {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
    color: var(--ink-2);
    border-top: 1px solid var(--border);
}

.menu-check-next {
    border-top: none;
    padding-top: 0;
}

/* --- about dialog */
#about {
    max-width: min(44rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 1rem 1.5rem 1.25rem;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: 8px;
}

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

#about h3 {
    margin: 1rem 0 0.3rem;
    font-size: 0.9rem;
}

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

#about ul {
    padding-left: 1.2rem;
}

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

#about .reference {
    margin-top: 1rem;
    font-size: 0.8rem;
}

.about-close {
    float: right;
}

.about-close button {
    border: none;
    background: none;
    font-size: 1rem;
}

h2 {
    margin: 1rem 0 0.4rem;
    font-size: 0.95rem;
}

h2:first-child {
    margin-top: 0;
}

.subtitle {
    margin: 0.2rem 0 1rem;
    color: var(--ink-2);
}

main {
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr) 16rem;
    gap: 1rem;
    align-items: start;
}

@media (max-width: 1000px) {
    main {
        grid-template-columns: minmax(0, 1fr);
    }
}

aside,
.chart {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
}

#charts {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

#charts.empty {
    opacity: 0.4;
}

/* --- settings history: three icon buttons at the top right of the controls panel */
#controls-panel {
    position: relative;
}

.history-bar {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    display: flex;
    gap: 0.25rem;
}

.history-bar button {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.3rem;
}

.history-bar svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* --- controls */
.field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-bottom: 0.5rem;
}

.field-label {
    color: var(--ink-2);
    font-size: 0.85rem;
}

/* visible lines under a control: a computed value, or (warn) why the control is limited */
.field-note {
    display: block;
    color: var(--ink-2);
    font-size: 0.75rem;
}

.field-note.warn::before {
    content: '⚠ ';
}

.field-note + .field-note,
.check + .field-note {
    margin-top: -0.35rem;
    margin-bottom: 0.5rem;
}

.group {
    margin-bottom: 0.25rem;
}

.row {
    display: flex;
    gap: 0.5rem;
    align-items: end;
}

.row .field {
    flex: 1;
}

.row button {
    margin-bottom: 0.5rem;
}

.check {
    display: block;
    margin-bottom: 0.5rem;
}

input[type=number],
select,
textarea {
    width: 100%;
    font: inherit;
    padding: 0.2rem 0.3rem;
}

textarea {
    font-family: ui-monospace, Menlo, monospace;
    font-size: 0.8rem;
    margin-bottom: 0.4rem;
}

input[type=file] {
    margin-bottom: 0.5rem;
    max-width: 100%;
}

/* --- charts */
.plot {
    position: relative;
}

.plot canvas,
.plot svg {
    position: absolute;
    left: 0;
    top: 0;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    align-items: center;
    margin-bottom: 0.25rem;
    color: var(--ink-2);
    font-size: 0.85rem;
}

.legend .item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.legend .key {
    display: inline-block;
    width: 16px;
    height: 2px;
    border-radius: 1px;
}

.legend .key.glyph {
    width: auto;
    height: auto;
    font-size: 0.7rem;
    letter-spacing: 1px;
}

.legend .key.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.residual-legend .key {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.legend-title {
    color: var(--ink);
    font-weight: 600;
}

.ramp {
    display: inline-block;
    width: 90px;
    height: 12px;
    border-radius: 2px;
}

.ramp-end {
    font-variant-numeric: tabular-nums;
}

.axis text {
    fill: var(--muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.axis line,
.axis path {
    stroke: var(--axis);
}

.axis-title {
    fill: var(--muted);
    font-size: 11px;
}

.grid line {
    stroke: var(--grid);
}

.overlay {
    fill: transparent;
    cursor: crosshair;
}

.crosshair line {
    stroke: var(--muted);
    stroke-width: 1;
}

.crosshair circle {
    fill: var(--ink);
    stroke: var(--surface);
    stroke-width: 2;
}

.interval-highlight {
    fill: var(--highlight);
}

.cell-hover {
    fill: none;
    stroke: var(--ink);
    stroke-width: 1;
}

/* --- tooltip */
.tooltip {
    position: absolute;
    z-index: 10;
    pointer-events: none;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    padding: 0.4rem 0.55rem;
    font-size: 0.8rem;
    max-width: 22rem;
}

.tooltip-title {
    color: var(--ink-2);
    margin-bottom: 0.2rem;
}

.tooltip-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-variant-numeric: tabular-nums;
}

.tooltip-row span {
    color: var(--ink-2);
}

.tooltip-key {
    display: inline-block;
    width: 12px;
    height: 2px;
}

.tooltip-note {
    margin-top: 0.25rem;
    color: var(--ink-2);
}

.tooltip-note.alert {
    color: var(--violation);
    font-weight: 600;
}

/* --- readouts */
#readouts dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.6rem;
    margin: 0;
}

#readouts dt {
    color: var(--ink-2);
}

#readouts dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.verdict {
    margin: 0 0 0.75rem;
}

.verdict.ok strong {
    color: var(--ok);
}

.verdict.bad strong {
    color: var(--violation);
}

.notes {
    margin: 0.75rem 0 0;
    padding-left: 1.1rem;
    color: var(--ink-2);
    font-size: 0.8rem;
}

/* --- footer */
footer {
    margin-top: 1rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--grid);
    color: var(--ink-2);
    font-size: 0.8rem;
}

footer a {
    color: var(--series-1);
}

#status:empty {
    display: none;
}

.error {
    color: var(--violation);
}

.pending {
    opacity: 0.45;
    transition: opacity 0.15s;
}

.overlays {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-bottom: 0.5rem;
}

.overlays label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
}

.overlays .swatch {
    display: inline-block;
    width: 14px;
    height: 3px;
    border-radius: 1px;
}

.band-fill {
    fill: var(--band);
}

.band-empty {
    fill: var(--violation);
    fill-opacity: 0.35;
}

.band-edge {
    fill: none;
    stroke: var(--band-edge);
    stroke-width: 1;
}

.legend .key.box {
    width: 14px;
    height: 10px;
    border-radius: 2px;
}

.band-exact {
    fill: none;
    stroke: var(--ink);
    stroke-width: 1.25;
    stroke-dasharray: 4 3;
}

.radio-row {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 0.4rem;
}

/* a status warning: icon + text, never color alone */
.warning {
    margin: 0 0 0.6rem;
    padding: 0.35rem 0.5rem 0.35rem 0.6rem;
    border-left: 3px solid #fab219;
    background: rgba(250, 178, 25, 0.10);
    font-size: 0.8rem;
}

.warning::before {
    content: '⚠ ';
}

.gap-connector {
    fill: none;
    stroke-width: 1.25;
    stroke-dasharray: 2 3;
}

/* --- ⓘ explanations (info.js) instead of inline hints */
.info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1em;
    height: 1.1em;
    margin-left: 0.2em;
    border: 1px solid var(--muted);
    border-radius: 50%;
    color: var(--muted);
    font: italic 600 0.7rem/1 Georgia, 'Times New Roman', serif;
    vertical-align: 0.1em;
    cursor: help;
    user-select: none;
}

.info:hover,
.info:focus-visible,
.info[aria-expanded='true'] {
    color: var(--ink);
    border-color: var(--ink-2);
    outline: none;
}

.info-tip {
    position: absolute;
    z-index: 20;
    max-width: 19rem;
    padding: 0.45rem 0.6rem;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    font-size: 0.8rem;
    line-height: 1.4;
}

.info-tip p,
.info-tip ul {
    margin: 0;
}

.info-tip * + p,
.info-tip * + ul {
    margin-top: 0.35em;
}

.info-tip ul {
    padding-left: 1.1em;
}

.info-tip li + li {
    margin-top: 0.2em;
}

.field-label .info,
h2 .info {
    font-size: 0.65rem;
}

/* readout notes live in ⓘ tips; labels stay on one line (with their ⓘ), values wrap */
#readouts p.claim .info,
#readouts p.verdict .info {
    margin-left: 0.3em;
}

#readouts dt {
    white-space: nowrap;
}

#readouts dl {
    grid-template-columns: max-content minmax(0, 1fr);
}

#readouts dd {
    white-space: normal;
}

.radio-row {
    align-items: center;
}

.radio-row .info {
    margin-left: -0.5rem;
    font-size: 0.65rem;
}

/* --- gallery: the readouts give way to the panes, two per row, with one legend */
body.gallery main {
    grid-template-columns: 15rem minmax(0, 1fr);
}

@media (max-width: 1000px) {
    body.gallery main {
        grid-template-columns: minmax(0, 1fr);
    }
}

#gallery {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.gallery-bar {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 0.5rem 1rem;
}

.gallery-bar .legend {
    margin-bottom: 0;
}

.gallery-bar select {
    width: auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

@media (max-width: 700px) {
    .gallery-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.pane {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
    min-width: 0;
}

.pane-head {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    margin-bottom: 0.3rem;
}

.pane-head select {
    flex: 1;
    min-width: 0;
}

.pane-open {
    padding: 0.1rem 0.45rem;
}

.pane .chart.compact {
    border: none;
    border-radius: 0;
    padding: 0;
    background: none;
}

/* a pane waiting for its turn to be recomputed still shows its previous fit, faded */
.pane.stale .plot {
    opacity: 0.4;
}

.pane-summary {
    margin: 0.3rem 0 0;
    color: var(--ink-2);
    font-size: 0.78rem;
    line-height: 1.35;
    /* one line; a narrow pane cuts it with an ellipsis, and the tooltip has it whole */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pane-summary.outside {
    white-space: normal;
}

.pane-outside {
    color: var(--violation);
}

.pane-summary.error {
    color: var(--violation);
    white-space: normal;
}

.view-toggle {
    display: inline-flex;
}

.view-toggle button {
    border-radius: 0;
}

.view-toggle button:first-child {
    border-radius: 6px 0 0 6px;
}

.view-toggle button:last-child {
    border-radius: 0 6px 6px 0;
    margin-left: -1px;
}

.view-toggle button[aria-pressed='true'] {
    background: var(--highlight);
    border-color: var(--series-1);
    position: relative;
}

/* a slider with its value beside it (Aₙ's shortest interval) */
.slider {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.slider input[type='range'] {
    flex: 1;
    min-width: 0;
}

.slider output {
    min-width: 3.2em;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Advanced: the rarely changed settings of a section, collapsed */
#controls details {
    margin-bottom: 0.5rem;
}

#controls summary {
    cursor: pointer;
    color: var(--ink-2);
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

/* a value line directly in the panel (the calibrated τ) keeps the fields' spacing below it */
#controls > .field-note {
    margin-bottom: 0.5rem;
}

#controls details > input[type=number] {
    margin-bottom: 0.5rem;
}
