/**
 * dataTools.css — the working area renderers and the features panels
 *
 * CONTENTS
 * --------
 *  1. Board furniture (heading, question, key, summary, empty state)
 *  2. Data table (shared by every chart tool)
 *  3. Pictogram
 *  4. Block / bar chart
 *  5. Tally chart
 *  6. Branching database
 *  7. Records and fields database
 *  8. Features panel (bottom bar) layout
 *  9. Charts made from the records database
 *
 * TWO RENDERINGS OF EVERY CHART
 * -----------------------------
 * Each chart is drawn twice into the DOM:
 *   - the visual chart, marked aria-hidden, built from CSS Grid
 *   - a real <table> with a <caption>, marked .sr-only, carrying the same
 *     numbers
 * A sighted child sees the chart; a child using a screen reader hears a proper
 * data table with row and column headers they can navigate cell by cell.  This
 * is far better than an aria-label summarising a chart in one long sentence,
 * and it means the underlying numbers are always available.  The table is also
 * what gets printed alongside the chart when "Include the data table" is
 * ticked in the print dialog.
 *
 * PATTERNS AS WELL AS COLOUR
 * --------------------------
 * Each series index gets a repeating-linear-gradient overlay in addition to its
 * fill colour (.series-0 … .series-11).  Bars therefore remain distinguishable
 * in greyscale, on a monochrome laser printer, and to a child with
 * deuteranopia — satisfying SC 1.4.1 rather than merely gesturing at it.
 */

/* ══ 1. Board furniture ════════════════════════════════════════════════════ */
.board-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--line);
}

.board-title {
  margin: 0;
  font-size: 1.375rem;
}

.board-view-name {
  padding: 0.15rem 0.6rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: var(--font-size-sm);
  font-weight: 700;
}

.board-head-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}

.board-head-summary .summary-chip {
  padding-block: 0.2rem;
}

.board-question {
  margin: 0 0 1rem;
  padding: 0.6rem 0.8rem;
  background: var(--panel-2);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--ink-soft);
  font-size: var(--font-size-lg);
  font-style: italic;
}

/* The pictogram key.  A pictogram without a stated key is meaningless, so it is
   rendered prominently and is never hidden. */
.board-key {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  font-weight: 700;
}

.board-key .key-symbol {
  font-size: 1.6rem;
  line-height: 1;
}

.board-key .key-symbol-image {
  width: 1.85rem;
  height: 1.85rem;
  object-fit: contain;
}

.board-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.summary-chip {
  padding: 0.3rem 0.7rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: var(--font-size-sm);
}

.summary-chip strong {
  color: var(--accent);
}

/* Empty state: never a blank screen.  Tells the child exactly what to do next
   and gives them a button that does it. */
.board-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
}

.board-empty h3 {
  margin: 0;
  color: var(--ink);
}

.board-empty p {
  max-width: 34rem;
}

.board-empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

/* ══ 2. Series colours and patterns ════════════════════════════════════════ */
.series {
  position: relative;
}

/* The pattern overlay. Each series gets a different angle and spacing, so the
   texture alone identifies the series. */
.series::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
}

.series-0::after {
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.42) 0 3px,
    transparent 3px 8px
  );
}
.series-1::after {
  background: repeating-linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.42) 0 3px,
    transparent 3px 8px
  );
}
.series-2::after {
  background: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.42) 0 3px,
    transparent 3px 9px
  );
}
.series-3::after {
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.42) 0 3px,
    transparent 3px 9px
  );
}
.series-4::after {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.38) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.38) 0 2px, transparent 2px 7px);
}
.series-5::after {
  background: radial-gradient(rgba(255, 255, 255, 0.55) 1.6px, transparent 1.7px);
  background-size: 8px 8px;
}
.series-6::after {
  background: repeating-linear-gradient(
    60deg,
    rgba(255, 255, 255, 0.42) 0 4px,
    transparent 4px 11px
  );
}
.series-7::after {
  background: repeating-linear-gradient(
    -60deg,
    rgba(255, 255, 255, 0.42) 0 4px,
    transparent 4px 11px
  );
}
.series-8::after {
  background: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.5) 0 1.5px,
    transparent 1.5px 6px
  );
}
.series-9::after {
  background: radial-gradient(rgba(255, 255, 255, 0.5) 2.4px, transparent 2.5px);
  background-size: 11px 11px;
}
.series-10::after {
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.36) 0 2px, transparent 2px 8px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.36) 0 2px, transparent 2px 8px);
}
.series-11::after {
  background: repeating-linear-gradient(
    30deg,
    rgba(255, 255, 255, 0.42) 0 5px,
    transparent 5px 13px
  );
}

