/* ─── marbling // a marbler's bath (marbling.js) ──────────────────────
   Namespace .mb-. Without JS, [data-marbling] is a figure showing its <img>
   (a real marbled endpaper). With JS the img gives way to the bath: a tray,
   the size (the bath's surface), the inks drawn as vector polygons, a canvas
   for the comb and stylus, and the sheet of paper that is laid on it.

   Theme on the figure or any parent:
     --mb-size     the empty bath                --mb-paper   the sheet
     --mb-tray     the tray's rim                --mb-rim     rim width
     --mb-aspect   bath shape (desktop)          --mb-aspect-phone  (<= 560px)
     --mb-bg       what the tool bar sits on (for the ink ring's gap)        */

[data-marbling] {
  --mb-size: #dbd4c4;
  --mb-paper: #f5f0e3;
  position: relative; margin: 0;
  color: var(--ink, #141312);
}
[data-marbling] > img {
  display: block; width: 100%; height: auto;
  aspect-ratio: var(--mb-aspect, 4 / 3); object-fit: cover;
}
[data-marbling].is-live > img { display: none; }

/* the tray */
.mb-stage {
  position: relative;
  padding: var(--mb-rim, clamp(8px, 1.2vw, 12px));
  background: var(--mb-tray, var(--paper-2, #e9e5da));
  box-shadow: inset 0 0 0 1px var(--rule, #cfcac0), 0 1px 0 rgba(255, 255, 255, .6);
  border-radius: 2px;
  transition: box-shadow .5s ease;
}
.mb-bath {
  position: relative; overflow: hidden;
  aspect-ratio: var(--mb-aspect, 4 / 3);
  background: var(--mb-size);
  cursor: crosshair; outline: none;
  touch-action: pan-y;                 /* a vertical drag scrolls the page; a sideways one pulls */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
@media (max-width: 560px) {
  .mb-bath { aspect-ratio: var(--mb-aspect-phone, var(--mb-aspect, 4 / 5)); }
}
.mb-bath:focus-visible { box-shadow: 0 0 0 2px var(--accent, #c96f4a); }

.mb-canvas, .mb-ghost, .mb-over {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none;
}
.mb-ghost { opacity: 0; }

/* the surface of the size: a breath of window light and the meniscus at the rim */
.mb-sheen {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(118deg, rgba(255, 253, 247, 0) 28%, rgba(255, 253, 247, .09) 41%, rgba(255, 253, 247, 0) 54%),
    radial-gradient(120% 90% at 30% 10%, rgba(255, 253, 247, .07), rgba(255, 253, 247, 0) 60%);
  box-shadow: inset 0 0 0 1px rgba(20, 19, 18, .1), inset 0 2px 16px rgba(20, 19, 18, .18), inset 0 0 3px rgba(20, 19, 18, .12);
}

.mb-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font: 500 10.5px/1 var(--sans, Inter, system-ui, sans-serif); letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3, #8a857d); white-space: nowrap; pointer-events: none;
  transition: opacity .8s ease;
}
.mb-hint.is-gone { opacity: 0; }

/* the sheet */
.mb-sheet {
  position: absolute; display: none; pointer-events: none;
  perspective: 1500px;
}
.mb-sheet.is-on { display: block; }
.mb-shadow {
  position: absolute; inset: 0; border-radius: 2px;
  background: rgba(38, 28, 18, .55);
  opacity: 0;
}
.mb-sheet-in {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  will-change: transform;
}
.mb-face {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  box-shadow: 0 0 0 .5px rgba(60, 48, 32, .18);
}
.mb-through { opacity: 0; box-shadow: none; }
.mb-shade { opacity: 0; box-shadow: none; background: linear-gradient(to bottom, rgba(70, 52, 30, .04), rgba(70, 52, 30, .2)); }
.mb-front { transform: rotateY(180deg); }
.mb.is-print .mb-bath { cursor: pointer; }

/* drawing mode (touch): the bath keeps the finger, and says so */
.mb.is-drawing .mb-bath { touch-action: none; }
.mb.is-drawing .mb-stage { box-shadow: inset 0 0 0 1.5px var(--accent, #c96f4a), 0 1px 0 rgba(255, 255, 255, .6); }

/* the tool bar */
.mb-bar {
  display: grid; gap: 4px; margin-top: 12px;
  font: 500 11px/1 var(--sans, Inter, system-ui, sans-serif); letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-2, #4a4744);
}
.mb-row { display: flex; align-items: center; justify-content: space-between; gap: 2px 12px; flex-wrap: wrap; }
.mb-inks, .mb-acts, .mb-presets, .mb-out { display: flex; align-items: center; flex-wrap: wrap; }
.mb-inks { margin-left: -7px; }
.mb-acts { gap: 2px; margin-left: auto; }

.mb-ink {
  width: 38px; height: 40px; margin: 0; padding: 0; border: 0; background: none;
  display: grid; place-items: center; cursor: pointer; border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}
.mb-ink span {
  width: 20px; height: 20px; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(20, 16, 12, .2), inset 0 -3px 5px rgba(20, 16, 12, .2), inset 0 2px 2px rgba(255, 255, 255, .22);
  transition: box-shadow .35s ease, transform .5s cubic-bezier(.2, .8, .2, 1);
}
.mb-ink:hover span { transform: scale(1.08); }
.mb-ink[aria-checked="true"] span {
  box-shadow: inset 0 0 0 1px rgba(20, 16, 12, .2), inset 0 -3px 5px rgba(20, 16, 12, .2), inset 0 2px 2px rgba(255, 255, 255, .22),
    0 0 0 3px var(--mb-bg, var(--paper, #f3f0e8)), 0 0 0 4.25px var(--ink, #141312);
}
.mb-ink:focus { outline: none; }
.mb-ink:focus-visible span { outline: 2px solid var(--accent, #c96f4a); outline-offset: 6px; }

.mb-btn, .mb-link {
  margin: 0; border: 1px solid transparent; background: none; color: inherit;
  font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: color .3s ease, border-color .3s ease, background-color .3s ease;
}
.mb-btn { min-height: 40px; padding: 0 14px; border-radius: 999px; }
.mb-btn:hover { border-color: var(--rule, #cfcac0); color: var(--ink, #141312); }
.mb-lay { border-color: var(--ink-3, #8a857d); color: var(--ink, #141312); }
.mb-lay:hover { border-color: var(--ink, #141312); }
.mb-btn:disabled { opacity: .45; cursor: default; }
.mb-btn[aria-pressed="true"] { background: var(--accent, #c96f4a); border-color: var(--accent, #c96f4a); color: var(--paper, #f3f0e8); }
.mb-draw { display: none; }
@media (pointer: coarse) { .mb-draw { display: inline-block; } }

.mb-link { min-height: 36px; padding: 0 8px; color: var(--ink-3, #8a857d); font-size: 10.5px; }
.mb-presets { margin-left: -8px; }
.mb-out { margin-left: auto; margin-right: -8px; }
.mb-link:hover, .mb-link[aria-current="true"] { color: var(--ink, #141312); }
.mb-link[aria-current="true"] { text-decoration: underline; text-underline-offset: 5px; text-decoration-thickness: 1px; }
.mb-btn:focus { outline: none; }
.mb-link:focus { outline: none; }
.mb-btn:focus-visible, .mb-link:focus-visible { outline: 2px solid var(--accent, #c96f4a); outline-offset: 2px; border-radius: 999px; }

.mb-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

@media print {
  .mb-bar { display: none; }
}

/* the size's texture, over the inks: the bath is a material, not a screen */
.mb-grain {
  position: absolute; inset: 0; pointer-events: none;
  mix-blend-mode: soft-light; opacity: var(--mb-grain, .55);
}
