/*
 * ILUSTRA — the carton tile (v5 §5), the market map (v5.1 §3), the record (v5.1 §6).
 * Markup: src/lib/illustrations.mjs.
 *
 * Every tile is a square container (`container-type: inline-size`), so
 * everything inside is measured in cqw and the picture scales as one piece,
 * like an SVG. Text that must stay legible on a phone takes a px floor.
 * Tokens are v5 §2 only; each carries its own fallback while tokens.css lands.
 * Motion: only transform / opacity / filter; ambient loops 6–7 s, paused by
 * [data-paused] on the tile or any ancestor, gone under reduced motion.
 */

/* ---- tile ------------------------------------------------------------------ */

.tile {
  --kraft: color-mix(in oklab, var(--copper-line, #B87333) 60%, var(--card, #F1ECE4));
  --shade: rgb(21 20 18 / 0.06);
  position: relative;
  inline-size: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  isolation: isolate;
  container-type: inline-size;
  border-radius: var(--r-tile, 32px);
  background: var(--card, #F1ECE4);
  color: var(--ink, #151412);
  font-family: var(--f-sans, 'Inter', 'Noto Sans SC', system-ui, -apple-system, sans-serif);
  font-feature-settings: 'tnum' 0;
  -webkit-user-select: none;
  user-select: none;
}
.tile img { display: block; }

/* ---- carton: kraft RSC in CSS 3D ---------------------------------------------
 * W × H × D = 54 × 40 × 36 cqw. [data-carton] is MOTION's to tilt; the resting
 * angle lives on .carton__box, the A sway on .carton__stage. */

.tile--carton {
  --cw: 54cqw;
  --ch: 40cqw;
  --cd: 36cqw;
  --print: color-mix(in oklab, var(--ink, #151412) 84%, var(--kraft));
  perspective: 240cqw;
  perspective-origin: 50% 30%;
}
.carton__floor {
  position: absolute;
  inset-inline: 14cqw;
  inset-block-start: 62cqw;
  block-size: 18cqw;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgb(21 20 18 / 0.16), rgb(21 20 18 / 0.05) 60%, transparent);
  transform: skewX(-24deg);
}
.carton__stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform-style: preserve-3d;
  animation: ill-sway 7s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate both;
}
.carton {
  position: relative;
  inline-size: var(--cw);
  block-size: var(--ch);
  transform-style: preserve-3d;
  translate: 1cqw 3cqw;
}
.carton__box {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(-17deg) rotateY(-31deg);
}
.carton__face {
  position: absolute;
  inset-inline-start: 50%;
  inset-block-start: 50%;
  overflow: hidden;
  backface-visibility: hidden;
  background: var(--kraft);
}
.carton__face--front {
  inline-size: var(--cw);
  block-size: var(--ch);
  margin: calc(var(--ch) / -2) 0 0 calc(var(--cw) / -2);
  transform: translateZ(calc(var(--cd) / 2));
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.07), rgb(0 0 0 / 0.03)),
    var(--kraft);
}
.carton__face--side {
  inline-size: var(--cd);
  block-size: var(--ch);
  margin: calc(var(--ch) / -2) 0 0 calc(var(--cd) / -2);
  transform: rotateY(90deg) translateZ(calc(var(--cw) / 2));
  background: color-mix(in oklab, var(--kraft) 90%, var(--ink, #151412));   /* shaded side, light enough for its printed code (APCA ≥ 45) */
}
.carton__face--top {
  inline-size: var(--cw);
  block-size: var(--cd);
  margin: calc(var(--cd) / -2) 0 0 calc(var(--cw) / -2);
  transform: rotateX(90deg) translateZ(calc(var(--ch) / 2));
  background: color-mix(in oklab, var(--kraft) 82%, var(--canvas, #FBF9F5));
}
/* Tape over the flap seam, running along W and folding down the short sides. */
.carton__tape,
.carton__tab {
  position: absolute;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 0.18), rgb(255 255 255 / 0) 40%, rgb(255 255 255 / 0.12)),
    color-mix(in oklab, var(--kraft) 70%, var(--canvas, #FBF9F5));
  box-shadow: 0 0 0 0.12cqw rgb(21 20 18 / 0.05);
}
.carton__tape {
  inset-inline: 0;
  inset-block-start: calc(50% - 3.4cqw);
  block-size: 6.8cqw;
}
.carton__face--top::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  inset-block-start: 50%;
  block-size: 0.15cqw;
  background: rgb(21 20 18 / 0.08);
}
.carton__tab {
  inset-block-start: 0;
  inset-inline-start: calc(50% - 3.4cqw);
  inline-size: 6.8cqw;
  block-size: 7cqw;
}
.carton__syms {
  position: absolute;
  inset-inline: 0;
  inset-block-start: 12cqw;
  display: flex;
  justify-content: center;
  gap: 2cqw;
  color: var(--print);
  opacity: 0.8;
}
.carton__sym { inline-size: 5.4cqw; block-size: 5.4cqw; }
.carton__sidecode {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 5cqw;
  text-align: center;
  font-size: 2.3cqw;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--print);
  opacity: 0.8;
}
/* Flexo print: the buyer's brand, in the carton's one ink. */
.carton__brand {
  position: absolute;
  inset-inline: 4.6cqw;
  inset-block-start: 4.6cqw;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: 5.4cqw;
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--print);
}
/* The white shipping label: model, name, the packing rows the catalogue prints. */
.carton__label {
  position: absolute;
  inset-inline-end: 3.6cqw;
  inset-block-end: 3.6cqw;
  inline-size: 30cqw;
  display: flex;
  flex-direction: column;
  gap: 0.5cqw;
  padding: 2.2cqw 2.4cqw 2.4cqw;
  border-radius: 0.8cqw;
  background: var(--canvas, #FBF9F5);
  box-shadow: 0 0.15cqw 0.4cqw rgb(21 20 18 / 0.1);
}
.carton__code {
  font-size: max(2.7cqw, calc(9px * var(--fl, 1)));
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: var(--copper, #7E4508);
}
.carton__name {
  font-size: max(2.3cqw, calc(8px * var(--fl, 1)));
  line-height: 1.25;
  color: var(--ink-2, #393532);
}
.carton__rows {
  display: grid;
  gap: 0.4cqw;
  margin-block-start: 1cqw;
  padding-block-start: 1.2cqw;
  border-block-start: 0.15cqw solid var(--rule, #DDD5C8);
}
.carton__row {
  display: flex;
  justify-content: space-between;
  gap: 1.6cqw;
  font-size: max(2.05cqw, calc(7.5px * var(--fl, 1)));
  line-height: 1.3;
}
.carton__k { color: var(--ink-3, #5E5852); }
.carton__v { font-weight: 500; color: var(--ink, #151412); text-align: end; }
@keyframes ill-sway {
  from { transform: rotateY(-5deg); }
  to { transform: rotateY(5deg); }
}
/* B on a pointer device: MOTION's tilt replaces the sway. */
@media (hover: hover) and (pointer: fine) {
  html.m-on .carton__stage { animation: none; }
}

/* ---- v5.1 map: dotted world, five market pins ----------------------------------
 * Dots are one dashed path per region (stroke width and pitch are attributes
 * written by the generator). The pressed pin's region warms to copper; a hovered
 * or focused pin previews it. Colour never animates: the copper layer fades. */

.map {
  position: relative;
  inline-size: 100%;
  aspect-ratio: var(--map-ar, 1000 / 432);
  font-family: var(--f-text, 'Inter', 'Noto Sans SC', system-ui, -apple-system, sans-serif);
}
.map__dots {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  overflow: visible;
}
.map__land { stroke: color-mix(in oklab, var(--card-2, #E8E1D5) 35%, var(--rule, #DDD5C8)); }
.map__region {
  stroke: var(--copper-line, #B87333);
  opacity: 0;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.map:has(.map__pin[data-market='north-america']:is(:hover, :focus-visible)) .map__region[data-region='north-america'],
.map:has(.map__pin[data-market='europe']:is(:hover, :focus-visible)) .map__region[data-region='europe'],
.map:has(.map__pin[data-market='southeast-asia']:is(:hover, :focus-visible)) .map__region[data-region='southeast-asia'],
.map:has(.map__pin[data-market='russia']:is(:hover, :focus-visible)) .map__region[data-region='russia'],
.map:has(.map__pin[data-market='latin-america']:is(:hover, :focus-visible)) .map__region[data-region='latin-america'] {
  opacity: 0.4;
}
.map:has(.map__pin[data-market='north-america'][aria-pressed='true']) .map__region[data-region='north-america'],
.map:has(.map__pin[data-market='europe'][aria-pressed='true']) .map__region[data-region='europe'],
.map:has(.map__pin[data-market='southeast-asia'][aria-pressed='true']) .map__region[data-region='southeast-asia'],
.map:has(.map__pin[data-market='russia'][aria-pressed='true']) .map__region[data-region='russia'],
.map:has(.map__pin[data-market='latin-america'][aria-pressed='true']) .map__region[data-region='latin-america'] {
  opacity: 0.85;
}

/* A pin: a 44 px target centred on its point; the label hangs below it. */
.map__pin {
  position: absolute;
  inset-inline-start: var(--px);
  inset-block-start: var(--py);
  display: grid;
  place-items: center;
  inline-size: 44px;
  block-size: 44px;
  margin: 0;
  padding: 0;
  translate: -50% -50%;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.map__halo,
.map__dot {
  grid-area: 1 / 1;
  border-radius: 50%;
}
.map__halo {
  inline-size: 26px;
  block-size: 26px;
  background: var(--copper-line, #B87333);
  opacity: 0.16;
  transform: scale(0.7);
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}
.map__dot {
  inline-size: 12px;
  block-size: 12px;
  background: var(--copper, #7E4508);
  box-shadow: 0 0 0 2px var(--canvas, #FBF9F5);
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.map__label {
  position: absolute;
  inset-block-start: calc(50% + 11px);
  inset-inline-start: 50%;
  translate: -50% 0;
  padding: 2px 8px;
  border-radius: var(--r-pill, 999px);
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
  white-space: nowrap;
  color: var(--ink-2, #393532);
  transition: opacity 0.2s ease;
}
.map__pin:hover .map__dot { transform: scale(1.15); }
.map__pin:hover .map__halo { transform: scale(0.95); }
.map__pin[aria-pressed='true'] .map__dot { transform: scale(1.2); }
.map__pin[aria-pressed='true'] .map__halo { transform: scale(1.15); opacity: 0.22; }
.map__pin[aria-pressed='true'] .map__label {
  background: var(--canvas, #FBF9F5);
  box-shadow: 0 1px 2px rgb(21 20 18 / 0.08), 0 4px 12px -4px rgb(21 20 18 / 0.16);
  font-weight: 600;
  color: var(--copper, #7E4508);
}
.map__pin:focus-visible { outline: none; }
.map__pin:focus-visible .map__dot { outline: 2px solid var(--copper-line, #B87333); outline-offset: 4px; }
.map__pin:active .map__dot { transform: scale(0.9); }
/* Narrow maps: only the chosen market keeps its label (the panel names it too). */
@media (max-width: 599px) {
  .map__pin:not([aria-pressed='true']) .map__label {
    opacity: 0;
    pointer-events: none;
  }
  .map__label { font-size: 12px; inset-block-start: calc(50% + 8px); }
  .map__dot { inline-size: 9px; block-size: 9px; }
  .map__halo { inline-size: 20px; block-size: 20px; }
}

/* ---- v5.1 record: token fills over the SVG's own attributes ----------------------
 * Placement, sleeve and spin are SISTEMA's and MOTION's. */

.record__svg { display: block; inline-size: 100%; block-size: 100%; }
.record__disc { fill: var(--ink, #151412); }
.record__grooves { stroke: var(--canvas, #FBF9F5); }
.record__label { fill: var(--copper-line, #B87333); }
.record__ring { stroke: var(--on-copper, #FFFFFF); }
.record__logo { fill: var(--on-copper, #FFFFFF); }
.record__hole { fill: var(--card, #F1ECE4); }

/* ---- very small containers: the px floors would break the drawing, so the
 * picture scales as a whole (text is then part of the image; the tile's
 * aria-label carries it). */

@container (max-width: 300px) {
  .tile > * { --fl: 0; }
}

/* ---- zh ------------------------------------------------------------------------ */

:lang(zh) .carton__brand,
:lang(zh) .carton__sidecode { letter-spacing: 0.08em; }

/* ---- pause and reduced motion ------------------------------------------------ */

.tile[data-paused] *,
[data-paused] .tile * {
  animation-play-state: paused !important;
}
@media (prefers-reduced-motion: reduce) {
  .tile *,
  .map * {
    animation: none !important;
    transition: none !important;
  }
}

/* The side code is printed text: ink, not a faint kraft tone (APCA ≥ 45 on the carton side). */
.carton__sidecode { color: var(--ink, #151412); opacity: 1; font-weight: 700; }