/* ══ 3. Data table (shared) ════════════════════════════════════════════════ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
}

.data-table caption {
  text-align: left;
  font-weight: 700;
  padding-bottom: 0.35rem;
  color: var(--ink-soft);
}

.data-table th,
.data-table td {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line-strong);
  text-align: left;
  vertical-align: middle;
}

.data-table thead th {
  background: var(--panel-2);
  font-weight: 700;
  /* Sticky header so a long records table keeps its column names visible while
     scrolling — the table equivalent of not losing your place. */
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--panel-2) 55%, transparent);
}

.data-table td.numeric,
.data-table th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .row-actions {
  display: flex;
  gap: 0.25rem;
  white-space: nowrap;
}

.table-scroll {
  max-height: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  scrollbar-width: thin;
}

/* The colour swatch shown beside each category name.  Border as well as fill,
   so it is visible against any background and in forced-colours mode. */
.swatch-dot {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  margin-right: 0.4rem;
  border: 1px solid var(--ink);
  border-radius: 3px;
  vertical-align: -0.15em;
}

/* ══ 4. Pictogram ══════════════════════════════════════════════════════════ */
.pictogram {
  gap: 0.5rem 0.75rem;
}

.pictogram-horizontal {
  display: grid;
}

.pictogram-horizontal .pictogram-group {
  display: grid;
  grid-template-columns: minmax(6rem, max-content) minmax(0, 1fr) auto;
  gap: 0.5rem 0.75rem;
  align-items: center;
}

.pictogram-vertical {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  min-width: min-content;
  overflow-x: auto;
  padding: 0.5rem 0.25rem 0.25rem;
  scrollbar-width: thin;
}

.pictogram-vertical .pictogram-group {
  display: flex;
  flex: 1 0 6rem;
  flex-direction: column;
  align-items: center;
  min-width: 6rem;
  max-width: 14rem;
}

