/* ==========================================================================
   Stitchkeeper — css/app.css
   Layout + components. Colors, fonts, radii and shadows come ONLY from the
   theme variables below (themes.css overrides them per html[data-theme]).
   The :root block is the "stardew-spring" default so the app is fully
   styled even if themes.css fails to load.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Theme variables (defaults = stardew-spring)
   -------------------------------------------------------------------------- */

:root {
  --bg: #fbf3e0;
  --bg-image: none;
  --surface: #fffaf0;
  --surface-2: #f4e8d2;
  --text: #4a3b2a;
  --text-muted: #8c7a62;
  --border: #e2d1b0;
  --primary: #7cb342;
  --primary-text: #ffffff;
  --primary-glow: rgba(124, 179, 66, 0.45);
  --accent: #f0a868;
  --accent-text: #4a3b2a;
  --accent-2: #4f9a3f;
  --danger: #c0563e;
  --success: #4c9a2a;
  --radius: 18px;
  --radius-sm: 10px;
  --shadow: 0 2px 0 rgba(160, 134, 94, 0.35), 0 8px 20px rgba(74, 59, 42, 0.10);
  --font-body: "Nunito", ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Fredoka", "Nunito", ui-rounded, "Segoe UI", system-ui, sans-serif;
  --counter-size: 96px;
  --tap-border: 2px solid #6b9c36;
  --header-bg: #9ccc65;
  --header-text: #2f3d1c;
  --mascot: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath d='M32 6 L43 22 H21 Z' fill='%238bc34a'/%3E%3Cellipse cx='32' cy='40' rx='20' ry='21' fill='%237cb342'/%3E%3Ccircle cx='25' cy='37' r='3.6' fill='%23263238'/%3E%3Ccircle cx='39' cy='37' r='3.6' fill='%23263238'/%3E%3Ccircle cx='26.2' cy='35.8' r='1.2' fill='%23ffffff'/%3E%3Ccircle cx='40.2' cy='35.8' r='1.2' fill='%23ffffff'/%3E%3Cpath d='M26 47 q6 6 12 0' stroke='%23263238' stroke-width='2.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  --overlay: rgba(52, 40, 26, 0.48);
  --color-scheme: light;

  /* layout sizes (not themed) */
  --topbar-h: 56px;
  --bottombar-h: 62px;
  --gap: 12px;
  --pad: 14px;
  --maxw: 640px;
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

* { box-sizing: border-box; }

html {
  color-scheme: var(--color-scheme);
  -webkit-text-size-adjust: 100%;
}

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

body {
  min-height: 100dvh;
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 700; }

p { margin: 0 0 0.6em; }

:focus-visible {
  outline: 3px solid var(--accent-2);
  outline-offset: 2px;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--text-muted); }
.hidden, [hidden] { display: none !important; }

/* --------------------------------------------------------------------------
   3. Screens
   -------------------------------------------------------------------------- */

.screen {
  position: fixed;
  inset: 0;
  /* A persistent top banner pushes every screen down rather than covering it. */
  top: var(--banner-h, 0px);
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--banner-h, 0px));
}

/* --------------------------------------------------------------------------
   3b. Top banners — a save that failed, private browsing, a second tab
   (13 #1–#3, 09 #2). Never dismissable; the user has to act or accept.
   -------------------------------------------------------------------------- */

.banners {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
}
.banners:empty { display: none; }

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px var(--pad);
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--danger);
  color: var(--primary-text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}
.banner-calm {
  background: var(--surface-2);
  color: var(--text);
}
.banner-text { flex: 1 1 200px; margin: 0; min-width: 0; }
.banner-actions { flex: 0 0 auto; display: flex; gap: 8px; flex-wrap: wrap; }
.banner .btn {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  border-color: var(--surface);
}
.banner-calm .btn { border-color: var(--border); }

/* "Your work lives only on this phone" (12 #1) — dismissible, on Home. */
.nag-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.nag-text { flex: 1 1 180px; margin: 0; font-size: 14px; font-weight: 700; line-height: 1.35; }
.nag-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 14px; }

.screen-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--pad);
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
}

.project-body {
  /* .bottombar is a flex sibling of this element, not an overlay, so no room
     needs reserving for it — reserving it pushed −1 / reset below the fold. */
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
/* The body scrolls; its sections must never be squashed to fit. */
.project-body > * { flex: 0 0 auto; }
/* …except the stitch section, which absorbs the leftover height so the big
   button is as large as the screen allows while −1 and reset stay visible. */
.project-body > .stitch-section { flex: 1 1 auto; min-height: 0; }
.project-body .stitch-btn { flex: 1 1 auto; min-height: max(30vh, 170px); }

/* --------------------------------------------------------------------------
   4. Top bar
   -------------------------------------------------------------------------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--topbar-h);
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid var(--border);
}

.topbar-mascot {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  background-image: var(--mascot);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.topbar-title {
  flex: 1 1 auto;
  font-size: 22px;
  letter-spacing: 0.3px;
  color: var(--header-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border-radius: var(--radius-sm);
  color: var(--header-text);
}
.icon-btn:active { transform: scale(0.94); }

.title-btn {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  color: var(--header-text);
  text-align: left;
}
.title-emoji { font-size: 22px; flex: 0 0 auto; }
.title-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.timer-chip.running {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

/* --------------------------------------------------------------------------
   5. Home
   -------------------------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 28px 18px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
}
.empty-mascot {
  width: 92px; height: 92px;
  margin: 0 auto 10px;
  background-image: var(--mascot);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}
.empty-state h2 { font-size: 22px; margin-bottom: 6px; }

.card-list { display: flex; flex-direction: column; gap: var(--gap); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad);
}

.project-card {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  grid-template-areas: "emoji name pill" "emoji summary summary" "emoji meta meta";
  gap: 2px 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad);
  color: var(--text);
}
.project-card:active { transform: scale(0.99); }
.pc-emoji { grid-area: emoji; font-size: 34px; line-height: 1; align-self: start; }
.pc-name {
  grid-area: name;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pc-pill { grid-area: pill; }
.pc-summary { grid-area: summary; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.pc-meta { grid-area: meta; font-size: 12px; color: var(--text-muted); }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
}
.pill.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.pill.paused { background: var(--surface-2); color: var(--text-muted); }
.pill.finished { background: var(--success); color: var(--primary-text); border-color: var(--success); }
.pill.frogged { background: var(--danger); color: var(--primary-text); border-color: var(--danger); }

.shelf { margin-top: 18px; }
.shelf-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 6px 4px;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 14px;
}
.shelf-caret { display: inline-block; transition: transform 0.15s ease; }
.shelf-toggle[aria-expanded="true"] .shelf-caret { transform: rotate(90deg); }

.fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 56px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-text);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 6px 18px var(--primary-glow);
  border: var(--tap-border);
}
.fab:active { transform: translateY(2px); }

/* --------------------------------------------------------------------------
   6. Part tabs
   -------------------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 6px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  /* 13 #10: a very long part name used to wrap into a block that filled the
     whole strip and pushed "＋ part" out of reach. */
  max-width: 11em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tab-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}
.tab-badge { opacity: 0.85; font-weight: 700; font-variant-numeric: tabular-nums; }
.tab-add { border-style: dashed; color: var(--text-muted); }

/* Wave G: the sizes of a multi-size booklet, one tab each, over the part
   chips of the open size. An underline tab, so it reads as a different level
   from the pill-shaped part chips under it; scrolls sideways on a phone. */
