/* NoteSpin for phones. The colours, the cards' cue, the editor, dialogs, menus and toasts are the desktop app's;
   the layout is a phone's: a strip at the top (where you are), the cards filling the screen, and four buttons at the
   bottom. Notes fill the screen; dialogs are sheets from the bottom; Settings is a page. Bigger screens get the
   desktop's centred note and dialogs. */

:root {
  color-scheme: dark;
  --bg: #15171c;
  --panel: #1a1d23;
  --surface: #22262e;
  --surface-2: #2a2f38;
  --border: #2b3039;
  --border-2: #3a404b;
  --text: #d9dee6;
  --text-strong: #f3f5f8;
  --text-2: #a0a8b5;
  --text-3: #707886;
  --accent: #f6cf57;
  --accent-ink: #1d1f24;
  --accent-soft: rgba(246, 207, 87, 0.14);
  --danger: #f07070;
  --ok: #8fd18a;
  --ink: #24262c;
  --font: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
  /* the screen's edges: the notch and the home bar (viewport-fit=cover) */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --top-h: 50px;
  --bar-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed; inset: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
input, textarea { font: inherit; user-select: text; -webkit-user-select: text; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
a { color: var(--accent); }
.noscript { padding: 40px; color: var(--text-2); }

/* ---------- the top strip: where you are ---------- */

.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  height: calc(var(--top-h) + var(--sat));
  padding: var(--sat) calc(12px + var(--sar)) 0 calc(14px + var(--sal));
  display: flex; align-items: center; gap: 8px;
  background: var(--bg);
}
.back-btn { margin-left: -8px; }
.where { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex: 1; }
.where .dot { align-self: center; }
.where-title { font-size: 17px; font-weight: 650; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.where-count { font-size: 13px; color: var(--text-3); white-space: nowrap; }
.where-pos { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }

/* the search the cards are narrowed to (its box put away) */
.chip {
  display: flex; align-items: center; min-width: 0; flex: 0 1 auto;
  height: 32px;
  border: 1px solid rgba(246, 207, 87, 0.55); border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text-strong);
  font-size: 13px; font-weight: 600;
  overflow: hidden;
}
.chip button { display: flex; align-items: center; gap: 6px; height: 100%; border: 0; background: transparent; cursor: pointer; }
.chip-open { padding: 0 4px 0 10px; min-width: 0; }
.chip-open span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-open svg { width: 14px; height: 14px; color: var(--accent); }
.chip-x { padding: 0 9px 0 4px; color: var(--text-2); }
.chip-x svg { width: 14px; height: 14px; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); color: var(--text-strong); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.small svg { width: 16px; height: 16px; }

/* ---------- search: over the top strip ---------- */

.search-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 7;
  height: calc(var(--top-h) + var(--sat));
  padding: var(--sat) calc(8px + var(--sar)) 0 calc(10px + var(--sal));
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  animation: slide-down 0.16s ease-out;
}
@keyframes slide-down { from { transform: translateY(-12px); opacity: 0; } }
.search {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  height: 38px;
  padding: 0 4px 0 11px;
  border: 1px solid var(--border-2);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-3);
}
.search:focus-within { border-color: var(--accent); color: var(--text-2); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text-strong); font-size: 16px; /* 16px: an iPhone doesn't zoom in */ }
.search input::-webkit-search-cancel-button { display: none; }
.search-info { font-size: 12.5px; color: var(--text-3); white-space: nowrap; }
.text-btn { border: 0; background: transparent; color: var(--accent); font-weight: 650; padding: 8px 6px; cursor: pointer; }

/* ---------- the cards ---------- */