.pictogram-label {
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.pictogram-vertical .pictogram-label {
  order: 3;
  width: 100%;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 2px solid var(--ink-soft);
  text-align: center;
}

.pictogram-symbols {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem;
  min-height: 2rem;
  padding: 0.15rem 0;
}

.pictogram-vertical .pictogram-symbols {
  order: 2;
  flex-direction: column-reverse;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.pictogram-symbol {
  font-size: 1.75rem;
  line-height: 1;
  /* The glyph is decorative here: the accessible name comes from the
     accompanying table, so repeating it per symbol would be very noisy. */
}

.pictogram-symbol-image {
  display: inline-flex;
  flex: 0 0 1.75rem;
  width: 1.75rem;
  height: 1.75rem;
}

.pictogram-symbol-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* A half symbol.  Clipped to the left half with a clip-path so it reads as
   "half of one" rather than "a smaller one" — the conventional pictogram
   notation children are taught. */
.pictogram-symbol.half {
  clip-path: inset(0 50% 0 0);
  margin-right: -0.5ch;
}

.pictogram-symbol-image.half {
  margin-right: -0.875rem;
}

.pictogram-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  min-width: 3ch;
  text-align: right;
}

.pictogram-vertical .pictogram-count {
  order: 1;
  min-height: 1.5em;
  text-align: center;
}

/* ══ 5. Block / bar chart ══════════════════════════════════════════════════ */
.chart {
  display: grid;
  gap: 0.5rem;
}

/* Vertical chart: a grid of columns with the axis on the left. */
.chart-vertical {
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr auto;
  align-items: stretch;
  min-height: 18rem;
}

.chart-axis-y {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  padding-right: 0.4rem;
  border-right: 2px solid var(--ink-soft);
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.chart-plot {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: flex-end;
  gap: clamp(0.25rem, 2vw, 1.25rem);
  padding: 0 0.5rem;
  /* Horizontal gridlines drawn with a repeating gradient rather than elements:
     one paint, no extra DOM, and they scale with the plot height. */
  background-image: repeating-linear-gradient(
    to top,
    var(--line) 0 1px,
    transparent 1px var(--gridline-step, 20%)
  );
  border-bottom: 2px solid var(--ink-soft);
}

.chart-bar-wrap {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  min-width: 2rem;
  height: 100%;
  gap: 0.2rem;
}

.chart-bar {
  width: 100%;
  max-width: 5rem;
  min-height: 2px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 3px 3px 0 0;
  transition: height var(--transition-normal);
}

.chart-bar-value {
  font-size: var(--font-size-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-labels {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  gap: clamp(0.25rem, 2vw, 1.25rem);
  padding: 0.35rem 0.5rem 0;
}

.chart-label {
  flex: 1 1 0;
  min-width: 2rem;
  text-align: center;
  font-size: var(--font-size-sm);
  font-weight: 600;
  overflow-wrap: anywhere;
  hyphens: auto;
}

/* Horizontal chart: easier to read with long category names, which is why it
   is offered as a choice rather than fixed. */
.chart-horizontal {
  grid-template-columns: minmax(5rem, max-content) 1fr;
  align-items: center;
}

.chart-horizontal .chart-row-label {
  text-align: right;
  font-weight: 600;
  font-size: var(--font-size-sm);
  overflow-wrap: anywhere;
}

.chart-horizontal .chart-row-track {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border-left: 2px solid var(--ink-soft);
  padding-left: 0.25rem;
}

.chart-horizontal .chart-bar-h {
  height: 1.6rem;
  min-width: 2px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 0 3px 3px 0;
  transition: width var(--transition-normal);
}

.chart-axis-caption {
  margin-top: 0.5rem;
  text-align: center;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--ink-soft);
}

/* Unit elements are always present so switching chart style is immediate.
   Solid-bar mode hides them and uses the parent bar's continuous fill. */
.chart-unit {
  display: none;
}

.chart-blocks .chart-bar,
.chart-blocks .chart-bar-h {
  display: flex;
  gap: 3px;
  padding: 0;
  background-color: transparent !important;
  border: 0;
  border-radius: 0;
}

.chart-blocks .chart-bar {
  flex-direction: column-reverse;
}

.chart-blocks .chart-bar-h {
  flex-direction: row;
}

.chart-blocks .chart-bar::after,
.chart-blocks .chart-bar-h::after {
  display: none;
}

.chart-blocks .chart-unit {
  display: block;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  background-color: var(--unit-colour);
  border: 1px solid rgba(0, 0, 0, 0.55);
  border-radius: 2px;
}

.chart-blocks .chart-bar .chart-unit {
  width: 100%;
}

.chart-blocks .chart-bar-h .chart-unit {
  height: 100%;
}

/* ══ 6. Tally chart ════════════════════════════════════════════════════════ */
.tally {
  display: grid;
  grid-template-columns: minmax(6rem, max-content) 1fr auto;
  gap: 0.5rem 0.75rem;
  align-items: center;
}

.tally-label {
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.tally-label-controls {
  display: grid;
  grid-template-columns:
    var(--min-touch-target)
    minmax(6ch, 1fr)
    var(--min-touch-target);
  align-items: center;
  justify-self: stretch;
  gap: 0.3rem;
}

.tally-label-text {
  min-width: 0;
  text-align: center;
  overflow-wrap: anywhere;
}

.tally-adjust {
  display: inline-grid;
  align-items: center;
  justify-content: center;
  width: var(--min-touch-target);
  height: var(--min-touch-target);
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  font: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: 1;
  cursor: pointer;
}

.tally-adjust:hover:not(:disabled) {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}

.tally-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  min-height: 2.25rem;
  align-items: center;
}

/* A group of five: four uprights plus a diagonal drawn as a border on an
   overlay, which is exactly the notation taught in class. */
.tally-group {
  position: relative;
  display: flex;
  gap: 3px;
  padding: 0 2px;
}

.tally-stroke {
  width: 3px;
  height: 1.8rem;
  background: var(--ink);
  border-radius: 1px;
}

.tally-group.of-five::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  height: 3px;
  background: var(--ink);
  border-radius: 1px;
  transform: rotate(-20deg);
  transform-origin: center;
}

.tally-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  min-width: 3ch;
  text-align: right;
}

/* ══ 7. Branching database ═════════════════════════════════════════════════ */

/* Two presentations, both always in the DOM:
     .branch-tree  the interactive, keyboard-accessible diagram
     .branch-outline a nested <ul> used when the key is printed. */
.branch-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  flex: 1 1 auto;
}

