/* Engineering pad: squared green paper, ink, a ballpoint for your guess and a red marking pen for the score.
   Dark mode is the same idea on a green chalkboard. */

@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url("/fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url("/fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-display: swap; src: url("/fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; font-display: swap; src: url("/fonts/barlow-condensed-latin-700-normal.woff2") format("woff2"); }

:root {
  color-scheme: light;
  --paper: #e4ecd9;
  --sheet: #edf3e5;
  --grid: #d3dfc6;
  --grid-major: #b3c79f;
  --ink: #1e2b22;
  --ink-2: #46564a;
  --faint: #5a695d;
  --pen: #2440b5;
  --pen-ink: #ffffff;
  --mark: #c62a1e;
  --wash: #d6e2c8;
  --body: "Barlow", "DIN Alternate", "Arial Narrow", Arial, sans-serif;
  --title: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
}
:root.is-dark {
  color-scheme: dark;
  --paper: #1d2b24;
  --sheet: #22332b;
  --grid: #2a3c33;
  --grid-major: #3b5246;
  --ink: #e9efe4;
  --ink-2: #b9c6b6;
  --faint: #9aa99a;
  --pen: #f2d65c;
  --pen-ink: #1d2b24;
  --mark: #ff8a7a;
  --wash: #2c4036;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font: 17px/1.5 var(--body);
  /* 5 mm squares, as printed on the pad */
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 20px 20px,
    var(--paper);
}
a { color: var(--pen); text-underline-offset: 2px; }
.is-dark a { color: var(--ink); text-decoration-color: var(--pen); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.only-dark { display: none; }
.is-dark .only-dark { display: block; }
.is-dark .only-light { display: none; }

/* Page frame */
.top, .foot, main {
  width: 100%;
  max-width: 900px;
  margin-inline: auto;
  padding-inline: 16px;
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 10px;
  border-bottom: 2px solid var(--ink);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 700 24px/1 var(--title);
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
}
.is-dark .brand { color: var(--ink); }
.top-actions { display: flex; gap: 2px; }
.foot {
  margin-top: auto;
  padding-block: 20px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  font-size: 14px;
  color: var(--faint);
}
.foot a { color: var(--ink-2); }
.foot .keys { margin-left: auto; }
kbd {
  font: 600 13px/1 var(--body);
  padding: 2px 5px;
  border: 1px solid var(--ink-2);
  border-radius: 2px;
  background: var(--sheet);
  color: var(--ink);
}

/* Buttons: square-cornered, inked */
button { font: inherit; color: inherit; }
.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1.5px solid transparent;
  border-radius: 3px;
  background: none;
  color: var(--ink-2);
  text-decoration: none;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--ink-2); color: var(--ink); }
.icon-btn:disabled { opacity: 0.35; cursor: default; border-color: transparent; }
.icon-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.primary {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  min-width: 72px;
  padding: 0 16px;
  border: 0;
  border-radius: 3px;
  background: var(--pen);
  color: var(--pen-ink);
  font: 700 18px/1 var(--title);
  cursor: pointer;
}
.primary:hover { filter: brightness(1.12); }
.primary:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }
.primary .i { width: 24px; height: 24px; stroke-width: 2.4; }

/* Captions: hover tooltips on mouse devices, short captions on touch screens */
.caption { display: none; }
@media (hover: none), (pointer: coarse) {
  .caption { display: inline; }
  .toolbar .primary { width: 156px; white-space: nowrap; } /* fits the longest caption, so the button never resizes */
  .top-actions .icon-btn, .topics .icon-btn { width: 48px; height: 48px; grid-template-rows: auto auto; align-content: center; gap: 1px; }
  .top-actions .caption, .topics .caption { font-size: 11px; line-height: 1; }
}
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .primary { height: 44px; }
}

[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  translate: -50% 0;
  z-index: 10;
  padding: 4px 8px;
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper);
  font: 600 13px/1.4 var(--body);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}
[data-tip]:focus-visible::after { opacity: 1; }
@media (hover: hover) and (pointer: fine) { [data-tip]:hover::after { opacity: 1; } }
@media (hover: none), (pointer: coarse) { [data-tip]::after { display: none; } }
.top-actions [data-tip]::after, .topics [data-tip]::after { left: auto; right: 0; translate: none; }
.shapes [data-tip]:first-child::after { left: 0; translate: none; }

