:root {
  --bg: #FFF8F4;
  --surface: #FFFFFF;
  --text: #2B2230;
  --muted: #7A6E80;
  --line: #EFE3E6;
  /* Contrast at least 4.5:1 (WCAG AA): white text on --accent, and --*-text as text on the background.
     --low/--empty are also used for borders and markings, where the requirement does not apply. */
  --accent: #D1345A;
  --accent-ink: #FFFFFF;
  --accent-text: #D1345A;
  --low: #E89B1E;
  --low-text: #A35F00;
  --empty: #D2232A;
  --empty-text: #D2232A;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(60, 20, 40, .08);
  color-scheme: light;
}
/* Dark theme: following the system, unless light is chosen in the menu (data-theme from theme.js) – or dark chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #19141C;
    --surface: #241E28;
    --text: #F4ECF2;
    --muted: #A99DAF;
    --line: #3A3140;
    --accent-text: #F06A8C;
    --low-text: #E89B1E;
    --empty-text: #FF6B6B;
    --shadow: 0 2px 10px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #19141C;
  --surface: #241E28;
  --text: #F4ECF2;
  --muted: #A99DAF;
  --line: #3A3140;
  --accent-text: #F06A8C;
  --low-text: #E89B1E;
  --empty-text: #FF6B6B;
  --shadow: 0 2px 10px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Clear focus when using the keyboard (also colors and patterns with role="button"). */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
html, body { margin: 0; }
/* The app cannot be zoomed (pinch or double tap) – only the pattern's grid has its own zoom. */
html { touch-action: pan-x pan-y; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  /* In landscape the camera/notch can be at the side of the screen. */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Header – on a phone in landscape there is no room to keep it fixed at the top. */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
@media (orientation: landscape) and (max-height: 500px) { .top { position: static; } }
.title-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 1.3rem; margin: 0; display: flex; align-items: center; gap: 10px; }
.logo { width: 44px; height: 44px; flex: none; }
.stats { display: flex; gap: 14px; margin: 6px 0 10px; font-size: .85rem; color: var(--muted); }
.stats b { color: var(--text); }
.stats .warn b { color: var(--low-text); }

#search {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; }
.chips { display: flex; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface);
  padding: 6px 14px; border-radius: 999px; font-size: .9rem;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
#sort { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 8px; font-size: .9rem; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
/* The apps have native tabs (the folders ios/ and android/), with the menu as the last tab: the web app's tabs and its
   menu button are hidden (the Menu tab still opens the menu via #menuBtn, see hplNative.receive in app.js). */
.native-app .tabs, .native-app #menuBtn { display: none; }
.tab {
  text-align: center; padding: 9px 8px; border-radius: 12px; text-decoration: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 600; font-size: .95rem;
  display: flex; align-items: center; justify-content: center; line-height: 1.2;
}
@media (max-width: 380px) { .tab { font-size: .85rem; padding: 8px 4px; } }
.tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
#stockHead { margin-top: 10px; }
#stockHead .stats { margin-top: 0; }
/* Bead size (Midi / Mini / Maxi) above the stock: the three share the width. */
.size-tabs { margin-bottom: 8px; }
.size-tabs .chip { flex: 1; }
.page-intro { margin-bottom: 10px; }
/* New pattern and the gallery next to each other */
.pattern-start { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.pattern-start > * {
  display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 8px;
  border-radius: 12px; font-weight: 600; text-align: center; line-height: 1.2;
}
#patternNewBtn { border: 0; }
.gallery-link { border: 1px solid var(--line); background: var(--surface); color: var(--accent-text); text-decoration: none; }
#pagePatterns .pattern-item { background: var(--surface); box-shadow: var(--shadow); }

.icon-btn {
  border: 0; background: transparent; font-size: 1.4rem; width: 40px; height: 40px;
  border-radius: 50%; display: grid; place-items: center;
}
.icon-btn:active { background: var(--line); }

/* Liste */
main { padding: 12px 16px; max-width: 720px; margin: 0 auto; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  background: var(--surface); border-radius: var(--radius); padding: 10px 12px;
  box-shadow: var(--shadow); border-left: 4px solid transparent;
}
.item.low { border-left-color: var(--low); }
.item.empty { border-left-color: var(--empty); }
.item-main { min-width: 0; cursor: pointer; }
.item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: .85rem; color: var(--muted); }
.item-meta .badge { font-weight: 600; }
.item.low .badge { color: var(--low-text); }
.item.empty .badge { color: var(--empty-text); }
.item-qty { display: flex; align-items: center; gap: 6px; }
.item-qty output { min-width: 3.5ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.round {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg); font-size: 1.2rem; line-height: 1;
}
.round:active { transform: scale(.94); }

