/*
 * TinkrkniT - desktop-first dark UI.
 *
 * The design grid is the point of the application, so the chrome is deliberately
 * dense and quiet: small type, low-contrast panel backgrounds, no decoration
 * that competes with the yarn colors. Anything colored on screen should be
 * either a yarn or a warning.
 *
 * Layout is one CSS grid with two custom properties for the dock widths, which
 * is what lets the resizers work without touching any element styles.
 */

:root {
  --dock-left-w: 272px;
  --dock-right-w: 340px;

  /* True neutral grays, built out from the panel at #272727. Untinted chrome
     is the one background that favors no yarn: a warm or cool cast shifts how
     every color in the palette reads. */
  --bg: #1f1f1f;
  --bg-panel: #272727;
  --bg-raised: #383838;
  --bg-input: #1c1c1c;
  --bg-head: #303030;
  --bg-dock: #1b1b1b;   /* behind the panel cards, so the gaps between them show */
  --line: #404040;
  --line-soft: #313131;

  /* Behind the drawn canvases. The editor and preview renderers fill with
     their canvas's computed background-color, so these are the only source. */
  --bg-well: #1a1a1a;
  --bg-well-deep: #141414;

  --ink: #ececec;
  --ink-dim: #ababab;
  --ink-faint: #7e7e7e;

  --accent: #a3c3e0;
  --accent-ink: #1f1f1f;
  --accent-dim: #8b9cad;   /* section headings: reads as chrome, not as a control */
  --accent-wash: color-mix(in srgb, var(--accent) 12%, transparent);
  --ok: #8fc4a0;
  --warn: #dcae5a;
  --error: #e27a72;

  --radius: 5px;
  --gap: 8px;

  color-scheme: dark;
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] loses to any author rule that sets display, and
 * several components here are flex. Make hiding win outright. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* --- shell ---------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-rows: 40px 1fr 26px;
  height: 100vh;
}

.workspace {
  display: grid;
  grid-template-columns: var(--dock-left-w) 4px 1fr 4px var(--dock-right-w);
  min-height: 0;
}

.stage {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

/* The canvas is absolute inside a sized box, never in flow: its bitmap is set
   from its measured size, so in flow it would grow the box it measures. */
.grid-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.grid-canvas {
  position: absolute;
  inset: 0;
  display: block;
  background: var(--bg-well); /* read back by editor/renderer.js */
  width: 100%;
  height: 100%;
  touch-action: none; /* the editor owns every pointer gesture */
  cursor: crosshair;
}

/* --- tool options bar ----------------------------------------------------- */

/*
 * The strip between the toolbar and the grid. It is a grid row rather than an
 * overlay: floating it would put it over the top-left of the canvas, which is
 * where the motif usually is, and the point of the bar is to get controls off
 * the sidebar without taking anything else away from the drawing.
 *
 * Empty means no tool is selected or the bar is switched off in the View menu,
 * and an empty strip is worse than no strip, so it collapses entirely. Nothing
 * writes a text node into it, so `:empty` is reliable here.
 */
.options-bar {
  /* Tinted like the selected tool button (.icon-btn.is-active), so it reads
     as belonging to that tool rather than as more of the toolbar above. */
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-panel));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  /* Narrow window, or a tool with a lot to set: scroll rather than wrap. A
     wrapped bar changes the canvas height as you switch tools. */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.options-bar:empty { display: none; }

.ob-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 8px;
  white-space: nowrap;
}

.ob-tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: var(--accent);
}

.ob-sep {
  flex: 0 0 auto;
  width: 1px;
  height: 18px;
  background: color-mix(in srgb, var(--accent) 35%, var(--line));
}

.ob-group, .ob-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Label beside the control, not above it: a 34px row has no second line. */
.options-bar .field {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}
.options-bar .field-label { color: var(--ink-dim); }

/* `.num` and `.select` are full-width in a panel column, where that is right.
   In a row they have to size to their content or one of them eats the bar. */
.options-bar .num { width: 52px; }
.options-bar .select { width: auto; }
.options-bar .num, .options-bar .select, .options-bar .text, .options-bar .btn { height: 24px; }

/* The stamp being placed, and the "pick one first" stand-in. */
.ob-name { color: var(--accent); max-width: 18ch; overflow: hidden; text-overflow: ellipsis; }
.ob-note { color: var(--ink-faint); font-size: 12px; }

/*
 * Text tool. The string and the font name are their own labels - a "Text:"
 * beside a box with a placeholder in it is a word of bar spent twice - so these
 * two sit in the row without a `.field` around them.
 */
.options-bar .ob-text { width: 132px; }
.options-bar .ob-font { max-width: 136px; }

/* Gradient: the two color chips with swap between, and the dither strip. */
.ob-tight { gap: 4px; }
.ob-chip {
  width: 28px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.ob-chip.is-op {
  width: auto;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  color: var(--ink-dim);
  background: var(--bg-raised);
  cursor: default;
}
.ob-gradient-strip { width: 80px; height: 16px; image-rendering: pixelated; border-radius: 2px; border: 1px solid var(--line); }
.ob-swatch-pop {
  position: fixed;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(6, 24px);
  gap: 4px;
  padding: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.ob-swatch { width: 24px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.ob-swatch.is-active { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Bold and italic. A pressed icon says it in 24px; a checkbox needs its name. */
.ob-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-dim);
  cursor: pointer;
}
.ob-toggle:hover { color: var(--ink); }
.ob-toggle.is-on {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-wash);
}

.ob-range { display: inline-flex; align-items: center; gap: 6px; }
.ob-range .range { width: 76px; }
.ob-range-value {
  /* Tabular so the slider does not shuffle sideways as the number changes. */
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--ink-faint);
  width: 3ch;
}