/* Round bar: score boxes, like the marks column on a form, then topic switches */
.round-bar { display: flex; align-items: center; gap: 12px; min-height: 44px; margin-top: 12px; }
.pips { display: flex; margin: 0; padding: 0; list-style: none; }
.pips li {
  display: grid;
  place-items: center;
  width: 38px;
  height: 30px;
  margin-left: -1.5px;
  border: 1.5px solid var(--ink-2);
  background: var(--sheet);
  font: 600 15px/1 var(--title);
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.pips li:first-child { margin-left: 0; }
.pips li.current { position: relative; z-index: 1; border: 2.5px solid var(--ink); color: var(--ink); }
.pips li.done { color: var(--mark); font-weight: 700; font-size: 17px; }
.total { margin-right: auto; font: 600 16px/1 var(--title); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.topics { display: flex; gap: 4px; }
.topics .icon-btn[aria-pressed="true"] { background: var(--wash); border-color: var(--ink); color: var(--ink); }
.topic[aria-pressed="false"] { border: 1.5px dashed var(--faint); color: var(--faint); }
.topic[aria-pressed="false"]:hover { border-style: solid; color: var(--ink); }

/* The question is the drawing's title block */
.question {
  display: flex;
  align-items: flex-end; /* spare space from the reserved second line sits above a one-line title */
  margin: 14px 0 0;
  min-height: 2.3em; /* two lines reserved so the chart and buttons never shift */
  font: 700 clamp(26px, 4.2vw, 36px)/1.08 var(--title);
  letter-spacing: -0.005em;
  text-wrap: balance;
}
.prompt { margin: 6px 0 10px; min-height: 3em; max-width: 80ch; color: var(--ink-2); font-size: 16px; line-height: 1.5; } /* two lines reserved */

.chart-wrap { position: relative; }
#chart {
  display: block;
  width: 100%;
  height: clamp(240px, calc(100dvh - 440px), 520px);
  border: 1.5px solid var(--ink-2);
  background: var(--sheet);
  touch-action: none;
  cursor: crosshair;
}
.chart-hint {
  position: absolute;
  inset: 0 24px 52px 40px;
  display: grid;
  place-items: center;
  margin: 0;
  text-align: center;
  text-wrap: balance;
  color: var(--ink-2);
  font: 600 20px/1.2 var(--title);
  pointer-events: none;
}

.toolbar { display: flex; align-items: center; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.shapes { display: flex; gap: 4px; padding-right: 8px; margin-right: 4px; border-right: 1.5px solid var(--grid-major); }
.shapes svg { width: 26px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; }
.toolbar .primary { margin-left: auto; }

.panel { margin-top: 12px; min-height: 132px; }
.sliders { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 28px; }
.slider { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; font-size: 15px; }
.slider span { color: var(--ink-2); }
.slider output { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.sliders-empty { grid-column: 1 / -1; margin: 0; color: var(--ink-2); font-size: 16px; }
.family-name { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; margin: 0; }
.family-name b { font: 700 19px/1.1 var(--title); }
.family-name span { color: var(--ink-2); font-size: 15px; }

/* Sliders as rulers: a scale with a tick every tenth and a square ink marker */
.slider input {
  grid-column: 1 / -1;
  width: 100%;
  height: 26px;
  margin: 2px 0 0;
  background: none;
  cursor: ew-resize;
  appearance: none;
}
.slider input::-webkit-slider-runnable-track {
  height: 26px;
  background:
    linear-gradient(var(--ink-2), var(--ink-2)) center / 100% 1.5px no-repeat,
    repeating-linear-gradient(90deg, var(--ink-2) 0 1px, transparent 1px 10%) center / 100% 9px no-repeat;
}
.slider input::-moz-range-track {
  height: 26px;
  background:
    linear-gradient(var(--ink-2), var(--ink-2)) center / 100% 1.5px no-repeat,
    repeating-linear-gradient(90deg, var(--ink-2) 0 1px, transparent 1px 10%) center / 100% 9px no-repeat;
}
.slider input::-webkit-slider-thumb {
  width: 12px;
  height: 24px;
  margin-top: 1px;
  border: 2px solid var(--sheet);
  border-radius: 1px;
  background: var(--pen);
  appearance: none;
}
.slider input::-moz-range-thumb {
  width: 8px;
  height: 20px;
  border: 2px solid var(--sheet);
  border-radius: 1px;
  background: var(--pen);
}
.slider input:focus-visible { outline: none; }
.slider input:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--ink); outline-offset: 1px; }
.slider input:focus-visible::-moz-range-thumb { outline: 2px solid var(--ink); outline-offset: 1px; }
@media (pointer: coarse) {
  /* separate rules: a browser drops a whole rule if it does not know one of its selectors */
  .slider input { height: 36px; }
  .slider input::-webkit-slider-runnable-track { height: 36px; }
  .slider input::-moz-range-track { height: 36px; }
  .slider input::-webkit-slider-thumb { width: 18px; height: 34px; }
  .slider input::-moz-range-thumb { width: 14px; height: 30px; }
}

/* Result: the score is marked in red pen, circled by hand */
.score-line { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; }
.score {
  display: inline-grid;
  place-items: center;
  min-width: 84px;
  height: 64px;
  padding: 0 14px;
  border: 2.5px solid var(--mark);
  border-radius: 48% 52% 44% 56% / 58% 46% 54% 42%;
  rotate: -4deg;
  color: var(--mark);
  font: 700 42px/1 var(--title);
  font-variant-numeric: tabular-nums;
}
.score-of { margin-left: -6px; color: var(--mark); font: 600 20px/1 var(--title); }
.metrics { font: 600 18px/1 var(--title); color: var(--ink); font-variant-numeric: tabular-nums; }
.legend { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 14px; }
.key { display: inline-block; width: 18px; }
.key.bars {
  height: 12px;
  border: 1.5px solid var(--ink-2);
  background: repeating-linear-gradient(-45deg, var(--ink-2) 0 1.5px, transparent 1.5px 4px);
}
.key.line { height: 3px; background: var(--pen); margin-left: 10px; border-radius: 2px; }
.note { margin: 10px 0 4px; max-width: 68ch; font-size: 18px; line-height: 1.45; }
.source { color: var(--ink-2); font-size: 15px; max-width: 76ch; }
.source summary { cursor: pointer; width: fit-content; }
.source summary:hover { color: var(--ink); }
.source p { margin: 4px 0 0; }

/* End-of-round sheet */
dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 22px 24px 24px;
  border: 2px solid var(--ink);
  border-radius: 2px;
  color: var(--ink);
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 20px 20px,
    var(--sheet);
}
dialog::backdrop { background: rgb(20 32 26 / 0.55); overflow: hidden; overscroll-behavior: contain; }
dialog:modal { overscroll-behavior: contain; }
dialog h2 { margin: 0; font: 700 22px/1.1 var(--title); }
.big-total { margin: 6px 0 0; font: 700 64px/1 var(--title); color: var(--mark); font-variant-numeric: tabular-nums; }
.big-total small { font-size: 26px; font-weight: 600; }
.best { margin: 2px 0 14px; color: var(--ink-2); font-size: 15px; }
.sum-list { margin: 0 0 20px; padding: 0; list-style: none; border-top: 1.5px solid var(--ink-2); }
.sum-list li { display: flex; gap: 12px; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--grid-major); font-size: 15px; }
.sum-list b { color: var(--mark); font: 700 18px/1.2 var(--title); font-variant-numeric: tabular-nums; }
.dialog-actions { display: flex; align-items: center; gap: 8px; }
.copied { color: var(--ink-2); font-size: 14px; }

