/* Colour tokens, page layout, top bar, buttons, sheet, toasts, dialogs. */
:root {
  --bg: #f7f4ef;
  --dot: #ddd6cb;
  --surface: #ffffff;
  --ink: #2b2a28;
  --muted: #7a756d;
  --line: #e7e1d8;
  --accent: #e2604f;
  --accent-ink: #ffffff;
  --danger: #c4372b;
  --shadow-1: 0 1px 2px rgba(40, 30, 20, .08), 0 4px 12px rgba(40, 30, 20, .08);
  --shadow-2: 0 2px 6px rgba(40, 30, 20, .10), 0 12px 32px rgba(40, 30, 20, .14);
  --radius: 18px;
  --topbar-h: 52px;
  --foot-h: 0px; /* phone footer with the canvas name (set below) */
  --font: system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---- top bar ---- */
.topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(247, 244, 239, .92);
  border-bottom: 1px solid var(--line);
  z-index: 20;
  touch-action: manipulation;
}
.canvas-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 650;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tools { display: flex; align-items: center; gap: 2px; }
.tool-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover:not(:disabled) { background: rgba(0, 0, 0, .06); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.main { position: relative; flex: 1 1 auto; min-height: 0; }

/* ---- buttons ---- */
.btn {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-danger { color: var(--danger); border-color: #f0c9c4; background: #fff6f5; }
.btn-modal-danger, .modal .btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-wide { width: 100%; }
.btn-text {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  padding: 8px 4px;
  cursor: pointer;
}

.fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + var(--foot-h));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: var(--shadow-2);
  cursor: pointer;
  z-index: 15;
  touch-action: manipulation;
}

/* ---- editor sheet: bottom sheet on phones, side panel on wide screens ---- */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 78dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -8px 40px rgba(40, 30, 20, .18);
  transform: translateY(105%);
  visibility: hidden;
  transition: transform .22s ease, visibility 0s .22s;
  z-index: 30;
  touch-action: auto;
}
.sheet.open { transform: none; visibility: visible; transition: transform .22s ease; }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
}
.sheet-title { margin: 0; font-size: 17px; }
.sheet-body {
  overflow-y: auto;
  padding: 4px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.app.editing .fab { display: none; }

@media (min-width: 760px) {
  .sheet {
    left: auto;
    top: calc(var(--topbar-h) + env(safe-area-inset-top));
    width: 360px;
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--line);
    box-shadow: -8px 0 32px rgba(40, 30, 20, .10);
    transform: translateX(105%);
  }
  .app.editing .fab { display: flex; right: 380px; align-items: center; justify-content: center; }
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field input[type="text"], .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* 16px stops Android/iOS zooming into the field */
  color: var(--ink);
  background: #fcfbf9;
  resize: none;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.toggle { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; min-height: 40px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--ink); }

/* ---- colour picker ---- */
.cp-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.cp-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, .08);
  cursor: pointer;
  padding: 0;
}
.cp-swatch.on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--ink); }
.cp-custom {
  background: conic-gradient(#f66, #fd6, #6d8, #6cf, #a8f, #f8c, #f66);
  position: relative;
}
.cp-custom::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--custom, transparent);
}
.cp-panel { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.cp-sv, .cp-hue { position: relative; border-radius: 12px; touch-action: none; cursor: crosshair; }
.cp-sv {
  height: 150px;
  background-color: var(--hue, #f00);
  background-image: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent);
}
.cp-hue {
  height: 22px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.cp-thumb {
  position: absolute;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .3), 0 2px 6px rgba(0, 0, 0, .3);
  pointer-events: none;
}
.cp-hue .cp-thumb { top: 50%; }
.cp-hexrow { display: flex; align-items: center; gap: 10px; }
.cp-preview { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); }
.cp-hex {
  width: 110px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 16px;
  font-family: ui-monospace, Consolas, monospace;
}

/* ---- toasts & dialogs ---- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom) + var(--foot-h));
  transform: translateX(-50%);
  z-index: 40;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 8px 10px 8px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow-2);
  pointer-events: auto;
}
.toast .btn-text { color: #ffb3a8; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(30, 25, 20, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  width: min(380px, 100%);
  background: var(--surface);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow-2);
}
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 20px; color: var(--muted); line-height: 1.4; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.fatal {
  position: fixed;
  inset: auto 16px 16px 16px;
  padding: 16px;
  background: #fff6f5;
  color: var(--danger);
  border: 1px solid #f0c9c4;
  border-radius: 14px;
  z-index: 100;
}

/* ---- settings ---- */
.choice-group { border: 0; margin: 0; padding: 6px 18px; display: flex; flex-direction: column; gap: 8px; }
.choice-group legend { padding: 0 0 8px; }
.choice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.choice input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--ink); }
.choice span { display: flex; flex-direction: column; gap: 2px; }
.choice small { color: var(--muted); line-height: 1.35; }
.settings-note { margin: 4px 18px 0; color: var(--muted); font-size: 13px; }