.size-tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border);
  margin: 0 0 2px;
}
.size-tabs::-webkit-scrollbar { display: none; }
.size-tabs[hidden] { display: none; }
.size-tab {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  max-width: 12em;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.size-tab-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.size-tab.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}
.size-tab.off .size-tab-name { text-decoration: line-through; opacity: 0.7; }
.size-tab-skip { font-weight: 400; font-size: 13px; }
.size-tab-done { color: var(--primary); }
.size-tab-more {
  flex: 0 0 auto;
  margin-left: auto;
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: 0;
  color: var(--text-muted);
  font-size: 20px;
  font-weight: 700;
}
.row-group-tag { text-transform: none; letter-spacing: 0; font-weight: 700; }
.pc-sizes { font-weight: 700; }
.parts-group-head {
  margin: 12px 0 4px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.parts-group-head:first-child { margin-top: 0; }
.size-menu-progress { margin: 0 0 10px; }
.menu-item.danger-item:not(:disabled) { color: var(--danger, #c0392b); }
.menu-item:disabled { opacity: 0.5; }
.imp-size-tabs { margin-bottom: 6px; }
.imp-size-tick { margin: 2px 0 6px; }
.imp-size-panel.skipped .imp-item { opacity: 0.5; }
.imp-place {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}
.imp-place-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repeat-readout {
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   7. Row counter
   -------------------------------------------------------------------------- */

.counter-card { text-align: center; padding: 10px var(--pad) 14px; }

.counter-label {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 2px;
  font-weight: 700;
  color: var(--text-muted);
}

.counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.big-number {
  flex: 1 1 auto;
  font-family: var(--font-display);
  font-size: var(--counter-size);
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.round-btn {
  flex: 0 0 auto;
  width: 62px; height: 62px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.round-btn.accent {
  background: var(--accent);
  color: var(--accent-text);
  border: var(--tap-border);
}
.round-btn:active { transform: scale(0.94); }

.progress { margin-top: 8px; }
.bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress.slim .bar { height: 6px; }
.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-2);
  transition: width 0.18s ease;
}
.bar-label {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   8. Pattern line
   -------------------------------------------------------------------------- */

.pattern-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
/* Wave I (the owner, on a phone: "a lil bigger would be awesome"): the strip
   reads about 1.2x larger than it did (tag 11 -> 13.5 px, instruction 15 -> 18
   px) and wraps to two lines at most; the whole text is a tap away in the
   pattern sheet. The stitch button gives the height back (see "17. Larger
   screens" and the short-screen blocks), so nothing overflows at 375 x 640. */
.pattern-line-tag {
  flex: 0 0 auto;
  font-size: 13.5px;
  font-weight: 900;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text);
}
.pattern-line-text {
  flex: 1 1 auto;
  font-size: 18px;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.pattern-line-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pattern-line-notes {
  font-size: 14px;
  line-height: 1.3;
  color: var(--text-muted);
}

/* Setup / foundation line, shown while the first row is being worked */
.setup-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
}
.setup-line-tag {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text);
}
.setup-line-text {
  flex: 1 1 auto;
  font-size: 14px;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* --------------------------------------------------------------------------
   9. Stitch button
   -------------------------------------------------------------------------- */

.stitch-section { position: relative; display: flex; flex-direction: column; gap: 8px; }

.stitch-btn {
  position: relative;
  width: 100%;
  min-height: max(42vh, 190px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: var(--radius);
  border: var(--tap-border);
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 6px 0 var(--primary-glow), var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}
.stitch-btn.pressed {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--primary-glow);
}
.stitch-btn.flash {
  animation: sk-flash 0.45s ease;
}
@keyframes sk-flash {
  0%, 100% { background: var(--primary); }
  30% { background: var(--danger); }
  65% { background: var(--primary); }
}

/* Without the 3D piece this is just the old centred stack. */
.stitch-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.stitch-caption {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 2px;
  opacity: 0.85;
}
.stitch-number {
  font-family: var(--font-display);
  font-size: calc(var(--counter-size) * 1.15);
  font-weight: 700;
  line-height: 1.02;
  font-variant-numeric: tabular-nums;
}
.stitch-hint { font-size: 12px; letter-spacing: 3px; text-transform: uppercase; opacity: 0.6; }

/* --- Live 3D diagram inside the stitch button --- */

.stitch-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  pointer-events: none;
}
/* 05 #1 — get the piece out from under the number.
   `STITCHES`, a 90 px numeral and the `TAP` pill used to run straight down the
   vertical axis of the button, which is exactly where a round-worked solid of
   revolution is: on the 6-round Ear the whole model sat behind the `STITCHES`
   pill. Now the readout is a single row pinned to the TOP of the button and
   everything below it belongs to the piece (app.js measures this row and hands
   the renderer matching `safeInsets`, so the fit box is the free area, not the
   canvas). The number stays the biggest, most legible thing on screen. */
.stitch-btn.has-diagram {
  justify-content: flex-start;
  gap: 0;
}
.stitch-btn.has-diagram .stitch-head {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  flex-direction: row;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 6px 14px 2px;
}
.stitch-btn.has-diagram .stitch-number {
  /* Smaller, because it no longer has to hold a whole button on its own: it
     is a pinned readout with the piece under it, not a backdrop. At 375 px
     this is still a ~65 px numeral — the largest thing on the screen after
     the round number — and it buys the piece 60 % more room. */
  font-size: calc(var(--counter-size) * 0.68);
  text-shadow:
    0 0 2px var(--primary),
    0 0 6px var(--primary),
    0 0 14px var(--primary),
    0 2px 3px rgba(0, 0, 0, 0.35);
}
.stitch-btn.has-diagram .stitch-caption {
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0.9;
  text-shadow: 0 0 6px var(--primary), 0 0 12px var(--primary);
}
/* The hint is a hairline at the very bottom, out of the piece's way. */
.stitch-btn.has-diagram .stitch-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  z-index: 1;
  opacity: 0.55;
  font-size: 11px;
  text-shadow: 0 0 6px var(--primary), 0 0 12px var(--primary);
  pointer-events: none;
}
/* Once counting has started the hint has done its job. */
.stitch-btn.has-diagram.counted .stitch-hint { opacity: 0; }

/* The deviation cue (05 #6): quiet, inline, under the stitch readout. */
.stitch-dev {
  font-size: 13px;
  font-weight: 700;
  color: var(--danger);
  text-align: center;
  padding: 0 4px;
}

/* 02 #8 / 07 #7–#8: out of the tap surface and into the actions row. It is a
   plain .btn now, so its colours come from --surface-2 / --text and pass
   contrast in all six themes (the old rule painted --primary-text on a fixed
   black scrim, which measured 1.81:1 in dragon-pixel and 2.53:1 in
   dragon-fury). */
.stitch-3d {
  flex: 0 0 auto;
  gap: 6px;
  min-height: 44px;
  padding: 6px 12px;
  font-size: 14px;
}
.stitch-3d-glyph { font-size: 16px; line-height: 1; }
.stitch-3d:active { transform: translateY(1px); }

/* --- 3D viewer sheet --- */

dialog.sheet.sheet-viewer .sheet-body {
  padding: 0;
  gap: 0;
}
.viewer-readout {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 800;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* "Pattern says 36 · instructions add up to 24" under the round readout. */
.viewer-readout-note {
  display: block;
  max-width: 150px;
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  white-space: normal;
  text-align: right;
}
.viewer-stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  background: var(--primary);
  touch-action: none;
}
.viewer-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.viewer-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pad);
  text-align: center;
  color: var(--primary-text);
  opacity: 0.85;
}
/* What the geometry made of this piece: "Sphere · 15 rounds · 48 around"
   (05 #2 / 12), plus the Rounds/Rows override that writes Part.workMode. */