#stage {
  position: fixed; z-index: 1;
  top: calc(var(--top-h) + var(--sat)); bottom: calc(var(--bar-h) + var(--sab));
  left: var(--sal); right: var(--sar);
  overflow: hidden;
}
#stage canvas { display: block; outline: none; touch-action: none; }
/* the cue under the front card (the scroll): "Tap to edit" */
.front-hint {
  position: absolute; z-index: 2;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 11px;
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 999px;
  background: rgba(14, 16, 22, 0.78);
  color: rgba(248, 250, 252, 0.92);
  font-size: 12px; font-weight: 500; letter-spacing: 0.02em; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.front-hint.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.front-hint svg { width: 12px; height: 12px; opacity: 0.85; }

.stage-empty {
  position: absolute; left: 50%; top: 22%;
  transform: translateX(-50%);
  width: max-content; max-width: min(420px, 88%);
  padding: 18px 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(26, 29, 35, 0.94);
  text-align: center;
  z-index: 2;
}
.stage-empty p { margin: 0 0 12px; color: var(--text-2); font-size: 15px; }
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 10px 18px;
  border: 0; border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  cursor: pointer;
}

/* ---------- the bar: Categories, Search, New note, Settings ---------- */

.bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  height: calc(var(--bar-h) + var(--sab));
  padding: 0 calc(6px + var(--sar)) var(--sab) calc(6px + var(--sal));
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.bar-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0;
  border: 0; background: transparent;
  color: var(--text-2);
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  cursor: pointer;
}
.bar-btn svg { width: 24px; height: 24px; }
.bar-btn > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bar-btn.on { color: var(--accent); }
.bar-btn:active { color: var(--text-strong); }
.bar-btn.new .bubble {
  display: grid; place-items: center;
  width: 52px; height: 30px; border-radius: 15px;
  background: var(--accent); color: var(--accent-ink);
}
.bar-btn.new .bubble svg { width: 22px; height: 22px; stroke-width: 2.4; }
.bar-btn.new { color: var(--text); }
.bar-btn.new:active .bubble { filter: brightness(1.08); transform: scale(0.96); }

/* a phone on its side: less room top to bottom */
@media (max-height: 480px) {
  :root { --top-h: 40px; --bar-h: 46px; }
  .bar-btn > span:not(.bubble) { display: none; }
  .bar-btn svg { width: 22px; height: 22px; }
}
/* on a bigger screen the bar's buttons sit closer together */
@media (min-width: 700px) {
  .bar { grid-template-columns: repeat(4, minmax(0, 120px)); justify-content: center; }
}

/* ---------- covering everything: opening, or the notebook open elsewhere ---------- */