/* Pan / Select mode button: highlighted in Select mode. */
.mode-btn.on, .mode-btn.on:hover:not(:disabled) { background: var(--ink); color: #fff; border-radius: 10px; }
.mode-btn svg rect { fill: none; }

/* "N selected · Delete · ✕" bar (R24). */
.select-bar {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom) + var(--foot-h));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 16px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow-2);
  z-index: 25;
}
.select-bar[hidden] { display: none; }
.select-count { font-weight: 600; white-space: nowrap; }

/* Segmented choice chips (line style / colour). */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  min-height: 36px;
}
.seg-btn.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); font-weight: 600; }
.line-look { display: flex; flex-direction: column; gap: 14px; }

/* Slider with a "Default" chip beside it (line thickness). */
.range-line { display: flex; align-items: center; gap: 10px; }
.range-line input[type=range] { flex: 1; height: 32px; accent-color: var(--ink); }

/* Slider field in settings (growth per inside item). */
.range-field { padding: 10px 18px 4px; display: flex; flex-direction: column; gap: 6px; }
.range-top { display: flex; justify-content: space-between; align-items: baseline; }
.range-top .field-label { margin: 0; }
.range-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.range-field input[type=range] { width: 100%; height: 32px; accent-color: var(--ink); }
.range-hint { color: var(--muted); line-height: 1.35; }
/* Settings tabs (Canvas | Motion). */
.settings-tabs { margin-bottom: 2px; }
.settings-pane { display: flex; flex-direction: column; gap: 16px; }
.settings-pane[hidden] { display: none; }

/* Motion switches (R33). */
.motion-panel { display: flex; flex-direction: column; gap: 12px; }
.toggle-list { display: flex; flex-direction: column; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.toggle-row span { display: flex; flex-direction: column; gap: 2px; }
.toggle-row small { color: var(--muted); line-height: 1.3; }
/* A switch drawn from a checkbox. */
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background .15s ease;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}
.switch:checked { background: var(--ink); }
.switch:checked::after { transform: translateX(18px); }

/* Settings side pane: fields use the sheet's own padding. On phones it
   takes half the screen (owner), the rest of the board stays visible. */
@media (max-width: 759px) {
  .settings-sheet { max-height: 50dvh; }
}
.settings-sheet .choice-group, .settings-sheet .range-field { padding: 0; }
.settings-section { padding: 10px 0 0; margin: 0; border-top: 1px solid var(--line); }
.settings-sheet .settings-note { margin: 0; }