.viewer-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.viewer-shape {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  min-width: 0;
}
.viewer-shape .viewer-shape-sub {
  display: block;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
}
.viewer-bar .seg { flex: 0 0 auto; }
.viewer-bar .seg button { font-size: 12px; padding: 5px 9px; }
/* Second row of the bar: the Auto/Top-down/Bottom-up chips and what Auto read
   out of the pattern. Its own line, so 375 wide never squeezes the chips. */
.viewer-bar-row {
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
/* "Top-down" / "Bottom-up" stay on one line — a chip broken over two lines
   reads as two chips — so the hint takes the line under them. */
.viewer-bar-row .seg button { white-space: nowrap; }
.viewer-bar-hint {
  flex: 1 0 100%;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
/* "Terms" in front of the Auto/UK/US chips, so they never read as a second
   copy of the Auto/Top-down/Bottom-up row above them. */
.viewer-bar-label {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
}
/* The Terms row keeps its (short) hint beside the chips: a third two-line
   row would take ~75 px off the piece at 375×812. */
.viewer-bar-row-inline { flex-wrap: nowrap; }
.viewer-bar-row-inline .viewer-bar-hint { flex: 1 1 0; }
/* "Showing a simple outline — 3D isn't available right now." */
.viewer-note {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 8px var(--pad);
  font-size: 12px;
  text-align: center;
  color: var(--primary-text);
  background: rgba(0, 0, 0, 0.35);
}
dialog.sheet.sheet-viewer .sheet-inner { height: 92dvh; }
@media (min-width: 700px) {
  dialog.sheet.sheet-viewer .sheet-inner { height: 86dvh; }
}

/* --- Yarn colours sheet --- */

.yarn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.yarn-row:last-child { border-bottom: none; }
.yarn-swatch {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
}
.yarn-main { flex: 1 1 auto; min-width: 0; }
.yarn-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.yarn-reset {
  font-size: 12px;
  padding: 0;
  text-align: left;
}
.yarn-pick {
  flex: 0 0 auto;
  width: 46px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.readout {
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-height: 20px;
}

.stitch-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
/* Wave I: on a phone a knitting part's four actions (−1, + marker, Work in
   3D, reset stitches) wrapped to a second 46 px line, which pushed the
   counter 46 px further over. Tighter padding keeps them on one line. */
@media (max-width: 420px) {
  .stitch-actions { gap: 6px; }
  .stitch-actions > .btn { min-width: 44px; padding-left: 8px; padding-right: 8px; }
  .stitch-actions > .linkish { padding: 0 2px; font-size: 13px; }
}

/* --------------------------------------------------------------------------
   10. Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--primary);
  color: var(--primary-text);
  border: var(--tap-border);
  box-shadow: 0 3px 0 var(--primary-glow);
}
.btn.accent { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: var(--primary-text); border-color: var(--danger); }
.btn.big { min-height: 54px; font-size: 17px; padding: 10px 24px; font-family: var(--font-display); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.45; }

.linkish {
  background: none;
  color: var(--text-muted);
  text-decoration: underline;
  font-size: 14px;
  min-height: 44px;
  padding: 0 8px;
}

/* --------------------------------------------------------------------------
   11. Bottom bar
   -------------------------------------------------------------------------- */

.bottombar {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 4px;
  min-height: var(--bottombar-h);
  padding: 4px 6px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bar-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  min-height: 52px;
}
.bar-btn .bar-icon { font-size: 20px; line-height: 1; }
.bar-btn.on { color: var(--text); background: var(--surface-2); }
.bar-btn[disabled] { opacity: 0.4; }

/* --------------------------------------------------------------------------
   12. Toasts
   -------------------------------------------------------------------------- */

.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bottombar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  width: min(92vw, 460px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 15px;
  font-weight: 700;
  animation: sk-toast-in 0.18s ease;
}
.toast-text { flex: 1 1 auto; }
.toast-action {
  flex: 0 0 auto;
  color: var(--text);
  font-weight: 800;
  text-decoration: underline;
  min-height: 36px;
  padding: 0 6px;
}
@keyframes sk-toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* "A new version is ready" — the fallback used only when App.toast is not up
   (index.html's service-worker registration builds it). */
.sw-update {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(92vw, 460px);
  padding: 8px 8px 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 15px;
  font-weight: 700;
  animation: sk-toast-in 0.18s ease;
}
.sw-update-action {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 800;
  text-decoration: underline;
}
@media (prefers-reduced-motion: reduce) {
  .sw-update { animation: none; }
}

/* --------------------------------------------------------------------------
   13. Sheets (dialog)
   -------------------------------------------------------------------------- */

dialog.sheet {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  max-height: none;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  overflow: hidden;
}
dialog.sheet::backdrop { background: var(--overlay); }
/* No showModal() (older iOS Safari): no top layer and no ::backdrop, so the
   dialog — which already fills the viewport — paints the tint itself and sits
   above the app's own fixed layers (banners 60-80), under the tour (200). A
   tap on the tint is a tap on the dialog, which closes it (UX sweep D3). */
dialog.sheet.sheet-fallback {
  z-index: 150;
  background: var(--overlay);
}

/* The corrupt-state recovery covers everything: the next write would destroy
   the evidence, so there is nothing else to do first (13 #3). */
dialog.sheet.sheet-corrupt .sheet-inner {
  top: 0;
  max-height: none;
  border-radius: 0;
  border: none;
}
dialog.sheet.sheet-corrupt .sheet-grab { display: none; }

dialog.sheet .sheet-inner {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  animation: sk-sheet-up 0.18s ease;
}
@keyframes sk-sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.sheet-head {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px var(--pad) 8px;
  border-bottom: 1px solid var(--border);
}
.sheet-grab {
  position: absolute;
  top: 6px; left: 50%;
  transform: translateX(-50%);
  width: 40px; height: 4px;
  border-radius: 999px;
  background: var(--border);
}
.sheet-title { flex: 1 1 auto; font-size: 19px; }
.sheet-close {
  flex: 0 0 auto;
  min-width: 40px; min-height: 40px;
  border-radius: var(--radius-sm);
  font-size: 18px;
  color: var(--text-muted);
}

.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-foot {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px var(--pad);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.sheet-foot .btn { flex: 1 1 0; min-width: 0; overflow: hidden; }
.sheet-foot .btn.wrap-label { font-size: 13px; line-height: 1.2; text-align: center; }

@media (min-width: 700px) {
  dialog.sheet .sheet-inner {
    position: relative;
    margin: 0 auto;
    top: 50%;
    transform: translateY(-50%);
    width: min(640px, 92vw);
    max-height: 86dvh;
    border-radius: var(--radius);
    border-bottom: 1px solid var(--border);
  }
  dialog.sheet .sheet-grab { display: none; }
  @keyframes sk-sheet-up {
    from { transform: translateY(-46%); opacity: 0.6; }
    to { transform: translateY(-50%); opacity: 1; }
  }
}

/* --------------------------------------------------------------------------
   14. Form controls
   -------------------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.field-hint { font-size: 12px; color: var(--text-muted); }
/* The FAQ sits inside the Help field, so it needs its own breathing room. */
.faq-label { margin-top: 18px; }

input[type="text"],
input[type="number"],
input[type="search"],
textarea,
select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px; /* prevents iOS zoom on focus */
}
textarea { min-height: 96px; resize: vertical; line-height: 1.4; }
textarea.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  min-height: 180px;
}

.row-flex { display: flex; gap: 10px; align-items: flex-end; }
.row-flex > * { flex: 1 1 0; min-width: 0; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { text-align: center; flex: 1 1 auto; }
.stepper button {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.seg {
  display: flex;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--surface-2);
}
.seg button {
  flex: 1 1 0;
  min-height: 46px;
  font-weight: 700;
  color: var(--text-muted);
}
.seg button.on { background: var(--primary); color: var(--primary-text); }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-weight: 700; }
.toggle-sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }

.switch {
  flex: 0 0 auto;
  position: relative;
  width: 56px; height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  transition: background 0.15s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.15s ease;
}
.switch[aria-checked="true"] { background: var(--accent-2); border-color: var(--accent-2); }
.switch[aria-checked="true"]::after { transform: translateX(24px); }

/* --------------------------------------------------------------------------
   15. Grids: emoji, templates, themes
   -------------------------------------------------------------------------- */

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 6px;
}
.emoji-btn {
  min-height: 50px;
  font-size: 26px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface-2);
}
.emoji-btn.on { border: var(--tap-border); background: var(--accent); }

