/* Items: organic animated blob, title/notes, states, controls, group
   indicator (mini shapes + badge), trays and minis.
   State selectors use ">" (direct children) so a group's state never leaks
   into the minis shown inside its tray.  B = "> .item-jelly > .item-body". */
.item {
  position: absolute;
  left: 0;
  top: 0;
  width: max-content; /* size from content (capped by the body's max-width), so wrapping inside long words can't shrink it */
  cursor: pointer;
}
.item.dragging { cursor: grabbing; pointer-events: none; }
.item-jelly {
  position: relative;
  transform-origin: 50% 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.item-body {
  position: relative;
  /* --grow (set by itemView.js): a closed blob on the board gets bigger with
     every item inside it, like drops merging (R30). 1 = no growth. */
  min-width: calc(110px * var(--grow, 1));
  max-width: calc(200px * var(--grow, 1));
  min-height: calc(96px * var(--grow, 1));
  padding: 24px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  background: var(--c, #ff8a7a);
  color: var(--tc, #1f1d1a);
  box-shadow: var(--shadow-1);
  border-radius: 50%; /* the living outline is set by js/ui/physics.js */
  overflow: hidden;   /* text never shows outside the outline */
  animation: bob var(--bd, 6s) ease-in-out var(--bdl, 0s) infinite;
  transition: box-shadow .15s ease, opacity .2s ease, filter .2s ease;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

/* Battery: pause the bob when off screen or while panning/zooming/dragging. */
.item.offscreen .item-body,
.board.moving .item-body,
.item.dragging .item-body { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .item-body, .kid-shape { animation: none; }
}
/* ⚙ Motion switches (R33; classes set on the app root by app.js). */
.m-no-bob .item-body, .m-no-bob .kid-shape { animation: none !important; }
.m-no-ui .tray, .m-no-ui .item.mini.pop { animation: none !important; }

.item-title {
  max-width: 100%;
  font-weight: 650;
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: break-word; /* whole words size the blob; only over-long words break */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item-title.untitled { opacity: .55; font-style: italic; }

.item-notes {
  max-width: 72%;     /* keep text well away from the curved edge */
  font-size: 13px;
  line-height: 1.35;
  opacity: .85;
  overflow-wrap: anywhere;
  /* Up to 3 lines, then fades out (it may hold lists, so no line-clamp). */
  max-height: calc(1.35em * 3);
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 1.1em), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 1.1em), transparent);
}

/* With notes the blob grows: wider, taller, extra padding so text stays
   inside the outline (physics also makes it a bit squarer). A collapsed
   blob shows up to 3 lines of notes (2 of title), then "…". */
.item.has-notes > .item-jelly > .item-body > .item-title { max-width: 84%; overflow-wrap: anywhere; }
.item.has-notes > .item-jelly > .item-body {
  width: calc(220px * var(--grow, 1));
  max-width: calc(240px * var(--grow, 1));
  min-height: calc(140px * var(--grow, 1));
  padding: 28px 30px;
}

/* Fully expanded (tap a selected blob): the whole description is shown and
   the outline morphs into a rounded card so it fits. */
.item.expanded.has-notes > .item-jelly > .item-body {
  width: 260px;
  max-width: 260px;
  padding: 26px 24px;
}
.item.expanded > .item-jelly > .item-body > .item-notes {
  max-width: 88%;
  max-height: none;
  overflow: visible;
  -webkit-mask-image: none;
  mask-image: none;
}

/* Done: greyed out + tick (outside the body so the outline can't clip it) */
.item-done {
  display: none;
  position: absolute;
  top: 3%;
  left: 14%;   /* relative, so it stays inside the curve on grown blobs */
  z-index: 1;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
}
.item.done > .item-jelly > .item-done { display: flex; }
.item.done > .item-jelly > .item-body { filter: saturate(.2); opacity: .55; }
/* An open container stays solid (its inside items are in it); only its title fades. */
.item.done.container-open > .item-jelly > .item-body { filter: none; opacity: 1; }
.item.done.container-open > .item-jelly > .item-body > .item-title { opacity: .55; }
.item.done > .item-jelly > .item-body > .item-title { text-decoration: line-through; }

/* States */
.item.selected > .item-jelly > .item-body { box-shadow: 0 0 0 4px #fff, 0 4px 16px rgba(40, 30, 20, .22); }
.item.holding > .item-jelly > .item-body { box-shadow: 0 0 0 8px rgba(226, 96, 79, .35), var(--shadow-1); }
.item.dragging > .item-jelly > .item-body { box-shadow: var(--shadow-2); }
.item.drop-target > .item-jelly > .item-body {
  box-shadow: 0 0 0 4px #fff, 0 0 0 9px color-mix(in srgb, var(--c) 55%, transparent), 0 8px 26px rgba(40, 30, 20, .25);
}
.item.ghosted { opacity: .25; }
.item.expanded { z-index: 900000; }

/* ---- collapsed group: mini shapes (2 rows x 3) + count badge ---- */
.item-kids {
  position: relative;
  margin-top: 8px;
  padding: 0 4px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.kid-shapes {
  display: grid;
  grid-template-columns: repeat(3, 14px);
  grid-auto-rows: 14px;
  gap: 4px;
}
.kid-shape {
  background: var(--c);
  border-radius: 45% 55% 50% 50% / 55% 45% 55% 45%;
  box-shadow: 0 1px 2px rgba(40, 30, 20, .18);
  animation: kid-wobble 4.5s ease-in-out var(--d, 0s) infinite;
}
@keyframes kid-wobble {
  0%, 100% { border-radius: 45% 55% 50% 50% / 55% 45% 55% 45%; transform: translateY(0); }
  50%      { border-radius: 55% 45% 45% 55% / 45% 55% 50% 50%; transform: translateY(-1px); }
}
.board.moving .kid-shape, .item.offscreen .kid-shape { animation-play-state: paused; }
.kid-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  margin-top: -4px;
}

/* ---- grid of inside items (tray or container) ----
   Equal cells, so it reads as a grid and reordering is predictable. */
.tray {
  --cell: 108px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), var(--cell));
  grid-auto-rows: minmax(84px, auto);
  justify-items: center;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 22px;
  cursor: default;
}
.tray-root {
  position: absolute;
  top: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-2);
  animation: tray-in .22s cubic-bezier(.2, .9, .3, 1.3);
}
.tray-nested {
  grid-column: 1 / -1;
  justify-self: stretch;
  background: rgba(40, 30, 20, .05);
  animation: tray-in .2s ease-out;
}
@keyframes tray-in {
  from { opacity: 0; transform: translateX(-50%) scale(.85); }
}
.tray-nested { animation-name: tray-nested-in; }
@keyframes tray-nested-in { from { opacity: 0; transform: scaleY(.6); } }

