/*  grid-theme.css

    Shared by every page: the colour tokens (light and dark), and the
    styles of the components in grid-ui.js.  Pages add only their own
    layout.
*/

:root {
  color-scheme: light;
  --paper:   #EDF0F3;
  --surface: #F8F9FB;
  --ink:     #1C2530;
  --muted:   #5E6A78;
  --line:    #C9D0D8;
  --red:     #D2453A;
  --green:   #2F9358;
  --blue:    #2E67C7;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper:   #151A21;
    --surface: #1D242D;
    --ink:     #E4E8ED;
    --muted:   #97A3B1;
    --line:    #36404C;
    --red:     #E5675C;
    --green:   #4DB27A;
    --blue:    #5B8FE6;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 16px/1.5 var(--sans); }
code { font: 400 0.92em var(--mono); }

/* Page frame: every page sets only its own max-width (and layout) on main.
   The header's bottom margin is the gap to whatever comes next, so the
   element after the header has no top margin of its own. */
main { margin: 0 auto; padding: 32px 28px 64px; }
header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 0 0 20px; }
h1 { font-family: "Arvo", serif; font-size: 1.75rem; font-weight: 400; margin: 0; }
h1 span { color: var(--muted); font-weight: 400; }
nav { display: flex; align-items: center; }
nav a { color: var(--muted); font-size: 0.88rem; margin-left: 14px; }

/* Small print under a control, and the rendered preview of a formula being typed */
.hint { font-size: 0.8rem; color: var(--muted); }
#preview { margin: 8px 0 0; font-size: 1.15rem; }
#preview:empty { display: none; }

/* A square grid drawing (GridUI.gridView) filling its box */
.stage svg { width: 100%; height: 100%; display: block; }

textarea, button, input, select, summary { font: inherit; }
textarea:focus-visible, button:focus-visible, select:focus-visible,
input:focus-visible, summary:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

textarea.formula-input {
  display: block; width: 100%; min-height: 5em; resize: vertical;
  font: 400 14px/1.5 var(--mono); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px;
}
.formula-view { line-height: 1.7; min-height: 2.2em; }
.formula-view .katex { white-space: normal; }

button.primary {
  font-weight: 500; font-size: 0.95rem; color: var(--paper); background: var(--ink);
  border: 1px solid var(--ink); border-radius: 6px; padding: 8px 18px; cursor: pointer;
}
button.primary:hover { opacity: 0.9; }
button.primary:disabled { opacity: 0.55; cursor: progress; }
button.ghost {
  font-weight: 500; font-size: 0.92rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button.ghost:hover { border-color: var(--muted); }
button.ghost:disabled { opacity: 0.55; cursor: default; }

/* Stepper: -/+ around a number field (GridUI.stepper) */
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line);
           border-radius: 6px; background: var(--surface); overflow: hidden; }