.tpl-grid { display: flex; flex-direction: column; gap: 8px; }
.tpl-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.tpl-card.on { border: var(--tap-border); background: var(--surface); }
.tpl-emoji { font-size: 28px; flex: 0 0 auto; }
.tpl-main { flex: 1 1 auto; min-width: 0; }
.tpl-name { font-weight: 800; }
.tpl-parts { font-size: 12px; color: var(--text-muted); }

.group-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 4px 0 0;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.theme-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  text-align: left;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.theme-card.on { border: var(--tap-border); box-shadow: 0 0 0 2px var(--primary-glow); }
.theme-name { font-weight: 800; font-size: 14px; }
.theme-tagline { font-size: 11px; color: var(--text-muted); line-height: 1.25; }
.swatches { display: flex; gap: 4px; }
.swatch {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   16. Lists: menu, checklist, history, pattern, status
   -------------------------------------------------------------------------- */

.list { display: flex; flex-direction: column; gap: 6px; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 8px 12px;
  text-align: left;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
}
.menu-icon { font-size: 20px; flex: 0 0 auto; }

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.check {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
}
.check[aria-checked="true"] {
  background: var(--success);
  border-color: var(--success);
  color: var(--primary-text);
}
.item-text { flex: 1 1 auto; min-width: 0; word-break: break-word; }
.list-item.done .item-text { text-decoration: line-through; color: var(--text-muted); }
.item-del {
  flex: 0 0 auto;
  min-width: 40px; min-height: 40px;
  color: var(--text-muted);
  font-size: 16px;
}

.hist-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.hist-item:last-child { border-bottom: none; }
.hist-when { color: var(--text-muted); flex: 0 0 auto; }

.pattern-lines { display: flex; flex-direction: column; }
.pline {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.pline.has-row { background: var(--surface-2); margin-bottom: 4px; }
.pline.on {
  border: var(--tap-border);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}
.pline.plain { color: var(--text-muted); cursor: default; }

.status-opt {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.status-opt.on { border: var(--tap-border); background: var(--surface); }
.status-opt b { font-size: 15px; }
.status-opt span { font-size: 12px; color: var(--text-muted); }

.pline-header {
  margin: 10px 0 4px;
  padding: 0 10px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text);
}
.pline-header:first-child { margin-top: 0; }

.pline-setup {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--surface-2);
  margin-bottom: 4px;
}
.pline-tag {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text);
}
.pline-body { flex: 1 1 auto; min-width: 0; }
.pline-count { font-weight: 800; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.pline.on .pline-count { color: var(--accent-text); }
.pline-note {
  margin: -2px 0 6px;
  padding: 0 10px 0 22px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-muted);
}

.parsed-note { font-size: 12px; color: var(--text-muted); font-weight: 700; }

.pattern-extras { display: flex; flex-direction: column; gap: 10px; }
.pattern-extras .linkish { display: inline; min-height: 0; padding: 0 2px; }

/* Import pattern sheet */
.imp-list { display: flex; flex-direction: column; gap: 8px; }
.imp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.imp-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.imp-name { min-height: 40px; background: var(--surface); }
.imp-meta { font-size: 12px; color: var(--text-muted); font-weight: 700; }
.imp-check-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
/* 01 #3: a suggestion we had to reconstruct arrives unticked and says so. */
.imp-weak { color: var(--text-muted); font-weight: 700; font-size: 12px; }

/* "Looks like UK terms" and friends (06 #3) — informational only. */
.imp-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.imp-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
}

/* "Don't set targets", in the sections header (01 #1) */
.imp-targets { display: flex; align-items: center; gap: 8px; margin: -4px 0 2px; }
.imp-targets-label { font-size: 13px; font-weight: 700; color: var(--text-muted); }

/* Backup import preview (09 #3, 12 #3) */
.imp-counts { margin: 0; font-weight: 800; }
.imp-rows { display: flex; flex-direction: column; gap: 10px; }
.imp-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.imp-row-name { font-weight: 800; overflow-wrap: anywhere; }
.imp-row-meta { font-size: 12px; font-weight: 700; color: var(--text-muted); line-height: 1.4; }

/* "These parts are not finished yet" on the project-done sheet (02 #2) */
.blocking-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 2px; }

/* PDF drop zone */
.dz-wrap { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.dz {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 108px;
  padding: 14px 12px;
  text-align: center;
  color: var(--text);
  background: var(--surface-2);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.dz:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.dz.over {
  border-color: var(--accent-2);
  border-style: solid;
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.dz.busy { cursor: progress; opacity: 1; }
.dz[disabled] { opacity: 1; }

.dz-icon { font-size: 26px; line-height: 1; }
.dz-line { font-size: 14px; line-height: 1.35; max-width: 26em; }
.dz-link { color: var(--text); font-weight: 800; text-decoration: underline; text-underline-offset: 2px; }
.dz-status { font-size: 13px; color: var(--text-muted); font-weight: 700; }

.dz-bar {
  display: block;
  width: min(220px, 80%);
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.dz-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent-2);
  transition: width 0.2s linear;
}
@media (prefers-reduced-motion: reduce) {
  .dz-bar-fill { transition: none; }
}

.dz-result { font-size: 12px; font-weight: 700; margin: 0; }
/* "Pages 12–20 had no readable text" (06 #4) */
.dz-empty { line-height: 1.4; }
/* 06 #6: the only way out of a long read */
.dz-cancel { min-height: 40px; font-size: 14px; }

/* "Have a pattern PDF?" pointer on the empty state and the new-project sheet */
.pdf-hint {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-muted);
  margin: 12px 0 0;
}

/* New project sheet: import a PDF while creating */
.new-pdf { display: flex; flex-direction: column; gap: 14px; }
.new-pdf .dz-wrap { margin-bottom: 0; }
.new-pdf .tpl-edit-link { margin-top: -10px; }
.new-pdf textarea { min-height: 110px; }
.imp-picker { display: flex; flex-direction: column; gap: 14px; }
.new-pdf-tpl { display: flex; flex-direction: column; gap: 8px; }
.new-pdf-tpl input[type="text"] { background: var(--surface); }
.new-pdf-tpl input[type="text"][disabled] { opacity: 0.6; }

/* Templates: list + editor */
.tpl-edit-link { display: flex; justify-content: flex-start; margin-top: -2px; }
.tpl-edit-link .linkish { min-height: 36px; padding: 0 2px; }

.tpl-item { text-align: left; }
.tpl-item-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tpl-item-name { font-weight: 800; word-break: break-word; }
.tpl-item-sub { font-size: 12px; color: var(--text-muted); }
.tpl-tag {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
}

.tpl-parts-edit,
.tpl-check-edit { display: flex; flex-direction: column; gap: 8px; }

.tpl-part-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.tpl-part-top,
.tpl-part-bot,
.tpl-part-attach,
.tpl-check-row { display: flex; align-items: center; gap: 8px; }
.tpl-part-attach .tpl-tag { color: var(--text); border-color: var(--accent-2); }
.tpl-attach-meta { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--text-muted); }
.tpl-part-name { flex: 1 1 auto; min-width: 0; background: var(--surface); }
.tpl-part-bot .stepper { flex: 1 1 auto; min-width: 0; }
.tpl-part-bot .stepper button { width: 42px; height: 42px; }
.tpl-check-row input[type="text"] { flex: 1 1 auto; min-width: 0; }
.tpl-mini-label {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
}
.tpl-mini {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}
.tpl-mini[disabled] { opacity: 0.35; }