/* ---- rich text editor (R32): toolbar + formatted box ---- */
.rich { display: flex; flex-direction: column; gap: 6px; }
.rich-bar { display: flex; flex-wrap: wrap; gap: 4px; }
.rich-btn {
  min-width: 36px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.rich-btn:hover { background: rgba(0, 0, 0, .05); }
.rich-box {
  min-height: 84px;
  max-height: 280px;
  overflow-y: auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  line-height: 1.45;
  outline: none;
  overflow-wrap: anywhere;
}
.rich-box:focus { border-color: var(--ink); }
.rich-box.empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
/* Compact (inside an open blob): smaller buttons, see-through box. */
.rich-compact .rich-btn { min-width: 30px; height: 28px; font-size: 13px; padding: 0 6px; background: rgba(255, 255, 255, .7); }
.rich-compact .rich-box { min-height: 48px; background: rgba(255, 255, 255, .55); color: #1f1d1a; font-size: 13.5px; }

/* ---- Bouncing (R34): top-bar button, menu, banner ---- */
.bouncing-btn .bouncing-text { display: none; }
.bouncing-btn svg circle { fill: currentColor; stroke: none; }
.bouncing-btn.is-off { opacity: .35; }
.bouncing-btn.is-off:hover { background: transparent; }
@media (min-width: 900px) {
  .bouncing-btn { width: auto; padding: 0 10px 0 8px; gap: 6px; font: inherit; font-weight: 600; }
  .bouncing-btn .bouncing-text { display: inline; }
}
.formation-menu {
  position: fixed;
  z-index: 40;
  min-width: 220px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
}
.formation-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.formation-about { margin: 6px 12px 8px; max-width: 240px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.formation-item small { color: var(--muted); font-weight: 400; font-size: 13px; }
.formation-item:hover, .formation-item:focus-visible { background: rgba(0, 0, 0, .05); outline: none; }
.formation-bar {
  position: fixed;
  left: 50%;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 24px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 8px 6px 16px;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow-2);
  z-index: 26;
}
.formation-title { font-weight: 700; }
.formation-hint { color: var(--muted); }
.formation-stepper { display: flex; align-items: center; }
.formation-count { min-width: 56px; text-align: center; font-weight: 600; }
.formation-step { font-size: 20px; font-weight: 600; }
.formation-align { flex-wrap: nowrap; }
.board.picking, .board.picking .item { cursor: pointer; }
.board.picking .items-layer > .item:hover > .item-jelly > .item-body { box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--ink); }

/* Choice dialog (Move already grouped items? / Dissolve). */
.modal-choice-list { display: flex; flex-direction: column; gap: 8px; }
.modal-choice { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; padding: 10px 16px; text-align: left; }
.modal-choice small { font-weight: 400; font-size: 13px; opacity: .8; }
.modal-choices h2 { margin-bottom: 14px; }
.modal-choices p { margin-bottom: 14px; }
/* Narrow phones: the top bar fits one more button. */
@media (max-width: 420px) {
  .tools { gap: 0; }
  .tools .icon-btn { width: 34px; }
  .tool-sep { margin: 0 2px; }
}

/* ---- phone footer: the canvas name moves to the bottom (owner) ---- */
.footbar { display: none; }
@media (max-width: 759px) {
  :root { --foot-h: 30px; }
  .topbar .canvas-name { display: none; }
  .topbar { justify-content: flex-end; }
  .footbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    height: calc(var(--foot-h) + env(safe-area-inset-bottom));
    padding: 0 max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
    background: rgba(247, 244, 239, .92);
    border-top: 1px solid var(--line);
    z-index: 20;
  }
  .foot-name { min-width: 0; font-weight: 650; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ---- pictures (phase 4): editor row, library grid, picker ---- */
.pic-field { display: flex; flex-direction: column; gap: 6px; }
.pic-row { display: flex; align-items: center; gap: 12px; }
.pic-row-btns { display: flex; align-items: center; gap: 8px; }
.pic-prev { width: 56px; height: 56px; border-radius: 12px; overflow: hidden; background: var(--line); flex: none; }
.pic-prev img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pic-note { color: var(--muted); }
.pic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.pic-empty { color: var(--muted); margin: 4px 0; grid-column: 1 / -1; }
.pic-cell { position: relative; }
.pic-thumb { display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--line); cursor: pointer; }
.pic-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pic-cell.on .pic-thumb { box-shadow: 0 0 0 3px var(--ink); }
.pic-del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgba(30, 25, 20, .7); color: #fff; font-size: 16px; line-height: 1; cursor: pointer;
}
.pic-modal { width: min(520px, 100%); max-height: min(80dvh, 640px); display: flex; flex-direction: column; gap: 12px; }
.pic-modal .pic-grid { overflow-y: auto; min-height: 90px; }
.pic-head { display: flex; align-items: center; justify-content: space-between; }
.pic-head h2 { margin: 0; }
.pic-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.add-pics { display: inline-flex; align-items: center; justify-content: center; align-self: flex-start; }
.add-pics.busy { opacity: .6; pointer-events: none; }

