/* Petit Point - natural canvas and wool. A woven-linen ground, a stretched-canvas frame on wooden bars, a yarn card
 * with punched holes, serif display type, monospace for counts. */
:root {
  --bg: #efe7d6; --weave: rgba(120, 96, 60, 0.07); --paper: #fbf7ee; --ink: #1f2a44; --muted: #5d6478; --line: #d8ccb2;
  --wool: #c8442f; --wool-ink: #ffffff; --moss: #4f6b3a; --mustard: #b8891a; --wood: #a8784a; --wood-dark: #7b5531;
  --ok: #3e6b35; --warn: #a3471f; --info: #3b5a8a; --chip: #f4ecdb; --shadow: 0 1px 0 rgba(60, 40, 10, 0.08), 0 8px 24px rgba(60, 40, 10, 0.08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1d1a; --weave: rgba(255, 240, 210, 0.04); --paper: #2a2723; --ink: #efe6d2; --muted: #b3a990; --line: #45403a;
    --wool: #e3664f; --wool-ink: #1b1410; --moss: #9cbc7e; --mustard: #e0b64a; --wood: #8a6440; --wood-dark: #5e4329;
    --ok: #9cc58c; --warn: #f0a07a; --info: #9fbbe8; --chip: #34302a; --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #1f1d1a; --weave: rgba(255, 240, 210, 0.04); --paper: #2a2723; --ink: #efe6d2; --muted: #b3a990; --line: #45403a;
  --wool: #e3664f; --wool-ink: #1b1410; --moss: #9cbc7e; --mustard: #e0b64a; --wood: #8a6440; --wood-dark: #5e4329;
  --ok: #9cc58c; --warn: #f0a07a; --info: #9fbbe8; --chip: #34302a; --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); font: 15px/1.5 var(--sans); background-color: var(--bg);
  background-image: repeating-linear-gradient(0deg, var(--weave) 0 1px, transparent 1px 4px), repeating-linear-gradient(90deg, var(--weave) 0 1px, transparent 1px 4px);
}
a { color: inherit; }
.hidden { display: none !important; }
.small { font-size: 13px; } .muted { color: var(--muted); } .mono { font-family: var(--mono); }
button, input, select, textarea { font: inherit; color: inherit; }

/* header */
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.back { text-decoration: none; color: var(--muted); font-size: 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-size: 19px; margin-right: auto; }
.mark { width: 22px; height: 22px; border-radius: 4px; display: inline-block;
  background: conic-gradient(var(--wool) 0 25%, var(--mustard) 0 50%, var(--moss) 0 75%, var(--ink) 0); background-size: 11px 11px; }