/* Checklist item controls */
.item-text-btn {
  background: none;
  border: none;
  color: inherit;
  text-align: left;
  font: inherit;
  padding: 6px 2px;
  min-height: 40px;
}
.item-edit { flex: 1 1 auto; min-width: 0; min-height: 40px; }
.item-move {
  flex: 0 0 auto;
  min-width: 34px;
  min-height: 40px;
  color: var(--text-muted);
  background: none;
  font-size: 13px;
}
.item-move[disabled] { opacity: 0.3; }

.danger-zone {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   16b. Guided help (tours) — spotlight overlay + card
   -------------------------------------------------------------------------- */

/* First-run welcome card in the home empty state */
.welcome-card {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: left;
}
.welcome-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 2px;
}
.welcome-text { font-size: 14px; color: var(--text-muted); margin-bottom: 10px; }
.welcome-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.welcome-actions .btn { flex: 1 1 auto; }

/* The overlay lives in <body>, or inside the open <dialog> when there is one
   (the top layer paints above everything else, so we have to join it). */
.tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  animation: sk-tour-in 0.16s ease;
}
@keyframes sk-tour-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Four dim panels leave a hole: the target stays visible and clickable.
   Geometry is set straight from JS with no transition — a spotlight that
   lags behind its card is worse than one that simply lands. */
.tour-dim {
  position: fixed;
  background: var(--overlay);
  pointer-events: auto;
}

