/* The stitching page: a full-screen tool. Phone first: the chart, with the thread list as a
   sheet under it; wide screens put the list beside the chart. Colors come from tokens.css. */

html, body { margin: 0; height: 100%; }

/* the page's own colors on top of tokens.css; the dark screen swaps them (the canvases' are theme.js) */
:root {
  --card: #fff;              /* menus, buttons, rows picked */
  --stage: #ebe6da;          /* around the chart (theme.js backdrop) */
  --accent: #e8590c;         /* theme.js accent */
  --danger: #c4452b;
  --band: #fbefe0; --band-line: #ecd2ad; --band-ink: #6b4a14;
  --shadow: rgba(0, 0, 0, 0.18);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #ece8e1; --ink-2: #cfc9bf; --ink-3: #958f86;
  --stone: #6c665e; --sand: #3a3733; --paper: #1f1e1c; --line: #3d3a35;
  --card: #2a2825; --stage: #1d1c1a; --accent: #ff8a3d; --danger: #ff7a59;
  --band: #3a2f1f; --band-line: #5a4527; --band-ink: #f2d7a8;
  --shadow: rgba(0, 0, 0, 0.5);
}
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 13px/1.5 var(--sans);
  letter-spacing: 0.02em;
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
button, .sew-pick, .sew-icon { -webkit-tap-highlight-color: transparent; }
:where(button, a, input, select, canvas):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sew {
  display: grid;
  grid-template-rows: 50px auto auto minmax(0, 1fr) auto;     /* the second row is the modes, the third the backup band (nothing when it is hidden) */
  grid-template-columns: minmax(0, 1fr);    /* the screen's width, never the bar's: a long name gives way, not the buttons */
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.sew-top { grid-row: 1; }
.sew-modes { grid-row: 2; }
.sew-band { grid-row: 3; }
.sew-stage { grid-row: 4; }
.sew-dock { grid-row: 5; }

/* ---------- top bar ---------- */
.sew-top {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}
.sew-back {
  display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin-left: -8px; flex: none;
  border-radius: 50%; color: var(--ink); text-decoration: none;
}
.sew-back:hover { background: var(--sand); }
.sew-grow { flex: 1; }
@media (max-width: 599px) { .sew-top { gap: 4px; padding: 0 10px; } .sew-top .sew-icon { width: 40px; height: 40px; } }   /* a phone: every button of the bar on it */
.sew-pick {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  padding: 6px 8px; border: 0; border-radius: 8px; background: none; font-weight: 500; cursor: pointer;
}
.sew-pick > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }   /* a long name gives way: the bar's buttons stay */
.sew-pick b { flex: none; padding: 3px 7px; border-radius: 99px; background: var(--sand); color: var(--ink-2); font: 500 12px/1 var(--mono); }
.sew-pick .px-glyph { color: var(--ink-3); }
.sew-edit {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none; margin-left: -6px;
  border: 0; border-radius: 50%; background: none; color: var(--ink-3); cursor: pointer;
}
.sew-edit:hover { background: var(--sand); color: var(--ink); }
.sew-edit[hidden], .sew-pick[hidden] { display: none; }
.sew-name { flex: 4 1 0; min-width: 0; max-width: 420px; }       /* most of the bar while the name is being changed */
.sew-name[hidden] { display: none; }
.sew-name .sew-input { width: 100%; padding: 7px 10px; border: 2px solid var(--ink); border-radius: 8px; font-weight: 500; }
.sew-name .sew-input:focus { outline: none; border-color: var(--accent); }
.sew-icon {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2); cursor: pointer;
}
.sew-icon:disabled { opacity: 0.35; cursor: default; }
.sew-icon[hidden] { display: none; }
/* how much is done, all along the bottom of the top bar */
.sew-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: var(--sand); }
.sew-progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }

.sew-menu {
  position: absolute; top: 46px; z-index: 10;
  min-width: 260px; max-width: calc(100vw - 24px); max-height: calc(100dvh - 60px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px var(--shadow); padding: 6px;
}
#patternMenu { left: 40px; }
.sew-more { right: 12px; }
.sew-menu a { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.sew-menu a[aria-current="true"] { background: var(--paper); }
.sew-menu a canvas { flex: none; border-radius: 4px; border: 1px solid var(--line); image-rendering: pixelated; }
.sew-menu-words { display: flex; flex-direction: column; min-width: 0; }
.sew-menu-words span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sew-menu a small { color: var(--ink-3); font-family: var(--mono); font-size: 11px; }
.sew-menu .sew-new { color: var(--ink-2); border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 4px; }
.sew-menu-title { margin: 6px 10px 4px; font-size: 11px; color: var(--ink-3); }
/* the ⋯ menu's two parts: this pattern, and how the chart looks */
.sew-menu-group {
  margin: 4px 10px 2px; padding-top: 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; color: var(--ink-2);
}
.sew-menu-group:first-child { padding-top: 2px; }
.sew-more .sew-menu-group:not(:first-child) { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.sew-more .sew-danger { margin-top: 6px; }
/* the pattern's own: tiles, a picture over its word */
.sew-tiles { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; padding: 4px 6px 10px; }
.sew-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; padding: 14px 4px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font-size: 12.5px; cursor: pointer;
}
.sew-tile[hidden] { display: none; }
.sew-tile .px-glyph { margin: 4px 0; transform: scale(1.5); color: var(--ink-2); }      /* 3 px a pixel: still crisp */
.sew-tile:hover { border-color: var(--ink-3); }
.sew-choice { display: flex; gap: 6px; padding: 0 6px 8px; }
.sew-choice button {
  flex: 1; padding: 8px 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--card);
  white-space: nowrap; font-size: 12.5px; cursor: pointer;
}
.sew-choice button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
/* the language switch in the top bars: just the code, quiet; the native list (by name) over it, unseen */
.sew-lang { position: relative; display: inline-flex; align-items: center; gap: 2px; padding: 4px 4px; border-radius: 6px;
  font: 500 11.5px var(--mono); letter-spacing: .06em; color: var(--ink-3); cursor: pointer; }
.sew-lang::after { content: ""; width: 0; height: 0; border: 3.5px solid transparent; border-top-color: currentColor; border-bottom: 0; margin-left: 2px; }
.sew-lang:hover, .sew-lang:focus-within { color: var(--ink); background: var(--card); }
.sew-lang select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 16px; }
.sew-item { display: block; width: 100%; padding: 10px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.sew-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sew-switch { position: relative; flex: none; width: 34px; height: 20px; border-radius: 99px; background: var(--stone); transition: background 0.15s; }
.sew-switch::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.sew-toggle[aria-pressed="true"] .sew-switch { background: var(--accent); }
.sew-toggle[aria-pressed="true"] .sew-switch::after { transform: translateX(14px); }
.sew-danger {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 12px 10px 8px;
  border: 0; border-top: 1px solid var(--line); background: none; color: var(--danger); font-size: 13px; cursor: pointer;
}

/* ---------- the modes: stitching, or changing the chart's colors ---------- */
.sew-modes {
  position: relative; display: flex; align-items: stretch; flex-wrap: wrap; gap: 4px; padding: 0 14px;
  border-bottom: 1px solid var(--line); background: var(--paper);
}
.sew-modes [role="tab"] {
  min-height: 42px; padding: 0 16px; border: 0; border-bottom: 3px solid transparent; background: none;
  color: var(--ink-3); font-weight: 500; font-size: 13.5px; cursor: pointer;
}
.sew-modes [role="tab"]:hover { color: var(--ink); }
.sew-modes [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.sew-mode-note { flex: 1 1 100%; order: 3; margin: 0; padding: 0 0 8px; color: var(--ink-2); font-size: 12px; line-height: 1.4; }
.sew-mode-note[hidden] { display: none; }
/* while colors are changed everything says so: the tab, a band, a dashed frame round the chart */
.recoloring .sew-modes { background: color-mix(in srgb, var(--accent) 12%, var(--paper)); border-bottom-color: var(--accent); }
.recoloring .sew-modes [role="tab"][aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.recoloring .sew-stage::after {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  border: 3px dashed var(--accent); opacity: 0.8;
}
.recoloring .sew-check, .recoloring .sew-finder { display: none; }
.recoloring .sew-toast { top: 92px; }

.sew-brushes {
  position: absolute; left: 50%; top: 34px; transform: translateX(-50%); z-index: 4;
  display: flex; gap: 2px; padding: 4px; max-width: calc(100% - 24px);
  background: var(--card); border: 1px solid var(--line); border-radius: 99px; box-shadow: 0 3px 10px var(--shadow);
}
.sew-brushes[hidden] { display: none; }
.sew-brush-set { display: flex; gap: 2px; }
.sew-brush-undo { display: inline-flex; align-items: center; gap: 5px; margin-left: 4px; border-left: 1px solid var(--line) !important; border-radius: 0 99px 99px 0 !important; }
.sew-brush-undo svg { flex: none; }
.sew-brush-undo:disabled { opacity: 0.35; cursor: default; }
@media (max-width: 399px) { .sew-brush-undo span { display: none; } .sew-brushes button { min-width: 44px; padding: 0 9px; } }
.sew-brushes button {
  min-width: 56px; min-height: 40px; padding: 0 12px; border: 0; border-radius: 99px; background: none;
  color: var(--ink-2); font-size: 12.5px; white-space: nowrap; cursor: pointer;
}
.sew-brushes button[aria-checked="true"] { background: var(--accent); color: #fff; }

.sew-dropper {
  display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink-2); white-space: nowrap; cursor: pointer;
}
.sew-dropper[hidden] { display: none; }
@media (max-width: 599px) { .sew-dropper { padding: 9px 11px; } .sew-dropper span { display: none; } }      /* a phone's peek has no room for its word */
.sew-dropper[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* the palette (the thread list while colors are changed) */
.sew-bar[hidden] { display: none; }
.sew-add.sew-change { width: auto; min-width: 56px; padding: 0 10px; font-size: 12px; color: var(--ink-2); border-style: solid; border-color: var(--line); }
.sew-add.sew-change:hover { border-color: var(--ink-3); color: var(--ink); }
.sew-addthread { border-color: var(--accent) !important; color: var(--accent) !important; }

/* ---------- the reminder to save a file ---------- */
.sew-band {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 7px 14px;
  background: var(--band); border-bottom: 1px solid var(--band-line); color: var(--band-ink); font-size: 12px;
}
.sew-band[hidden] { display: none; }
.sew-band { flex-wrap: wrap; row-gap: 4px; }
.sew-band > span { flex: 1 1 150px; min-width: 0; }
.sew-info, .sew-band-close {
  display: flex; align-items: center; justify-content: center; min-width: 36px; min-height: 36px;
  border: 0; background: none; color: inherit; cursor: pointer;
}
.sew-info { font-size: 15px; line-height: 1; margin: -9px -6px -9px -10px; }
.sew-band-save { margin-left: auto; padding: 9px 12px; border: 0; border-radius: 6px; background: var(--ink); color: var(--paper); cursor: pointer; }
.sew-band-close { font-size: 18px; line-height: 1; margin: -9px -10px -9px -2px; opacity: 0.7; }
.sew-tip {
  position: absolute; z-index: 12; left: 12px; right: 12px; top: calc(100% + 8px);
  padding: 12px 14px; background: var(--card); color: var(--ink-2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px var(--shadow); font-size: 12.5px; line-height: 1.55;
}
.sew-tip p { margin: 0 0 6px; }
.sew-tip p:last-child { margin: 0; }

/* ---------- the chart ---------- */
.sew-stage { position: relative; min-height: 0; overflow: hidden; background: var(--stage); }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.sew-map {
  position: absolute; left: 12px; bottom: 12px;
  padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 3px 10px var(--shadow);
}
.sew-map canvas { display: block; border-radius: 5px; touch-action: none; image-rendering: pixelated; }
.sew-map-fold {
  position: absolute; right: 6px; top: 6px; min-height: 24px; padding: 0 7px;
  border: 0; border-radius: 6px; background: color-mix(in srgb, var(--card) 85%, transparent); color: var(--ink-3); font-size: 11px; cursor: pointer;
}
.sew-map.folded { padding: 0; }
.sew-map.folded .sew-map-fold { position: static; min-height: 44px; padding: 0 14px; color: var(--ink-2); background: none; }

.sew-toast {
  position: absolute; left: 50%; top: 34px; transform: translateX(-50%); margin: 0;
  width: max-content; max-width: min(400px, calc(100% - 24px));
  padding: 8px 14px; border-radius: 10px; background: rgba(17, 17, 17, 0.85); color: #fff; font-size: 12.5px; line-height: 1.45;
  pointer-events: none; text-align: center; z-index: 4;
  white-space: pre-line;                    /* a sentence a line (the words say where: \n) */
}
.finding .sew-toast { top: 92px; }          /* under the finder bar at the top */

/* the thread picked: from one place it is left to the next */
.sew-finder {
  position: absolute; left: 50%; top: 34px; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; gap: 2px; padding: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 99px; box-shadow: 0 3px 10px var(--shadow);
}
.sew-finder button { min-width: 40px; height: 40px; border: 0; border-radius: 99px; background: none; color: var(--ink-2); cursor: pointer; font: inherit; }
.sew-finder button:disabled { opacity: 0.3; cursor: default; }
.sew-finder button:not(.sew-finder-label) { display: grid; place-items: center; }
.sew-finder-label { display: flex; align-items: center; gap: 8px; padding: 0 10px !important; white-space: nowrap; font: 500 12.5px/1 var(--sans) !important; color: var(--ink) !important; }
.sew-finder-label small { color: var(--ink-3); font: 400 11px/1 var(--sans); }
/* a phone: the thread's place over its count, so the arrows stay on the screen */
@media (max-width: 599px) {
  .sew-finder { width: max-content; max-width: calc(100% - 16px); }   /* (placed from the middle: it would take half the width only) */
  .sew-finder-label { min-width: 0; display: grid !important; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; row-gap: 3px; text-align: left; }
  .sew-finder-label .sew-finder-dot { grid-row: 1 / 3; }
  .sew-finder-label > span:not(.sew-finder-dot), .sew-finder-label small { overflow: hidden; text-overflow: ellipsis; }
}
.sew-finder-dot { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); background: var(--thread, transparent); box-shadow: 0 0 0 2px var(--accent); }
/* "N marks taken away · undo": above the buttons at the bottom */
.sew-snack {
  position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 12px; width: max-content; max-width: calc(100% - 24px);
  padding: 6px 6px 6px 14px; border-radius: 12px; background: rgba(17, 17, 17, 0.9); color: #fff; font-size: 12.5px;
  box-shadow: 0 4px 14px var(--shadow);
}
.sew-snack button {
  flex: none; min-height: 36px; padding: 0 12px; border: 0; border-radius: 8px;
  background: none; color: #ffb38a; font: inherit; font-weight: 600; cursor: pointer;
}
.sew-note.ok { background: rgba(17, 17, 17, 0.85); }
.sew-note {
  position: fixed; z-index: 30; left: 50%; top: 64px; transform: translateX(-50%); margin: 0; max-width: calc(100vw - 24px);
  padding: 7px 12px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; white-space: pre-line;
}

.sew-tools {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.sew-fit {
  display: flex; align-items: center; gap: 7px; cursor: pointer; padding: 6px 12px; font-size: 12px; min-height: 36px;
  background: var(--card); border: 1px solid var(--line); border-radius: 99px; color: var(--ink-2);
  box-shadow: 0 3px 10px var(--shadow);
}
/* "mark as done" is a .px-btn: an empty box while off, a check while on (pressed in) */
.sew-check > span { display: contents; }
.sew-check:not([aria-pressed="true"]) .sew-ck-on, .sew-check[aria-pressed="true"] .sew-ck-off { display: none; }

/* ---------- thread list ---------- */
.sew-dock {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--paper); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; box-shadow: 0 -8px 24px var(--shadow);
  position: relative; z-index: 2;
}
.sew-peek { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
/* a thread: its photo where there is one, its color under it */
.sew-swatch, .sew-dot { background: var(--thread) center / cover no-repeat; border: 1px solid rgba(0, 0, 0, 0.13); }
.sew-swatch { width: 34px; height: 34px; flex: none; border-radius: 8px; }
.sew-swatch.set { background: conic-gradient(var(--accent) 0 25%, var(--sand) 0 50%, var(--accent) 0 75%, var(--sand) 0); }
.sew-cur { flex: 1; min-width: 0; }
.sew-cur b { display: block; font-weight: 500; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sew-cur small { display: block; color: var(--ink-3); font-size: 12px; line-height: 1.3; }
.sew-sym-inline { font-family: var(--mono); }
.sew-open {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink-2);
  white-space: nowrap; cursor: pointer;
}
.sew-sheet { display: none; flex-direction: column; min-height: 0; height: 46dvh; }
.sew-fold { display: none; }
/* the threads being stitched, on the folded list's tab (wide screens): a colour boxed with its number */
.sew-worktabs { display: none; flex-direction: column; align-items: center; gap: 6px; padding: 0 5px 12px; min-height: 0; overflow-y: auto; }
.sew-worktab {
  display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100%; padding: 4px 2px 3px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card); cursor: pointer;
}
.sew-worktab b { font: 500 10px/1.1 var(--mono); letter-spacing: 0; color: var(--ink); max-width: 100%; overflow: hidden; text-overflow: clip; white-space: nowrap; }
.sew-worktab[aria-pressed="true"] { border: 2px solid var(--accent); padding: 3px 1px 2px; }
/* none being stitched: the strip's empty pocket, a dashed guide that opens the list */
.sew-worktab.empty { height: 46px; justify-content: center; border: 1.5px dashed var(--stone); background: none; color: var(--ink-3); }
.sew-worktab.empty:hover { border-color: var(--ink-3); color: var(--ink); }
.sheet-open .sew-sheet { display: flex; }
.sew-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 8px; }
.sew-filters button {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--ink-2); cursor: pointer;
}
.sew-filters button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.sew-filters .sew-clear { border-style: dashed; background: none; }
.sew-find { display: flex; gap: 8px; margin: 0 16px 8px; }
.sew-search, .sew-sort, .sew-input {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit;
}
.sew-search { flex: 1; min-width: 0; }
.sew-sort { flex: none; max-width: 42%; }
.sew-list { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 10px 10px; }
.sew-row { position: relative; display: flex; align-items: center; border-radius: 10px; }
.sew-row-main {
  flex: 1; min-width: 0; display: grid; grid-template-columns: 26px 24px 1fr 86px; gap: 10px; align-items: center;
  min-height: 52px; padding: 8px; border: 0; border-radius: 10px; background: none; text-align: left; cursor: pointer;
}
.sew-row.picked { background: var(--card); box-shadow: 0 0 0 1.5px var(--accent); }
.sew-row.picked::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--accent);
}
.sew-row.in-set:not(.picked) { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.sew-row.finished { opacity: 0.5; }
.sew-dot { width: 26px; height: 26px; border-radius: 6px; }
.sew-sym { font: 16px var(--mono); text-align: center; }
.sew-nm { min-width: 0; }
.sew-nm b { display: block; font-weight: 500; }
.sew-nm small { display: block; color: var(--ink-3); font-size: 11px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sew-pg { text-align: right; font-size: 11px; color: var(--ink-2); }
.sew-pg .sew-sk { display: block; color: var(--ink-3); font-size: 10.5px; line-height: 1.2; }
.sew-bar { display: block; height: 4px; margin-top: 3px; border-radius: 2px; background: var(--sand); overflow: hidden; }
.sew-bar i { display: block; height: 100%; background: var(--ink); }
.sew-add {
  flex: none; width: 40px; height: 40px; margin-left: 2px; border: 1px dashed var(--stone); border-radius: 10px;
  background: none; color: var(--ink-3); font-size: 15px; cursor: pointer;
}
.sew-add[aria-pressed="true"] { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.sew-done { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
.sew-done summary { padding: 10px 8px; color: var(--ink-3); cursor: pointer; }

/* ---------- dialogs, empty page ---------- */
.sew-card {
  width: min(340px, 88vw); padding: 22px; border: 0; border-radius: 16px; background: var(--paper); color: var(--ink);
  box-shadow: 0 10px 40px var(--shadow);
}
.sew-card::backdrop { background: rgba(17, 17, 17, 0.5); }
.sew-card h2 { margin: 0 0 6px; font-weight: 500; font-size: 16px; }
.sew-card p { margin: 0 0 16px; color: var(--ink-2); white-space: pre-line; }
.sew-card .sew-card-note { margin-top: -8px; color: var(--ink-3); font-size: 12px; }
.sew-card .link-login { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--sand); color: var(--ink-2); font-size: 13px; line-height: 1.6; white-space: pre-line; }
#linkLoginGo { text-decoration: none; }
.sew-card canvas { display: block; max-width: 100%; margin: 0 auto 14px; border: 1px solid var(--line); border-radius: 6px; }
.sew-actions { display: flex; gap: 8px; }
.sew-actions .px-btn { flex: 1; justify-content: center; }
.sew-actions.stack { flex-direction: column; }
/* ---------- my stitching: the patterns kept here ---------- */
.sew-library { min-height: 100dvh; overflow-y: auto; height: 100dvh; padding: 0 0 40px; }
.sew-lib-top {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.sew-lib-top h1 { display: flex; align-items: center; gap: 8px; margin: 0 0 0 6px; font-weight: 600; font-size: 16px; color: var(--ink); }
.sew-lib-top h1 svg { display: block; image-rendering: pixelated; }
.sew-lib-top h1 .smoke { animation: sew-smoke 3.2s ease-in-out infinite; }
@keyframes sew-smoke { 0%, 100% { transform: translate(0, 0); opacity: .9; } 50% { transform: translate(.6px, -.8px); opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .sew-lib-top h1 .smoke { animation: none; } }
.sew-lib-top h1 { min-width: 0; white-space: nowrap; }
.sew-lib-top h1 span { overflow: hidden; text-overflow: ellipsis; }   /* a long name gives way to the buttons */
.sew-lib-top .px-btn { flex: none; }
.sew-me { display: flex; flex: none; }
@media (max-width: 520px) {
  .sew-lib-top { gap: 6px; padding: 8px 12px; }
  .sew-lib-top h1 { margin: 0; font-size: 15px; }
  .sew-lib-top .px-btn-fold { display: none; }
  .sew-me .g-me > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }   /* the chip by its picture (its name still read out) */     /* the folder alone says "open a file" (its name stays for screen readers) */
}
.sew-lib-band { margin: 12px 16px 0; padding: 10px 12px; gap: 10px; border: 1px solid var(--band-line); border-radius: 10px; font-size: 13px; line-height: 1.5; }
.sew-lib-band > span { flex: 1 1 180px; }
.sew-lib-band .px-btn { flex: none; }
.sew-lib-note { margin: 16px; padding: 10px 14px; border-radius: 10px; background: var(--band); color: var(--band-ink); }
.sew-lib-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 12px;
  max-width: 1100px; margin: 0 auto; padding: 18px 16px;
}
.sew-lib-card {
  display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.sew-lib-card:hover { border-color: var(--ink); }
.sew-lib-pic { display: grid; place-items: center; aspect-ratio: 4 / 3; padding: 8px; border-radius: 8px; background: var(--stage); overflow: hidden; }
.sew-lib-link { flex: none; display: inline-flex; margin-left: 5px; color: var(--ink-3); }   /* the pattern has a link (sharing.js) */
.sew-lib-link svg { width: 14px; height: 14px; }
.sew-lib-pic canvas { image-rendering: pixelated; max-width: 100%; max-height: 100%; height: auto !important; object-fit: contain; }
@media (min-width: 700px) { .sew-lib-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; } }
.sew-lib-card b { display: flex; align-items: center; min-width: 0; font-weight: 500; font-size: 14px; white-space: nowrap; }
.sew-lib-card b > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.sew-lib-card small { color: var(--ink-3); font-size: 11.5px; }
.sew-lib-meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2px 8px; font-size: 12px; color: var(--ink-2); }
.sew-lib-meta span:first-child { font-family: var(--mono); font-weight: 500; color: var(--ink); }
.sew-lib-card .sew-bar { margin: 0; height: 5px; }
.sew-lib-card .sew-bar i { background: var(--accent); }
.sew-library .sew-empty { height: auto; min-height: 60dvh; }
.sew-empty { display: grid; place-content: center; justify-items: center; gap: 18px; height: 100dvh; text-align: center; padding: 24px; }
.sew-empty p { margin: 0; color: var(--ink-2); }
.sew-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.sew-empty .sew-empty-note { max-width: 300px; color: var(--ink-3); font-size: 12px; }

/* a phone with the thread list open: the little chart left is for the chart, not the map */
@media (max-width: 599px) {
  .sheet-open .sew-map, .sheet-open .sew-fit { display: none; }
}

/* ---------- wide screens: the list beside the chart; folded away, a tab at the edge (like a binder's
   index: the picked thread's colour, and the list's name down it) ---------- */
@media (min-width: 900px) {
  .sew { grid-template-columns: minmax(0, 1fr) 52px; grid-template-rows: 50px auto auto minmax(0, 1fr); }
  .sheet-open .sew { grid-template-columns: minmax(0, 1fr) 340px; }
  .sew-top, .sew-modes, .sew-band { grid-column: 1 / -1; }
  .sew-tip { right: auto; width: 420px; }
  .sew-stage { grid-column: 1; }
  .sew-dock { grid-column: 2; grid-row: 4; border-radius: 0; border-top: 0; border-left: 1px solid var(--line); box-shadow: none; }
  .sheet-open .sew-peek { border-bottom: 1px solid var(--line); margin-bottom: 8px; }
  .sheet-open .sew-sheet { flex: 1; height: auto; }
  .sew-dock { position: relative; z-index: 2; }
  .sew-open { display: none; }
  /* the index tab: on the list's left edge, sticking out over the chart */
  .sew-fold {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    position: absolute; left: -26px; top: 16px; width: 26px; height: 76px; padding: 0;
    border: 1px solid var(--line); border-right: 0; border-radius: 9px 0 0 9px; background: var(--card); color: var(--ink-2); cursor: pointer;
    box-shadow: -3px 2px 8px var(--shadow);
  }
  .sew-fold:hover { color: var(--ink); }
  .sew-fold svg:not(.sew-fold-arrow) { width: 14px; height: 14px; }
  .sew-fold[aria-expanded="false"] .sew-fold-arrow { transform: scaleX(-1); }
  :root:not(.sheet-open) .sew-peek { display: none; }
  :root:not(.sheet-open) .sew-worktabs { display: flex; padding-top: 12px; }
  /* the one action in the middle, "whole pattern" in the corner (the map has the other one) */
  .sew-tools { left: 12px; right: 12px; bottom: 16px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; pointer-events: none; }
  .sew-tools > * { pointer-events: auto; }
  .sew-mode-note { flex: 1 1 0; order: 0; align-self: center; padding: 0 0 0 12px; }
  .sew-check { grid-column: 2; grid-row: 1; }
  .sew-fit { grid-column: 3; grid-row: 1; justify-self: end; }
}

/* ---------- print · PDF: its name and which of the three (main.js pdf) ---------- */
.sew-card .sew-pdf-name { width: 100%; margin: 6px 0 0; }
.sew-card .sew-pdf-hint { margin: 6px 0 0; }
.sew-kinds { border: 0; margin: 12px 0 16px; padding: 0; display: grid; gap: 6px; }
.sew-kind { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.sew-kind:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.sew-kind input { accent-color: var(--ink); width: 16px; height: 16px; margin: 0; flex: none; }
.sew-kind b { font-weight: 500; font-size: 14px; }
.sew-kind b span { color: var(--ink-3); font-weight: 400; }
.sew-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }


/* the way to the pattern's history, at the foot of the thread panel: with the list open (a wide screen's
   folded strip keeps its icon, at the bottom) */
.sew-history { display: none; align-items: center; justify-content: center; gap: 7px; flex: none; margin-top: auto; padding: 11px 10px;
  border: 0; border-top: 1px solid var(--line); background: none; color: var(--ink-2); font: 500 12.5px var(--sans); letter-spacing: .04em; cursor: pointer; }
.sew-history:hover { color: var(--ink); background: var(--card); }
.sheet-open .sew-history { display: flex; }
@media (min-width: 900px) {
  .sew-history { display: flex; }
  :root:not(.sheet-open) .sew-history { padding: 12px 0; }
  :root:not(.sheet-open) .sew-history span { display: none; }
}

/* a passed-on link's pattern (linkview.js): tapped, shown big */
.link-map { position: relative; display: block; margin: 0 auto 14px; padding: 0; border: 0; background: none; cursor: zoom-in; }
.sew-card .link-map canvas { margin: 0; }
.link-zoom { position: absolute; right: 6px; bottom: 6px; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px;
  background: rgba(17, 17, 17, .55); color: #fff; font-size: 14px; line-height: 1; }
.sew-card.link-view { width: min(464px, 92vw); }

/* nothing drawn after a while (stitch.html): what went wrong, and a reload */
.sew-stuck { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 24px; text-align: center; background: var(--paper); color: var(--ink); }
.sew-stuck[hidden] { display: none; }
.sew-stuck p { margin: 0; }
.sew-stuck pre { max-width: min(560px, 90vw); max-height: 40vh; overflow: auto; margin: 0; padding: 10px; border-radius: 8px; background: var(--sand); color: var(--ink-2); font-size: 11px; text-align: left; white-space: pre-wrap; word-break: break-all; }