.bead {
  --c: #ccc;
  width: 40px; height: 40px; border-radius: 50%; flex: none; cursor: pointer;
  background: radial-gradient(circle, var(--surface) 0 26%, var(--c) 28%);
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.18), inset 0 3px 5px rgba(255,255,255,.35), 0 0 0 1px rgba(0,0,0,.08);
}
.bead.big { width: 56px; height: 56px; }
/* Transparent beads (CLEAR_CODES in app.js) are shown semi-transparent. */
.bead.clear, .print-swatch.clear { opacity: .55; }

.empty-state { text-align: center; color: var(--muted); padding: 40px 0; }
#patternEmpty + .intro:not([hidden]) { margin-top: -16px; }
/* About the app on the front page, until there is a pattern */
.intro {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 16px 8px; margin-bottom: 16px; line-height: 1.5;
}
.intro h2 { font-size: 1.05rem; margin: 12px 0 4px; }
.intro ul { margin: 0; padding-left: 1.2em; }
.intro li { margin: 6px 0; }
.intro a { color: var(--accent-text); font-weight: 600; }

.fab {
  position: fixed; right: calc(20px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(232, 69, 107, .45);
}

/* Bundark */
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh;
  margin: auto auto 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  border: 0; border-radius: 22px 22px 0 0;
  background: var(--surface); color: var(--text);
  overflow-y: auto;
}
.sheet[open] { animation: up .2s ease-out; }
.sheet::backdrop { background: rgba(20, 10, 20, .45); }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 22px; } }

.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.sheet-head > div { flex: 1; min-width: 0; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .85rem; margin-top: 10px; }
.muted a { color: var(--accent-text); }
.legal { text-align: center; }

.qty-box { background: var(--bg); border-radius: 14px; padding: 12px; margin-bottom: 14px; }
.qty-box > label { font-size: .85rem; color: var(--muted); }
.qty-input { display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; margin: 6px 0 10px; }
.qty-input input {
  text-align: center; font-size: 1.6rem; font-weight: 700; padding: 8px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.step { border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-size: 1.6rem; }
.quick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.quick button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 8px 0; font-size: .8rem; font-variant-numeric: tabular-nums;
}