/* ---- tags (R10, R11; phase 5) ---- */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 9px;
  border: 0;
  border-radius: 999px;
  background: var(--tag, #ddd);
  color: var(--tag-ink, #1f1d1a);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
  white-space: nowrap;
}
.tag-chip > span { overflow: hidden; text-overflow: ellipsis; }
button.tag-chip { cursor: pointer; min-height: 30px; padding: 4px 12px; font-size: 13px; }
.tag-chip.off { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--tag); }
.tag-x { border: 0; background: none; color: inherit; font-size: 15px; line-height: 1; padding: 0 0 0 2px; cursor: pointer; opacity: .75; }
.tag-field { position: relative; }
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.tag-chips:focus-within { border-color: var(--ink); }
.tag-input { flex: 1 1 90px; min-width: 90px; border: 0; outline: none; background: transparent; font: inherit; padding: 4px 2px; }
.tag-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  z-index: 5;
}
.tag-option { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; font: inherit; text-align: left; cursor: pointer; color: var(--ink); }
.tag-option.on, .tag-option:hover { background: rgba(0, 0, 0, .06); }
.tag-option.create { font-weight: 600; }
.tag-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--tag); flex: none; }
.tag-hint { padding: 8px 10px; color: var(--muted); font-size: 13px; }
.tag-manager { display: flex; flex-direction: column; gap: 10px; }
.tag-add { display: flex; gap: 8px; }
.tag-add input, .tag-row input[type=text] { flex: 1 1 auto; min-width: 0; min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--surface); }
.tag-rows { display: flex; flex-direction: column; gap: 6px; }
.tag-row { display: flex; align-items: center; gap: 8px; }
.tag-row small { color: var(--muted); white-space: nowrap; }
.tag-row-wrap { display: flex; flex-direction: column; gap: 6px; padding-bottom: 4px; }
.tag-swatch { width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--tag); cursor: pointer; flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.tag-swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); }
.tag-palette { display: flex; flex-wrap: wrap; gap: 8px; padding-left: 36px; }
.tag-del { width: 34px; height: 34px; font-size: 18px; flex: none; }
.filter-btn { position: relative; }
.filter-btn svg path { stroke-linejoin: round; }
.filter-btn.on { background: var(--ink); color: #fff; border-radius: 10px; }
.filter-badge {
  position: absolute; top: 2px; right: 1px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px;
}
.filter-menu {
  position: fixed;
  z-index: 40;
  width: min(320px, calc(100vw - 16px));
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
}
.filter-menu .formation-about { margin: 0; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 40dvh; overflow-y: auto; }
.filter-actions { display: flex; gap: 8px; }
.filter-actions .btn { flex: 1 1 auto; }
.btn:disabled { opacity: .45; cursor: default; }

/* ---- + menu: Blob / Text / Shapes (R37, R38) ---- */
.fab { transition: transform .15s ease; }
.fab.open { transform: rotate(45deg); }
.add-menu {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + var(--foot-h) + 66px);
  z-index: 16;
  width: min(300px, calc(100vw - 32px));
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-2);
}
.add-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.add-label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 4px 0; }
.add-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px; border: 0; border-radius: 12px; background: none; color: var(--ink);
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.add-item:hover, .add-item:focus-visible { background: rgba(0, 0, 0, .05); outline: none; }
.add-item svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.add-item svg path.fill { fill: #ffb066; stroke: none; }
.shape-pick .shape-btn { width: 44px; padding: 6px; display: inline-flex; align-items: center; justify-content: center; }
.shape-btn svg { width: 24px; height: 24px; }
.shape-btn svg path { fill: currentColor; opacity: .7; }
.shape-btn.on svg path { opacity: 1; }

/* ---- canvases (phase 6): the name opens the canvas menu ---- */
.canvas-name, .foot-name { border: 0; background: none; font: inherit; text-align: left; cursor: pointer; padding: 6px 8px; margin-left: -8px; border-radius: 10px; color: inherit; }
.canvas-name { font-weight: 650; font-size: 16px; }
.canvas-name::after, .foot-name::after { content: ' \25BE'; color: var(--muted); font-size: .8em; }
.canvas-name:hover, .foot-name:hover { background: rgba(0, 0, 0, .05); }
.foot-name { font-weight: 650; font-size: 13px; color: var(--muted); padding: 4px 8px; max-width: 100%; }
.canvas-menu {
  position: fixed;
  z-index: 40;
  width: min(300px, calc(100vw - 16px));
  max-height: min(70dvh, 560px);
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
}
.canvas-list { display: flex; flex-direction: column; }
.canvas-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 0; border-radius: 10px; background: none; font: inherit; color: var(--ink); text-align: left; cursor: pointer; }
.canvas-row span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.canvas-row small { color: var(--muted); white-space: nowrap; }
.canvas-row:hover { background: rgba(0, 0, 0, .05); }
.canvas-row.on { background: rgba(0, 0, 0, .07); }
.canvas-row.on span::before { content: '\2713  '; }
.canvas-acts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding-top: 6px; border-top: 1px solid var(--line); }
.canvas-act { padding: 9px 10px; border: 0; border-radius: 10px; background: none; font: inherit; font-weight: 600; color: var(--ink); text-align: left; cursor: pointer; }
.canvas-act:hover { background: rgba(0, 0, 0, .05); }
.canvas-act.danger { color: var(--danger); }
.modal-input { width: 100%; min-height: 44px; padding: 0 12px; margin: 0 0 12px; border: 1px solid var(--line); border-radius: 12px; font: inherit; background: var(--surface); }
.modal-input:focus { outline: none; border-color: var(--ink); }
.modal-error { color: var(--danger); font-size: 13px; margin: -6px 0 12px; }