.tour-ring {
  position: fixed;
  border: 3px solid var(--accent-2);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

.tour-card {
  position: fixed;
  left: 12px;
  top: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad);
  font-family: var(--font-body);
}
.tour-card.centered {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.tour-count {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.tour-title {
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.25;
  margin-bottom: 6px;
}
.tour-body {
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 8px;
}
.tour-try {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
}
.tour-extra {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.tour-extra .btn { min-height: 44px; }

.tour-foot {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tour-spacer { flex: 1 1 auto; }
.tour-skip {
  color: var(--text-muted);
  text-decoration: underline;
  font-size: 14px;
  min-height: 44px;
  padding: 0 4px;
}
.tour-nav {
  min-height: 42px;
  padding: 6px 14px;
  font-size: 15px;
}
.tour-nav[disabled] { opacity: 0.4; }

/* Help & tours (settings) */
.help-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.help-item:last-of-type { border-bottom: none; }
.help-main { flex: 1 1 auto; min-width: 0; }
.help-name { font-weight: 700; font-size: 15px; }
.help-blurb { font-size: 13px; color: var(--text-muted); }
.help-seen { color: var(--success); font-weight: 800; flex: 0 0 auto; }
.help-item .btn { flex: 0 0 auto; min-height: 40px; padding: 4px 14px; font-size: 14px; }

.faq {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 8px 10px;
}
.faq + .faq { margin-top: 8px; }
.faq > summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  list-style: none;
}
.faq > summary::-webkit-details-marker { display: none; }
.faq > summary::before { content: '› '; color: var(--text-muted); }
.faq[open] > summary::before { content: '⌄ '; }
.faq > p {
  font-size: 14px;
  color: var(--text-muted);
  margin: 8px 0 2px;
  line-height: 1.5;
}

/* --------------------------------------------------------------------------
   16b. Crafts (docs/CRAFTS.md)

   The shell's share of the craft plumbing: the #screen-craft body a module
   renders into, the New-project craft picker, the read-only tag in Edit
   project and the little craft badge on a home card. Theme variables only —
   each craft's own look lives in css/xstitch.css / css/sewing.css.
   -------------------------------------------------------------------------- */

/* The <main> a craft module owns. Same scrolling column as .project-body, but
   with no fixed bottom bar reserved: a craft renders its own inside. */
.craft-body {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.craft-body > * { flex: 0 0 auto; }

/* A craft that wants a bottom bar renders .bottombar inside .craft-body. */
.craft-body .bottombar {
  margin-top: auto;
  position: sticky;
  bottom: calc(-1 * (20px + env(safe-area-inset-bottom)));
  margin-left: calc(-1 * var(--pad));
  margin-right: calc(-1 * var(--pad));
  margin-bottom: calc(-1 * (20px + env(safe-area-inset-bottom)));
}

/* The card shown when a project's craft module did not load. */
.craft-missing { text-align: center; }
.craft-missing-emoji { font-size: 40px; line-height: 1; }
.craft-missing-title { font-size: 18px; margin: 8px 0 4px; }
.craft-missing .btn { margin-top: 12px; }

/* New project → the craft picker. A .seg with an emoji in each label, so it
   needs a little more room and wraps on a narrow phone. */
/* Three crafts have to share 375px without wrapping the third onto its own
   row, so the segments share the width evenly and the label can drop a line. */
.craft-seg { flex-wrap: nowrap; }
.craft-seg button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 52px;
  font-size: 14px;
  padding: 4px 2px;
  line-height: 1.2;
}

/* Edit project → the craft, read-only. */
.craft-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
}
.craft-tag-emoji { font-size: 20px; line-height: 1; }

/* Craft-specific New-project fields mount here. */
.craft-fields:empty { display: none; }

/* Templates list: which craft a template sets up. */
.tpl-craft-tag { white-space: nowrap; }

/* Home card: which craft this project is, under its emoji. */
.pc-craft {
  grid-area: emoji;
  align-self: end;
  justify-self: center;
  font-size: 15px;
  line-height: 1;
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   17. Larger screens
   -------------------------------------------------------------------------- */

@media (min-width: 700px) {
  .stitch-btn { min-height: min(46vh, 380px); }
  .screen-body { padding: 20px; }
  .fab { right: calc(50% - min(320px, 46vw)); }
}

@media (min-height: 900px) {
  .stitch-btn { min-height: 44vh; }
}

/* UX sweep D4 / L10 (Wave E) — short phones. Below ~760 px of viewport the
   counter overflowed and −1 / reset sat under the bottom bar with no scroll
   cue (93 px over at 375×640; 76 px over even at 812 on a round with a setup
   line and a three-line instruction). The order of things is unchanged; the
   row card sheds whitespace, the instruction lines clamp tighter, and the big
   button gives up its fixed floor first — it is still the largest target on
   the screen, and it grows back as soon as there is room. */
@media (max-height: 860px) {
  .project-body .stitch-btn { min-height: max(20vh, 140px); }
  .setup-line-text { -webkit-line-clamp: 1; }
}
/* Wave G: a multi-size project spends one 44 px strip on its size tabs; the
   part chips tuck up under it and the big button gives the rest back, so the
   counter still fits a 375 x 812 screen. */
.project-body .size-tabs:not([hidden]) + .tabs { margin-top: calc(8px - var(--gap)); }
@media (max-height: 860px) {
  .project-body.has-sizes .stitch-btn { min-height: max(calc(20vh - 44px), 112px); }
}
@media (max-height: 760px) {
  .project-body.has-sizes .stitch-btn { min-height: 96px; }
}
@media (max-height: 760px) {
  .project-body { gap: 8px; padding-top: 8px; }
  .project-body .counter-card { padding: 4px var(--pad) 8px; }
  .project-body .counter-card .big-number { font-size: min(var(--counter-size), 60px); }
  .project-body .counter-card .round-btn { width: 50px; height: 50px; font-size: 26px; }
  .project-body .counter-card .progress { margin-top: 2px; }
  .project-body .counter-card .bar-label { margin-top: 2px; font-size: 12px; }
  .project-body .tabs { padding-bottom: 2px; }
  .pattern-line { padding: 6px 10px; }
  /* wave I: 14 -> 17 px, the same 1.2x as the tall layout */
  .pattern-line-text { -webkit-line-clamp: 2; font-size: 17px; }
  .pattern-line-notes { font-size: 13px; }
  .setup-line { padding: 4px 10px; }
  .project-body .stitch-section { gap: 4px; }
  .project-body .stitch-btn { min-height: 120px; }
}

/* Wave I — the larger pattern strip pays for itself. Measured on the owner's
   bee (3 sizes, so the 44 px size strip is up too) over every round of every
   part: at 375 x 812 the strip's worst round (a colour change, the turn into
   rows, a two-line instruction and a note) came out 32 px over, and at
   375 x 640 a multi-size project was already up to 32 px over BEFORE this
   wave (46 px after the bigger text). So, on phones that are not tall:
   - each progress label sits beside its bar instead of under it (one line);
   - the strip loses 2 px of padding;
   - the big button's floor in a multi-size project gives up 20 px (812) or
     16 px (640). It still takes every pixel that is free, and the full-screen
     working mode (⤢ Work in 3D) is the big target on a small phone now;
   - below 760 px the note under an instruction is one line (the whole text
     is in the pattern sheet, a tap away).
   0 px over at both sizes on every round of the bee, Keyring, Medium and Big. */
@media (max-height: 860px) {
  .project-body .progress { display: flex; align-items: center; gap: 8px; }
  .project-body .progress .bar { flex: 1 1 auto; min-width: 0; }
  .project-body .progress .bar-label { flex: 0 0 auto; margin-top: 0; }
  .pattern-line { padding: 8px 12px; }
  .project-body.has-sizes .stitch-btn { min-height: max(calc(20vh - 64px), 96px); }
  /* a knitting part carries a 40 px marker strip under the readout (and a
     short-row strip on those rows): its button gives that height back */
  .project-body:has(.knit-markers:not([hidden])) .stitch-btn { min-height: max(calc(20vh - 56px), 100px); }
}
@media (max-height: 760px) {
  .pattern-line { padding: 4px 10px; }
  .project-body .pattern-line-notes { -webkit-line-clamp: 1; }
  .project-body.has-sizes .stitch-btn,
  .project-body:has(.knit-markers:not([hidden])) .stitch-btn { min-height: 80px; }
  /* the short-row strip keeps to one line: its "rows 89–102 · …" clips */
  .project-body .knit-short { flex-wrap: nowrap; }
  .project-body .knit-short-text { white-space: nowrap; }
  .project-body .knit-short-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* --------------------------------------------------------------------------
   17b. Wave F — size-once, yarn changes, count confidence, set the row
   -------------------------------------------------------------------------- */

/* "ROW · M": whose numbers these are */
.row-size-tag { text-transform: none; letter-spacing: 0; font-weight: 700; color: var(--text-muted); }

/* 03 #6: the big number is a control (tap / Enter → "Set the row count") */
.row-number-btn { cursor: pointer; border-radius: var(--radius-sm); }
.row-number-btn:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.goto-row { display: flex; align-items: center; justify-content: center; gap: 12px; }
.goto-row input {
  width: 7ch;
  min-height: 56px;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* The chosen size's number inside a size list */
mark.size-mark {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 4px;
  padding: 0 2px;
  font-weight: 800;
}
.pline.on mark.size-mark { background: var(--surface); color: var(--text); }
.pline.other-size { opacity: 0.5; }
.pline-size { margin: 0 0 8px; font-size: 13px; color: var(--text-muted); font-weight: 700; }
.pline-count.warn { color: var(--danger); }

/* 02 #3 / 10 #1: the yarn this row is worked in, and the change */
.yarn-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  /* wave I: 13 -> 16 px with the pattern line it sits on */
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.yarn-line[hidden] { display: none; }
.yarn-cur, .yarn-change { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.yarn-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.yarn-tag-swatch {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 5px;
  vertical-align: -1px;
  border-width: 1.5px;
}
.yarn-line.changing {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow);
}
.yarn-line.changing .yarn-swatch { border-color: var(--accent-text); }
.yarn-change { font-weight: 800; }
.yarn-arrow { font-weight: 800; }
.yarn-swatch {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid var(--text);
  background: transparent;
}
.yarn-swatch.unknown { border-style: dashed; }

/* 06 #1: "≈ why?" beside the stitch readout */
.count-why {
  position: relative;
  margin-left: 8px;
  vertical-align: middle;
  min-height: 26px;
  padding: 1px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}
.count-why[hidden] { display: none; }
.count-why::before {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: max(100%, 44px); height: 44px;
  transform: translate(-50%, -50%);
}
.count-why.warn { color: var(--danger); border-color: var(--danger); }
.why-text { margin: 0 0 10px; line-height: 1.45; }
.why-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: var(--surface);
}
.why-line-text { line-height: 1.35; }
.why-part { margin-top: 10px; font-size: 13px; }

/* Import preview: the size pick and one confidence line per part */
.size-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.size-chip {
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 800;
}
.size-chip.on { background: var(--accent); color: var(--accent-text); border: var(--tap-border); }
.size-chip:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.size-field.needs-pick > label { color: var(--danger); }
.size-field.nudge { animation: size-nudge 0.5s ease 2; }
@keyframes size-nudge {
  0%, 100% { transform: none; }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}
.size-pick { display: flex; flex-direction: column; gap: 6px; }
.imp-conf { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.imp-conf.warn, .parsed-note.warn, .part-conf.warn { color: var(--danger); }

/* On the row where the yarn changes the strip takes one line, so the
   instruction gives one up (the whole text is a tap away). */
@media (max-height: 860px) {
  .yarn-line:not([hidden]) + .pattern-line .pattern-line-text { -webkit-line-clamp: 2; }
  /* Wave G: the notes under an instruction clamp too (the whole text is in
     the pattern sheet) - one line on a row whose strip is showing. */
  .pattern-line-notes {
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .pattern-line-notes[hidden] { display: none; }
  .yarn-line:not([hidden]) + .pattern-line .pattern-line-notes { -webkit-line-clamp: 1; }
}
/* Wave G: a colour change and the rounds -> rows turn share the one strip */
.turn-change .turn-icon { font-size: 18px; line-height: 1; }
@media (max-height: 760px) {
  .yarn-line { padding: 2px 8px; font-size: 15px; }
  .yarn-line:not([hidden]) + .pattern-line .pattern-line-text { -webkit-line-clamp: 1; }
}

/* --------------------------------------------------------------------------
   18. Touch targets and focus rings

   Everything you can tap gets at least 44 x 44 px. Controls that have to stay
   visually small (a 34px tick box, a 32px switch) keep their looks and get an
   invisible ::before that carries the extra area, so nothing reflows.
   -------------------------------------------------------------------------- */

.sheet-close { min-width: 44px; min-height: 44px; }
.item-del { min-width: 44px; min-height: 44px; }
.timer-chip { min-height: 44px; min-width: 44px; justify-content: center; }
.tab { min-height: 44px; }
.help-item .btn { min-height: 44px; }

/* The part-tab strip clips overflow on the y axis, which used to cut the top
   of a focused tab's ring off. */
.tabs { padding-top: 6px; }

.faq > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
}

.switch, .check { position: relative; }
.switch::before, .check::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(100%, 44px);
  height: 44px;
  transform: translate(-50%, -50%);
}

/* .seg hides its overflow to keep the rounded ends, which clipped the outline
   ring off a focused segment. An inset ring is not clipped. */
.seg button:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px var(--accent-2);
}

/* --------------------------------------------------------------------------
   19. Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
  /* The stitch-alert flash is the only visual cue for "check your pattern",
     and a 0.01ms animation makes it invisible — hold the danger colour
     instead of flashing it. */
  .stitch-btn.flash { animation: none !important; background: var(--danger); }
}

/* --------------------------------------------------------------------------
   Wave H — knitting on the counter (knit-counter). Only a knitting project
   ever gets these elements; colours come from the theme tokens so all six
   themes keep their contrast.
   -------------------------------------------------------------------------- */

/* RS / WS chip in the row label */
.knit-side-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  min-width: 40px;
  justify-content: center;
  margin-left: 4px;
  padding: 0 9px;
  border-radius: 999px;
  border: 2px solid var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  vertical-align: middle;
}
.knit-side-chip.ws { background: var(--surface); color: var(--text); }
.knit-side-chip.unknown { background: var(--surface); color: var(--text-muted); border-style: dashed; border-color: var(--border); }
.knit-side-chip.mine { box-shadow: 0 0 0 2px var(--accent); }
.knit-short-tag { letter-spacing: 1px; }
/* the UK / US Terms rows are hidden on a knitting project */
.viewer-bar-row[hidden], .field[hidden] { display: none; }

/* cable ring: fills as the crossing row comes, flashes on it */
.knit-cable {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
}
.knit-cable-ring {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) var(--knit-fill, 0deg), var(--border) 0);
  -webkit-mask: radial-gradient(circle, transparent 4px, #000 4.5px);
  mask: radial-gradient(circle, transparent 4px, #000 4.5px);
}
.knit-cable.now { color: var(--text); }
.knit-cable.now .knit-cable-ring { animation: knit-cable-pulse 1.2s ease-in-out 3; }
@keyframes knit-cable-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.35); }
}

