/* Haberdash: one phone-height column per puzzle. Shared thread palette: teal, madder, mustard, plum on a cool chalk paper. */
:root {
  --paper: #EDF0EA;
  --surface: #FAFBF8;
  --ink: #1C2A2B;
  --muted: #5A6A68;
  --rule: #D3DAD3;
  --pick: #CCD5CE;
  --thread: #6FCBBD;
  --line: #F28CA0;
  --warm: #F0C255;
  --plum: #C3B1E8;
  --bad: #C2362C;
  --on-fill: #14201F;
  --stitch: #FAFBF8;
  --display: "Bricolage Grotesque", "Trebuchet MS", "Segoe UI", sans-serif;
  --body: "Figtree", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0F1B1B; --surface: #182827; --ink: #E6EEEA; --muted: #93A5A1; --rule: #2A3D3C;
    --pick: #3A5152; --thread: #1F7F74; --line: #C2415A; --warm: #9A7016; --plum: #6A57A5;
    --bad: #F0786E; --on-fill: #F4F8F5; --stitch: #0F1B1B;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0F1B1B; --surface: #182827; --ink: #E6EEEA; --muted: #93A5A1; --rule: #2A3D3C;
  --pick: #3A5152; --thread: #1F7F74; --line: #C2415A; --warm: #9A7016; --plum: #6A57A5;
  --bad: #F0786E; --on-fill: #F4F8F5; --stitch: #0F1B1B;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font-family: var(--body); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.app { height: 100%; max-width: 480px; margin: 0 auto; padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }
.mark { font-family: var(--display); font-weight: 800; font-size: 30px; letter-spacing: -0.03em; margin: 0; line-height: 1; }
.mark span { color: var(--line); }
.gname { font-family: var(--display); font-weight: 800; font-size: 22px; letter-spacing: -0.02em; margin: 0; flex: 1; }
.back { font-weight: 600; font-size: 14px; text-decoration: none; border: 1.5px solid var(--ink); border-radius: 999px; padding: 0 12px; min-height: 40px; display: inline-flex; align-items: center; white-space: nowrap; }
.btn { border: 1.5px solid var(--ink); background: transparent; border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px; min-height: 40px; white-space: nowrap; }
.btn.solid { background: var(--ink); color: var(--paper); }
.btn.on { background: var(--thread); border-color: var(--thread); color: var(--on-fill); }
.btn:disabled { opacity: .45; cursor: default; }
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.live { min-height: 34px; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; font-size: 22px; letter-spacing: .08em; text-align: center; }
.live.msg { font-family: var(--body); font-weight: 600; font-size: 15px; letter-spacing: 0; color: var(--muted); }
.live.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; flex-wrap: wrap; }
.count { font-size: 15px; color: var(--muted); }
.count b { color: var(--ink); font-variant-numeric: tabular-nums; }
.done { font-size: 15px; }
.done strong { font-family: var(--display); font-size: 18px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pill { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 9px; border: 1.5px solid var(--rule); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--thread); border-color: var(--thread); color: var(--on-fill); }

/* menu */
.lede { margin: 2px 0 2px; font-size: 16px; color: var(--muted); max-width: 34ch; }
.menu { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; flex: 1; min-height: 0; }
.card { display: flex; align-items: center; gap: 12px; text-decoration: none; background: var(--surface); border: 1.5px solid var(--rule); border-radius: 12px; padding: 8px 12px; flex: none; }
.card:hover { border-color: var(--ink); }
.card svg { width: 42px; height: 42px; flex: none; }
.card .what { flex: 1; min-width: 0; }
.card h2 { font-family: var(--display); font-weight: 700; font-size: 19px; letter-spacing: -0.02em; margin: 0; }
.card p { margin: 1px 0 0; font-size: 13px; color: var(--muted); line-height: 1.25; }
.note { font-size: 13px; color: var(--muted); margin: 0; }

/* dialog */
dialog { border: 1.5px solid var(--rule); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 18px; width: min(92vw, 420px); max-height: 86%; }
dialog::backdrop { background: rgba(10, 20, 20, .55); }
dialog h3 { font-family: var(--display); font-size: 22px; margin: 0 0 10px; letter-spacing: -0.02em; }
dialog p, dialog li { font-size: 15px; line-height: 1.5; }
dialog ul { padding-left: 20px; margin: 0 0 14px; }
.list { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 6px; }
.list button { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; background: var(--paper); border: 1.5px solid var(--rule); border-radius: 10px; padding: 10px 12px; min-height: 46px; }
.list button[aria-current="true"] { border-color: var(--ink); }
.list .n { font-variant-numeric: tabular-nums; color: var(--muted); width: 22px; flex: none; }
.list .c { flex: 1; font-weight: 600; }
.row { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; margin-right: 2px; }