.branch-pan-hint {
  margin: 0;
  color: var(--muted);
  font-size: var(--font-size-sm);
}

.branch-tree-viewport {
  width: 100%;
  height: auto;
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
  touch-action: pan-x pan-y;
  cursor: grab;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--panel-2) 38%, var(--panel));
}

.branch-tree-viewport:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus);
  outline-offset: var(--focus-ring-offset);
}

.branch-tree-viewport.is-panning {
  cursor: grabbing;
  user-select: none;
}

.branch-tree {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  box-sizing: border-box;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  overflow: visible;
  padding: 1rem 3rem 2rem;
}

.branch-subtree {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  min-width: max-content;
}

.branch-children {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0.75rem;
}

.branch-node {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 9rem;
  max-width: 14rem;
  padding: 0.55rem 0.7rem;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  text-align: left;
  cursor: pointer;
}

.branch-node:hover {
  background: var(--panel-2);
}

.branch-node[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.branch-node.is-question {
  border-style: solid;
}

/* Answers are visually distinct by shape (pill) and by a leading marker, not
   only by colour. */
.branch-node.is-answer {
  border-radius: 999px;
  border-style: dashed;
  text-align: center;
}

.branch-node-kind {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.branch-node-text {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.branch-edges {
  display: flex;
  gap: 0.35rem;
  font-size: 0.6875rem;
  color: var(--muted);
}

.branch-outline ul {
  margin: 0;
  padding-left: 1.5rem;
}

.branch-outline li {
  margin: 0.2rem 0;
}

.branch-answer-tag {
  font-weight: 700;
  color: var(--success);
}

/* The identify-it walkthrough: one question at a time with two big buttons.
   This is the mode children use to *use* a key someone else built. */
.branch-walk {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 1rem;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  text-align: center;
}

.branch-walk:focus {
  outline: var(--focus-ring-width) solid var(--focus);
  outline-offset: var(--focus-ring-offset);
}

.branch-walk-question {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
}

.branch-walk-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.branch-walk-buttons .btn {
  min-width: 8rem;
  min-height: 56px;
  font-size: var(--font-size-lg);
}

.branch-walk-answer {
  padding: 1rem 1.5rem;
  background: var(--panel);
  border: 3px solid var(--success);
  border-radius: var(--radius);
  font-size: 1.5rem;
  font-weight: 800;
}

.branch-walk-path {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--ink-soft);
  text-align: left;
  max-width: 34rem;
}

.branch-walk-path li {
  margin: 0.15rem 0;
}

/* ══ 8. Records and fields ═════════════════════════════════════════════════ */
.records-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.records-search {
  min-width: 12rem;
}

.records-search-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.records-search-controls input[type="search"] {
  min-width: 10rem;
}

.record-advanced-search {
  display: grid;
  gap: 0.9rem;
}

.record-advanced-search-join {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1.2rem;
  margin: 0;
  padding: 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.record-advanced-search-join legend,
.record-advanced-search-rule legend {
  padding-inline: 0.3rem;
  font-weight: 800;
}

.record-advanced-search-join label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: var(--min-touch-target);
}

.record-advanced-search-rules {
  display: grid;
  gap: 0.75rem;
}

.record-advanced-search-rule {
  display: grid;
  grid-template-columns:
    minmax(9rem, 1fr)
    minmax(10rem, 1fr)
    minmax(9rem, 1fr)
    auto;
  align-items: end;
  gap: 0.65rem;
  margin: 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}

.record-advanced-no-value {
  display: flex;
  align-items: center;
  min-height: var(--min-touch-target);
  margin: 0;
}

.record-advanced-search-status {
  min-height: 1.4em;
  margin: 0;
}

@media (max-width: 48rem) {
  .record-advanced-search-rule {
    grid-template-columns: 1fr;
  }

  .record-advanced-search-rule > .btn {
    justify-self: start;
  }
}

/* Sortable column headers are real buttons inside the <th>, with
   aria-sort on the <th>, which is the only pattern screen readers announce
   correctly. */
.data-table th .sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  width: 100%;
  min-height: var(--min-touch-target);
  padding: 0.2rem 0.1rem;
  background: transparent;
  border: 0;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.data-table th[aria-sort] .sort-btn::after {
  content: "\2195";
  margin-left: auto;
  color: var(--muted);
}

.data-table th[aria-sort="ascending"] .sort-btn::after {
  content: "\25B2";
  color: var(--accent);
}

.data-table th[aria-sort="descending"] .sort-btn::after {
  content: "\25BC";
  color: var(--accent);
}

.records-count {
  font-size: var(--font-size-sm);
  color: var(--ink-soft);
  font-weight: 600;
}

.record-picture {
  display: block;
  inline-size: 4.5rem;
  block-size: 4.5rem;
  object-fit: contain;
}

.record-picture-empty {
  color: var(--muted);
  font-size: var(--font-size-sm);
  font-style: italic;
}

.records-table tbody .record-selectable,
.record-card.record-selectable {
  cursor: pointer;
}

.records-table tbody .record-selectable:hover > * {
  background: color-mix(in srgb, var(--accent-soft) 50%, var(--panel));
}

.records-table tbody .record-selectable.is-selected > * {
  background: var(--accent-soft);
  box-shadow: inset 0 3px 0 var(--accent), inset 0 -3px 0 var(--accent);
}

.records-table tbody .record-selectable.is-selected > :first-child {
  box-shadow:
    inset 3px 0 0 var(--accent),
    inset 0 3px 0 var(--accent),
    inset 0 -3px 0 var(--accent);
}

.records-table tbody .record-selectable.is-selected > :last-child {
  box-shadow:
    inset -3px 0 0 var(--accent),
    inset 0 3px 0 var(--accent),
    inset 0 -3px 0 var(--accent);
}

.record-selectable:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.record-card.record-selectable:hover {
  border-color: var(--accent);
}

.record-card.record-selectable.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent);
}