.cover {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: calc(24px + var(--sat)) 24px calc(24px + var(--sab));
  background: var(--bg);
}
.cover-box { max-width: 380px; text-align: center; }
.cover-logo { width: 56px; height: 56px; color: var(--accent); stroke-width: 1.4; }
.cover h1 { margin: 8px 0 6px; font-size: 22px; font-weight: 650; color: var(--text-strong); }
.cover p { margin: 0 0 18px; color: var(--text-2); }
.cover-btns { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + var(--sab) + 12px);
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 20px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 80;
  pointer-events: none;
}
body.note-open .toasts { bottom: calc(14px + var(--sab)); }
/* with a sheet or Settings up, messages show at the top, clear of its buttons */
body:has(.dlg-back) .toasts { bottom: auto; top: calc(var(--sat) + 12px); }
.toast {
  display: flex; align-items: center; gap: 10px;
  max-width: 100%;
  padding: 9px 6px 9px 14px;
  border: 1px solid var(--border-2);
  border-radius: 12px;
  background: #262a32;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  color: var(--text-strong);
  font-size: 14px;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast.error { border-color: rgba(240, 112, 112, 0.6); }
.toast.out { opacity: 0; transform: translateY(6px); transition: 0.18s; }
.toast button { flex: none; border: 0; background: transparent; color: var(--accent); font-weight: 650; cursor: pointer; padding: 6px 8px; border-radius: 7px; }
.toast button:active { background: rgba(255, 255, 255, 0.07); }
.toast button.x { color: var(--text-3); font-size: 18px; line-height: 1; padding: 4px 8px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- the editor (js/editor.js) ---------- */

.ed-layer {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(12, 14, 18, 0.5);
  z-index: 20;
}
.ed-card {
  --paper: #fff2a6;
  --band: #e9cf5c;
  display: flex; flex-direction: column;
  width: min(780px, 100%);
  height: min(880px, 100%);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  user-select: text; -webkit-user-select: text;
  transform-origin: center;
  container-type: inline-size;   /* the toolbar tightens up in a narrow note (below) */
}
.ed-band {
  display: flex; align-items: center; gap: 4px;
  padding: 7px 8px 7px 14px;
  background: var(--band);
}
.ed-cat { position: relative; display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0; color: rgba(25, 27, 32, 0.75); }
.ed-cat input {
  field-sizing: content;
  flex: 0 1 auto; min-width: 6em; max-width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
}
.ed-cat input::placeholder { color: rgba(25, 27, 32, 0.6); }
.ed-cat input:focus { outline: 0; background: rgba(255, 255, 255, 0.5); border-color: rgba(0, 0, 0, 0.18); }
.ed-catlist {
  position: absolute; left: 0; top: calc(100% + 8px);
  width: min(300px, calc(100vw - 24px)); max-height: 300px; overflow: auto;
  padding: 5px;
  border: 1px solid var(--border-2);
  border-radius: 12px;
  background: #23272f;
  color: var(--text);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  z-index: 3;
}
.ed-catlist .opt { display: flex; align-items: center; gap: 9px; padding: 10px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-catlist .opt:hover, .ed-catlist .opt.on { background: var(--surface-2); color: var(--text-strong); }
.ed-catlist .opt.new { color: var(--accent); }
.ed-catlist .none { padding: 8px; color: var(--text-3); }
.ed-status { font-size: 12px; color: rgba(25, 27, 32, 0.6); margin-right: 2px; white-space: nowrap; }
.ed-status[data-state="error"] { color: #a3201b; font-weight: 600; }
.ed-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: rgba(25, 27, 32, 0.78);
  cursor: pointer;
}
.ed-btn svg { width: 20px; height: 20px; }
.ed-btn:active { background: rgba(0, 0, 0, 0.09); color: #111; }
.ed-btn.on { background: rgba(22, 24, 30, 0.85); color: #fff; }
.ed-btn.ed-done { background: rgba(22, 24, 30, 0.82); color: #fff; margin-left: 4px; }
.ed-btn.ed-done svg { stroke-width: 2.4; }

.ed-tools {
  display: flex; align-items: center; flex-wrap: nowrap; gap: 2px;
  padding: 5px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
  background: rgba(255, 255, 255, 0.18);
  overflow-x: auto; scrollbar-width: none;
}
.ed-tools::-webkit-scrollbar { display: none; }
.ed-tools button {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 34px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: rgba(25, 27, 32, 0.75);
  cursor: pointer;
}
.ed-tools button.on { background: rgba(22, 24, 30, 0.82); color: #fff; }
.ed-tools button:disabled { opacity: 0.35; cursor: default; background: transparent; }
.ed-sep { width: 1px; height: 18px; margin: 0 4px; background: rgba(0, 0, 0, 0.15); flex: none; }
.ed-lockinfo { display: flex; align-items: center; gap: 6px; margin-left: auto; padding-left: 6px; font-size: 12px; color: rgba(25, 27, 32, 0.7); white-space: nowrap; }
.ed-lockinfo svg { width: 14px; height: 14px; }

.ed-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 18px 30px 30px; cursor: text; }
.ed-body {
  position: relative;
  min-height: 100%;
  outline: none;
  font-size: calc(16.5px * var(--text-size, 1));   /* the text size (Settings), for every note */
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  caret-color: #111;
}
.ed-body.empty::before {
  content: "Start typing. The first line is the title.";
  position: absolute; left: 0; top: 0;
  color: rgba(36, 38, 44, 0.42);
  pointer-events: none;
}
.ed-body p { margin: 0 0 0.35em; }
/* a list item's indent is its own (at its start: the left, or the right when it reads right to left) */
.ed-body ul, .ed-body ol { margin: 0.1em 0 0.45em; padding: 0; }
.ed-body li { margin: 0.12em 0; margin-inline-start: 1.7em; padding-inline-start: 0.15em; }
.ed-body li > ul, .ed-body li > ol, .ed-body ul > ul, .ed-body ol > ol, .ed-body ul > ol, .ed-body ol > ul { margin: 0.1em 0; }
.ed-body ul.check { list-style: none; }
.ed-body ul.check > li { position: relative; margin-inline-start: 0.1em; padding-inline-start: 1.85em; }
.ed-body ul.check > li::before {
  content: "";
  position: absolute; inset-inline-start: 0.1em; top: 0.28em;
  width: 1.1em; height: 1.1em;
  border: 1.7px solid rgba(36, 38, 44, 0.62);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.4);
  cursor: pointer;
}
.ed-body ul.check > li.done::before {
  background: rgba(36, 38, 44, 0.82) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.4 6.5 11.3 12.5 4.8' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 85% no-repeat;
  border-color: transparent;
}
.ed-body ul.check > li.done { color: rgba(36, 38, 44, 0.5); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.ed-card.locked .ed-body > :first-child { background: rgba(255, 255, 255, 0.35); box-shadow: -8px 0 0 rgba(255, 255, 255, 0.35), 8px 0 0 rgba(255, 255, 255, 0.35); border-radius: 3px; }
::highlight(ns-search) { background-color: #ff9f1c; color: #111; }
.ed-foot { padding: 7px 16px 9px; font-size: 12px; color: rgba(25, 27, 32, 0.55); border-top: 1px solid rgba(0, 0, 0, 0.06); }

/* a narrow note: the toolbar closes up */
@container (max-width: 400px) {
  .ed-card .ed-tools { gap: 0; padding-inline: 4px; }
  .ed-card .ed-tools button { width: 33px; }
  .ed-card .ed-sep { margin: 0 2px; }
  .ed-card .ed-lockinfo > span { display: none; }
}

/* On a phone the note is the whole screen, above the keyboard (--vvt and --vvh: the part of the screen it leaves) */
@media (max-width: 700px), (max-height: 560px) {
  .ed-layer { inset: auto 0; top: var(--vvt, 0px); height: var(--vvh, 100%); padding: 0; background: var(--bg); }
  .ed-card { width: 100%; height: 100%; border-radius: 0; box-shadow: none; }
  .ed-band { padding-top: calc(7px + var(--sat)); padding-left: calc(12px + var(--sal)); padding-right: calc(6px + var(--sar)); }
  .ed-tools { padding-left: calc(8px + var(--sal)); padding-right: calc(8px + var(--sar)); }
  .ed-scroll { padding: 14px calc(18px + var(--sar)) 28px calc(18px + var(--sal)); }
  .ed-foot { padding-bottom: calc(9px + var(--sab)); }
  /* with the keyboard up the top strip has no notch to clear, and the foot gives its room to the text */
  body.keyboard .ed-band { padding-top: 7px; }
  body.keyboard .ed-foot { display: none; }
}

svg.inline-icon { width: 15px; height: 15px; vertical-align: -3px; }

/* ---------- dialogs ---------- */

.dlg-back {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(8, 10, 14, 0.6);
  z-index: 50;
  animation: fade-in 0.14s ease-out;
}
.dlg {
  width: min(440px, 100%);
  max-height: calc(100% - 32px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 20px 22px 16px;
  border: 1px solid var(--border-2);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  user-select: text; -webkit-user-select: text;
  animation: pop-in 0.16s ease-out;
}
.dlg.dlg-wide { width: min(580px, 100%); }
.dlg h2 { margin: 0 0 12px; font-size: 18px; font-weight: 650; color: var(--text-strong); }
.dlg h3 { margin: 22px 0 8px; font-size: 12px; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.07em; }
.dlg h3:first-child { margin-top: 4px; }
.dlg p { margin: 0 0 10px; color: var(--text); overflow-wrap: anywhere; }
.dlg p.lead { color: var(--text-strong); font-weight: 600; }
.dlg p.hint, .dlg .hint { color: var(--text-2); font-size: 13.5px; }
.dlg p.err { color: var(--danger); font-weight: 600; }
.dlg p.ok { color: var(--ok); font-weight: 600; }
.dlg ol.steps { margin: 0 0 12px; padding-left: 1.4em; color: var(--text); }
.dlg ol.steps li { margin: 4px 0; }
.dlg-buttons { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.dlg.shake { animation: shake 0.32s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.97) translateY(6px); } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0.4; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border-2);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text-strong);
  font-weight: 600;
  cursor: pointer;
}
.btn svg { width: 17px; height: 17px; }
.btn:active { background: #333944; }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: 13.5px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.primary:active { filter: brightness(1.06); }
.btn.danger { background: transparent; border-color: rgba(240, 112, 112, 0.55); color: var(--danger); }
.btn.primary.danger { background: #c94646; border-color: #c94646; color: #fff; }
.btn.left { margin-right: auto; }
.btn:disabled { opacity: 0.55; cursor: default; }

.field { display: flex; flex-direction: column; gap: 5px; margin: 0 0 12px; }
.field > span:first-child { font-size: 13px; color: var(--text-2); font-weight: 550; }
.field input, .cat-row input, .add-row input {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-strong);
  font-size: 16px;   /* an iPhone zooms in on smaller text fields */
  outline: 0;
}
.field input:focus, .cat-row input:focus, .add-row input:focus { border-color: var(--accent); }
.pw { display: flex; }
label.check { display: flex; align-items: center; gap: 10px; margin: 2px 0 12px; color: var(--text-2); font-size: 14px; cursor: pointer; min-height: 32px; }
label.check input { accent-color: var(--accent); width: 20px; height: 20px; flex: none; }
.range-row { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; color: var(--text-2); font-size: 14px; }
.range-row input { flex: 1; min-width: 0; accent-color: var(--accent); height: 28px; }
.range-row output { min-width: 3em; font-variant-numeric: tabular-nums; }
.size-row > span { min-width: 4.6em; }
.style-row { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; color: var(--text-2); font-size: 14px; }
.style-row > span { min-width: 4.6em; }
.seg { display: flex; padding: 3px; gap: 3px; border-radius: 11px; background: var(--bg); border: 1px solid var(--border); }
.seg button {
  flex: 1;
  min-height: 34px;
  padding: 6px 14px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--surface-2); color: var(--text-strong); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); }
.dlg .size-sample {
  margin: 0 0 8px; padding: 8px 12px; border-radius: 8px;
  color: #24262c; font-size: calc(16.5px * var(--text-size, 1)); line-height: 1.45; overflow-wrap: anywhere;
}
.row-btns { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
.build { color: var(--text-3); font-size: 12.5px; }

.cat-list { display: flex; flex-direction: column; gap: 8px; }
.cat-row, .add-row { display: flex; align-items: center; gap: 8px; }
.cat-row .swatch {
  width: 36px; height: 36px; flex: none;
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 10px;
  cursor: pointer;
}
.cat-row input:disabled { color: var(--text-2); background: transparent; border-color: transparent; }
.cat-row .count { width: 62px; flex: none; color: var(--text-3); font-size: 12.5px; text-align: right; }
.cat-row .icon-btn:disabled { visibility: hidden; }
.add-row { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

.palette {
  position: fixed; z-index: 70;
  display: grid; grid-template-columns: repeat(6, 36px); gap: 8px;
  padding: 10px;
  border: 1px solid var(--border-2);
  border-radius: 14px;
  background: #23272f;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}
.palette button { width: 36px; height: 36px; border: 1px solid rgba(0, 0, 0, 0.35); border-radius: 10px; cursor: pointer; }
.palette button.on { outline: 2px solid var(--accent); outline-offset: 2px; }

.safety-list { display: flex; flex-direction: column; gap: 8px; }
.safety-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.safety-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.safety-text strong { color: var(--text-strong); font-size: 14px; }
.safety-text span { color: var(--text-3); font-size: 12.5px; }

/* On a phone: dialogs are sheets from the bottom (above the keyboard), Settings a page of its own */
@media (max-width: 600px) {
  .dlg-back { align-items: flex-end; padding: 0; inset: auto 0; top: var(--vvt, 0px); height: var(--vvh, 100%); }
  .dlg, .dlg.dlg-wide {
    width: 100%;
    max-height: calc(100% - var(--sat) - 16px);
    padding: 20px calc(18px + var(--sar)) calc(14px + var(--sab)) calc(18px + var(--sal));
    border-radius: 20px 20px 0 0;
    border-width: 1px 0 0;
    animation: sheet-in 0.2s ease-out;
  }
  body.keyboard .dlg { padding-bottom: 14px; }
  .dlg-buttons .btn { flex: 1 1 auto; min-height: 46px; }
  .dlg-buttons .btn.left { margin-right: 0; }
}
/* Settings: the whole screen, its title at the top and Done at the bottom, the rest scrolling between */
.dlg.dlg-page { display: flex; flex-direction: column; padding: 0; overflow: hidden; height: min(820px, 100%); width: min(620px, 100%); }
.dlg-page > h2 { margin: 0; padding: 18px 22px 10px; border-bottom: 1px solid var(--border); }
.dlg-page > .dlg-body { flex: 1; overflow: auto; overscroll-behavior: contain; padding: 6px 22px 18px; }
.dlg-page > .dlg-buttons { margin: 0; padding: 10px 16px 14px; border-top: 1px solid var(--border); }
@media (max-width: 600px) {
  .dlg-back:has(.dlg-page) { top: 0; height: 100%; }
  .dlg.dlg-page { height: 100%; max-height: none; border-radius: 0; border: 0; animation: sheet-in 0.2s ease-out; }
  .dlg-page > h2 { padding: calc(14px + var(--sat)) calc(18px + var(--sar)) 10px calc(18px + var(--sal)); }
  .dlg-page > .dlg-body { padding: 4px calc(18px + var(--sar)) 18px calc(18px + var(--sal)); }
  .dlg-page > .dlg-buttons { padding: 10px calc(14px + var(--sar)) calc(10px + var(--sab)) calc(14px + var(--sal)); }
}

/* ---------- menus (a card's, pressed and held) ---------- */

.menu {
  position: fixed; z-index: 60;
  min-width: 220px; max-width: min(340px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid var(--border-2);
  border-radius: 14px;
  background: #23272f;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.5);
  animation: pop-in 0.12s ease-out;
}
.menu-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px 8px 6px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible, .menu-item:active { background: var(--surface-2); color: var(--text-strong); outline: 0; }
.menu-item .tick { width: 16px; color: var(--accent); font-weight: 700; text-align: center; }
.menu-item .lbl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-item .mhint { color: var(--text-3); font-size: 12.5px; }
.menu-item.danger { color: var(--danger); }
.menu-item:disabled { opacity: 0.45; cursor: default; background: transparent; }
.menu-sep { height: 1px; margin: 5px 6px; background: var(--border); }
.menu-head { padding: 6px 10px 3px 30px; font-size: 11px; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }

/* a mouse (a computer's browser): hover shows what can be clicked */
@media (hover: hover) {
  .icon-btn:hover { background: var(--surface-2); color: var(--text-strong); }
  .bar-btn:hover { color: var(--text-strong); }
  .btn:hover { background: #333944; }
  .btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
  .btn.danger:hover { background: rgba(240, 112, 112, 0.12); }
  .ed-btn:hover { background: rgba(0, 0, 0, 0.09); color: #111; }
  .ed-btn.ed-done:hover { background: rgba(22, 24, 30, 0.95); color: #fff; }
  .ed-tools button:hover:not(:disabled):not(.on) { background: rgba(0, 0, 0, 0.08); color: #111; }
  #stage canvas { cursor: grab; }
}