/* on-screen keyboard */
.kb { display: flex; flex-direction: column; gap: 6px; user-select: none; -webkit-user-select: none; }
.kb div { display: flex; gap: 5px; justify-content: center; }
.kb button { flex: 1; max-width: 44px; height: 48px; border: 0; border-radius: 7px; background: var(--pick); font-weight: 700; font-size: 15px; padding: 0; }
.kb button.wide { flex: 1.6; max-width: 70px; font-size: 12px; }
.kb button.c { background: var(--thread); color: var(--on-fill); }
.kb button.p { background: var(--warm); color: var(--on-fill); }
.kb button.a { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1.5px var(--rule); }
.kb button.used { background: transparent; box-shadow: inset 0 0 0 1.5px var(--rule); color: var(--muted); }

/* Skein */
.clue { background: var(--surface); border: 1.5px solid var(--rule); border-left: 6px solid var(--thread); border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.clue h2 { font-family: var(--display); font-weight: 700; font-size: 23px; letter-spacing: -0.02em; margin: 2px 0 0; text-wrap: balance; line-height: 1.15; }
.boardwrap { flex: 1; min-height: 0; display: flex; }
.board { width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.board text { font-family: var(--body); font-weight: 600; font-size: 46px; fill: var(--ink); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.board text.on { fill: var(--on-fill); }
.board .dot { fill: var(--surface); }
.board .path { stroke-width: 20; stroke-linecap: round; stroke-linejoin: round; }
.board .stitch { fill: none; stroke: var(--stitch); stroke-width: 3; stroke-dasharray: 9 11; stroke-linecap: round; opacity: .75; }
.board .t { fill: var(--thread); stroke: var(--thread); }
.board .s { fill: var(--line); stroke: var(--line); }
.board .p { fill: var(--pick); stroke: var(--pick); }
.board polyline.path { fill: none; }
.board .ring { fill: none; stroke: var(--ink); stroke-width: 4; stroke-dasharray: 8 9; }
.board .order { fill: none; stroke: var(--ink); stroke-width: 4; stroke-dasharray: 2 12; stroke-linecap: round; }
.board .pop { animation: pop .35s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes pop { 0% { transform: scale(.7); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
.hint { position: relative; overflow: hidden; isolation: isolate; }
.hint i { position: absolute; inset: 0 auto 0 0; background: var(--thread); z-index: -1; transition: width .25s; }
.trail { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.trail span { width: 14px; height: 14px; border-radius: 50%; background: var(--thread); }
.trail .s { background: var(--line); }
.trail .h { background: transparent; border: 2.5px dashed var(--ink); }

/* Plaid */
.fit { flex: 1; min-height: 0; container-type: size; display: flex; align-items: center; justify-content: center; }
.pgrid { width: min(100cqw, 100cqh * 5 / 6, 340px); aspect-ratio: 5 / 6; display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(6, 1fr); gap: 6px; }
.pgrid div { display: flex; align-items: center; justify-content: center; border: 2px solid var(--rule); border-radius: 6px; font-weight: 700; font-size: clamp(18px, 7cqw, 30px); text-transform: uppercase; background: var(--surface); }
.pgrid .f { border-color: var(--ink); }
.pgrid .c { background: var(--thread); border-color: var(--thread); color: var(--on-fill); }
.pgrid .p { background: var(--warm); border-color: var(--warm); color: var(--on-fill); }
.pgrid .a { background: var(--pick); border-color: var(--pick); color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-family: var(--display); font-size: 24px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.result { background: var(--surface); border: 1.5px solid var(--rule); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }

/* Four Ply */
.fgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.fgrid button { aspect-ratio: 1 / .78; border: 0; border-radius: 8px; background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--rule); font-weight: 700; font-size: 13px; padding: 2px; overflow-wrap: anywhere; line-height: 1.1; }
.fgrid button.long { font-size: 10.5px; }
.fgrid button.sel { background: var(--ink); color: var(--paper); box-shadow: none; }
.groups { display: flex; flex-direction: column; gap: 6px; }
.grp { border-radius: 8px; padding: 10px 8px; text-align: center; color: var(--on-fill); }
.grp b { display: block; font-family: var(--display); font-size: 16px; }
.grp span { font-size: 13px; font-weight: 500; }
.g0 { background: var(--thread); } .g1 { background: var(--warm); } .g2 { background: var(--line); } .g3 { background: var(--plum); }
.grp.missed { outline: 2.5px dashed var(--ink); outline-offset: -5px; }
.lives { display: inline-flex; gap: 5px; vertical-align: middle; margin-left: 6px; }
.lives i { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); }
.lives i.off { background: transparent; box-shadow: inset 0 0 0 2px var(--rule); }
.scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Nine Patch */
.sgrid { width: min(100cqw, 100cqh); aspect-ratio: 1; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); border: 2.5px solid var(--ink); background: var(--surface); }
.sgrid button { border: 0; border-left: 1px solid var(--rule); border-top: 1px solid var(--rule); background: transparent; padding: 0; font-size: clamp(16px, 6cqw, 26px); font-weight: 500; color: var(--ink); border-radius: 0; position: relative; min-width: 0; min-height: 0; }
.sgrid button.bl { border-left: 2px solid var(--ink); }
.sgrid button.bt { border-top: 2px solid var(--ink); }
.sgrid button.c0 { border-left: 0; } .sgrid button.r0 { border-top: 0; }
.sgrid button.given { font-weight: 800; }
.sgrid button.peer { background: color-mix(in srgb, var(--pick) 45%, transparent); }
.sgrid button.same { background: color-mix(in srgb, var(--thread) 55%, transparent); }
.sgrid button.sel { background: var(--thread); color: var(--on-fill); }
.sgrid button.clash { color: var(--bad); text-decoration: underline; text-decoration-thickness: 2px; }
.sgrid button:focus-visible { outline-offset: -3px; }
.sgrid .nt { position: absolute; inset: 1px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); font-size: clamp(7px, 2.1cqw, 10px); font-weight: 600; color: var(--muted); line-height: 1; align-items: center; }
.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; }
.pad button { height: 50px; border: 0; border-radius: 8px; background: var(--pick); font-weight: 700; font-size: 20px; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.pad button small { font-size: 9px; font-weight: 600; color: var(--muted); margin-top: 3px; }
.pad button.full { background: transparent; box-shadow: inset 0 0 0 1.5px var(--rule); color: var(--muted); }
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 0 12px; min-height: 37px; font-weight: 600; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* Unravel */
.quote { flex: 1; min-height: 0; overflow-y: auto; background: var(--surface); border: 1.5px solid var(--rule); border-radius: 12px; padding: 14px 12px; }
.qtext { display: flex; flex-wrap: wrap; gap: 14px 16px; align-content: flex-start; }
.uw { display: inline-flex; gap: 2px; align-items: flex-start; }
.uc { width: 24px; border: 0; background: transparent; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; border-radius: 4px; }
.uc b { width: 100%; height: 30px; display: flex; align-items: center; justify-content: center; font-size: 19px; font-weight: 700; border-bottom: 2.5px solid var(--ink); border-radius: 4px 4px 0 0; }
.uc i { font-style: normal; font-size: 12px; font-weight: 600; color: var(--muted); }
.uc.same b { background: var(--pick); }
.uc.sel b { background: var(--thread); color: var(--on-fill); }
.uc.clash b { color: var(--bad); border-bottom-color: var(--bad); }
.uc.given b { border-bottom-style: dashed; }
.up { font-size: 19px; font-weight: 700; height: 30px; display: flex; align-items: center; }
.by { margin: 14px 0 0; font-size: 14px; color: var(--muted); text-align: right; }
.links { display: flex; gap: 8px; margin-top: 4px; }
.links .btn { text-decoration: none; display: inline-flex; align-items: center; }
.bar .note { flex: 1; }
.hrow { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1.5px solid var(--rule); border-radius: 10px; padding: 10px 12px; }
.hrow .what { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hrow b { font-size: 15px; overflow-wrap: anywhere; }
.hrow span { font-size: 13px; color: var(--muted); }
input[type="text"], input[type="password"], textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--surface); border: 1.5px solid var(--rule); border-radius: 8px; padding: 10px 12px; }
input:focus-visible, textarea:focus-visible { outline: 3px solid var(--ink); outline-offset: 1px; }
.form { display: flex; flex-direction: column; gap: 6px; }
.form .eyebrow { margin-top: 6px; }
.form .actions { justify-content: flex-start; margin-top: 8px; }
.sub { font-family: var(--display); font-size: 18px; margin: 14px 0 2px; }
pre.grid { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; line-height: 1.5; letter-spacing: .1em; background: var(--surface); border: 1.5px solid var(--rule); border-radius: 10px; padding: 12px; margin: 8px 0; text-align: center; }
@media (prefers-reduced-motion: reduce) { .board .pop, .live.shake { animation: none; } .hint i { transition: none; } }

/* Crosshatch */
.lgrid { --n: 8; --lab: 74px; display: grid; grid-template-columns: var(--lab) repeat(var(--n), 1fr); background: var(--surface); border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; flex: none; }
.lgrid > * { border-left: 1px solid var(--rule); border-top: 1px solid var(--rule); min-width: 0; }
.lgrid .ch { height: var(--lab); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 5px; border-top: 0; }
.lgrid .ch i { writing-mode: vertical-rl; transform: rotate(180deg); font-style: normal; font-size: 12px; font-weight: 600; white-space: nowrap; }
.lgrid .rh { display: flex; align-items: center; padding: 0 6px; font-size: 12px; font-weight: 600; border-left: 0; overflow: hidden; white-space: nowrap; }
.lgrid > span:first-child { border: 0; }
.lgrid button { aspect-ratio: 1; border-width: 1px 0 0 1px; border-style: solid; border-color: var(--rule); border-radius: 0; background: transparent; padding: 0; font-size: 17px; font-weight: 700; line-height: 1; color: var(--muted); }
.lgrid button.yes { background: var(--thread); color: var(--on-fill); }
.lgrid button.no.auto { opacity: .45; }
.lgrid button.bad { box-shadow: inset 0 0 0 2.5px var(--bad); }
.lgrid .bl { border-left: 2px solid var(--ink); }
.lgrid .bt { border-top: 2px solid var(--ink); }
.lgrid .void { background: var(--paper); }
.lgrid button:focus-visible { outline-offset: -3px; }
.clues { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; counter-reset: clue; }
.clues button { counter-increment: clue; width: 100%; text-align: left; background: var(--surface); border: 1.5px solid var(--rule); border-radius: 8px; padding: 9px 11px; font-size: 14.5px; line-height: 1.35; display: flex; gap: 8px; }
.clues button::before { content: counter(clue) "."; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 700; }
.clues button.struck { text-decoration: line-through; color: var(--muted); background: transparent; }

/* Knots */
.ask { margin: 0; font-size: 16px; line-height: 1.45; background: var(--surface); border: 1.5px solid var(--rule); border-left: 6px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.scale { width: 100%; max-height: 130px; flex: none; }
.scale text { font-family: var(--body); font-size: 11px; font-weight: 700; fill: var(--on-fill); text-anchor: middle; }
.coins { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
.coins button { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--warm); color: var(--on-fill); font-weight: 800; font-size: 16px; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .12); }
.coins button.l { background: var(--thread); }
.coins button.r { background: var(--line); }
.coins button.pickable { outline: 2.5px dashed var(--ink); outline-offset: 2px; }
.verdict { margin: 0; padding: 11px 13px; border-radius: 10px; font-weight: 600; font-size: 15px; line-height: 1.4; border: 1.5px solid var(--rule); background: var(--surface); }
.verdict.ok { border-color: var(--thread); border-left: 6px solid var(--thread); }
.verdict.no { border-color: var(--bad); border-left: 6px solid var(--bad); }
.wlog { margin: 0; padding-left: 22px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.jugs { display: flex; gap: 28px; justify-content: center; align-items: flex-end; }
.jug { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 14px; }
.glass { width: 74px; border: 2.5px solid var(--ink); border-top: 0; border-radius: 0 0 10px 10px; display: flex; align-items: flex-end; overflow: hidden; background: var(--surface); }
.glass i { display: block; width: 100%; background: var(--thread); transition: height .25s; }
.moves { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.banks { display: grid; grid-template-columns: 1fr 44px 1fr; gap: 0; min-height: 150px; }
.bank { background: var(--surface); border: 1.5px solid var(--rule); border-radius: 10px; padding: 10px 8px; display: flex; flex-direction: column; gap: 7px; align-items: stretch; }
.bank.here { border-color: var(--ink); }
.water { background: repeating-linear-gradient(180deg, var(--thread) 0 3px, transparent 3px 11px); opacity: .55; margin: 8px 0; }
.water.span { background: repeating-linear-gradient(90deg, var(--ink) 0 3px, transparent 3px 9px); opacity: .35; height: 10px; align-self: center; margin: 0; }
.chip { border: 1.5px solid var(--ink); background: transparent; border-radius: 999px; min-height: 40px; padding: 0 10px; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; }
.chip.sel { background: var(--ink); color: var(--paper); }
.chip.me { background: var(--warm); border-color: var(--warm); color: var(--on-fill); }
.chip:disabled { opacity: .55; cursor: default; }
.hintline { margin: 0; font-size: 15px; line-height: 1.45; }
.answer { background: var(--surface); border: 1.5px solid var(--thread); border-radius: 10px; padding: 12px 14px; }
.answer p { margin: 4px 0 0; font-size: 15.5px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) { .glass i { transition: none; } }