/*
 * Shape picker. One row of thumbnails, no labels: eight named shapes is a grid,
 * and these are recognizable at a glance in a way the word "Diamond" is not.
 * The name is in the tooltip.
 */
.shape-strip { display: flex; align-items: center; gap: 2px; }

.shape-chip-btn {
  display: block;
  padding: 1px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 4px;
  line-height: 0;
  cursor: pointer;
}
.shape-chip-btn:hover { border-color: var(--line); }
.shape-chip-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-wash);
}

.shape-chip {
  width: 26px;
  height: 26px;
  /* Drawn at a whole-number scale, so this only guards against browser zoom. */
  image-rendering: pixelated;
}

.resizer {
  background: var(--line-soft);
  cursor: col-resize;
  touch-action: none;
}
.resizer:hover { background: var(--accent); }

/* --- toolbar -------------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  white-space: nowrap;
}

/*
 * Brand and project name, sized off the left dock's width so the separator
 * after it lands where the stage begins and the Projects icon sits directly
 * above the tool icon in the options bar. The offset is the toolbar's own
 * padding, gaps and the separator's margins; it tracks the dock resizer
 * because both read the same custom property.
 */
.tb-lead {
  display: flex;
  align-items: center;
  flex: 0 0 calc(var(--dock-left-w) - 28px);
  min-width: 0;
  overflow: hidden;
}
.tb-lead .project-name-input { flex: 0 1 auto; min-width: 0; }

.brand {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  height: 32px;
  padding: 3px 4px;
  margin-right: 6px;
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.brand:hover { background: var(--line); }
.brand img { display: block; height: 26px; width: auto; }

.project-name {
  color: var(--ink-dim);
  max-width: 24ch;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The name reads as a label until you point at it, then shows it is a field.
   Wide enough for a real name; the toolbar never wraps (5). */
.project-name-input {
  /* Fits the name it holds, within limits; the fixed width is the fallback. */
  width: 22ch;
  field-sizing: content;
  min-width: 10ch;
  max-width: 30ch;
  height: 26px;
  margin-right: 6px;
  padding: 0 7px;
  color: var(--ink-dim);
  font: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  text-overflow: ellipsis;
}
.project-name-input:hover { border-color: var(--line); color: var(--ink); }
.project-name-input:focus {
  outline: 0;
  color: var(--ink);
  background: var(--bg-input);
  border-color: var(--accent);
}

.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--line);
  margin: 0 8px;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.tb-btn:hover:not(:disabled) { background: var(--bg-raised); border-color: var(--line); }
.tb-btn:active:not(:disabled) { background: var(--line); }
.tb-btn:disabled { opacity: 0.5; cursor: default; }

/* Most of the toolbar is ghost buttons, which is right for things you reach for
   by position. Save is reached for by name, so it carries a border - and picks
   up the accent while there is something to save, which doubles as the dirty
   flag the `*` after the project name only whispers. */
.tb-solid {
  border-color: var(--line);
  background: var(--bg-raised);
}
.tb-solid.is-dirty {
  border-color: var(--accent);
  color: var(--accent);
}

/* Knit is the one filled button in the bar: it is where a design ends up, and
   it should be findable without reading. While patterning runs it says so. */
.tb-btn.tb-knit {
  margin-left: 4px;
  padding: 0 12px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.tb-btn.tb-knit:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 85%, white);
  border-color: var(--accent);
}
.tb-btn.tb-knit.is-live { background: var(--ok); border-color: var(--ok); }
/* No Web Serial in this browser: a warning dot, the reason in the tooltip. */
.tb-btn.tb-knit.no-serial::after {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 1.5px var(--accent-ink);
}

/* --- view controls -------------------------------------------------------
 * Undo/redo and zoom, floating in the grid's bottom-right corner (main.js).
 * The box itself lets pointer events through so it never blocks drawing
 * between the pills; only the pills catch clicks.
 */
