/* Fig. 06 · Aristotle's puzzle: hex board, line sums, backtracking search.
   Copper for structure, phosphor only for the live cell and lines at 38, fault for conflicts. */

.demo--aristotle {
  container: ar / inline-size;
  display: grid;
  gap: 12px;
  padding: clamp(16px, 4cqw, 20px);
  color: var(--text-1);
}
.demo--aristotle .ctl { min-height: 40px; }

/* ---------------------------------------------------------------- toolbar */
.demo--aristotle .ar-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.demo--aristotle .ar-go { min-width: 78px; }
.demo--aristotle .ar-speed { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.demo--aristotle .switch { padding: 2px; }
.demo--aristotle .switch > button { min-height: 36px; min-width: 44px; }

/* ---------------------------------------------------------------- layout */
.demo--aristotle .ar-main { display: grid; gap: 12px; align-items: start; }
.demo--aristotle .ar-side { display: contents; }
.demo--aristotle .ar-pad { order: 1; }
.demo--aristotle .ar-ro { order: 2; }
.demo--aristotle .ar-sols { order: 3; }

/* ---------------------------------------------------------------- board */
.demo--aristotle .ar-stage {
  display: grid; place-items: center; padding: 8px;
  border-radius: var(--r-2); background: var(--bg-0); box-shadow: inset 0 0 0 1px var(--line-1);
}
.demo--aristotle .ar-board { position: relative; width: 100%; max-width: 400px; container-type: inline-size; user-select: none; -webkit-user-select: none; }
.demo--aristotle .ar-traces { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.demo--aristotle .ar-traces path { fill: none; stroke-width: 1; vector-effect: non-scaling-stroke; }
.demo--aristotle .ar-rail { stroke: var(--accent); opacity: 0; transition: opacity 0.2s; }
.demo--aristotle .ar-rail.is-hl { opacity: 1; }
.demo--aristotle .ar-stub { stroke: var(--accent-lo); transition: stroke 0.2s; }
.demo--aristotle .ar-stub.is-ok { stroke: var(--signal); }
.demo--aristotle .ar-stub.is-bad { stroke: var(--fault); }
.demo--aristotle .ar-via { fill: var(--bg-0); stroke: var(--accent-lo); stroke-width: 1; vector-effect: non-scaling-stroke; }

.demo--aristotle .ar-cell {
  position: absolute; display: grid; place-items: center;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  font-family: var(--f-mono); font-size: calc(var(--s) * 0.58); font-weight: 500; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em; color: var(--text-1);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.demo--aristotle .ar-cell:focus-visible { outline: none; }
.demo--aristotle .ar-cell svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.demo--aristotle .ar-cell polygon {
  fill: var(--bg-2); stroke: var(--line-2); stroke-width: 1; vector-effect: non-scaling-stroke;
  transition: fill 0.25s, stroke 0.25s;
}
.demo--aristotle .ar-cell span { position: relative; transition: color 0.25s; }
@media (hover: hover) {
  .demo--aristotle .ar-cell:hover polygon { fill: var(--bg-3); stroke: var(--line-3); }
}
.demo--aristotle .ar-cell[data-s="user"] polygon { fill: var(--bg-3); stroke: var(--line-3); }
.demo--aristotle .ar-cell[data-s="set"] polygon { fill: color-mix(in srgb, var(--accent) 9%, var(--bg-1)); stroke: var(--accent-lo); }
.demo--aristotle .ar-cell[data-s="set"] span { color: var(--accent-hi); }
.demo--aristotle .ar-cell[data-s="try"] polygon { fill: color-mix(in srgb, var(--signal) 14%, var(--bg-1)); stroke: var(--signal); }
.demo--aristotle .ar-cell[data-s="try"] span { color: var(--signal); }
.demo--aristotle .ar-cell[data-s="bad"] polygon,
.demo--aristotle .ar-cell[data-s="pop"] polygon { fill: color-mix(in srgb, var(--fault) 14%, var(--bg-1)); stroke: var(--fault); }
.demo--aristotle .ar-cell[data-s="bad"] span { color: var(--fault); }
/* live states snap on, then fade out through the base transition (a short afterglow) */
.demo--aristotle .ar-cell[data-s="try"] polygon, .demo--aristotle .ar-cell[data-s="try"] span,
.demo--aristotle .ar-cell[data-s="bad"] polygon, .demo--aristotle .ar-cell[data-s="bad"] span,
.demo--aristotle .ar-cell[data-s="pop"] polygon { transition: none; }
.demo--aristotle .ar-cell.is-hl polygon { stroke: var(--accent-hi); }
.demo--aristotle .ar-cell.is-sel polygon,
.demo--aristotle .ar-cell:focus-visible polygon { stroke: var(--accent); stroke-width: 2; }
.demo--aristotle.is-solved .ar-cell span { color: var(--text-1); }

.demo--aristotle .ar-sum {
  position: absolute; display: grid; place-items: center;
  border-radius: 3px; background: var(--bg-1); box-shadow: inset 0 0 0 1px var(--line-2);
  font-family: var(--f-mono); font-size: calc(var(--s) * 0.4); font-weight: 500; line-height: 1;
  font-variant-numeric: tabular-nums; color: var(--text-3); cursor: default;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
}
.demo--aristotle .ar-sum.is-ok { color: var(--signal); background: color-mix(in srgb, var(--signal) 9%, var(--bg-0)); box-shadow: inset 0 0 0 1px var(--signal-a40); }
.demo--aristotle .ar-sum.is-bad { color: var(--fault); background: color-mix(in srgb, var(--fault) 11%, var(--bg-0)); box-shadow: inset 0 0 0 1px var(--fault); }
.demo--aristotle .ar-sum.is-hl { box-shadow: inset 0 0 0 1px var(--accent); }
.demo--aristotle .ar-sum.is-hl:not(.is-ok):not(.is-bad) { color: var(--text-1); }

/* ---------------------------------------------------------------- readouts, pad, solutions */
.demo--aristotle .ar-ro { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.demo--aristotle .readout { min-width: 0; padding: 6px 10px; }
.demo--aristotle .readout b { line-height: 1.3; white-space: nowrap; }

.demo--aristotle .ar-pad { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.demo--aristotle .ar-key {
  min-height: 36px; border-radius: 5px; background: var(--bg-2); box-shadow: inset 0 0 0 1px var(--line-1), var(--edge);
  font-family: var(--f-mono); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--text-1);
  transition: background 0.15s, color 0.15s; touch-action: manipulation;
}
.demo--aristotle .ar-key:hover { background: var(--bg-3); }
.demo--aristotle .ar-key:active { background: var(--bg-4); }
.demo--aristotle .ar-key.is-used { color: var(--text-4); }
.demo--aristotle .ar-key--del { grid-column: span 2; font-size: 11px; letter-spacing: 0; color: var(--text-3); }

.demo--aristotle .ar-sols { display: grid; gap: 6px; }
.demo--aristotle .ar-sols__row { display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px; gap: 6px; align-items: center; }
.demo--aristotle .ar-sols__row .ctl { padding: 0; }
.demo--aristotle .ar-sols__row .ctl svg { width: 10px; height: 10px; }
.demo--aristotle .ar-sols__sum { margin: 0; font-size: 11px; line-height: 1.4; color: var(--text-2); }
.demo--aristotle .ar-sols__note { margin: 0; font-size: 12px; line-height: 1.4; color: var(--text-3); min-height: 2.8em; }

/* ---------------------------------------------------------------- footer */
.demo--aristotle .ar-foot { display: flex; align-items: center; gap: 10px; min-height: 20px; padding-top: 2px; }
.demo--aristotle .ar-status { margin: 0; min-width: 0; font-family: var(--f-mono); font-size: 12px; line-height: 1.45; color: var(--text-2); }
.demo--aristotle .ar-cap { margin: 0; }

/* ---------------------------------------------------------------- widths */
@container ar (max-width: 459px) {
  .demo--aristotle .ar-bar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .demo--aristotle .ar-bar > .ctl { min-width: 0; padding: 0; }
  .demo--aristotle .ar-speed { grid-column: 1 / -1; margin-left: 0; justify-content: space-between; }
  .demo--aristotle .ar-sols__note { min-height: 0; }
}
@container ar (min-width: 400px) and (max-width: 579px) {
  .demo--aristotle .ar-ro { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@container ar (min-width: 580px) {
  .demo--aristotle .ar-main { grid-template-columns: minmax(0, 1fr) 216px; }
  .demo--aristotle .ar-stage { padding: 10px; }
  .demo--aristotle .ar-side { display: grid; gap: 12px; align-content: start; }
  .demo--aristotle .ar-ro { order: 0; }
  .demo--aristotle .ar-pad { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .demo--aristotle .ar-key--del { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .demo--aristotle .ar-cell polygon, .demo--aristotle .ar-cell span, .demo--aristotle .ar-sum, .demo--aristotle .ar-stub { transition: none; }
}