/* Text pages */
.prose { padding-block: 8px 24px; }
.prose h1 { font: 700 clamp(32px, 5vw, 44px)/1.05 var(--title); margin: 20px 0 10px; }
.prose h2 { font: 700 24px/1.15 var(--title); margin: 30px 0 6px; }
.prose p, .prose li { max-width: 66ch; }
.prose .lead { font-size: 20px; line-height: 1.45; color: var(--ink-2); }
.prose code { font: 600 0.95em var(--body); background: var(--wash); padding: 0 4px; }
.src-list { padding: 0; list-style: none; border-top: 1.5px solid var(--ink-2); }
.src-list li { padding: 12px 0; border-bottom: 1px solid var(--grid-major); }
.src-list .q { font: 700 20px/1.2 var(--title); }
.src-list .meta { display: block; color: var(--ink-2); font-size: 15px; }

@media (max-width: 600px) {
  /* Topics get their own row, so the score boxes never reflow when the total appears. */
  .round-bar { flex-wrap: wrap; row-gap: 6px; }
  .topics { order: -1; width: 100%; justify-content: flex-end; }
  .shapes { border-right: 0; padding-right: 0; margin-right: 0; gap: 2px; }
  .toolbar .primary { flex: 1 0 100%; margin-left: 0; margin-top: 4px; }
  .legend { margin-left: 0; width: 100%; }
  .foot .keys { display: none; }
}

@media (min-width: 1000px) {
  /* Every title and prompt fits on one line at this width (checked for all puzzles), so reserve one line, not two. */
  .question { min-height: 1.08em; }
  .prompt { min-height: 1.5em; }
}

@media (prefers-reduced-motion: reduce) {
  [data-tip]::after { transition: none; }
}
