@font-face { font-family: "Plex Mono"; src: url("./fonts/IBMPlexMono-500.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("./fonts/IBMPlexSans-400.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
/* Fraunces draws the clue numbers on the board only; the chrome is Plex (minimal brief). */
@font-face { font-family: "Fraunces"; src: url("./fonts/fraunces.woff2") format("woff2"); font-weight: 400 800; font-display: swap; }

/* The board keeps its loom palette (--wall … --q-*): the game is about the cloth's colours.
 * The chrome around it uses the brief's greys (--bg, --text, --sub, --line, --frame, --band, --scrim).
 * "Loom at night" (dark) and "whitewash in shade" (light); [data-theme] overrides both. */
/* "Loom at night" (dark) and "whitewash in shade" (light). Dark is the
 * default under prefers-color-scheme: dark; [data-theme] overrides both. */
:root {
  color-scheme: light;
  --wall: #d6dbd9; --rail: #cbd1cf; --ink: #2a2119; --ink-dim: rgba(42, 33, 25, .56);
  --warp: #8f7656; --warp-ply: #5f4d36;
  --weft: #6b4f36; --weft-hi: #8a6a4c; --weft-sh: #4a3524; --weft-met: #4a3524;
  --knot: #a63b28; --knot-ring: #5a1d12;
  --clay: #8d5636; --clay-hi: #b97d55; --wood: #6e5946; --wood-hi: #9a8068;
  --lamp: rgba(255, 236, 170, .45); --guide: #8a6420; --flag: #b3261e; --focus: #2a2119;
  --line: #d4d4d4;
  --bg: #ffffff; --text: #111111; --sub: #5e5e5e; --frame: #1c1c1c; --band: rgba(0, 0, 0, .05); --scrim: rgba(255, 255, 255, .84);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --wall: #16171b; --rail: #1d1e23; --ink: #eadfc6; --ink-dim: rgba(234, 223, 198, .42);
    --warp: #cdb991; --warp-ply: #8c7a58;
    --weft: #ece1c6; --weft-hi: #fff8e6; --weft-sh: #b9ab8c; --weft-met: #c9b88f;
    --knot: #c4513a; --knot-ring: none;
    --clay: #a0623d; --clay-hi: #c4895f; --wood: #6e5946; --wood-hi: #8f7760;
    --lamp: rgba(255, 214, 140, .07); --guide: #d4a24c; --flag: #ff7a5c; --focus: #eadfc6;
    --line: #2f2f2f;
    --bg: #000000; --text: #ededed; --sub: #a6a6a6; --frame: #ededed; --band: rgba(255, 255, 255, .06); --scrim: rgba(0, 0, 0, .8);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --wall: #16171b; --rail: #1d1e23; --ink: #eadfc6; --ink-dim: rgba(234, 223, 198, .42);
  --warp: #cdb991; --warp-ply: #8c7a58;
  --weft: #ece1c6; --weft-hi: #fff8e6; --weft-sh: #b9ab8c; --weft-met: #c9b88f;
  --knot: #c4513a; --knot-ring: none;
  --clay: #a0623d; --clay-hi: #c4895f; --wood: #6e5946; --wood-hi: #8f7760;
  --lamp: rgba(255, 214, 140, .07); --guide: #d4a24c; --flag: #ff7a5c; --focus: #eadfc6;
  --line: #2f2f2f;
  --bg: #000000; --text: #ededed; --sub: #a6a6a6; --frame: #ededed; --band: rgba(255, 255, 255, .06); --scrim: rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  --mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--wall); color: var(--text);
  font: 400 16px/1.45 var(--sans); -webkit-text-size-adjust: 100%;
  height: 100vh; height: 100dvh; overflow: hidden;
  display: grid; min-width: 0;
}
button, input { font: inherit; color: inherit; }
button, a, input, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button { user-select: none; -webkit-user-select: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
a { color: inherit; }
kbd { font: 500 .9em/1 var(--mono); }

/* The cloth owns the screen: a one-line readout at the top, the bar at the bottom. */
body {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) calc(60px + env(safe-area-inset-bottom));
  grid-template-areas: "loom" "bar";
  padding-top: env(safe-area-inset-top);
}
.loom-area { grid-area: loom; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.loom-scroll { position: absolute; inset: 0; overflow: hidden; overscroll-behavior: none; }
.loom-scroll.zoomed { overflow: auto; }
#loom { display: block; cursor: crosshair; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.loom-area, .loom-scroll { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.loom-scroll:not(.zoomed), .loom-area { touch-action: none; }
.loom-scroll.panning #loom { touch-action: pan-x pan-y; cursor: grab; }

/* ── top readout: puzzle, size, time ── */
.readout { position: absolute; z-index: 2; top: 8px; left: 50%; transform: translateX(-50%); margin: 0; display: flex; gap: 1.4ch; white-space: nowrap; pointer-events: none;
  font: 500 13px/1 var(--mono); letter-spacing: .02em; font-variant-numeric: tabular-nums; color: var(--sub); }
.readout #clock { min-width: 4ch; }

/* ── bar: board actions left, Settings and Help right ── */
.bar { grid-area: bar; display: flex; justify-content: space-between; align-items: center; padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); background: var(--wall); }
.bar .group { display: flex; align-items: center; gap: 2px; }
.tools, .tools[hidden] { display: none; }
.ib { position: relative; flex: none; width: 48px; height: 48px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 0; background: none; color: var(--text); cursor: pointer; transition: opacity .15s, transform .1s; }
.ib:active { transform: scale(.94); }
.ib svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.ib svg circle { fill: currentColor; stroke: none; }
.ib svg .ring { fill: none; stroke: currentColor; }
.ib svg rect.m-fill { fill: currentColor; stroke: none; }
.ib:disabled { opacity: .32; cursor: default; }
@media (hover: hover) { .ib:hover:not(:disabled) { background: var(--band); } }
#mark-mode .m-dot { display: none; } #mark-mode[aria-pressed="true"] .m-fill { display: none; } #mark-mode[aria-pressed="true"] .m-dot { display: inline; }
#mark-mode[aria-pressed="true"] { background: var(--text); color: var(--wall); }
/* New, armed mid-weave: the strip asks for the second tap */
.ib[data-armed="true"] { background: var(--band); }
.bar button > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 359px) { .bar .group { gap: 0; } .bar .ib { width: 44px; } }
/* Landscape phones: the bar is a 64px rail on the right */
body[data-arr="land"] { grid-template-columns: minmax(0, 1fr) calc(64px + env(safe-area-inset-right)); grid-template-rows: minmax(0, 1fr); grid-template-areas: "loom bar"; }
body[data-arr="land"] .bar { flex-direction: column; justify-content: space-between; padding: max(4px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) 8px; overflow-y: auto; }
body[data-arr="land"] .bar .group { flex-direction: column; gap: 0; }
body[data-arr="land"] .ib { width: 48px; height: 44px; }

/* ── one-line strip above the bar ── */
.strip { position: fixed; z-index: 4; left: 50%; transform: translateX(-50%); bottom: calc(64px + env(safe-area-inset-bottom)); margin: 0; max-width: min(36rem, calc(100% - 32px)); padding: 6px 12px; background: var(--wall); color: var(--text); text-align: center; text-wrap: balance; }
.strip:empty { display: none; }
body[data-arr="land"] .strip { bottom: max(8px, env(safe-area-inset-bottom)); left: calc(50% - 32px); }

/* ── finished: a caption below the cloth and the next control ── */
.finish { position: absolute; z-index: 3; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.finish p { margin: 0; font: 500 13px/1.3 var(--mono); letter-spacing: .02em; font-variant-numeric: tabular-nums; color: var(--text); }

/* ── sheets: fixed head, only the body scrolls ── */
dialog.sheet { width: min(32rem, calc(100vw - 16px)); max-width: none; max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding: 0; margin: auto; border: 1px solid var(--frame); border-radius: 0; background: var(--bg); color: var(--text); overflow: hidden; }
dialog.sheet[open] { display: block; }
dialog.sheet::backdrop { background: var(--scrim); }
.sheet-in { max-height: calc(100dvh - 18px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); display: flex; flex-direction: column; min-height: 0; }
.sheet-head { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.sheet-head form { margin: 0; }
.sheet h2 { margin: 0; font: 500 16px/1.3 var(--mono); }
.sheet h2:focus { outline: none; }
.sheet-x { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 0; background: none; color: var(--text); cursor: pointer; }
.sheet-x svg { width: 24px; height: 24px; }
.sheet-body { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 20px 24px; }
.sheet p { margin: 0 0 16px; }
.sheet h3 { margin: 0 0 8px; font: 400 1em/1.4 var(--sans); }
.sheet section + section, .sheet section + details { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 16px; }
#more .sheet-body > section { display: grid; gap: 8px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 16px; min-height: 44px; margin: 0; }
.value, .session { color: var(--sub); font-variant-numeric: tabular-nums; }
.session { gap: 4px 24px; justify-content: flex-start; }
.session-note { color: var(--sub); margin: 8px 0; }
.text-action { appearance: none; min-width: 44px; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 0; background: none; color: var(--text); font: 500 15px/1.3 var(--mono); cursor: pointer; }
.text-action[aria-pressed="true"] { border-color: var(--frame); }
.text-action:disabled { opacity: .45; cursor: default; }
@media (hover: hover) { .text-action:hover:not(:disabled) { background: var(--band); } }
.sizes { border: 0; padding: 0; }
.sizes legend { float: left; padding: 0; margin-right: auto; line-height: 44px; }
.sizes .choices { display: flex; gap: 4px; margin-left: auto; }
.sizes label { position: relative; display: grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0 8px; border: 1px solid transparent; color: var(--sub); font: 500 15px/1 var(--mono); cursor: pointer; }
.sizes input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.sizes label:has(input:checked) { border-color: var(--frame); color: var(--text); }
.sizes label:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
.check { cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 12px; accent-color: var(--text); flex: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.sheet-foot { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 20px; }
.foot-btn { display: inline-flex; align-items: center; min-height: 44px; color: var(--sub); text-underline-offset: 3px; }
.bolt summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.bolt h3 { margin: 12px 0 2px; }
.bolt-sub { margin: 0 0 6px; color: var(--sub); }
.bolt-strip { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; }
.bolt-strip button { flex: none; border: 1px solid var(--line); border-radius: 0; background: transparent; padding: 3px; cursor: pointer; }
.bolt-strip canvas { display: block; height: 96px; width: auto; }
.empty { color: var(--sub); }
.awards { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 0; }
.awards li { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0 16px; padding: 8px 0; border-top: 1px solid var(--line); color: var(--sub); }
.awards li.got { color: var(--text); }
.awards b { font-weight: 400; }
.book h3 { margin: 16px 0 8px; color: var(--sub); }
.book section:first-child h3 { margin-top: 0; }
.book-row { display: flex; flex-wrap: wrap; gap: 8px; }
.book-pic { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 90px; padding: 10px; border: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--text); cursor: pointer; font: 500 13px/1.2 var(--mono); }
@media (hover: hover) { .book-pic:hover, .bolt-strip button:hover { background: var(--band); } }
.book-pic canvas { width: 60px; height: 60px; image-rendering: pixelated; }
@media (max-width: 480px) { .sheet-body { padding: 16px; } .sheet-head { padding: 8px 12px; } }

/* ── ?tune=1 (review only) ── */
.tune { position: fixed; z-index: 40; right: 8px; top: 52px; width: 240px; max-height: calc(100dvh - 140px); overflow: auto; padding: 8px 10px; border: 1px solid var(--line); background: var(--bg); font: 400 12px/1.3 var(--mono); }
.tune label { display: grid; grid-template-columns: 74px 1fr 38px; align-items: center; gap: 4px; }
.tune input { width: 100%; }
.tune .btn { min-height: 32px; padding: 2px 10px; margin-top: 6px; border: 1px solid var(--line); border-radius: 0; background: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Quipu material palette: the knot is the filled cell; a red cross stays bare. */
:root { --q-cord: #8f7656; --q-cord-ply: #5f4d36; --q-cord-b: #77613f; --q-cord-b-ply: #4f3f2a;
 --q-knot: #4a3524; --q-knot-sh: #2e2116; --q-num: #f4efe6; --q-weft: #7d7466; --q-weft-2: #6c6457; --q-primary: #5e4a39; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
 --q-cord: #a8966f; --q-cord-ply: #6e6048; --q-cord-b: #7d6a4e; --q-cord-b-ply: #54462f;
 --q-knot: #ece1c6; --q-knot-sh: #b9ab8c; --q-num: #16171b; --q-weft: #8a8070; --q-weft-2: #9d927f; --q-primary: #8e7965; } }
:root[data-theme="dark"] {
 --q-cord: #a8966f; --q-cord-ply: #6e6048; --q-cord-b: #7d6a4e; --q-cord-b-ply: #54462f;
 --q-knot: #ece1c6; --q-knot-sh: #b9ab8c; --q-num: #16171b; --q-weft: #8a8070; --q-weft-2: #9d927f; --q-primary: #8e7965; }
@media (forced-colors: active) {
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) { --wall:Canvas; --rail:Canvas; --bg:Canvas; --text:CanvasText; --sub:CanvasText; --frame:CanvasText; --ink:CanvasText; --ink-dim:GrayText; --line:CanvasText; --focus:Highlight; --guide:Highlight; --knot:Highlight; }
  canvas { forced-color-adjust:none; }
  .text-action[aria-pressed="true"], #mark-mode[aria-pressed="true"] { outline: 2px solid Highlight; outline-offset: -3px; }
  .sizes label:has(input:checked) { border-color: Highlight; }
}

/* How to play: Notan's interactive lessons in Quipu's materials (2026-10-06).
   A practice cell is a cord crossing; a knot is a cream bead, a bare cell a red overhand knot. */
#howto .lesson-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
#howto .lesson-heading h3 { margin: 0; }
#lesson-count { color: var(--sub); }
#lesson-count { white-space: nowrap; }
#howto .practice-line { display: grid; grid-template-columns: 1fr min(calc(100% - 5em), 280px) 1fr; justify-content: center; align-items: center; column-gap: 12px; row-gap: 8px; margin: 18px 0 10px; }
#practice-clue { grid-column: 1; justify-self: end; font: 600 20px/1.3 "Fraunces", Georgia, serif; text-align: right; white-space: nowrap; }
#practice { grid-column: 2; width: 100%; touch-action: none; user-select: none; }
#practice-row { display: grid; grid-template-columns: repeat(5, 1fr); }
.practice-cell { aspect-ratio: 1; min-width: 44px; min-height: 44px; position: relative; border: 1px solid var(--line); border-right: 0; background: linear-gradient(var(--q-cord), var(--q-cord)) center / 3px 100% no-repeat; touch-action: none; }
.practice-cell:last-child { border-right: 1px solid var(--line); }
.practice-cell.ink::before { content: ""; position: absolute; inset: 20% 24%; border-radius: 45%; background: var(--q-knot); box-shadow: inset 0 -3px 0 var(--q-knot-sh); }
.practice-cell.mark::before { content: ""; position: absolute; inset: 22%; background: var(--knot);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.2' stroke-linecap='round'%3E%3Cpath d='M12 1v4c0 2 4 2 5 5s-1 7-5 7-6-3-5-6 4-3 5-1 0 5 0 7v6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.2' stroke-linecap='round'%3E%3Cpath d='M12 1v4c0 2 4 2 5 5s-1 7-5 7-6-3-5-6 4-3 5-1 0 5 0 7v6'/%3E%3C/svg%3E") center / contain no-repeat; }
.practice-cell:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
#lesson-possibilities { grid-column: 2; }
#lesson-possibilities:not([hidden]) { display: grid; gap: 6px; }
.possibility { display: grid; grid-template-columns: repeat(5, 1fr); height: 14px; border: 1px solid var(--line); }
.possibility i { border-right: 1px solid var(--line); }
.possibility i:last-child { border-right: 0; }
.possibility i.on { background: var(--q-knot); }
#howto .practice-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 22px; }
#practice-feedback { margin: 6px 0 8px; min-height: 1.45em; text-align: center; color: var(--sub); }
#practice-reset[hidden] { display: none; }
#howto .lesson-nav { display: flex; justify-content: space-between; gap: 8px; }
/* Controls, at a glance (Luke, 2026-10-06: "don't need much more text whatsoever"). */
#howto .controls { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
#howto .controls div { display: flex; flex-wrap: wrap; gap: 0 .5ch; }
#howto .controls dt { font-weight: 400; }
#howto .controls dt::after { content: " \2014"; font-weight: 400; }
#howto .controls dd { margin: 0; }

/* The possibility bars keep their space in every lesson, so the sheet never changes height. */
#lesson-possibilities { display: grid !important; }
#lesson-possibilities.is-off { visibility: hidden; }

/* Lesson tasks reserve two lines, so a one-line task does not shrink the sheet. */
#lesson-task { min-height: 2lh; }

/* Holding a lesson square marks it; it must not start a text selection or callout. */
#howto { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* Double-tap zoom: touch-action is intersected across every ancestor, so
   manipulation on the root stops double-tap zoom page-wide (readouts, gaps
   between controls, sheet backdrops) while pinch zoom still works. */
html, body { touch-action: manipulation; }