.view-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.pill {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 34px;
  padding: 0 4px;
  background: color-mix(in srgb, var(--bg-raised) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 28px;
  height: 26px;
  padding: 0 7px;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.pill-btn:hover:not(:disabled) { background: var(--line); }
.pill-btn:disabled { color: var(--ink-faint); opacity: 0.5; cursor: default; }

.pill-sep {
  width: 1px;
  height: 16px;
  margin: 0 3px;
  background: var(--line);
}

.zoom-readout {
  min-width: 5ch;
  text-align: center;
  color: var(--ink-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.grow { flex: 1; min-width: 0; }

.menu-host { position: relative; }

/* Fixed, not absolute: the toolbar clips its overflow so it never wraps, and an
   absolutely positioned child would be clipped with it. ui/menu.js sets
   top/left from the trigger's rect. */
.menu-pop {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 190px;
  padding: 8px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);

  /* A long project list scrolls inside the menu rather than off the screen;
     the cap itself is set in JS from the space under the trigger.
     `overflow-x` is set explicitly because a `visible` axis beside a scrolling
     one computes to `auto`, which is where the export menu's sideways
     scrollbar came from. Rows wrap instead. */
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.menu-pop hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* Menus that hold a list or a form, not just a column of checkboxes. */
.menu-pop.menu-wide {
  min-width: 340px;
  max-width: 420px;
  padding: 10px;
}

.tb-menu.is-open {
  background: var(--bg-raised);
  border-color: var(--accent);
  color: var(--accent);
}
.menu-caret { display: inline-flex; margin-left: -3px; color: var(--ink-faint); }
.tb-menu.is-open .menu-caret { color: inherit; }

/* A column of full-width rows, the way a menu behaves, rather than a grid of
   buttons. The rows run to the popup's padding edge so the hover highlight
   reads as a menu row and not as a control sitting inside one. */
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.menu-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover:not(:disabled) { background: var(--line); }
.menu-item:disabled { opacity: 0.45; cursor: default; }
.menu-item.is-checked { color: var(--accent); }

/* Fixed width and always rendered, even when empty: it is what lines every
   label in the menu up on the same edge. */
.menu-item-icon {
  flex: 0 0 17px;
  display: flex;
  align-items: center;
  height: 19px;
  color: var(--ink-dim);
}
.menu-item:hover .menu-item-icon { color: inherit; }
.menu-item.is-checked .menu-item-icon { color: var(--accent); }

.menu-item-text { flex: 1 1 auto; min-width: 0; }
.menu-item-text small {
  display: block;
  color: var(--ink-faint);
  font-size: 10.5px;
  line-height: 1.35;
}

.menu-item-detail {
  flex: 0 0 auto;
  align-self: center;
  color: var(--ink-faint);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

/* Prose between rows. All three of these carry `margin: 0` for panel use, so
   inside the list's 1px gap they would butt straight against the row above. */
.menu-list > .hint,
.menu-list > .note-line { padding: 6px 8px; }
.menu-list > .warn-line { margin: 4px 0; }
.menu-rule { height: 1px; margin: 6px 0 4px; background: var(--line-soft); }

/* --- docks and panels -----------------------------------------------------
 * Each panel is a card on a darker dock. Butted together with a 1px rule, the
 * panels ran into one another and nothing said where Tools ended and Colors
 * began; the gap of dock background between cards does that before a single
 * word is read.
 */

.dock {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-dock);
  min-height: 0;
}

.dock-side { border-inline: 1px solid var(--line); }
.dock-bottom {
  flex-direction: row;
  align-items: flex-start;
  border-top: 1px solid var(--line);
  max-height: 40vh;
}
.dock-bottom:empty, .dock-bottom.is-empty { display: none; }
.dock-bottom > .panel { flex: 1 1 260px; }

.dock.drop-target { outline: 2px dashed var(--accent); outline-offset: -3px; }

/* An empty side dock still needs to be a visible drop target. */
.dock-side.is-empty::after {
  content: "Drag a panel here";
  display: block;
  padding: 14px 10px;
  color: var(--ink-faint);
  text-align: center;
  font-size: 12px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  /* Not overflow: hidden - it would break the sticky header below. The head
     rounds its own top corners instead. */
}
.panel.is-flash { border-color: var(--accent); transition: border-color 0.2s; }

/*
 * A side dock is a scrolling flex column. Flex items shrink by default, so
 * without this every panel gets squeezed below its own content height and the
 * bodies spill over the panel beneath - the dock never scrolls because nothing
 * ever overflows it. Panels keep their natural height; the dock scrolls.
 */
.dock-side > .panel { flex: 0 0 auto; }

/* Grow into spare space, but still never shrink below content. */
.dock-side > .panel-grow { flex: 1 0 auto; }
.dock-bottom > .panel-grow { flex: 1 1 260px; }

/* Scrolling past several panels, the title tells you where you are. The dock's
   own padding would leave a strip of scrolled content above it at top: 0. */
.dock-side > .panel > .panel-head {
  position: sticky;
  top: -6px;
  z-index: 2;
}

/*
 * The panel heading is a different kind of thing from a section heading inside
 * a panel (`.sub-title`), so it must not look like one: sentence case at full
 * ink and a size up, an icon in the accent, on its own band. The section
 * headings stay small, uppercase and tinted.
 */
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 6px 0 10px;
  background: var(--bg-head);
  border-bottom: 1px solid var(--line-soft);
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  user-select: none;
  flex: 0 0 auto;
}
.panel.is-collapsed > .panel-head { border-bottom: 0; border-radius: 6px; }
.panel-head:hover { background: var(--line-soft); }
.panel-head:active { cursor: grabbing; }

.panel-icon { display: flex; color: var(--accent); }
.panel-title {
  flex: 1;
  font-weight: 650;
  font-size: 13px;
  color: var(--ink);
}
/* Only there to say "this can be dragged", so only there when you point at it. */
.panel-grip { color: var(--ink-faint); letter-spacing: -2px; opacity: 0; }
.panel-head:hover .panel-grip { opacity: 1; }

.panel-toggle {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.panel-toggle:hover { background: var(--line); color: var(--ink); }

.panel-body {
  padding: 10px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 0;
}
.panel-grow > .panel-body { flex: 1; }

body.dragging-panel .panel-body { pointer-events: none; }

/* --- generic controls ----------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.row { display: flex; gap: 6px; align-items: flex-end; flex-wrap: wrap; }
.row > * { min-width: 0; }

/*
 * Section headings were gray on gray, the same weight and color as a ghost
 * button, so a panel read as an undifferentiated list of controls. They now
 * carry a rule and the accent tint: nothing else in a panel body is that
 * color, so the eye finds the structure before it reads the words.
 */
.sub-title {
  margin: 9px 0 1px;
  padding: 7px 0 0;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--accent-dim);
}
.sub-title:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

/*
 * Settings panels: all controls, no drawing surface, and every group already
 * announced by a `.sub-title`. With the headings doing the grouping the gaps
 * inside a group can come well under the generic --gap - at --gap they were
 * the same size as the gaps between groups, so the panel read as one long
 * evenly spaced list. Scoped to `.settings` so panels you work in while
 * drawing keep their looser spacing.
 */
.settings { gap: 5px; }
.settings .row { gap: 5px; }
.settings .field { gap: 2px; }
.settings .sub-title { margin: 6px 0 0; padding-top: 5px; }
.settings .sub-title:first-child { margin-top: 0; padding-top: 0; }

/* Label beside the value rather than above it: one line instead of two. */
.settings .stat { flex-direction: row; align-items: baseline; gap: 6px; }
.settings .stat-value { font-size: 12px; }

/*
 * A field on its own line puts its label beside the control rather than above
 * it: stacked, every one costs a label line plus a control, which is what made
 * Name, Machine and Alignment look far apart when the gap between them is only
 * 5px. Direct children only - a field sharing a `.row` with another (Stitches
 * and Rows) has no width to give a label column and stays stacked.
 */
.settings > .field { flex-direction: row; align-items: center; gap: 8px; }
.settings > .field > .field-label { flex: 0 0 74px; }

/*
 * `flex: 1 1 96px` is a *horizontal* instruction: "at least 96px wide, share
 * whatever slack is left". That is only true inside a `.row`. A `.stack` is a
 * column, so for a field on its own line the same basis is a 96px *height* -
 * the field box was padded out to 96px around 44px of label and control, and
 * Name, Machine and Alignment each floated in half a centimeter of nothing.
 * The sizing therefore belongs on the field's position, not on the field.
 */
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.row > .field { flex: 1 1 96px; }
.field-label { font-size: 11px; color: var(--ink-dim); }
.field-hint { font-size: 10px; color: var(--ink-faint); }

.num, .select, .text {
  width: 100%;
  height: 26px;
  padding: 0 6px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
}
.text.notes { height: auto; padding: 5px 6px; resize: vertical; line-height: 1.4; }
.num:focus, .select:focus, .text:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

.range { width: 100%; accent-color: var(--accent); }

.color-input {
  width: 100%;
  height: 26px;
  padding: 2px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.check { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; font-size: 12px; }
.check input { accent-color: var(--accent); margin: 0; }

.btn {
  height: 26px;
  padding: 0 10px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--ink-faint); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger:hover:not(:disabled) { border-color: var(--error); color: var(--error); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-dim); padding: 0 6px; }

.hint { margin: 0; font-size: 11px; color: var(--ink-faint); line-height: 1.4; }
.note-line { margin: 0; font-size: 11px; color: var(--ink-dim); }
.warn-line {
  margin: 0;
  padding: 8px 10px;
  font-size: 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 22%, transparent);
  color: var(--ink);
}

.list { display: flex; flex-direction: column; gap: 1px; }

/* --- tools ---------------------------------------------------------------- */

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 3px;
}

.icon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 4px;
  background: var(--bg-raised);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink-dim);
  font: inherit;
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line); }
.icon-btn.is-active { color: var(--accent); border-color: var(--accent); background: var(--accent-wash); }

