/* Loops board. Inherits the existing theme tokens (--text, --muted, --line, --accent,
   --ink, --action-text, --canvas); it introduces no colour of its own. */
.loops { display: grid; justify-items: center; gap: 1.25rem; width: 100%; color: inherit; }
/* The lattice keeps every side at a full-size target: a board wider than the screen scrolls
   inside this frame instead, so the page itself never scrolls sideways. */
.loops-frame { width: 100%; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
/* One narrow track for each lattice corner and one cell-sized track between them, so every
   side spans a whole cell: 3rem and never under 48px along its length, with --reach of extra
   tolerance either side of the line. The padding is --reach as well, so a side that overhangs
   the rim stays inside the frame. The renderer sets --columns and --rows for the board in hand.
   Both tracks are set in rem, so a board grows with the reader's text rather than crowding it.
   A side's thickness is the corner track plus --reach on each side, so the corner track states
   the 44px floor rather than leaving it to whatever 1.25rem happens to be: at the default text
   size the sides were 48x38, which is under the target every other family keeps. Widening the
   corner track rather than --reach keeps the overlap at each junction exactly where the design
   already put it; the lattice grows by a few pixels and scrolls inside its own frame on a
   narrow screen, as it already did. */
.loops-lattice {
  --reach: .55rem;
  --corner: max(1.25rem, calc(44px - 2 * var(--reach)));
  --cell: max(48px, 3rem);
  display: grid;
  grid-template-columns: repeat(var(--columns, 5), var(--corner) var(--cell)) var(--corner);
  grid-template-rows: repeat(var(--rows, 5), var(--corner) var(--cell)) var(--corner);
  width: max-content;
  margin-inline: auto;
  padding: var(--reach);
  background: color-mix(in srgb, currentColor 3%, transparent);
}
/* The corners are the board's only furniture, as they are on paper. */
.loops-dot { justify-self: center; align-self: center; width: max(5px, .3em); height: max(5px, .3em); border-radius: 50%; background: var(--line, #c2ccbd); }
/* A side reaches beyond its own narrow track, so the hit area is generous across the line as
   well as along it. Cells are not interactive, so nothing overlaps another target. */
.loops-edge { position: relative; box-sizing: border-box; z-index: 1; display: grid; place-items: center; margin: 0; padding: 0; font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; }
.loops-edge.is-across { width: 100%; height: calc(var(--corner) + 2 * var(--reach)); margin-block: calc(-1 * var(--reach)); }
.loops-edge.is-down { height: 100%; width: calc(var(--corner) + 2 * var(--reach)); margin-inline: calc(-1 * var(--reach)); }
.loops-edge::before { content: ''; position: absolute; background: transparent; border-radius: 999px; transition: background .15s ease; }
.loops-edge.is-across::before { top: 50%; right: 0; left: 0; height: 3px; transform: translateY(-50%); }
.loops-edge.is-down::before { top: 0; bottom: 0; left: 50%; width: 3px; transform: translateX(-50%); }
.loops-edge.is-drawn::before { background: currentColor; }
.loops-edge.is-across.is-drawn::before { height: 4px; }
.loops-edge.is-down.is-drawn::before { width: 4px; }
.loops-edge:hover:not(.is-drawn)::before { background: color-mix(in srgb, currentColor 28%, transparent); }
.loops-edge.is-crossed::before { background: transparent; }
.loops-edge:focus-visible { outline: 3px solid currentColor; outline-offset: -2px; }
/* A crossed-out side is the player's own note that no line runs there. */
.loops-ink { position: relative; z-index: 1; display: block; font-size: max(.7rem, .6em); line-height: 1; color: var(--muted, currentColor); }
.loops-cell { position: relative; box-sizing: border-box; width: 100%; height: 100%; min-width: 0; display: grid; place-items: center; margin: 0; padding: 0; font: inherit; font-size: clamp(1rem, 3.5vw, 1.35rem); font-variant-numeric: tabular-nums; line-height: 1; color: inherit; background: transparent; border: 0; cursor: pointer; }
.loops-number { display: block; }
/* A number with all its lines steps back quietly; one with too many is marked in text as well
   as colour, the way a repeated digit is marked on the Sudoku board. */
.loops-cell.is-met .loops-number { color: var(--muted, currentColor); }
.loops-cell.is-over .loops-number { color: var(--accent, currentColor); text-decoration: underline double; text-underline-offset: .16em; }
.loops-cell:hover { background: color-mix(in srgb, currentColor 6%, transparent); }
.loops-cell[aria-current="true"] { box-shadow: inset 0 0 0 3px var(--accent, currentColor); }
.loops-cell:focus-visible { outline: 3px solid currentColor; outline-offset: -4px; }
.loops-tally { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem 1.75rem; margin: 0; font-size: .875rem; }
.loops-metric { display: inline-flex; align-items: baseline; gap: .5rem; }
.loops-label { color: var(--muted, currentColor); }
.loops-value { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.loops-pad { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; width: min(100%, 22rem); }
.loops-key { min-height: 48px; min-width: 0; width: 100%; padding: .5rem .35rem; font: inherit; color: inherit; background: transparent; border: 1px solid currentColor; border-radius: 3px; cursor: pointer; }
.loops-key:hover:not(:disabled) { background: color-mix(in srgb, currentColor 8%, transparent); }
.loops-key:disabled { opacity: .55; cursor: default; }
.loops-key:focus-visible { outline: 3px solid currentColor; outline-offset: 4px; }
.loops-mode[aria-pressed="true"] { border-width: 3px; border-style: double; background: var(--accent, currentColor); color: var(--action-text, var(--canvas, #fff)); font-weight: 650; }
.loops-hint { max-width: 34rem; margin: 0; font-size: .875rem; line-height: 1.5; color: var(--muted, currentColor); }
.loops[data-state="solved"] .loops-edge.is-drawn::before { background: var(--accent, currentColor); }
.loops[data-state="blocked"] .loops-edge, .loops[data-state="waiting"] .loops-edge,
.loops[data-state="blocked"] .loops-cell, .loops[data-state="waiting"] .loops-cell { cursor: default; }
@media (max-width: 380px) {
  .loops { gap: 1rem; }
  .loops-pad { width: 100%; max-width: 100%; }
  .loops-key { padding: .5rem .1rem; }
  .loops-tally { gap: .3rem 1.1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .loops-edge::before { transition: none; }
}
@media (forced-colors: active) {
  .loops-dot { background: CanvasText; }
  .loops-edge.is-drawn::before { background: CanvasText; }
  .loops-ink { color: CanvasText; }
  .loops-cell.is-over { background: Highlight; color: HighlightText; }
  .loops-cell[aria-current="true"] { outline: 3px solid Highlight; outline-offset: -3px; }
  .loops-mode[aria-pressed="true"] { background: Highlight; color: HighlightText; }
}