.weight { margin-top: 12px; }
.weight > label { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.weight-row { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
form .weight-row input { margin-top: 0; background: var(--surface); }
.weight-row button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 0 10px; font-size: .8rem;
}
.weight .small { margin-top: 6px; }

form label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
form input:not([type=color]):not([type=checkbox]):not([type=radio]):not([type=range]), form textarea, form select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
form input[type=color] {
  display: block; width: 100%; height: 44px; margin-top: 4px; padding: 2px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
.error { color: var(--empty-text); margin: 0 0 10px; }

.actions { display: flex; gap: 10px; margin-top: 6px; }
.actions button { flex: 1; padding: 13px; border-radius: 12px; border: 0; font-weight: 600; }
.primary { background: var(--accent); color: var(--accent-ink); }
.danger { background: transparent; color: var(--empty-text); border: 1px solid var(--line) !important; }

.menu-list { display: grid; gap: 8px; }
button.menu-item { border: 0; width: 100%; text-align: left; }
/* Language and theme (Settings): the drop-down to the right – .menu-item.* so display: block below does not win. */
.menu-item.lang-item, .menu-item.theme-item { display: flex; align-items: center; gap: 10px; }
.lang-item select, .theme-item select { margin-left: auto; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 8px; font-size: .9rem; }

/* Installér-banner */
.install {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
  background: var(--surface); border-radius: var(--radius); padding: 10px 8px 10px 12px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.install img { border-radius: 10px; flex: none; }
.install-text { flex: 1; min-width: 0; font-size: .85rem; color: var(--muted); }
.install-text b { display: block; color: var(--text); font-size: .95rem; }
.install-btn {
  border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
}
.menu-item {
  display: block; padding: 14px; border-radius: 12px; background: var(--bg);
  color: var(--text); text-decoration: none; cursor: pointer; font-size: 1rem !important;
}

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: .9rem; transition: .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Color chart */
.catalog { max-width: 720px; height: 92dvh; }
.catalog-tools { display: flex; gap: 8px; margin-bottom: 12px; }
#catalogSearch {
  flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
}
#catalogSort { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 6px 8px; font-size: .9rem; }
.swatches {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px;
}
.swatch {
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  padding: 10px 6px; border-radius: 14px; background: var(--bg); cursor: pointer; min-width: 0;
}
.swatch:active { transform: scale(.97); }
.swatch b { font-size: 1.05rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.swatch-name { font-size: .8rem; line-height: 1.2; width: 100%; overflow-wrap: anywhere; }
.swatch-qty { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.swatch.low .swatch-qty { color: var(--low-text); font-weight: 600; }
.swatch.empty .swatch-qty { color: var(--empty-text); }

/* Scan barcode */
.scan-view { position: relative; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; background: #000; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 30% 10%; border: 3px solid rgba(255,255,255,.85); border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.25);
}
.manual { display: flex; gap: 8px; margin-top: 10px; }
.manual input { margin-top: 0 !important; flex: 1; min-width: 0; }
.manual button { border: 0; border-radius: 10px; padding: 0 16px; font-weight: 600; }
.confirm-after { margin: 0 0 12px; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .95rem; }
label.check input { flex: none; width: 20px; height: 20px; accent-color: var(--accent); }

/* Patterns and figures */
.wide-sheet { max-width: 720px; }
.pattern-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pattern-item {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px;
  background: var(--bg); cursor: pointer;
}
.pattern-item:active { transform: scale(.99); }
.pattern-icon { font-size: 1.6rem; width: 48px; text-align: center; flex: 0 0 auto; }
.pattern-thumb {
  width: 48px; height: 48px; flex: 0 0 auto; object-fit: contain; border-radius: 10px;
  background: repeating-conic-gradient(#E6E0DC 0 25%, #F6F2EF 0 50%) 0 0 / 12px 12px;
}
.file-btn {
  display: flex !important; align-items: center; justify-content: center; gap: 8px;
  padding: 14px; border-radius: 12px; border: 2px dashed var(--line);
  background: var(--bg); color: var(--text) !important; font-size: 1rem !important; cursor: pointer; text-align: center;
}
/* "Choose picture", "Paste picture" and "Draw yourself" the same size: side by side, on a phone below each other */
.pick-row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; margin-bottom: 10px; }
@media (max-width: 520px) { .pick-row { grid-auto-flow: row; } }
/* The same size: "Choose picture" is a <label> and otherwise gets margin from "form label" */
.pick-row .file-btn { margin: 0; }
/* Draw yourself. Fixed height: otherwise the grid moves when the color list below it grows (the dialog sits at the bottom) */
#patternDraw { height: 92dvh; }
.draw-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.draw-tools button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: .8rem; }
.draw-tools .tool-icon { font-size: 1.25rem; line-height: 1; }
.draw-tools [aria-pressed="true"] { border-color: var(--accent) !important; box-shadow: inset 0 0 0 1px var(--accent); }
.draw-tools button:disabled { opacity: .45; }
.draw-colors { position: relative; display: flex; gap: 6px; overflow-x: auto; padding: 6px 6px 8px; margin-top: 6px; }
.draw-colors .bead { width: 36px; height: 36px; border: 0; padding: 0; }
.draw-colors .bead[aria-checked="true"] { outline: 3px solid var(--accent); outline-offset: 2px; }
#drawColorName { margin: 0 0 8px; }
#drawBoards { margin: -4px 0 8px; }
/* Full screen: only top bar, tools, colors, zoom and grid */
#patternDraw.full[open] {
  width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0;
  padding: calc(8px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom));
  overflow: hidden; animation: none;
}
#patternDraw.full #drawForm { display: flex; flex-direction: column; height: 100%; }
#patternDraw.full #drawForm > :not(.sheet-head, .draw-tools, .draw-colors, .board-wrap) { display: none; }
#patternDraw.full .board-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#patternDraw.full .sheet-head { margin-bottom: 6px; }
#patternDraw.full #drawSub, #patternDraw.full .sheet-head [data-close], #patternDraw.full #drawFull { display: none; }
#patternDraw.full .draw-tools, #patternDraw.full .draw-colors { flex: none; margin-bottom: 4px; }
#patternDraw.full .draw-board { flex: 1; min-height: 0; max-height: none; margin: 0; }
.draw-board canvas { touch-action: none; cursor: crosshair; display: block; }
/* Room to the right of the grid for the zoom buttons – like #patternBoard .board-grid. */
.draw-grid { display: inline-block; vertical-align: top; padding-right: 54px; } /* = ZOOM_PAD i app.js */
.size-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; }
.size-row .times { padding-bottom: 20px; color: var(--muted); }
.palette-choice { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 0; margin: 10px 0 12px; }
.palette-choice legend { font-size: .85rem; color: var(--muted); padding: 0 4px; }
#patternBoards { margin: -4px 0 0; }
.pattern-board {
  overflow: auto; max-height: 55dvh; border-radius: 12px; border: 1px solid var(--line);
  background: #F1ECE8; margin-bottom: 12px; text-align: center;
}
.pattern-board.big { max-height: 62dvh; }
.crop-box { text-align: center; margin-bottom: 12px; }
.crop-box canvas { display: block; margin: 0 auto 4px; border-radius: 8px; touch-action: none; cursor: grab; }
.crop-box canvas:active { cursor: grabbing; }
.crop-zoom { display: flex; align-items: center; gap: 10px; max-width: 320px; margin: 4px auto; }
.crop-zoom input { flex: 1; accent-color: var(--accent); }
.pattern-board canvas { display: inline-block; vertical-align: top; }
#patternFull, #drawFull { display: grid; place-items: center; }
/* The pattern's zoom buttons float over the grid in the bottom right corner. */
.board-wrap { position: relative; }
/* On top of each other: full screen at the top, then + and −. */
.zoom-tools { position: absolute; right: 8px; bottom: 8px; z-index: 3; display: flex; flex-direction: column; gap: 6px; }
.zoom-tools .round { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.board-hint { margin: -6px 0 12px; text-align: center; }

/* The pattern's grid: pinch to zoom (handled in app.js), the numbers at the top and left side stay fixed */
#patternBoard { touch-action: pan-x pan-y; overscroll-behavior: contain; }
.board-grid { display: inline-grid; grid-template-columns: auto auto; vertical-align: top; text-align: left; }
/* Room to the right of the grid (= ZOOM_PAD in app.js), so the last beads can be scrolled clear of the zoom buttons. */
#patternBoard .board-grid { padding-right: 54px; }
.board-grid canvas { display: block; }
.ruler-corner { position: sticky; top: 0; left: 0; z-index: 2; background: #E6DFDA; }
#patternCols { position: sticky; top: 0; z-index: 1; }
#patternRows { position: sticky; left: 0; z-index: 1; }

/* Full screen: only top bar, zoom and grid */
#patternView.full[open] {
  display: flex; flex-direction: column;
  width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0;
  padding: calc(8px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom));
  overflow: hidden; animation: none;
}
#patternView.full > :not(.sheet-head, .board-wrap) { display: none; }
#patternView.full .board-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#patternView.full .sheet-head { margin-bottom: 6px; }
#patternView.full .sheet-head h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#patternView.full #patternViewSub, #patternView.full .sheet-head [data-close], #patternView.full #patternFull { display: none; }
#patternView.full .pattern-board { flex: 1; min-height: 0; max-height: none; margin: 0; }
#patternStock.warn { color: var(--low-text); }
.legend { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.legend-item {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 12px; background: var(--bg); cursor: pointer;
  border-left: 4px solid transparent;
}
.legend-item .bead { width: 32px; height: 32px; }
/* With a "Swap" button (own pattern) the button gets its own column. */
.legend-item:has([data-swap], .shop-link) { grid-template-columns: auto 1fr auto auto; }
.shop-link { text-decoration: none; color: inherit; text-align: center; }
.legend-item.short { border-left-color: var(--low); }
.legend-item.short span { color: var(--low-text); }
.legend-item.active { outline: 2px solid var(--accent); }
.legend-main { min-width: 0; display: flex; flex-direction: column; }
.legend-main b { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-main span { font-size: .8rem; color: var(--muted); }
.legend-item output { font-weight: 700; font-variant-numeric: tabular-nums; }
.pattern-image {
  display: block; max-width: 100%; max-height: 160px; margin: 0 auto 10px; border-radius: 12px;
  background: repeating-conic-gradient(#E6E0DC 0 25%, #F6F2EF 0 50%) 0 0 / 16px 16px;
}
.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line) !important; }
.actions .danger { flex: 0 0 auto; padding-left: 20px; padding-right: 20px; }
#patternUsed { text-align: center; margin: 0 0 8px; }

/* User: a green dot on the menu button when the stock is saved online */
#menuBtn { position: relative; color: var(--text); }
#menuBtn.signed-in::after {
  content: ''; position: absolute; right: 3px; top: 5px; width: 10px; height: 10px;
  border-radius: 50%; background: #2EA44F; border: 2px solid var(--bg);
}
#account form { display: grid; gap: 12px; margin-top: 14px; }
#accountIn .actions + .actions { margin-top: 10px; }
#deleteForm { margin-top: 14px; }
.login-actions { flex-direction: row-reverse; }