.icon-label {
  font-size: 10px;
  line-height: 1.1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* --- palette -------------------------------------------------------------- */

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 3px;
}

.swatch {
  position: relative;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.swatch-index { position: absolute; left: 3px; top: 1px; font-size: 9px; opacity: 0.6; }
.swatch-pin { position: absolute; right: 3px; top: 1px; font-size: 11px; opacity: 0.75; }
.swatch.is-unused { opacity: 0.45; }
/* Two rings rather than two colors, so the swatch itself stays honest. */
.swatch.is-primary { outline: 2px solid var(--ink); outline-offset: 1px; }
.swatch.is-secondary { box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.45); }
/* D for drawing, B for base, so the pair reads off the grid without a legend. */
.swatch-role {
  position: absolute;
  right: 2px;
  bottom: 2px;
  padding: 0 3px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 13px;
  letter-spacing: 0.5px;
}

.pair-readout {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
}
.pair-card {
  display: grid;
  grid-template-columns: 28px 1fr;
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-items: center;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
}
.pair-card i {
  grid-row: 1 / 3;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.pair-card.is-primary { border-color: var(--ink-dim); }
.pair-label { font-size: 11px; font-weight: 600; color: var(--ink); }
.pair-name {
  font-size: 10px;
  color: var(--ink-faint);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pair-swap {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--ink-dim);
  cursor: pointer;
}
.pair-swap:hover { color: var(--ink); border-color: var(--line); }

.slot-editor { border-top: 1px solid var(--line-soft); padding-top: 8px; }

/* --- stamps --------------------------------------------------------------- */

.stamp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 4px;
}

.stamp-tile { position: relative; }

/* All stamps, then Save selection as stamp: full width, one above the other. */
.stamp-actions { display: grid; gap: 6px; }
.stamp-actions .btn { width: 100%; justify-content: center; }

.stamp-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  padding: 5px 2px;
  background: var(--bg-raised);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink-dim);
  font: inherit;
  cursor: pointer;
}
.stamp-tile.is-active .stamp-pick { border-color: var(--accent); color: var(--accent); }
.stamp-pick canvas { image-rendering: pixelated; border-radius: 2px; }
/* One line of name, so every chip is the same height. */
.stamp-pick .icon-label { width: 100%; white-space: nowrap; }