.record-picture-editor {
  display: grid;
  gap: 0.45rem;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}

.record-picture-editor input[type="file"] {
  max-inline-size: 100%;
}

.record-picture-preview-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.record-picture-preview {
  inline-size: 6rem;
  block-size: 6rem;
  padding: 0.25rem;
  object-fit: contain;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.record-picture-preview[hidden],
.record-picture-preview-row > .btn[hidden] {
  display: none;
}

.record-picture-status,
.record-picture-form-status {
  min-block-size: 1.4em;
  margin: 0;
  font-size: var(--font-size-sm);
}

.record-create-form {
  display: grid;
  gap: 1rem;
}

.record-create-fieldset {
  display: grid;
  gap: 0.7rem;
  margin: 0;
  padding: 0.8rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.record-create-fieldset legend {
  padding-inline: 0.3rem;
  font-weight: 800;
}

.record-create-fields {
  display: grid;
  gap: 0.65rem;
}

.record-create-field-row {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) minmax(11rem, auto) auto;
  align-items: end;
  gap: 0.65rem;
}

.record-create-field-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.record-create-status {
  min-block-size: 1.4em;
  margin: 0;
}

@media (max-width: 42rem) {
  .record-create-field-row {
    grid-template-columns: 1fr;
  }

  .record-create-field-actions {
    justify-self: start;
  }
}

/* Record cards: the same records shown one per card, which is how the
   curriculum first introduces the idea of a record. */
.record-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.75rem;
}

.record-card {
  padding: 0.75rem;
  background: var(--panel);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.record-card dl {
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1fr;
  gap: 0.2rem 0.6rem;
  margin: 0;
}

.record-card dt {
  font-weight: 700;
  color: var(--ink-soft);
  font-size: var(--font-size-sm);
}

.record-card dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.record-card dd:empty::after {
  content: "not filled in";
  color: var(--muted);
  font-style: italic;
}

/* ══ 9. Features panel (bottom bar) ════════════════════════════════════════ */
.panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: var(--font-size-sm);
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-rows {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.9rem;
  min-width: 0;
}

.panel-group {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--panel-2) 45%, transparent);
}

.panel-group > .field-label {
  align-self: center;
}

.pictogram-image-control {
  align-items: center;
}

.pictogram-image-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--min-touch-target);
  min-height: var(--min-touch-target);
  padding: 0.25rem;
  background: var(--panel);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.pictogram-image-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.pictogram-image-button-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 2rem;
  width: 2rem;
  height: 2rem;
  object-fit: contain;
  font-size: 1.55rem;
  line-height: 1;
}