/* Login with Apple, Google, Facebook, Discord and GitHub (the providers' own colors) */
.oauth { display: grid; gap: 10px; margin-top: 14px; }
.oauth-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 12px; border-radius: 12px; border: 1px solid transparent; font-weight: 600; font-size: 1rem;
}
.oauth-apple { background: #000; color: #fff; }
.oauth-google { background: #fff; color: #1F1F1F; border-color: #747775; }
.oauth-google svg { color: #4285F4; }
.oauth-facebook { background: #1877F2; color: #fff; }
.oauth-discord { background: #5865F2; color: #fff; }
.oauth-github { background: #24292F; color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .oauth-apple { background: #fff; color: #000; }
}
:root[data-theme="dark"] .oauth-apple { background: #fff; color: #000; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .9rem; margin: 16px 0 0; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.sub-head { font-size: 1rem; margin: 18px 0 8px; }
/* Sections in Settings (Account and App) */
.identities { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.identities li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.identity-name { flex: 1; display: grid; font-weight: 600; min-width: 0; }
.identity-name small { color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small-btn { padding: 8px 14px; border-radius: 10px; font-weight: 600; }
.guest-note { color: var(--muted); font-size: .9rem; margin: 10px 2px 0; }
.stock-note { margin: 0 2px 10px; }
.link-btn { border: 0; background: none; color: var(--accent-text); font-weight: 600; padding: 0; text-decoration: underline; }

/* Subscription: usage, plans (Free, Go, Pro) and receipts */
.plan-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; margin: 0 0 12px; }
.plan-row span { font-weight: 600; }
.usage { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 4px; }
.usage li { display: flex; justify-content: space-between; gap: 10px; font-size: .95rem; }
.usage li.over b { color: var(--low-text); }
.period-chips { margin: 0 0 12px; }
.period-chips .chip { flex: 1; }
.plans { display: grid; gap: 10px; }
.plan { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--surface); }
.plan.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.plan-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.plan-head h3 { margin: 0; font-size: 1.1rem; }
.plan-price { font-weight: 700; }
.plan ul { margin: 8px 0 12px; padding-left: 20px; color: var(--muted); font-size: .92rem; }
.plan button { width: 100%; padding: 11px; border-radius: 12px; border: 0; font-weight: 600; }
.plan button:disabled { opacity: .6; }
.billing-actions { flex-wrap: wrap; }
.invoices { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; font-size: .92rem; }
.invoices li { display: flex; gap: 10px; justify-content: space-between; align-items: center; }
.invoices li span:first-child { flex: 1; }
.invoices a { color: var(--accent-text); font-weight: 600; }

/* Printing a pattern (#printArea, built by printPattern in app.js) – only it is shown on paper. */
.print-area { color: #000; background: #fff; font-size: 10pt; }
.print-area h1 { font-size: 18pt; margin: 0 0 4pt; }
.print-area h2 { font-size: 12pt; margin: 0 0 6pt; }
.print-area p { margin: 0 0 8pt; }
.print-area img { display: block; max-width: 100%; max-height: 180mm; margin: 0 auto 10pt; }
.print-page { break-before: page; }
.print-legend { width: 100%; border-collapse: collapse; }
.print-legend th, .print-legend td { padding: 3pt 6pt; border-bottom: 1px solid #ccc; text-align: left; }
.print-swatch {
  display: inline-block; width: 12pt; height: 12pt; margin-right: 6pt; border-radius: 50%; vertical-align: middle;
  background: var(--c); border: 1px solid #888; -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
@media print {
  @page { margin: 12mm; }
  body.printing { background: #fff; padding: 0; }
  body.printing > :not(#printArea) { display: none !important; }
  body.printing > #printArea { display: block !important; }
}

/* Finished pegboards/rows in a pattern (renderDone in app.js). */
.done-box { margin: 4px 0 10px; }
.done-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.done-chips .chip { padding: 6px 10px; }
#patternDoneHint { margin: 8px 0 0; }
/* The numbers mark a row/column as finished (not in a shared link) */
#patternView:has(#patternDoneBox:not([hidden])) :is(#patternCols, #patternRows) { cursor: pointer; }

/* Backup reminder: text and ✕ at the top, the buttons next to each other below. */
.backup-banner { flex-wrap: wrap; }
.backup-banner .install-text { flex: 1 1 calc(100% - 56px); }
.backup-banner .install-btn { flex: 1; }

/* Cookie banner (analytics.js) – fixed at the bottom, so the content does not move */
.cookie-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: 560px; margin: 0 auto; padding: 12px 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: .9rem; line-height: 1.45;
}
.cookie-banner p { margin: 0 0 10px; }
.cookie-banner a { color: var(--accent-text); font-weight: 600; }
.cookie-btns { display: flex; gap: 8px; }
.cookie-btns button { flex: 1; border: 0; border-radius: 999px; padding: 10px; font-weight: 600; background: var(--accent); color: var(--accent-ink); }

/* The gallery (free patterns, #gallery – drawn by app.js from the API) */
#gallerySearch { margin: 0; width: 100%; box-sizing: border-box; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 12px; padding: 10px 12px; font: inherit; }
.gallery-filters { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 8px; }
#galleryForm select { width: auto; flex: 0 1 auto; margin: 0; max-width: 100%; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; }
.gallery-check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: .9rem; color: var(--text); }
.gallery-cats { flex-wrap: nowrap; overflow-x: auto; margin: 12px -16px 4px; padding: 0 16px 4px; scrollbar-width: none; }
.gallery-cats::-webkit-scrollbar { display: none; }
.gallery-cats .chip { flex: none; }
.gallery-cats .chip { color: var(--text); }
.gallery-cats .chip.active { color: var(--accent-ink); }
.gallery-note, .gallery-clear { margin: 8px 0 0; }
.gallery-h { font-size: 1.05rem; margin: 18px 0 8px; }
#galleryBody[aria-busy="true"] { opacity: .55; transition: opacity .2s; }
.motifs { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.motifs li { margin: 0; min-width: 0; }
.motif-card { display: flex; flex-direction: column; gap: 2px; width: 100%; height: 100%; padding: 8px; text-align: left; font: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); cursor: pointer; }
.motif-card img { width: 100%; height: 110px; object-fit: contain; border-radius: 8px; background: #EEEAE4; margin-bottom: 4px; image-rendering: pixelated; }
.motif-card b { overflow-wrap: anywhere; }
.motif-card span { color: var(--muted); font-size: .85rem; }
.gallery-more { margin: 8px 0 0; }
.gallery-status { text-align: center; padding: 16px 0; }
#gallerySentinel { height: 1px; }
.gallery-report { text-align: center; margin: 12px 0 0; }

/* A static page in the store apps (#docView, the text from GET /api/pages/:name) – the same look as pages.css */
.doc-sheet { min-height: 70dvh; }
.doc-sheet .sheet-head h2 { flex: 1; margin: 0; font-size: 1.2rem; line-height: 1.25; }
.doc { line-height: 1.5; overflow-wrap: anywhere; }
.doc h2 { font-size: 1.1rem; margin: 26px 0 6px; }
.doc h3 { font-size: 1rem; margin: 18px 0 4px; }
.doc p { margin: 8px 0; }
.doc .muted { margin: 0 0 16px; }
.doc a { color: var(--accent-text); }
.doc ul, .doc ol { padding-left: 1.2em; }
.doc li { margin: 5px 0; }
.doc li::marker { color: var(--accent-text); }
.doc ol > li::marker { font-weight: 700; }
.doc table { width: 100%; border-collapse: collapse; margin: 12px 0 4px; font-variant-numeric: tabular-nums; }
.doc th, .doc td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
.doc th { font-size: .9rem; color: var(--muted); }
.doc tbody tr:last-child td { border-bottom: 0; }
.doc .box { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line)); border-radius: var(--radius); padding: 14px 16px; margin: 24px 0 8px; }
.doc .box p { margin: 4px 0; }
/* "Open the app" makes no sense inside the app. */
.doc .box:has(.cta[href="./"]), .doc .cta[href="./"] { display: none; }
.doc footer { margin-top: 24px; padding: 12px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.doc .colors { list-style: none; padding: 0; margin: 16px 0 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.doc .colors li { display: flex; align-items: center; gap: 8px; margin: 0; padding: 6px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.doc .colors li::marker, .doc .color-chart li::marker { content: none; }
.doc .color-chart { list-style: none; padding: 0; margin: 16px 0 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.doc .color-chart li { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; margin: 0; padding: 10px 6px; text-align: center; background: var(--bg); border-radius: 14px; }
.doc .color-chart b { margin-top: 4px; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.doc .color-chart span:last-child { width: 100%; font-size: .8rem; line-height: 1.2; overflow-wrap: anywhere; }
.doc .bead { --c: #ccc; flex: none; width: 40px; height: 40px; border-radius: 50%; background: radial-gradient(circle, var(--bg) 0 26%, var(--c) 28%);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, .18), inset 0 3px 5px rgba(255, 255, 255, .35), 0 0 0 1px rgba(0, 0, 0, .08); }
.doc .bead.clear { opacity: .55; }