.session { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.credits { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.pill { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 14px; cursor: pointer; text-decoration: none; font-size: 14px; line-height: 1.3; display: inline-block; }
.pill:hover { border-color: var(--ink); }
.pill.solid { background: var(--wool); color: var(--wool-ink); border-color: var(--wool); }
.pill.big { padding: 10px 22px; font-size: 16px; font-weight: 600; }
.pill:disabled { opacity: 0.5; cursor: not-allowed; }

/* hero */
.hero { max-width: 1240px; margin: 0 auto; padding: 34px 16px 10px; }
.kicker { font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--wool); margin: 0 0 8px; }
.hero h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(30px, 5vw, 50px); line-height: 1.05; margin: 0 0 12px; letter-spacing: -0.01em; }
.sub { max-width: 720px; color: var(--muted); font-size: 17px; margin: 0 0 16px; }
.examples { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ex-label { font-size: 13px; color: var(--muted); }
.chip { border: 1px dashed var(--wood); background: var(--chip); border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.chip.on { border-style: solid; border-color: var(--wool); box-shadow: inset 0 0 0 1px var(--wool); }

/* workbench */
.wrap { max-width: 1240px; margin: 0 auto; padding: 12px 16px 40px; }
.bench { display: grid; grid-template-columns: 280px minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.panel h2, .bhead h2 { font-family: var(--serif); font-size: 20px; margin: 0 0 10px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel h3 { font-family: var(--serif); font-size: 16px; margin: 16px 0 6px; }
.num { width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--paper); font: 600 13px/24px var(--mono); text-align: center; flex: none; }
.paid { font: 600 11px var(--mono); background: var(--mustard); color: #1b1410; border-radius: 4px; padding: 1px 6px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.tab { background: transparent; border: 0; padding: 8px; cursor: pointer; }
.tab.on { background: var(--ink); color: var(--paper); }
.drop { display: block; border: 2px dashed var(--wood); border-radius: 8px; padding: 18px 12px; text-align: center; cursor: pointer; background: var(--chip); }
.drop.over { border-color: var(--wool); background: color-mix(in srgb, var(--wool) 10%, var(--chip)); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:focus-within { outline: 2px solid var(--wool); outline-offset: 2px; }
#chart:focus-visible { outline: 2px solid var(--wool); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin: 10px 0 0; min-width: 0; }
.field output { font-family: var(--mono); color: var(--ink); }
.field input[type="number"], .field input[type="text"], .field select, .field textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 7px 9px; color: var(--ink); width: 100%; min-width: 0; }
.field textarea { resize: vertical; font-family: var(--mono); text-transform: uppercase; }
#notes { text-transform: none; font-family: var(--sans); }
.field input[type="range"] { width: 100%; accent-color: var(--wool); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-top: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.sizeline { font-family: var(--mono); font-size: 12px; color: var(--ink); background: var(--chip); border-radius: 6px; padding: 8px; margin: 12px 0 0; }

/* the stretched canvas */
.framebar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg-b { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; font-size: 14px; }
.seg-b.on { background: var(--ink); color: var(--paper); }
.zoom { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.zoom input { width: 110px; accent-color: var(--wool); }
.stretcher { padding: 14px; border-radius: 6px; background: linear-gradient(135deg, var(--wood) 0%, var(--wood-dark) 100%); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15); }
.chartscroll { overflow: auto; max-height: 70vh; background: #f4efe2; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); line-height: 0; }
#chart { display: block; touch-action: pan-x pan-y; }
#chart.painting { cursor: crosshair; touch-action: none; }
.frame .small { margin: 8px 0 0; }

/* yarn card */
.yarncard { background-image: radial-gradient(circle at 14px 14px, var(--bg) 0 5px, transparent 6px); background-color: var(--paper); padding-top: 26px; }
.keylist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.keyrow { width: 100%; display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center; text-align: left; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 4px; cursor: pointer; }
.keyrow:hover { border-color: var(--line); }
.keyrow.sel { border-color: var(--wool); background: color-mix(in srgb, var(--wool) 8%, transparent); }
.ksym { grid-row: 1 / span 2; width: 28px; height: 28px; border-radius: 50%; font: 700 13px/28px var(--mono); text-align: center; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
.kname { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcode { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.kcount { grid-column: 2; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.kyd { grid-column: 3; grid-row: 1 / span 2; font-family: var(--mono); font-size: 12px; }
.swapbox { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.tray { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.sw { aspect-ratio: 1; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.2); cursor: pointer; padding: 0; min-width: 0; }
.sw:hover { transform: scale(1.12); }
.totals { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 14px 0 6px; font-size: 14px; }
.totals dt { color: var(--muted); } .totals dd { margin: 0; font-family: var(--mono); font-size: 13px; }
.facts, .recon { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.facts li, .recon li { padding-left: 14px; position: relative; }
.facts li::before, .recon li::before { content: ""; position: absolute; left: 0; top: 7px; width: 7px; height: 7px; border-radius: 2px; background: var(--muted); }
li.ok::before { background: var(--ok) !important; } li.warn::before { background: var(--warn) !important; } li.info::before { background: var(--info) !important; }
li.none { color: var(--muted); list-style: none; }

/* plan */
.block { margin-top: 28px; }
.bhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.bhead p { color: var(--muted); margin: 0; font-size: 14px; }
.planform { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 0 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 14px; box-shadow: var(--shadow); }
.planform .wide { grid-column: span 1; }
.planform > p, .planform > a, .planform .runrow { grid-column: 1 / -1; }
.meter { font-family: var(--mono); font-size: 13px; margin: 12px 0 0; }
.note { font-size: 13px; color: var(--muted); background: var(--chip); border-left: 3px solid var(--mustard); padding: 6px 10px; margin: 8px 0 0; border-radius: 0 6px 6px 0; }
.gate { font-size: 14px; margin: 10px 0 0; }
.runrow { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.progress { margin-top: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.ptitle { font-family: var(--serif); font-size: 17px; margin: 0 0 6px; }
.steps { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: 13px; }
.step { color: var(--muted); } .step.active { color: var(--ink); font-weight: 600; } .step.done { color: var(--ok); }
.step-ic { display: inline-block; width: 14px; }
.raw { white-space: pre-wrap; word-break: break-word; background: var(--chip); padding: 10px; border-radius: 6px; font-size: 12px; max-height: 300px; overflow: auto; }
.result { margin-top: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 18px; box-shadow: var(--shadow); }
.rhead { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 8px; }
.rhead h3 { font-family: var(--serif); font-size: 24px; margin: 0 0 4px; }
.rhead p { margin: 0; }
.stamp { flex: none; font: 700 13px var(--mono); letter-spacing: 0.1em; padding: 10px 12px; border: 2px solid currentColor; border-radius: 50%; transform: rotate(-8deg); min-width: 84px; text-align: center; }
.stamp.v-reads { color: var(--ok); } .stamp.v-tweak { color: var(--mustard); } .stamp.v-rework { color: var(--warn); }
.result h4 { font-family: var(--serif); font-size: 16px; margin: 16px 0 6px; }
.rgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.issues, .moves { padding-left: 18px; margin: 0; }
.issues li, .moves li { margin-bottom: 8px; }
.where, .fix, .why { display: block; font-size: 13px; color: var(--muted); }
.fix::before { content: "Fix: "; font-weight: 600; color: var(--ink); }
.act { font: 600 11px var(--mono); text-transform: uppercase; background: var(--chip); border-radius: 4px; padding: 1px 6px; margin-right: 6px; }
.ychip { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 12px; margin-right: 6px; white-space: nowrap; }
.ydot { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); display: inline-block; }
.tablewrap { overflow-x: auto; }
.stitches { border-collapse: collapse; width: 100%; font-size: 14px; }
.stitches th, .stitches td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.stitches th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.stitch { font-weight: 600; white-space: nowrap; }
.order { padding-left: 20px; margin: 0; } .order li { margin-bottom: 6px; }
.codes { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.meta { font-family: var(--mono); font-size: 12px; color: var(--muted); margin: 14px 0 0; }
.exports { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* history */
.hist { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.hist li { display: flex; gap: 12px; align-items: center; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; flex-wrap: wrap; }
.hist li.cur { border-color: var(--wool); }
.thumb { width: 48px; height: 48px; border-radius: 4px; background: var(--chip); flex: none; image-rendering: pixelated; }
.hbody { display: flex; flex-direction: column; flex: 1; min-width: 180px; }
.ht { font-weight: 600; } .hm { font-size: 12px; color: var(--muted); }
.hrow { display: flex; gap: 6px; }

/* footer, toasts, docs */
.foot { max-width: 1240px; margin: 0 auto; padding: 20px 16px 40px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 50; pointer-events: none; }
.toast { pointer-events: auto; max-width: 420px; background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); transition: opacity 0.5s; }
.toast.err { background: var(--warn); color: #fff; }
.toast.gone { opacity: 0; }
.toast a { color: inherit; font-weight: 600; }
.printsheet { display: none; }
.doc { max-width: 900px; margin: 0 auto; padding: 24px 16px 40px; }
.doc h1 { font-family: var(--serif); } .doc h2 { font-family: var(--serif); margin-top: 32px; }
.doc pre { background: var(--chip); padding: 12px; border-radius: 6px; overflow-x: auto; font-size: 12px; }
.doc code { font-family: var(--mono); font-size: 0.92em; }
.doc table { border-collapse: collapse; width: 100%; font-size: 14px; display: block; overflow-x: auto; }
.doc th, .doc td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.langtabs, .lang-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 8px 0; }
.langtabs button, .lang-tabs button { border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: 3px 10px; cursor: pointer; font-size: 13px; }
.langtabs button.on, .lang-tabs button.on, .langtabs button[aria-selected="true"], .lang-tabs button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.statebox { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.tokenrow { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.tokenbox { font-family: var(--mono); font-size: 13px; background: var(--chip); padding: 10px; border-radius: 6px; word-break: break-all; width: 100%; }

@media (max-width: 1080px) {
  .bench { grid-template-columns: 1fr 1fr; }
  .frame { grid-column: 1 / -1; order: -1; }
}
@media (max-width: 720px) {
  .bench, .rgrid, .planform { grid-template-columns: 1fr; }
  .row3 { grid-template-columns: 1fr 1fr 1fr; }
  .rhead { flex-direction: column; }
  .chartscroll { max-height: 60vh; }
}
@media print {
  body { background: #fff; color: #000; }
  .bar, .hero, .wrap, .foot, .toasts { display: none !important; }
  .printsheet { display: block; font: 12px/1.4 Georgia, serif; }
  .pchart { max-width: 100%; }
  .ptile { break-before: page; page-break-before: always; }
  .ptile .ptitle { margin: 0 0 6px; font-size: 11px; }
  .ptileimg { display: block; max-width: 100%; }
  .pkey { border-collapse: collapse; margin-top: 10px; } .pkey th, .pkey td { border: 1px solid #999; padding: 3px 6px; }
}