.data-editor-control {
  align-items: center;
}

.data-editor-launch-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: var(--min-touch-target);
  min-height: var(--min-touch-target);
  padding: 0.25rem 0.7rem;
  background: var(--panel);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.data-editor-launch-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.data-editor-launch-icon {
  flex: 0 0 1.75rem;
  width: 1.75rem;
  height: 1.75rem;
}

/* A segmented control: radio semantics, button appearance.  Real radios in a
   fieldset so arrow keys work and the group has a legend. */
.segmented {
  display: flex;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segmented-group-inline {
  align-items: center;
  flex-wrap: nowrap;
}

.segmented-visible-label {
  white-space: nowrap;
}

.pictogram-data-actions .btn {
  padding-inline: 0.55rem;
  white-space: nowrap;
}

.pictogram-data-actions .btn-icon {
  padding: 0.35rem;
}

.bar-chart-icon-groups {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  min-width: 0;
}

.bar-chart-icon-groups .panel-group {
  flex-wrap: nowrap;
}

/* Bar-chart segmented controls include a 2px inner border. Match that vertical
   footprint so moving to the compact Tally panel does not resize the bottom
   bar. */
.tally-panel-actions {
  padding-top: calc(0.25rem + 2px);
  padding-bottom: calc(0.35rem + 2px);
}

.segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.segmented label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--min-touch-target);
  min-height: var(--min-touch-target);
  padding: 0.35rem 0.7rem;
  background: var(--panel);
  border-right: 1px solid var(--line-strong);
  cursor: pointer;
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.segmented label svg {
  width: 1.5rem;
  height: 1.5rem;
  pointer-events: none;
}

.segmented label:last-of-type {
  border-right: 0;
}

.segmented input[type="radio"]:checked + label {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}

/* The focus ring must appear on the visible label, not the hidden input. */
.segmented input[type="radio"]:focus-visible + label {
  outline: var(--focus-ring-width) solid var(--focus);
  outline-offset: calc(-1 * var(--focus-ring-width));
  z-index: 1;
}

/* Stepper: a minus button, a number input, a plus button — every one 44px,
   which is the accessible alternative to dragging or to the native 12px
   spinner arrows (SC 2.5.7, 2.5.8). */
.stepper {
  display: flex;
  align-items: stretch;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stepper button {
  min-width: var(--min-touch-target);
  min-height: var(--min-touch-target);
  padding: 0 0.5rem;
  background: var(--panel-2);
  border: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
}

.stepper button:hover:not(:disabled) {
  background: var(--accent-soft);
}

.stepper input {
  width: 4.5rem;
  border: 0;
  border-left: 1px solid var(--line-strong);
  border-right: 1px solid var(--line-strong);
  border-radius: 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* The category editor inside the Data table panel. */
.cat-editor {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  max-height: 12rem;
  overflow-y: auto;
  padding-right: 0.25rem;
  scrollbar-width: thin;
}

.cat-row {
  display: grid;
  grid-template-columns: 1.5rem minmax(6rem, 1fr) auto auto;
  align-items: center;
  gap: 0.35rem;
}

.cat-row input[type="text"] {
  min-width: 0;
}

/* Symbol picker: a radio group of glyphs.  Each has a visible label for its
   name, because "star" must be available as text, not only as ★. */
.symbol-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  max-width: 22rem;
}

.symbol-option {
  position: relative;
}

.symbol-option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.symbol-option label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--min-touch-target);
  min-height: var(--min-touch-target);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  background: var(--panel);
}

