:root{
  --onaccent:#fff;       /* text on the accent and on ink */
}

/* ---------- design ---------- */
/* name and size share one line, as Pattern Maker's file card does: the name truncates,
   the size keeps the width it needs */
.dline{display:flex;align-items:baseline;gap:3px 9px;min-width:0}
.dname{flex:0 1 auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:13px}
.dmeta{flex:0 0 auto;margin-left:auto;font-size:11px;color:var(--muted);letter-spacing:.08em;font-weight:300}
.note{margin:10px 0 0;color:var(--muted);font-size:12px;line-height:1.5;font-weight:300}
.note[hidden]{display:none}
.links{display:flex;flex-wrap:wrap;gap:8px 14px;margin-top:14px}
.warn{margin:10px 0 0;color:var(--accent);font-size:12px;line-height:1.5}
.warn[hidden]{display:none}
.link:disabled{color:var(--muted);border-bottom-color:transparent;cursor:default}
.link:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
/* a beading design: the bead-stitch chips and their note share one row */
.stitchrow{display:flex;align-items:center;gap:16px;margin-top:12px}
.stitchrow .stitches,.stitchrow .note{margin:0}
.stitchrow .stitches{flex:0 0 auto}
.stitchrow:not(:has(> :not([hidden]))){display:none}
.stitches[hidden]{display:none}
/* the side-by-side rail lists the saved designs itself; the drawer opens them in an overlay */
#designs{display:none}
.help{margin:0;font-size:13px;line-height:1.55;color:var(--muted);font-weight:300}

/* ---------- saved designs ---------- */
/* the rail never scrolls: the section takes the spare height and the list scrolls inside
   it. min-height:0 lets the section shrink below its content */