/* short rows: one line under the row counter */
.knit-short {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 6px 0 0;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
.knit-short[hidden] { display: none; }
.knit-short-icon { font-weight: 800; color: var(--text); }
.knit-short-text { font-weight: 800; }
.knit-short-sub { flex: 1 1 auto; min-width: 0; color: var(--text-muted); font-size: 12px; font-weight: 700; }
.knit-short-end { margin-left: auto; min-height: 32px; }

/* chart / length / partner chips under the pattern line */
.knit-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 0;
}
.knit-extra[hidden] { display: none; }
/* wave H (knit-qa-2): with the chart / length chips showing, the stitch pad
   keeps its own height (the screen scrolls) instead of shrinking under them;
   at 375x640 its "STITCHES" caption slid up under the chart chip */
.knit-extra:not([hidden]) ~ .stitch-section { flex-shrink: 0; }
.knit-chip {
  min-height: 36px;
  max-width: 100%;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* the marker strip under the stitch readout */
.knit-markers {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  font-size: 13px;
}
.knit-markers[hidden] { display: none; }
.knit-marker-row {
  display: flex;
  gap: 6px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
}
.knit-marker-row::-webkit-scrollbar { display: none; }
.knit-marker {
  flex: 0 0 auto;
  min-height: 32px;
  min-width: 44px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.knit-marker.next { border: 2px solid var(--primary); }
.knit-marker.here { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.knit-marker-info { text-align: center; line-height: 1.3; }
.knit-seg-dot { color: var(--text-muted); }
.knit-marker-next { font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.knit-segments { color: var(--text-muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.knit-seg-bar { margin: 0 5px; opacity: 0.6; }
.knit-seg.on { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.knit-add-marker { min-height: 44px; padding: 6px 12px; font-size: 14px; }
.knit-add-marker[hidden] { display: none; }

/* two at a time: one tab, two halves */
.tab-pair {
  flex: 0 0 auto;
  display: inline-flex;
  max-width: 15em;
}
.tab-pair .tab-half { max-width: 9em; }
.tab-pair .tab-half:first-child { border-radius: 999px 0 0 999px; padding-right: 8px; }
.tab-pair .tab-half:last-child { border-radius: 0 999px 999px 0; border-left: 0; padding-left: 8px; }

/* the part editor's Knitting card */
.knit-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.knit-card-title { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.knit-gauge-row input { min-width: 0; }
.knit-gauge-result { display: flex; flex-direction: column; gap: 6px; }
.knit-until-item { display: flex; flex-direction: column; gap: 1px; }
.knit-until-say { font-weight: 800; font-variant-numeric: tabular-nums; }
.knit-until-line { font-size: 12px; color: var(--text-muted); }

/* glossary */
.knit-glossary { display: flex; flex-direction: column; gap: 2px; }
.knit-gloss-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.knit-gloss-abbr { flex: 0 0 6.5em; font-weight: 800; }
.knit-gloss-meaning { flex: 1 1 12em; min-width: 0; }
.knit-gloss-src { font-size: 11px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.knit-gloss-more > summary { cursor: pointer; padding: 8px 0; font-weight: 700; color: var(--text-muted); }

/* chart page */
.knit-chart-row { display: flex; flex-direction: column; gap: 2px; }
.knit-chart-text { font-weight: 700; line-height: 1.4; }
.knit-chart-stage { overflow: auto; max-height: 60vh; border-radius: var(--radius-sm); background: var(--surface); }
.knit-chart-img { display: block; width: 100%; height: auto; }
.knit-chart-tools { justify-content: flex-end; }
.knit-chart-tools .btn { flex: 0 0 auto; min-width: 48px; min-height: 44px; }

@media (max-height: 760px) {
  .knit-short { margin-top: 4px; padding: 4px 10px; }
  .knit-extra { margin-top: 4px; }
  .knit-chip { min-height: 32px; }
}

/* --------------------------------------------------------------------------
   Wave I — working mode (js/app.js "15c. Working mode"). The project screen
   in a full-screen dress: the stitch button, with the live 3D piece in it,
   fills the screen and is still the one tap target; #work-hud floats the
   readouts and the big controls over it. The HUD lets every tap through
   except on its own controls, so a tap on its text counts a stitch.
   -------------------------------------------------------------------------- */

#screen-project.work-mode > .topbar,
#screen-project.work-mode > .bottombar { display: none; }
#screen-project.work-mode .project-body {
  position: static;
  overflow: hidden;
  padding: 0;
  max-width: none;
}
#screen-project.work-mode .project-body > :not(.stitch-section),
#screen-project.work-mode .stitch-section > :not(.stitch-btn) { display: none !important; }
#screen-project.work-mode .stitch-section { position: static; }
/* the screen (position: fixed) is the containing block, so the button is the
   whole screen under the banner strip */
#screen-project.work-mode .stitch-btn {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: none;
}
#screen-project.work-mode .stitch-btn.pressed {
  transform: none;
  box-shadow: inset 0 0 0 6px var(--primary-glow);
}
#screen-project.work-mode .stitch-btn:focus-visible {
  outline: 3px solid var(--accent-2);
  outline-offset: -6px;
}
#screen-project.work-mode .stitch-head,
#screen-project.work-mode .stitch-hint { display: none; }

.work-hud {
  --work-glow: 0 0 2px var(--primary), 0 0 6px var(--primary), 0 0 14px var(--primary), 0 2px 3px rgba(0, 0, 0, 0.35);
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: "head" "stack" "." "foot" "btns";
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  color: var(--primary-text);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
.work-hud button,
.work-hud .work-panel,
.work-hud .work-scrim { pointer-events: auto; }

/* header: close, whose piece, Options */
.work-head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 2px;
}
.work-icon {
  flex: 0 0 auto;
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  box-shadow: var(--shadow);
}
.work-more { padding: 0 14px; font-size: 15px; }
.work-more.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary-text); }
.work-more-caret { font-size: 13px; }
.work-title {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: var(--work-glow);
}

/* the readouts: rows done | stitches, in big digits */
.work-stack {
  grid-area: stack;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 0 12px;
}
.work-read { display: flex; gap: 10px; align-items: flex-start; }
.work-cell {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  text-shadow: var(--work-glow);
}
.work-cap {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  opacity: 0.95;
}
.work-numline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  column-gap: 6px;
  max-width: 100%;
}
.work-big {
  font-family: var(--font-display);
  /* digits at least 40 px tall at arm's length: 60 px Fredoka draws a 45 px
     numeral (56 px: 42, 54 px: 40). The pixel theme sets its own size in
     css/themes.css, because its font draws digits nearly a full em tall. */
  font-size: 60px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.work-of {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 0.92;
}
.work-of:empty { display: none; }
.work-sub { font-size: 13px; font-weight: 700; line-height: 1.3; }
.work-sub:empty { display: none; }
.work-meta { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px 8px; }
.work-tags { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px; text-shadow: none; }
.work-tags .knit-side-chip { min-height: 36px; min-width: 48px; margin-left: 0; font-size: 15px; }
.work-tags .knit-cable { text-shadow: var(--work-glow); }

/* the pattern line: the strip's own text, larger */
.work-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.work-line-tag {
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
.work-line-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.work-line-text {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.28;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.work-line-notes {
  font-size: 14px;
  line-height: 1.3;
  color: var(--text-muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

/* colour change, turn, short rows, knitting chips, "3 more than..." */
.work-hints { display: flex; flex-direction: column; gap: 4px; }
.work-hint {
  margin: 0;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.work-hint.stitch-dev { color: var(--danger); text-align: center; }
.work-hint.knit-extra { background: transparent; box-shadow: none; padding: 0; }
.work-hint .yarn-text { white-space: normal; }
.work-markers { margin: 0; padding: 4px 8px; border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }

/* what comes next, and the first-tap tip */
.work-foot {
  grid-area: foot;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 0 12px 4px;
}
.work-tip {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow: var(--work-glow);
}
.work-next {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  box-shadow: var(--shadow);
}
.work-next-tag {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.work-next-text { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* the bottom corners: -1, Undo ... row -, row + */
.work-btns {
  grid-area: btns;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 4px 12px 12px;
}
.work-gap { flex: 1 1 auto; }
.work-btn {
  flex: 0 0 auto;
  min-width: 64px;
  min-height: 64px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--shadow);
}
.work-btn:active { transform: scale(0.95); }
.work-btn:disabled { opacity: 0.45; }
.work-btn:focus-visible, .work-icon:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.work-row-plus {
  min-width: 96px;
  background: var(--accent);
  color: var(--accent-text);
  border: var(--tap-border);
}
.work-btn-glyph { font-size: 30px; }
.work-st-minus .work-btn-glyph { font-size: 24px; }
.work-btn-word { font-size: 14px; letter-spacing: 1px; text-transform: uppercase; }

/* the folded chips */
.work-scrim { position: absolute; inset: 0; z-index: 4; background: rgba(0, 0, 0, 0.3); }
.work-panel {
  position: absolute;
  z-index: 5;
  top: calc(env(safe-area-inset-top) + 60px);
  left: 8px;
  right: 8px;
  max-height: calc(100% - env(safe-area-inset-top) - 72px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.work-shape { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-weight: 800; }
.work-shape-sub { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.work-panel-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.work-panel-row .seg { flex: 1 1 220px; }
.work-panel-label {
  flex: 0 0 6.5em;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.work-panel-hint { flex: 1 1 100%; font-size: 12px; color: var(--text-muted); }
.work-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.work-actions .btn { flex: 1 1 auto; min-height: 44px; padding: 6px 12px; font-size: 14px; }
.work-actions .btn.on { background: var(--accent); color: var(--accent-text); }

/* short phones: the piece keeps a fair share */
@media (max-height: 700px) {
  .work-big { font-size: 56px; }
  .work-line-text { font-size: 19px; -webkit-line-clamp: 2; }
  .work-line { padding: 6px 10px; }
  .work-hint { font-size: 15px; padding: 2px 10px; }
  .work-hint .knit-short-sub { display: none; }
  .work-btn { min-height: 58px; min-width: 58px; }
  .work-btns { padding-bottom: 8px; }
}

/* side by side: the readouts in a left column, the piece on the right */
@media (orientation: landscape) {
  .work-hud {
    grid-template-columns: minmax(0, min(46%, 520px)) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "head head" "stack ." "foot ." "btns btns";
  }
  /* the column clips rather than run under the buttons (a knitting short
     row with markers is the tallest it gets) */
  .work-stack { min-height: 0; overflow: hidden; align-self: start; max-height: 100%; }
  .work-foot { padding-top: 4px; }
  .work-title { text-align: left; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .work-head { padding-top: 4px; }
  .work-stack { gap: 4px; }
  .work-icon { min-height: 44px; min-width: 44px; }
  .work-big { font-size: 54px; }
  .work-line-text { font-size: 18px; -webkit-line-clamp: 2; }
  .work-line { padding: 4px 10px; }
  .work-line-notes { display: none; }
  .work-hint { font-size: 14px; padding: 2px 8px; }
  .work-hint .knit-short-sub { display: none; }
  .work-tip { display: none; }
  .work-btn { min-height: 56px; min-width: 56px; }
  .work-btns { padding: 2px 12px 8px; }
  .work-panel { top: calc(env(safe-area-inset-top) + 54px); max-height: calc(100% - env(safe-area-inset-top) - 62px); }
}
@media (min-width: 700px) {
  .work-panel { left: auto; width: 440px; }
}