.symbol-option input:checked + label {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.symbol-option input:focus-visible + label {
  outline: var(--focus-ring-width) solid var(--focus);
  outline-offset: var(--focus-ring-offset);
}

/* Small-screen features panel: stack the groups so nothing is cut off. */
@media (max-width: 640px) {
  .panel-rows {
    flex-direction: column;
    align-items: stretch;
  }
  .panel-group {
    flex-wrap: wrap;
  }
  .segmented-group-inline {
    align-items: flex-start;
  }
  .pictogram-horizontal .pictogram-group,
  .tally {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
  .pictogram-horizontal .pictogram-label,
  .tally-label {
    text-align: left;
    margin-top: 0.5rem;
  }
  .tally-label-controls {
    justify-self: stretch;
  }
  .pictogram-horizontal .pictogram-count,
  .tally-count {
    text-align: left;
  }
}

@media (forced-colors: active) {
  .series::after {
    /* Patterns rely on translucent white, which forced-colours flattens.
       Replace with a border-based distinction instead. */
    background: none;
  }
  .chart-bar,
  .chart-bar-h {
    background: Canvas !important;
    border: 2px solid CanvasText;
  }
  .chart-blocks .chart-bar,
  .chart-blocks .chart-bar-h {
    background: transparent !important;
    border: 0;
  }
  .chart-blocks .chart-unit {
    background: Canvas !important;
    border: 2px solid CanvasText;
  }
  .tally-stroke,
  .tally-group.of-five::after {
    background: CanvasText;
  }
  .swatch-dot {
    border: 2px solid CanvasText;
  }
}

/* ══ 10. Charts made from the records database ══════════════════════════════
   Two groups of styles:
     (a) the two wizard dialogs — the type chooser and the axis chooser;
     (b) the three SVG-based renderers (line, scatter, pie) and the grouped-bar
         additions to the existing bar renderer.

   The bar and pictogram renderers reuse the dataset chart classes above
   unchanged, which is deliberate: a bar chart drawn from records should look
   identical to one drawn from the data table, because to a child they are the
   same kind of object.

   These live here rather than in modals.css because they are data-tool
   concerns; modals.css stays responsible for dialog chrome only. */

/* ── (a) The type chooser ─────────────────────────────────────────────────── */
.chart-type-fieldset {
  margin: 0 0 0.75rem;
  padding: 0;
  border: 0;
}

.chart-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 0.6rem;
}

.chart-type-option {
  position: relative;
}

/* The radio is visually hidden but still focusable and still the thing that
   carries the state — never display:none, which would take it out of the tab
   order and out of the accessibility tree. */
.chart-type-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.chart-type-option label {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "thumb name"
    "thumb summary"
    "warn  warn";
  align-items: center;
  gap: 0.1rem 0.7rem;
  height: 100%;
  min-height: var(--min-touch-target);
  padding: 0.7rem 0.8rem;
  background: var(--panel);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.chart-type-option label:hover {
  background: var(--panel-2);
}

/* Selected state carries three simultaneous signals — fill, border weight and
   an inset ring — so it survives greyscale, forced colours and colour vision
   deficiency (SC 1.4.1). */
.chart-type-option input[type="radio"]:checked + label {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.chart-type-option input[type="radio"]:focus-visible + label {
  outline: var(--focus-ring-width) solid var(--focus);
  outline-offset: var(--focus-ring-offset);
}

.chart-type-option input[type="radio"]:disabled + label {
  opacity: 0.65;
  cursor: not-allowed;
}

.chart-type-thumb {
  grid-area: thumb;
  width: 48px;
  height: 36px;
  color: var(--muted);
}

.chart-type-name {
  grid-area: name;
  font-weight: 700;
}

.chart-type-summary {
  grid-area: summary;
  color: var(--muted);
  font-size: var(--font-size-sm);
  line-height: 1.35;
}

.chart-type-warning {
  grid-area: warn;
  margin-top: 0.35rem;
  color: var(--warning);
  font-size: var(--font-size-sm);
  font-weight: 700;
}

/* ── (a) The axis chooser ─────────────────────────────────────────────────── */
.chart-step-lead {
  margin-bottom: 1rem;
  padding: 0.6rem 0.8rem;
  background: var(--panel-2);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.chart-axis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
  align-items: start;
}

.chart-axis-column {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.chart-axis-mode {
  margin: 0;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
}

.chart-axis-mode legend {
  padding: 0 0.35rem;
}

.chart-radio-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chart-radio {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "radio label"
    ".     hint";
  align-items: center;
  gap: 0 0.5rem;
}

.chart-radio input[type="radio"] {
  grid-area: radio;
  /* 24px is the SC 2.5.8 minimum; the label beside it extends the hit area
     well past that, because a <label for> is part of the control's target. */
  width: 24px;
  height: 24px;
  margin: 0;
}

.chart-radio label {
  grid-area: label;
  min-height: var(--min-touch-target);
  display: flex;
  align-items: center;
  font-weight: 600;
  cursor: pointer;
}

.chart-radio .hint {
  grid-area: hint;
  margin: 0;
}

.chart-radio input[type="radio"]:disabled + label {
  opacity: 0.65;
  cursor: not-allowed;
}

.chart-axis-detail {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.chart-axis-detail .hint {
  margin: 0;
}

/* The live summary sentence.  Bordered and given room, because it is the only
   feedback a screen-reader user gets about what their choices will produce. */
.chart-axes-summary {
  margin: 1rem 0 0;
  padding: 0.7rem 0.85rem;
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  font-weight: 600;
  min-height: 3.25rem;
}

/* ── (b) SVG renderers: line and scatter ──────────────────────────────────── */
.chart-svg {
  display: block;
  width: 100%;
  max-width: 44rem;
  height: auto;
  margin: 0 auto;
}

.chart-svg-gridline {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-svg-axis {
  stroke: var(--ink-soft);
  stroke-width: 2;
}

.chart-svg-axis-label,
.chart-svg-tick {
  fill: var(--ink-soft);
  font-size: 12px;
  font-family: inherit;
}

.chart-svg-value {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
}

.chart-svg-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* A white ring round each dot keeps overlapping points distinguishable, which
   is the whole difficulty of reading a scatter graph. */
.chart-svg-dot {
  stroke: var(--panel);
  stroke-width: 2;
}

/* ── (b) Pie chart ────────────────────────────────────────────────────────── */
.chart-pie-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
}

.chart-pie {
  max-width: 20rem;
  flex: 0 1 20rem;
}

.chart-pie-slice {
  stroke: var(--panel);
  stroke-width: 2;
}

.chart-pie-label {
  fill: #ffffff;
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  /* A dark outline keeps the percentage legible on a light slice as well as a
     dark one, so no slice colour can make its own label unreadable. */
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* The legend is the only place a pie's categories are named, so it is a real
   list rather than a row of floating labels. */
.chart-legend {
  flex: 1 1 12rem;
  margin: 0;
  padding: 0;
  list-style: none;
  min-width: 0;
}

.chart-legend-item {
  display: flex;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.2rem 0;
  font-size: var(--font-size-sm);
  overflow-wrap: anywhere;
}

/* ── (b) Grouped bar additions ────────────────────────────────────────────── */
.chart-bar-cluster .chart-cluster-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  width: 100%;
  height: 100%;
}

.chart-cluster-bars .chart-bar {
  flex: 1 1 0;
  max-width: 2.5rem;
}

/* The second series is the same hue at reduced opacity plus a heavier outline,
   so the pair reads as "two of the same thing" rather than as two unrelated
   colours — and the outline keeps them apart in greyscale. */
.chart-bar-second {
  opacity: 0.55;
  border: 2px dashed rgba(0, 0, 0, 0.6);
}

.chart-horizontal .chart-bar-second {
  border-radius: 0 3px 3px 0;
}

@media (max-width: 640px) {
  .chart-type-grid {
    grid-template-columns: 1fr;
  }
  .chart-pie-wrap {
    flex-direction: column;
  }
}

@media (forced-colors: active) {
  .chart-type-option input[type="radio"]:checked + label {
    border: 3px solid Highlight;
    box-shadow: none;
  }
  .chart-svg-line,
  .chart-svg-axis {
    stroke: CanvasText;
  }
  .chart-svg-gridline {
    stroke: GrayText;
  }
  .chart-svg-dot,
  .chart-pie-slice {
    fill: Canvas;
    stroke: CanvasText;
    stroke-width: 2;
  }
  .chart-pie-label,
  .chart-svg-value,
  .chart-svg-tick,
  .chart-svg-axis-label {
    fill: CanvasText;
    stroke: none;
  }
  .chart-bar-second {
    opacity: 1;
    border: 2px dashed CanvasText;
  }
}

/* The grouped bar chart's series legend, shown under the chart on screen.  Laid
   out in a row rather than the pie's column, because there are only ever two
   entries and they read as a pair. */
.chart-series-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  justify-content: center;
  margin-top: 0.6rem;
  padding: 0.4rem 0;
  border-top: 1px solid var(--line);
}

.chart-series-legend .chart-legend-item {
  font-weight: 600;
}