.stamp-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  opacity: 0;
}
.stamp-tile:hover .stamp-del,
.yarn-row:hover .stamp-del,
.project-row:hover .stamp-del { opacity: 1; }
.stamp-del:hover { background: var(--error); color: #fff; }

/* --- yarns and projects --------------------------------------------------- */

.yarn-row, .project-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 6px;
  background: var(--bg-raised);
  border-radius: var(--radius);
}
.yarn-row small, .project-row small { display: block; color: var(--ink-faint); font-size: 10px; }
.yarn-row .btn { height: 22px; padding: 0 7px; font-size: 11px; }

.dot {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--line);
}

.yarn-est {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.project-thumb {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  object-fit: contain;
  image-rendering: pixelated;
  background: var(--bg-input);
  border-radius: 3px;
}

.project-open {
  text-align: left;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
}
.project-row.is-open { outline: 1px solid var(--accent); }

/* --- stats and validation ------------------------------------------------- */

.result {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 4px;
  padding: 7px;
  background: var(--bg-raised);
  border-radius: var(--radius);
}

.stat { display: flex; flex-direction: column; }
.stat-label { font-size: 10px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 13px; font-variant-numeric: tabular-nums; }

/* segmented(): a row of exclusive choices, e.g. Fair Isle / Jacquard. */
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 26px;
  padding: 0 10px;
  border: 0;
  background: var(--bg-input);
  color: var(--ink-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-on { background: var(--accent); color: var(--accent-ink); }

.verdict {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: var(--radius);
  font-size: 12px;
}
.verdict svg { flex: 0 0 auto; }
.verdict strong { display: block; font-weight: 650; }
.verdict small { display: block; color: var(--ink-dim); font-size: 11px; }
.verdict.is-ok { background: color-mix(in srgb, var(--ok) 13%, transparent); color: var(--ok); }
.verdict.is-warn { background: color-mix(in srgb, var(--warn) 13%, transparent); color: var(--warn); }
.verdict.is-error { background: color-mix(in srgb, var(--error) 13%, transparent); color: var(--error); }

.issue-rows { display: flex; flex-direction: column; gap: 2px; }

.issue-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  background: var(--bg-raised);
  border: 0;
  border-radius: 3px;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.issue-row:hover { background: var(--line); }
.issue-num { font-variant-numeric: tabular-nums; color: var(--ink-dim); min-width: 6ch; }

.tag { font-size: 10px; padding: 1px 5px; border-radius: 9px; }
.tag-error { background: color-mix(in srgb, var(--error) 18%, transparent); color: var(--error); }
.tag-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag-ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); white-space: nowrap; }

/* "Flag floats longer than [7] stitches": a number inside a sentence. */
.inline-field { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--ink-dim); }
.inline-field .num { width: 56px; }

/* A button that reads as a link, for "go there" shortcuts. */
.link {
  padding: 0;
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.link:hover { color: var(--ink); }

/* --- preview -------------------------------------------------------------- */

/*
 * The canvas is absolutely positioned so its bitmap size (set from this box's
 * measured size every frame) can never feed back into layout. In flow, with
 * `flex-basis: auto`, it could - and the panel grew a device pixel a frame.
 */
.preview-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 200px;
  border-radius: var(--radius);
  overflow: hidden;
}
.preview-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg-well); /* read back by preview/knitPreview.js */
  cursor: grab;
  touch-action: none;
}
.preview-canvas.is-panning { cursor: grabbing; }

/* Zoom buttons in the corner of the docked preview (ui/panels/preview.js). */
.preview-zoom {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg-panel) 88%, transparent);
  overflow: hidden;
}
.preview-zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 24px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.preview-zoom-btn:hover { color: var(--ink); background: var(--bg-raised); }
.preview-zoom-level { min-width: 42px; }
.preview-controls { display: flex; flex-direction: column; gap: 5px; }

/* --- full-window preview --------------------------------------------------
 * The docked preview is a thumbnail; this is the one you judge a motif in.
 * It owns its own viewport so zoom and pan cannot leak back into the panel.
 *
 * A fixed overlay at inset 0, not the Fullscreen API: it covers the viewport
 * without taking the browser's own chrome away. See ui/previewOverlay.js.
 */

.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: var(--bg-well-deep);
}

.preview-overlay-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  height: 38px;
  padding: 0 10px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
}
.preview-overlay-bar .select { width: auto; min-width: 104px; }
.preview-overlay-bar .sep {
  width: 1px;
  height: 18px;
  background: var(--line);
}
.preview-overlay-bar .grow { flex: 1; }
.preview-overlay-title { font-weight: 600; font-size: 12px; }
.preview-overlay-hint {
  color: var(--ink-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.preview-overlay-stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}
.preview-overlay-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg-well-deep);
  cursor: grab;
  touch-action: none;
}
.preview-overlay-canvas.is-panning { cursor: grabbing; }

/* --- open project dialog ---------------------------------------------------
 * A native <dialog> (ui/projectBrowser.js): the browser supplies the backdrop
 * and the focus trap. A fixed size rather than shrink-to-fit, so the grid does
 * not jump around as a search narrows it.
 */

.pb {
  width: min(960px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 32px));
  padding: 0;
  background: var(--bg-panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.pb[open] { display: flex; flex-direction: column; }
.pb::backdrop { background: rgba(0, 0, 0, 0.55); }

.pb-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 0 0 auto;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-head);
}
.pb-title { margin: 0; font-size: 14px; font-weight: 600; white-space: nowrap; }