.stepper input { width: 2.6em; border: none; background: transparent; color: var(--ink);
                 text-align: center; padding: 5px 0; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.stepper button { all: unset; box-sizing: border-box; width: 1.9em; text-align: center;
                  cursor: pointer; color: var(--muted); user-select: none; touch-action: none;
                  font: 500 1.05rem/1 var(--sans); display: flex; align-items: center; justify-content: center; }
.stepper button:hover { color: var(--ink); background: var(--paper); }
.stepper button:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.stepper button[aria-disabled="true"] { opacity: 0.35; cursor: default; }

/* Grid view (GridUI.gridView) */
.gv .axis { font: 400 13px var(--mono); fill: var(--muted); }
.gv .swatch { stroke: var(--paper); stroke-width: 6; transition: fill 0.3s ease; }
.gv .swatch.red   { fill: var(--red); }
.gv .swatch.green { fill: var(--green); }
.gv .swatch.blue  { fill: var(--blue); }
.gv .swatch.empty { fill: transparent; stroke: var(--line); stroke-width: 2; stroke-dasharray: 6 5; }
.gv .swatch.unknown { fill: var(--line); opacity: 0.35; stroke: var(--paper); }
.gv .digit { font: 500 54px var(--sans); fill: var(--ink); pointer-events: none;
             text-anchor: middle; dominant-baseline: central; }
.gv .digit.on-colour { fill: #fff; }
.gv .slot { cursor: pointer; outline: none; }
.gv .slot:hover .swatch:not(.empty) { stroke: var(--surface); }
.gv .slot:focus-visible .swatch { stroke: var(--ink); stroke-width: 4; stroke-dasharray: none; }
@media (prefers-reduced-motion: reduce) { .gv .swatch { transition: none; } }

/* Player over the time points (GridUI.player) */
.gv-player { display: flex; align-items: center; gap: 8px; width: 100%; }
.gv-player[hidden] { display: none; }
.gv-player button { color: var(--ink); background: var(--surface); border: 1px solid var(--line);
                    border-radius: 6px; min-width: 2.4em; padding: 6px 10px; cursor: pointer; font-weight: 500; }
.gv-player input[type=range] { flex: 1; min-width: 60px; accent-color: var(--ink); }
.gv-player .label { font: 400 0.9rem var(--mono); color: var(--muted);
                    white-space: nowrap; min-width: 6.5em; text-align: right; }

/* Formula list (GridUI.formulaList) */
.formula-list { margin: 10px 0 0; max-height: 26em; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.formula-list .fl-empty { margin: 4px 0; font-size: 0.88rem; color: var(--muted); }
.fl-item { display: grid; grid-template-columns: auto 1.6em minmax(0, 1fr) auto; align-items: center; gap: 6px;
           padding: 4px 6px; border-radius: 8px; border: 1px solid transparent; }
.fl-item:hover { background: var(--surface); }
.fl-item.editing { border-color: var(--ink); background: var(--surface); }
.fl-item.off .fl-tex, .fl-item.off .fl-num { opacity: 0.4; }
.fl-item.has-error { border-color: var(--red); }
.fl-num { font-size: 0.78rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.fl-comment { grid-column: 3 / 4; grid-row: 1; margin: 2px 0 0; font-size: 0.8rem; color: var(--muted); line-height: 1.3; cursor: pointer; }
/* (everything but the heading and the error message in the formula's row) */
.fl-item.with-comment > :not(.fl-comment):not(.fl-error):not(.fl-check) { grid-row: 2; }
.fl-item.with-comment > .fl-error { grid-row: 3; }
.fl-tex { cursor: pointer; font-size: 1.05rem; line-height: 1.5; overflow-x: auto; }
.fl-tex .katex { white-space: normal; }
.fl-remove { border: none; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 0 4px; border-radius: 4px; }
.fl-remove:hover { color: var(--red); background: var(--surface); }
.fl-error { grid-column: 2 / -1; margin: 0; font-size: 0.82rem; color: var(--red); }
/* The checking mode: whether each formula holds on the grid, and why */
.fl-check { grid-column: 2 / -1; margin: 0; font-size: 0.82rem; }
.fl-check.holds { color: var(--green); }
.fl-check.fails { color: var(--red); }
.fl-check.neutral { color: var(--muted); }
.fl-item.with-comment > .fl-check { grid-row: 3; }
.fl-item.with-comment.has-error > .fl-check { grid-row: 4; }
.fl-input-error { margin: 4px 0 0; min-height: 1.1em; font-size: 0.82rem; color: var(--red); }
.fl-toolbar { display: flex; justify-content: flex-end; gap: 6px; margin: 10px 0 -6px; }
.fl-copy { border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 0.78rem;
           padding: 2px 9px; border-radius: 6px; cursor: pointer; }
.fl-copy:hover:not(:disabled) { color: var(--ink); }
.fl-copy:disabled { opacity: 0.5; cursor: default; }
.definition-preview { margin: 6px 0 0; font-size: 1.05rem; }
.definition-preview:empty { display: none; }
.definitions-panel #definitions { max-height: 30em; }
.fl-add-row { display: flex; gap: 8px; align-items: center; margin: 8px 0 0; }

/* Notation panel (live.html) */
details.notation { font-size: 0.92rem; color: var(--muted); }
details.notation summary { cursor: pointer; color: var(--ink); font-weight: 500; }
details.notation table { border-collapse: collapse; margin: 8px 0; }
details.notation td { padding: 3px 14px 3px 0; vertical-align: top; }
details.notation code { font-size: 12.5px; color: var(--ink); }
details.notation p { margin: 6px 0; max-width: 62ch; }

/* Under the hood (GridUI.internalsPanel): the solver's steps as a quiet
   pipeline of text tabs (Formula › Expanded › ...), the selected one
   underlined (the › is an inline block, so the underline leaves it out), then a line about it, its first lines and a footer.
   Inside a control card (the live page's Solver card) it continues the
   card; on its own it is a light panel. */
details.internals { font-size: 0.88rem; color: var(--muted); margin: 18px 0 0; min-width: 0; }
details.internals summary { cursor: pointer; }
details.internals[open] summary { color: var(--ink); }
.internals .in-body { transition: opacity 0.15s; }
.internals.updating .in-body { opacity: 0.55; }
.internals .in-status { margin: 8px 0 0; }
.internals .in-status[hidden] { display: none; }
.internals .in-tabs { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 0; margin: 8px 0 6px; }
.internals .in-tabs button { all: unset; cursor: pointer; padding: 2px 0 3px; color: var(--muted);
                             text-underline-offset: 5px; text-decoration-thickness: 1.5px; }
.internals .in-tabs button:hover { color: var(--ink); }
.internals .in-tabs button[aria-selected="true"] { color: var(--ink); text-decoration-line: underline; }
.internals .in-tabs button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
.internals .in-tabs button + button::before { content: "›"; color: var(--line); margin: 0 8px;
                                              display: inline-block; pointer-events: none; }
.internals .in-panel[hidden] { display: none; }
.internals .in-about { margin: 0 0 6px; max-width: 70ch; font-size: 0.82rem; line-height: 1.45; }
.internals .in-lines { max-height: 360px; overflow: auto; color: var(--ink);
                       background: var(--surface); border-radius: 6px; padding: 8px 10px; }
.internals .in-lines pre { margin: 0; font: 400 12px/1.5 var(--mono); white-space: pre; }
.internals .in-formula { margin: 0 0 6px; }
.internals .in-foot { margin: 4px 0 0; font-size: 0.78rem; text-align: right; }
.internals .in-download { all: unset; cursor: pointer; color: var(--blue); }
.internals .in-download:hover { text-decoration: underline; }
.internals .in-download:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.internals .in-download:disabled { color: var(--muted); cursor: default; }
.ctrl-card details.internals { margin: 2px 0 0; }
.ctrl-card .internals .in-lines { background: var(--paper); }


/* Given cells, set by hand (GridUI.givens): outlined */
.gv g.given rect.swatch { stroke: var(--ink); stroke-width: 7; }
.gv g.given rect.swatch.empty { stroke-dasharray: none; }
/* Squares a check is about (a counterexample, a witness): a dashed ring */
.gv g.highlight rect.swatch { stroke: var(--ink); stroke-width: 8; stroke-dasharray: 16 9; }
.fl-item.special .fl-comment { color: var(--ink); }

/* Drawing controls (GridUI.drawing) */
.drawing-controls .click-mode { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin: 10px 0 0;
                                color: var(--muted); font-size: 0.9rem; }
.drawing-controls .click-mode label { display: flex; align-items: center; gap: 5px; color: var(--ink); }
.drawing-controls .hint { font-size: 0.82rem; }
.drawing-controls .click-mode[hidden] { display: none; }

/* Names on the axes (GridUI.gridView) */
.gv .axis.named { fill: var(--ink); }

/* Legend (GridUI.legend) */
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 12px 0 0; padding: 0; list-style: none;
          color: var(--muted); font-size: 0.88rem; }
.legend li { display: flex; align-items: center; gap: 7px; }
.legend i.key { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend i.key.red { background: var(--red); } .legend i.key.green { background: var(--green); }
.legend i.key.blue { background: var(--blue); } .legend i.key.empty { border: 1.5px dashed var(--muted); }

/* Soft formulas (GridUI.formulaList) */
.fl-soft { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.fl-soft button { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 10px;
                  padding: 0 8px; font-size: 0.75rem; cursor: pointer; }
.fl-soft.on button { color: var(--ink); border-color: var(--muted); }
.fl-soft input { width: 3.2em; font-size: 0.75rem; padding: 0 2px; }
.fl-violated { margin-left: 4px; color: var(--green); }
.fl-violated.bad { color: var(--red); }
.formula-list.soft .fl-item { grid-template-columns: auto 1.6em minmax(0, 1fr) auto auto; }

/* A hard formula's chip shows only when pointing at the formula: hard is
   the normal case, and a chip on every formula would be noise. */
.fl-soft:not(.on) { opacity: 0; transition: opacity 0.15s; }
.fl-item:hover .fl-soft, .fl-soft:focus-within { opacity: 1; }