/* A grid lit up as the drop target for a blob dragged from outside */
.tray.drop-pane {
  box-shadow: inset 0 0 0 3px var(--ink), 0 8px 26px rgba(40, 30, 20, .2);
  background: rgba(255, 255, 255, .55);
  transition: box-shadow .12s ease, background .12s ease;
}

/* "+" tile at the end of a tray: adds an item inside */
.tray-add {
  align-self: center;
  width: 64px;
  height: 64px;
  border-radius: 45% 55% 50% 50% / 55% 45% 55% 45%;
  border: 2px dashed rgba(40, 30, 20, .25);
  background: rgba(255, 255, 255, .6);
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.tray-add:hover { background: #fff; color: var(--ink); transform: scale(1.06); }

/* Minis: same component, smaller, laid out by the grid. */
.item.mini {
  position: relative;
  zoom: .62;
}
.item.mini.has-notes > .item-jelly > .item-body { width: 168px; } /* fits a cell */
.item.mini.pop { animation: mini-pop .42s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes mini-pop { from { transform: scale(.3); opacity: 0; } }

/* ---- container view: the expanded blob holds its own grid ----
   It springs into a rounded rectangle (physics roundness), title on top,
   then the description box, then the grid of inside items. */
.item.expanded.container-open > .item-jelly > .item-body {
  width: auto;
  min-width: 300px;
  max-width: 440px; /* long descriptions wrap instead of stretching it */
  max-height: none;
  padding: 16px 14px 12px;
  justify-content: flex-start;
  gap: 10px;
  cursor: default;
}
.item.container-open > .item-jelly > .item-body > .item-title {
  max-width: 90%;
  font-size: 17px;
  -webkit-line-clamp: 3;
}
.item.container-open > .item-jelly > .item-body > .item-notes { display: none; }
.item-desc, .desc-show { display: none; }
.item.container-open > .item-jelly > .item-body > .item-desc:not([hidden]) {
  display: block;
  position: relative;
  align-self: stretch;
  padding: 10px 34px 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .32);
  text-align: left;
  cursor: text;
}
.desc-text {
  font-size: 13.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.desc-text.empty { opacity: .6; font-style: italic; }
.desc-input {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  resize: none;
  outline: none;
}
.desc-hide {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .55);
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.item.container-open > .item-jelly > .item-body > .desc-show:not([hidden]) {
  display: inline-block;
  align-self: flex-start;
  border: 0;
  border-radius: 12px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, .4);
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.tray-inline {
  align-self: center;
  padding: 6px 2px 4px;
  background: rgba(255, 255, 255, .22);
  border-radius: 16px;
}
/* An open container inside a container spans a full row, at full size. */
.tray-inline > .item.mini.container-open { grid-column: 1 / -1; zoom: 1; justify-self: stretch; width: auto; }
.tray-inline > .item.mini.container-open > .item-jelly > .item-body { min-width: 0; }
.item.container-open > .item-jelly > .item-kids { display: none; }
.item.mini.expanded > .item-jelly > .item-body { box-shadow: 0 0 0 4px #fff, var(--shadow-1); }

/* Ghost: the full-size copy that follows the finger when a mini is dragged */
.item.ghost { pointer-events: none; }

/* ---- control: ✎ top-right ----
   Shown on hover (PC) or when selected (phone). */
.item-ctl {
  position: absolute;
  top: -6px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  box-shadow: var(--shadow-1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  /* Constant on-screen size when zoomed in; when zoomed out they shrink
     with the board (down to ~60%) so they don't cover small blobs. */
  transform: scale(max(min(calc(1 / var(--z, 1)), 1.18), calc(.6 / var(--z, 1))));
  transition: opacity .15s ease;
  z-index: 2;
}
.item-edit { right: -6px; }
.item.selected > .item-ctl { opacity: 1; pointer-events: auto; }
@media (hover: hover) {
  .item:not(.dragging):hover > .item-ctl { opacity: 1; pointer-events: auto; }
}
@media (pointer: coarse) {
  .item-ctl { width: 40px; height: 40px; top: -10px; }
  .item-edit { right: -10px; }
}
.item.mini > .item-ctl { zoom: 1.5; }
/* Hover (mouse): the ✎ and ↗ buttons stand out so they read as clickable. */
@media (hover: hover) {
  .item-ctl:hover { background: #f1ede6; box-shadow: 0 0 0 2px var(--ink), var(--shadow-1); }
  .item-edit:hover { cursor: pointer; }
  .item-link:hover { cursor: crosshair; }
}
.item.dragging > .item-ctl, .item.ghost > .item-ctl { opacity: 0; }

/* ---- connect handle (thin arrow), top-left (R21) ----
   Drag it onto another blob on the board to draw a line. Not on minis. */
.item-link { left: -6px; }
.item-link { cursor: crosshair; }
.item-link > svg { width: 18px; height: 18px; fill: none; stroke: #111; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
@media (pointer: coarse) { .item-link { left: -10px; } }
.item.mini > .item-link, .item.ghost > .item-link { display: none; }
.item.link-target > .item-jelly > .item-body { box-shadow: 0 0 0 4px #fff, 0 4px 16px rgba(40, 30, 20, .22); }

/* ---- formatted descriptions (R32) ---- */
.rich-text h3 { font-size: 1.12em; font-weight: 700; margin: 0 0 2px; }
.rich-text ul, .rich-text ol { margin: 2px 0; padding-left: 1.25em; text-align: left; }
.rich-text li { margin: 1px 0; }
.rich-text ul[data-b="circle"] { list-style-type: circle; }
.rich-text ul[data-b="square"] { list-style-type: square; }
.rich-text ul[data-b="dash"] { list-style-type: '– '; }
.rich-text ul[data-b="arrow"] { list-style-type: '→ '; }
.rich-text ul[data-b="star"] { list-style-type: '★ '; }
.rich-text ul[data-b="tick"] { list-style-type: '✓ '; }
/* Inside a closed blob the lists sit centred as a block, text left-aligned. */
.item-notes.rich-text ul, .item-notes.rich-text ol { display: inline-block; max-width: 100%; vertical-align: top; }

/* ---- picture cards (phase 4, R8) ----
   Thumbnails on + a picture: a rounded card, picture on top keeping its own
   shape (aspect set by itemView.js, 0.6–1.6), the title on a dark pill over
   the picture's bottom edge, notes underneath. Grows with inside items (R30). */
.item-pic { display: none; }
.item.card > .item-jelly > .item-body {
  width: calc(180px * var(--grow, 1));
  min-width: 0;
  max-width: none;
  min-height: 0;
  padding: 0 0 10px;
  justify-content: flex-start;
  gap: 8px;
}
.item.card > .item-jelly > .item-body > .item-pic {
  display: block;
  position: relative;
  align-self: stretch;
  overflow: hidden;
  background: rgba(0, 0, 0, .08);
}
.item.card > .item-jelly > .item-body > .item-pic > img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; user-select: none; }
.item.card > .item-jelly > .item-body > .item-pic > .item-title {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  max-width: none;
  margin: 0 auto;
  width: max-content;
  max-width: calc(100% - 16px);
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(20, 16, 12, .62);
  color: #fff;
  font-size: 14px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.item.card > .item-jelly > .item-body > .item-notes { max-width: none; padding: 0 14px; align-self: stretch; }
.item.card:not(.has-notes) > .item-jelly > .item-body { padding-bottom: 0; }
.item.card.expanded > .item-jelly > .item-body { width: calc(220px * var(--grow, 1)); }
.item.card > .item-jelly > .item-done { top: 8px; left: 8px; }

/* A mini with a picture: the picture as a round crop instead of the colour;
   its title gets a pill so it stays readable. */
.item.pic-blob > .item-jelly > .item-body { background: var(--c) var(--pic) center / cover no-repeat; }
.item.pic-blob > .item-jelly > .item-body > .item-title { padding: 2px 8px; border-radius: 9px; background: rgba(20, 16, 12, .6); color: #fff; }
.item.pic-blob > .item-jelly > .item-body > .item-notes { display: none; }
.kid-shape.has-pic { background: var(--c) var(--pic) center / cover no-repeat; }
/* (beats the expanded-with-notes size rule) */
.item.card.expanded.has-notes > .item-jelly > .item-body { width: calc(220px * var(--grow, 1)); max-width: none; padding: 0 0 12px; }

/* ---- tag chips on items (R10) and the filter fade (R11, C6) ---- */
.item-tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; max-width: 92%; }
.item-tags .tag-chip { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .75); font-size: 11px; line-height: 16px; padding: 1px 8px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.item.card > .item-jelly > .item-body > .item-tags { padding: 0 10px; }
.item.card:not(.has-notes).has-tags > .item-jelly > .item-body { padding-bottom: 10px; }
.item.mini > .item-jelly > .item-body > .item-tags { display: none; }
.item.faded { opacity: .2; transition: opacity .2s ease; }
.item.faded.selected { opacity: .45; }

/* A card opened into a container (editing in place): its picture stays as a
   faded background (about a third shows through the item colour), so text
   and the inside grid stay readable; corners stay the card's. */
.item.pic-open > .item-jelly > .item-body {
  background:
    linear-gradient(color-mix(in srgb, var(--c) 68%, transparent), color-mix(in srgb, var(--c) 68%, transparent)),
    var(--pic) center / cover no-repeat,
    var(--c);
}

/* ---- shapes (R37): an SVG outline in the item colour, title on top ---- */
.item.kind-shape > .item-jelly > .item-body {
  min-width: 0;
  max-width: none;
  min-height: 0;
  padding: 10px 14px;
  background: transparent;
  box-shadow: none;
  border-radius: 0 !important; /* the outline is the SVG, not the box */
  overflow: visible;
}
.shape-bg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.shape-bg path { fill: var(--c); filter: drop-shadow(0 2px 4px rgba(40, 30, 20, .16)); transition: stroke-width .15s ease; }
.item.kind-shape > .item-jelly > .item-body > .item-title { position: relative; max-width: 86%; }
.item.shape-triangle > .item-jelly > .item-body > .item-title { margin-top: 30%; max-width: 62%; }
.item.shape-diamond > .item-jelly > .item-body > .item-title,
.item.shape-hexagon > .item-jelly > .item-body > .item-title { max-width: 66%; }
.item.kind-shape.selected > .item-jelly > .item-body,
.item.kind-shape.link-target > .item-jelly > .item-body,
.item.kind-shape.dragging > .item-jelly > .item-body { box-shadow: none; }
.item.kind-shape.selected > .item-jelly > .item-body > .shape-bg path,
.item.kind-shape.link-target > .item-jelly > .item-body > .shape-bg path { stroke: #fff; stroke-width: 4px; }
.item.kind-shape.selected > .item-jelly > .item-body > .shape-bg { filter: drop-shadow(0 4px 10px rgba(40, 30, 20, .25)); }
.item.kind-shape.box-hit > .item-jelly > .item-body > .shape-bg path { stroke: var(--ink); stroke-width: 2px; }
.item.kind-shape.holding > .item-jelly > .item-body { box-shadow: none; }
.item.kind-shape.done > .item-jelly > .item-body { filter: none; opacity: 1; }

/* resize handles: right edge, bottom edge, corner — on the selected shape */
.shape-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px var(--ink), var(--shadow-1);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  transform: translate(-50%, -50%) scale(max(min(calc(1 / var(--z, 1)), 1.4), calc(.7 / var(--z, 1))));
}
.shape-handle.h-e { left: 100%; top: 50%; cursor: ew-resize; }
.shape-handle.h-s { left: 50%; top: 100%; cursor: ns-resize; }
.shape-handle.h-se { left: 100%; top: 100%; cursor: nwse-resize; }
.item.kind-shape.selected > .shape-handle { opacity: 1; pointer-events: auto; }
.board.multi .shape-handle, .item.dragging > .shape-handle { opacity: 0 !important; pointer-events: none !important; }
@media (pointer: coarse) { .shape-handle { width: 24px; height: 24px; } }
.item.resizing > .item-ctl { opacity: 0; }

/* ---- free text (R38): formatted text straight on the canvas ---- */
.item.kind-text > .item-jelly > .item-body {
  min-width: 24px;
  max-width: 320px;
  min-height: 0;
  width: max-content;
  padding: 4px 6px;
  background: transparent;
  box-shadow: none;
  border-radius: 6px !important;
  color: var(--c, #2b2a28);
  text-align: left;
  align-items: stretch;
  animation: none;
}
.text-content { font-size: 15px; line-height: 1.4; overflow-wrap: anywhere; }
.text-content.empty { opacity: .45; font-style: italic; }
.text-content h3 { font-size: 1.3em; }
.item.kind-text.selected > .item-jelly > .item-body { box-shadow: 0 0 0 1.5px rgba(43, 42, 40, .55); }
.item.kind-text.box-hit > .item-jelly > .item-body { box-shadow: 0 0 0 1.5px var(--ink); }
.item.kind-text.text-editing > .item-jelly > .item-body { background: rgba(255, 255, 255, .92); box-shadow: 0 0 0 1.5px var(--ink), var(--shadow-1); width: 320px; cursor: text; }
.text-edit { width: 100%; }
.item.kind-text > .item-link { display: none; }
.item.kind-text.done > .item-jelly > .item-body { filter: none; opacity: 1; }