.pb-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  max-width: 420px;
  margin-left: auto;
  color: var(--ink-faint);
}
.pb-search svg { position: absolute; left: 8px; pointer-events: none; }
.pb-search .text { height: 30px; padding-left: 30px; }

.pb-close {
  display: flex;
  padding: 5px;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--ink-dim);
  cursor: pointer;
}
.pb-close:hover { background: var(--line); color: var(--ink); }

.pb-body { display: flex; flex: 1 1 auto; min-height: 0; }

/* The views. Tag filters, when they exist, are more entries here. */
.pb-rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 0 0 180px;
  padding: 10px 8px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.pb-rail-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--ink-dim);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pb-rail-item:hover { background: var(--line); color: var(--ink); }
.pb-rail-item.is-active { background: var(--accent-wash); color: var(--accent); }
.pb-count { font-size: 10.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

.pb-main { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.pb-main-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-height: 42px;
  padding: 8px 14px;
}
.pb-heading { flex: 1 1 auto; color: var(--ink-dim); font-size: 12px; }
.pb-sort { width: auto; min-width: 120px; }

.pb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  align-content: start;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  padding: 2px 14px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pb-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 6px;
  background: var(--bg-raised);
  border: 1px solid transparent;
  border-radius: 6px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pb-card:hover { border-color: var(--ink-faint); }
.pb-card.is-selected { border-color: var(--accent); background: var(--accent-wash); }
.pb-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.pb-thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  margin-bottom: 3px;
  background: var(--bg-well);
  border-radius: 4px;
  overflow: hidden;
}
.pb-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.pb-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  padding: 2px 6px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}
.pb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.pb-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-faint);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.pb-empty { grid-column: 1 / -1; padding: 30px 0; text-align: center; }

.pb-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-head);
}
.pb-details { flex: 1 1 auto; min-width: 0; }
.pb-details strong,
.pb-details small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pb-details small { color: var(--ink-faint); font-size: 10.5px; }
.pb-delete { display: inline-flex; align-items: center; gap: 5px; }
.pb-foot .btn { height: 30px; }
.pb-foot .btn.primary { min-width: 84px; }

@media (max-width: 640px) {
  .pb-rail { display: none; }
  .pb-title { display: none; }
}

/* --- toasts --------------------------------------------------------------- */

#toasts {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

/* The whole toast is the status color, so success and failure read from
   across the room without reading the words. */
.toast {
  max-width: 460px;
  padding: 12px 18px;
  border-radius: 8px;
  background: var(--bg-raised);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  transition: opacity 0.3s;
}
.toast-ok { background: var(--ok); color: var(--accent-ink); }
.toast-warn { background: var(--warn); color: var(--accent-ink); }
.toast-error { background: var(--error); color: var(--accent-ink); }
.toast-info { background: var(--accent); color: var(--accent-ink); }

/* --- boot failure --------------------------------------------------------- */

.boot-error {
  max-width: 620px;
  margin: 12vh auto;
  padding: 22px 26px;
  background: color-mix(in srgb, var(--error) 22%, var(--bg-panel));
  border-radius: 8px;
}
.boot-error h1 { margin-top: 0; font-size: 19px; }
.boot-error li { margin-bottom: 7px; }

/* --- narrow screens ------------------------------------------------------
 * Phones are for reviewing a pattern, not building one, so the docks stack
 * under the grid and the whole thing scrolls instead of fighting for space.
 */

@media (max-width: 900px) {
  html, body { overflow: auto; }

  .app { height: auto; grid-template-rows: auto 1fr; }

  .workspace {
    grid-template-columns: 1fr;
    grid-auto-rows: min-content;
  }

  .resizer { display: none; }

  .stage { height: 60vh; }
  .dock-side { border-inline: 0; border-top: 1px solid var(--line); max-height: none; }
  .dock-bottom { flex-direction: column; max-height: none; }

  .toolbar { overflow-x: auto; }
}

/* --- knit screen (knit/screen.js) ------------------------------------------
 * The screen you stand at the machine with. It swaps in for the designer in
 * the same page. Same tokens, but the few things that matter mid-pass - the
 * row, the carriage direction, the yarns, the markers - are set large enough
 * to read from arm's length.
 */

/* Both views set their own display, which would beat the attribute. */
.app[hidden], .knit-app[hidden] { display: none; }

.knit-app {
  display: grid;
  grid-template-rows: 40px 1fr 26px;
  height: 100vh;
}
.knit-bar { gap: 8px; }
.knit-job-name { max-width: 60ch; }
.knit-bar-mode {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-wash);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.knit-pill { font-size: 12px; color: var(--ink-faint); }
.knit-pill::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
}
.knit-pill.is-on { color: var(--ok); }
.knit-pill.is-on::before { background: var(--ok); }

.knit-main {
  display: grid;
  grid-template-columns: 1fr 380px;
  min-height: 0;
}

/* The canvas is absolutely placed in a sized box (CLAUDE.md 5). */
.knit-chart { position: relative; min-width: 0; min-height: 0; }
.knit-chart-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg-well); /* read back by knit/main.js */
  cursor: pointer;
}

.knit-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  overflow-y: auto;
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
}

.knit-card {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg-head);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}
.knit-card.is-change { border-color: var(--warn); }