.saved{min-height:0}
.saved .list{flex:1 1 0;min-height:0;overflow-y:auto}
.saved .help{margin-top:12px;font-size:11px;line-height:1.5}
.list{list-style:none;margin:0;padding:0}
.list li{display:flex;align-items:baseline;gap:4px 14px;padding:12px 0;border-top:1px solid var(--rule);flex-wrap:wrap}
.list li:last-child{border-bottom:1px solid var(--rule)}
.list .lname{flex:1 1 160px;min-width:0;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.list .lmeta{flex:0 0 auto;font-size:11px;color:var(--muted);letter-spacing:.08em;font-weight:300}
.list .lacts{flex:0 0 auto;display:flex;gap:12px;margin-left:auto}
.list .now{font-size:11px;color:var(--muted);letter-spacing:.08em}
.list .lnone{padding:12px 0;color:var(--muted);font-size:13px;font-weight:300;border:0}

/* ---------- chips ---------- */
/* a word chip, the look of Pattern Maker's .ratio */
.chips{display:flex;flex-wrap:wrap;gap:8px}
.chip{
  border:1px solid var(--rule);background:var(--card);color:var(--muted);
  font:inherit;font-size:10px;letter-spacing:.18em;text-transform:uppercase;
  padding:8px 14px;cursor:pointer;transition:all .18s;
}
.chip:hover{border-color:var(--accent);color:var(--ink)}
.chip[aria-pressed="true"]{background:var(--accent);border-color:var(--accent);color:var(--onaccent)}
.chip:focus-visible{outline:2px solid var(--accent);outline-offset:2px}

/* ---------- swatches ---------- */
.swatches{display:grid;grid-template-columns:repeat(auto-fill,minmax(28px,1fr));gap:4px;padding:3px}
.sw{
  position:relative;display:block;padding:0;border:1px solid rgba(42,39,36,.18);
  cursor:pointer;font:inherit;min-width:0;
}
.sw[hidden]{display:none}
.sw:focus-visible{outline:2px solid var(--accent);outline-offset:2px;z-index:1}
.sw[aria-pressed="true"]{outline:2px solid var(--accent);outline-offset:1px;z-index:1}
/* the number shows on hover and focus, in black or white by the shade's lightness */
.palette .sw:hover::after,.palette .sw:focus-visible::after,
.pickrow .sw:hover::after,.pickrow .sw:focus-visible::after{
  content:attr(data-code);position:absolute;inset:0;display:flex;align-items:center;justify-content:center;
  font-size:8px;letter-spacing:0;color:#000;
}
.palette .sw.dark:hover::after,.palette .sw.dark:focus-visible::after,
.pickrow .sw.dark:hover::after,.pickrow .sw.dark:focus-visible::after{color:#fff}
/* a special finish — metallic, AB and the rest — that a flat colour cannot show */
.sw.fin::before{
  content:"";position:absolute;top:-1px;right:-1px;width:7px;height:7px;
  background:var(--card);border-left:1px solid var(--ink);border-bottom:1px solid var(--ink);
}

/* ---------- stage ---------- */
/* the edit bar on top, the grid under it. The stage is a size container, so the bar
   takes one row or two by the stage's own width, not the window's */
.stage{display:flex;flex-direction:column;container-type:inline-size}
.editbar{
  flex:0 0 auto;display:grid;align-items:center;gap:8px 14px;padding:10px 16px;
  grid-template-columns:auto auto minmax(0,1fr) auto;grid-template-areas:"tools history pal sel";
  background:var(--card);border-bottom:1px solid var(--rule);
}
.editbar .tools{grid-area:tools}
.editbar .history{grid-area:history}
.mypal{grid-area:pal;display:flex;align-items:center;gap:8px;min-width:0}
.selected{
  grid-area:sel;margin:0;min-width:0;max-width:280px;font-size:12px;color:var(--muted);font-weight:300;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-align:right;
}
.selected .code{color:var(--ink);font-weight:400;font-variant-numeric:tabular-nums}
.selected .fin{color:var(--accent)}

/* an icon button: the chip's box and states, with a line icon in place of a word. A set
   shares its borders, as one control */
.iconset{display:flex}
.icon{
  flex:0 0 auto;width:36px;height:36px;display:flex;align-items:center;justify-content:center;padding:0;
  border:1px solid var(--rule);background:var(--card);color:var(--ink);cursor:pointer;
  transition:border-color .18s,color .18s,background .18s;
}
.iconset .icon + .icon{margin-left:-1px}
.icon svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round}
.icon:hover:not(:disabled){border-color:var(--accent);color:var(--accent);position:relative;z-index:1}
.icon[aria-pressed="true"]{background:var(--accent);border-color:var(--accent);color:var(--onaccent);position:relative;z-index:1}
.icon:disabled{background:var(--bg);color:var(--muted);cursor:default;opacity:.55}
.icon:focus-visible{outline:2px solid var(--accent);outline-offset:2px;position:relative;z-index:2}

/* the design's own colours, then + to add more. Padding, so a selected swatch's ring is
   not clipped */
.mine{display:flex;flex-wrap:wrap;gap:6px;padding:3px;min-width:0}
.mine:empty{display:none}
.mine .sw{flex:0 0 28px;width:28px;height:28px}

.canvasbox{position:relative;flex:1 1 auto;min-height:0;overflow:hidden}
/* the canvas fills the box: it draws only the visible cells, so a large grid never needs
   a canvas larger than the screen. touch-action:none hands every touch to app.js — one
   finger paints, two pan and zoom */
#grid{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none;cursor:crosshair}
#grid.panning{cursor:grabbing}
.zoombar{position:absolute;right:16px;bottom:16px;display:flex;gap:6px}
.zoom{
  min-width:36px;height:36px;padding:0 10px;border:1px solid var(--rule);background:var(--card);color:var(--ink);
  font:inherit;font-size:16px;line-height:1;cursor:pointer;transition:border-color .18s,color .18s;
}
.zoom.fit{font-size:10px;letter-spacing:.18em;text-transform:uppercase}
.zoom:hover{border-color:var(--accent);color:var(--accent)}
.zoom:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.notice{
  position:absolute;left:50%;top:34px;transform:translateX(-50%);max-width:calc(100% - 64px);
  margin:0;padding:10px 16px;background:var(--card);border:1px solid var(--rule);
  font-size:12px;line-height:1.45;text-align:center;pointer-events:none;z-index:3;
}
.notice[hidden]{display:none}

/* a narrow stage: the colours take a row of their own, and scroll sideways rather than
   take more height from the grid */
@container (max-width:700px){
  .editbar{grid-template-columns:auto auto minmax(0,1fr);grid-template-areas:"tools history sel" "pal pal pal"}
  .selected{max-width:none}
  .mine{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:thin}
}

/* ---------- overlays ---------- */
.overlay:focus{outline:none}
.overlayhead .eyebrow{margin:0;margin-right:auto}
.overlayacts{display:flex;align-items:center;gap:20px;min-width:0}
/* the start screen's link back names a design, which may be long */
#newback{max-width:min(60vw,360px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.overlaybody{flex:1;overflow-y:auto;padding:32px 26px}
.form{max-width:440px;margin:0 auto;display:flex;flex-direction:column}
.form.wide{max-width:640px}
.form > .eyebrow,.form label > .eyebrow,.form > div > .eyebrow{margin:22px 0 10px}
.form > .eyebrow:first-child{margin-top:0}
.field{
  width:100%;border:1px solid var(--rule);background:var(--card);color:var(--ink);
  font:inherit;font-size:14px;padding:9px 12px;border-radius:0;
}
.field:focus{outline:2px solid var(--accent);outline-offset:-1px;border-color:var(--accent)}
.sourceline{margin:0;font-size:13px}
.sourceline[hidden],#newsources[hidden],#newstitchwrap[hidden]{display:none}
.sizes,.sides{display:grid;grid-template-columns:1fr 1fr;gap:0 16px}

/* the caption bar with the overlay's one action, so the action is always in view. Its
   ends line up with the overlay's content, of width --content, so the action sits near
   the form and not in the far corner of a wide screen */
#newov{--content:936px}
#resizeov{--content:440px}
#colourov{--content:760px}
.actfoot{
  display:flex;align-items:center;flex-wrap:wrap;gap:12px 24px;
  padding-left:max(26px,calc((100% - var(--content))/2));padding-right:max(26px,calc((100% - var(--content))/2));
}
.footline{margin:0;flex:1 1 240px;min-width:0;line-height:1.6}
.actfoot .btn{flex:0 0 auto;margin-left:auto}

/* new design: the form, and beside it the grid it makes */
.setup{display:grid;grid-template-columns:minmax(0,400px) minmax(0,480px);justify-content:center;gap:28px 56px;align-items:start}
.setup .form{margin:0;max-width:none}
.preview{margin:0}
.previewbox{position:relative}
#preview{display:block;width:100%;max-height:min(52vh,440px)}
.preview .note{margin-top:12px}
.preview .note:empty{display:none}

/* the colours: the design's own colours and the search stay put, and the shade grid
   scrolls under them */
.colourbody{display:flex;flex-direction:column;align-items:center;overflow:hidden;padding-bottom:14px}
.colourbody > *{width:100%;max-width:760px}
.colourtop{flex:0 0 auto}
.sourcename{font-size:12px;color:var(--muted);font-weight:300;letter-spacing:.04em}
.pickrow{grid-template-columns:repeat(auto-fill,28px);grid-auto-rows:28px;gap:8px;padding:4px;max-height:calc(3*28px + 2*8px + 8px);overflow-y:auto}
.pickrow:empty{display:none}
#pickhelp{margin-top:8px;font-size:12px}
.search{margin-top:16px;font-size:13px;padding:8px 12px}
.free{display:flex;align-items:center;gap:16px;margin-top:16px}
.free input[type=color]{width:52px;height:34px;padding:2px;border:1px solid var(--rule);background:var(--card);cursor:pointer}
.free input[type=color]:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.search[hidden],.free[hidden],.palette[hidden],.palettenotes[hidden]{display:none}
.colourbody .palette{flex:1 1 0;min-height:64px;overflow-y:auto;margin-top:14px;align-content:start;grid-auto-rows:28px}

/* the CC BY credit for third-party data. Its own class, not .credit: tool.css hides .credit
   on the stacked layout, and the licence needs the credit wherever the data shows */
.palettenote{margin:12px 0 0;font-size:10px;line-height:1.5;letter-spacing:.04em;color:var(--muted);font-weight:300}
.palettenote[hidden]{display:none}
.palettenote a{color:inherit;text-decoration:none;border-bottom:1px solid var(--rule);transition:color .18s,border-color .18s}
.palettenote a:hover{color:var(--accent);border-bottom-color:var(--accent)}
.palettenote a:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
/* in the colours overlay the two lines run on as one paragraph */
.palettenotes{flex:0 0 auto;margin-top:10px;font-size:10px;line-height:1.5}   /* the strut of the inline lines */
.palettenotes .palettenote{display:inline;margin:0}
.palettenotes .palettenote + .palettenote::before{content:" "}

/* ---------- print ---------- */
#printout{display:none}

/* the stacked layout. Must match shared/tool.css and shared/tool.js */
@media (max-width:820px) and (min-height:500px){
  .saved{display:none}
  #designs{display:inline-block}
  .block.design{padding-top:0}
  .design .eyebrow{display:none}
  /* the size line drops under the name when both do not fit */
  .dline{flex-wrap:wrap}
  .dmeta{margin-left:0}
  .links{margin-top:10px}
  .editbar{padding:8px 12px}
  .icon{width:38px;height:38px}
  .mine .sw{flex-basis:30px;width:30px;height:30px}
  .overlayhead{padding:14px 20px;gap:14px}
  .overlayfoot{padding:12px 20px}
  .overlaybody{padding:24px 20px}
  .colourbody{padding-bottom:12px}
  .zoombar{right:12px;bottom:12px}
}

/* a narrow window: the preview sits above the form, at a fixed height */
@media (max-width:820px){
  .setup{grid-template-columns:minmax(0,440px)}
  .preview{order:-1}
  #preview{max-height:170px}
}
@media (max-width:560px){
  .actfoot .btn{flex:1 1 100%}
}

/* a phone held sideways, or a very short window: the strapline and the credit go */
@media (min-width:821px) and (max-height:500px), (max-width:820px) and (max-height:499px){
  .brand{padding:12px 26px 10px}
  .brand p{display:none}
  .block{padding:8px 26px}
  .eyebrow{margin-bottom:6px}
  .links{margin-top:8px}
  .saved .help{display:none}
  .btn{padding:11px}
  .credit{display:none}
  .editbar{padding:6px 12px}
  .overlaybody{padding:16px 26px}
  .overlayfoot{padding-top:10px;padding-bottom:10px}
}

/* the printed chart: only the pages print. tool.css sets html and body to the screen's
   height and clips .app, and Firefox and Safari then print only the first page, so all
   three go back to their natural height here */
@media print{
  @page{size:A4 portrait;margin:12mm}
  html,body,.app{height:auto!important;overflow:visible!important}
  body{background:#fff}
  .app,.overlay{display:none!important}
  #printout{display:block}
  .ppage{break-after:page;page-break-after:always}
  .ppage:last-child{break-after:auto;page-break-after:auto}
  .ppage img{display:block;width:186mm;height:auto}

  /* the colour key: one A4 page holds the 45-colour maximum. Swatch grounds print only
     with print-color-adjust, which the browser otherwise turns off to save ink */
  .key{color:#000;font-size:10pt}
  .key h1{margin:0;font-weight:300;font-size:20pt;letter-spacing:.06em}
  .kmeta{margin:2mm 0 6mm;color:#555;font-size:10pt}
  .key table{width:100%;border-collapse:collapse}
  .key th{text-align:left;font-weight:400;font-size:8pt;letter-spacing:.14em;text-transform:uppercase;color:#555;padding:0 3mm 2mm 0;border-bottom:.3mm solid #000}
  .key td{padding:0 3mm 0 0;height:5mm;border-bottom:.2mm solid #ccc;vertical-align:middle}
  .key .ksym{width:12mm;font-size:12pt;text-align:center}
  .key .ksw{width:10mm}
  .key .ksw span{display:block;width:8mm;height:4mm;border:.2mm solid #888;-webkit-print-color-adjust:exact;print-color-adjust:exact}
  .key .kyarn{width:55mm;border-bottom:.2mm solid #000}
  .key .kgap{width:0;padding:0}
  .key .kcount{text-align:right;white-space:nowrap;font-variant-numeric:tabular-nums}
  .key tfoot td{border:0;padding-top:3mm;font-size:10pt}
  .knote{margin:4mm 0 0;font-size:8pt;line-height:1.4;color:#555}
  .knote a{color:inherit}
}

@media (prefers-reduced-motion:reduce){*{transition:none!important}}