.knit-row-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.knit-row-num {
  font-size: 56px;
  font-weight: 650;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.knit-row-num small { font-size: 20px; font-weight: 500; color: var(--ink-faint); }
.knit-next { font-size: 14px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.knit-next strong { color: var(--ink); font-weight: 650; }

.knit-progress { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.knit-progress span { display: block; height: 100%; background: var(--accent); }
.knit-step { align-items: center; }

.knit-carriage { display: flex; align-items: center; gap: 12px; }
.knit-carriage strong { display: block; font-size: 15px; }
.knit-carriage small { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.knit-arrow { font-size: 38px; line-height: 1; color: var(--accent); }

.knit-change {
  font-weight: 650;
  color: var(--warn);
}
/* The rethread before a pass and the next one ahead (knit/screen.js). */
.knit-swap { display: flex; align-items: center; gap: 8px; font-size: 15px; flex-wrap: wrap; }
.knit-swap small { color: var(--ink-dim); font-size: 11px; min-width: 56px; }
.knit-swap-arrow { color: var(--warn); font-weight: 700; }
.knit-chip {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.knit-then {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.knit-then small { color: var(--ink-dim); font-size: 11px; }
.knit-then .grow { text-align: right; }
.knit-then-yarn { display: inline-flex; align-items: center; gap: 6px; }

.knit-yarn { display: flex; align-items: center; gap: 12px; }
.knit-yarn-chip {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.knit-yarn-text { display: flex; flex-direction: column; min-width: 0; }
.knit-yarn-text small { color: var(--ink-dim); font-size: 11px; }
.knit-yarn-text strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn.knit-go { height: 44px; font-size: 15px; }
.btn.knit-go.is-stop { border-color: var(--error); color: var(--error); background: transparent; font-weight: 600; }

.knit-note { margin: 0; font-size: 12px; }
.knit-note.is-warn,
.knit-note.is-error {
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--ink);
}
.knit-note.is-warn { background: color-mix(in srgb, var(--warn) 22%, transparent); }
.knit-note.is-error { background: color-mix(in srgb, var(--error) 24%, transparent); }

.knit-details { padding: 0; gap: 0; }
.knit-details summary {
  padding: 10px 12px;
  cursor: pointer;
  color: var(--ink-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.knit-details[open] summary { border-bottom: 1px solid var(--line-soft); }
.knit-opts { display: flex; flex-direction: column; gap: 8px; padding: 12px; }

/* Yarns: design color -> yarn letter and the cone's real color (knit/screen.js).
   Folds out at the foot of the yarn card, so it sits above Start patterning. */
.knit-yarn-setup { margin: 0 -12px -12px; border-top: 1px solid var(--line-soft); }
.knit-yarn-setup summary {
  padding: 8px 12px;
  cursor: pointer;
  color: var(--ink-dim);
  font-size: 12px;
}
.knit-yarns { display: flex; flex-direction: column; gap: 8px; padding: 4px 12px 12px; }
.knit-yarns .link { align-self: flex-start; }
.knit-yarn-row { display: flex; align-items: center; gap: 8px; }
.knit-yarn-row .select { flex: 1 1 auto; }
.knit-yarn-color {
  flex: 0 0 auto;
  width: 32px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: none;
  cursor: pointer;
}
/* The feeder chip is itself the picker: no border, the swatch fills it. */
.knit-yarn-color.knit-yarn-chip { width: 40px; height: 40px; border: 0; border-radius: 8px; overflow: hidden; }
.knit-yarn-color::-webkit-color-swatch-wrapper { padding: 0; }
.knit-yarn-color::-webkit-color-swatch { border: 0; border-radius: inherit; }
.knit-yarn-color::-moz-color-swatch { border: 0; border-radius: inherit; }

.knit-count { align-items: center; font-size: 12px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

/* Needle markers. Numbers as the bed prints them, L or R of center, never a
   minus sign. Before they are confirmed the card leads the panel in the
   accent, because a forgotten point cam ruins the first row. */
.knit-bed.is-setup { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--bg-head)); }
.knit-bed-head { display: flex; align-items: center; gap: 8px; }
.knit-bed-range { font-size: 26px; font-weight: 650; line-height: 1.15; font-variant-numeric: tabular-nums; }

.knit-markers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.knit-marker { display: flex; flex-direction: column; gap: 4px; }
.knit-marker-label { font-size: 12px; color: var(--ink-dim); }
.knit-marker-input { display: flex; gap: 6px; }
.knit-marker-input .num {
  width: 100%;
  min-width: 0;
  height: 38px;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}
.knit-seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.knit-seg-btn {
  width: 32px;
  border: 0;
  background: var(--bg-input);
  color: var(--ink-faint);
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}
.knit-seg-btn + .knit-seg-btn { border-left: 1px solid var(--line); }
.knit-seg-btn.is-on { background: var(--accent); color: var(--accent-ink); }
.knit-seg-btn:disabled { cursor: default; opacity: 0.6; }
/* Whole panel / Repeat tile in the knit bar: word labels, toolbar height. */
.knit-scope { flex: 0 0 auto; height: 28px; }
.knit-scope .knit-seg-btn { width: auto; padding: 0 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
/* The machine is the knitter's setting, so it sits in the bar beside the mode. */
.knit-machine { flex: 0 0 auto; width: auto; height: 28px; font-size: 12px; }

.knit-strip { display: flex; flex-direction: column; gap: 3px; }
.knit-strip-bed {
  position: relative;
  height: 14px;
  border-radius: 3px;
  background: var(--bg-well-deep);
  /* A tick every 10 needles, as the bed is marked. */
  background-image: repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px 5%);
}
.knit-strip-range, .knit-strip-panel { position: absolute; top: 0; bottom: 0; }
.knit-strip-range { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.knit-strip-panel { top: 3px; bottom: 3px; background: var(--accent); border-radius: 2px; }
.knit-strip-center { position: absolute; top: -3px; bottom: -3px; left: 50%; width: 2px; margin-left: -1px; background: var(--ink); }
.knit-strip-scale { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink-faint); }

.knit-bed-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 12px; }
.knit-inline { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-dim); }
.knit-inline .select { width: auto; }
.btn.knit-confirm { height: 38px; font-size: 14px; }

.knit-log {
  max-height: 220px;
  overflow-y: auto;
  padding: 8px 12px;
  font: 11px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--ink-dim);
  white-space: pre-wrap;
}
.knit-log .is-error { color: var(--error); }
.knit-log .is-warn { color: var(--warn); }

.knit-banner {
  flex: 0 0 auto;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 14px;
  background: color-mix(in srgb, var(--warn) 24%, transparent);
}
.knit-banner p { margin: 4px 0 10px; color: var(--ink-dim); }

.knit-empty { padding: 24px 8px; color: var(--ink-dim); }
.knit-empty strong { display: block; font-size: 16px; color: var(--ink); margin-bottom: 6px; }

/* --- settings dialogs ------------------------------------------------------ */
/*
 * Project settings and Library (ui/dialog.js). Same frame as the Open project
 * dialog; a narrower box, because the pages are forms, not a grid of cards.
 */

.pb.dlg { width: min(760px, calc(100vw - 32px)); height: min(620px, calc(100vh - 32px)); }
.dlg .pb-head { gap: 10px; }
.dlg-rail { flex-basis: 170px; }

.dlg-scroll { flex: 1 1 auto; min-width: 0; overflow-y: auto; padding: 16px 20px 24px; }

.dlg-groups { display: flex; flex-direction: column; gap: 22px; }
.dlg-group { display: flex; flex-direction: column; gap: 10px; }
.dlg-group + .dlg-group { padding-top: 18px; border-top: 1px solid var(--line-soft); }
.dlg-group-title { margin: 0; font-size: 13px; font-weight: 650; color: var(--ink); }
.dlg-group .row { flex-wrap: wrap; }

/* About (ui/about.js) */
.about-hero { display: flex; align-items: center; gap: 18px; }
.about-logo { width: 72px; height: auto; flex: 0 0 auto; }
.about-name { margin: 0 0 4px; font-size: 22px; font-weight: 650; letter-spacing: 0.02em; }
.about-link { display: flex; align-items: center; gap: 10px; color: var(--ink-dim); }
.about-link > svg { flex: 0 0 auto; }
.about-link .link { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; }
.about-link .link:hover { text-decoration: underline; }

.yarn-est-list .yarn-row { cursor: default; }

.lib-stamp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.lib-stamp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  text-align: center;
}
.lib-stamp canvas { image-rendering: pixelated; border-radius: 2px; }
.lib-stamp strong { font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-stamp small { color: var(--ink-faint); font-size: 10.5px; }
.lib-stamp .row { margin-top: 4px; justify-content: center; }
.lib-stamp .btn { height: 24px; padding: 0 8px; font-size: 11px; }
.lib-stamp.is-active { border-color: var(--accent); }
.lib-stamp-thumb { display: flex; padding: 0; border: 0; background: none; cursor: pointer; }

/* Name and tags edit in place: plain text until hovered or focused, so a grid
   of cards reads as a gallery rather than a form. */
.lib-stamp .lib-stamp-name,
.lib-stamp .lib-stamp-tags {
  width: 100%;
  height: 24px;
  text-align: center;
  background: transparent;
  border-color: transparent;
}
.lib-stamp .lib-stamp-name { font-size: 12px; font-weight: 600; color: var(--ink); }
.lib-stamp .lib-stamp-tags { font-size: 11px; color: var(--ink-faint); }
.lib-stamp .lib-stamp-name:hover, .lib-stamp .lib-stamp-tags:hover { border-color: var(--line-soft); }
.lib-stamp .lib-stamp-name:focus, .lib-stamp .lib-stamp-tags:focus { background: var(--bg); }

.lib-stamp-bar { display: flex; align-items: center; gap: 8px; }
.lib-stamp-bar .select { width: auto; height: 30px; }
.lib-search { margin-left: 0; }
.lib-stamp-count { font-size: 12px; white-space: nowrap; }

.lib-tags { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.lib-tag-filter { justify-content: flex-start; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--bg-raised);
  color: var(--ink-dim);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.chip small { color: var(--ink-faint); font-size: 10px; }
.chip:hover { border-color: var(--line); color: var(--ink); }
.chip.is-on { border-color: var(--accent); color: var(--accent); }

/* --- status bar ------------------------------------------------------------ */
/*
 * Tile and panel size, always in view and the way into Project settings; the
 * knittability verdict in one line; the cursor's stitch and row.
 */

.statusbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 0 8px;
  background: var(--bg-head);
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-dim);
  overflow: hidden;
  white-space: nowrap;
}
.sb-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--ink-dim);
  font: inherit;
  cursor: pointer;
}
.sb-chip:hover { border-color: var(--line); background: var(--bg-raised); color: var(--ink); }
.sb-chip strong { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.sb-chip svg { color: var(--accent); }
.sb-chip.is-ok, .sb-chip.is-ok svg { color: var(--ok); }
.sb-chip.is-warn, .sb-chip.is-warn svg { color: var(--warn); }
.sb-chip.is-error, .sb-chip.is-error svg { color: var(--error); }
.sb-dot { color: var(--ink-faint); }
.sb-cursor { font-variant-numeric: tabular-nums; white-space: pre; }
