.market-shell {
  --market-paper: #fff5e1;
  --market-ink: #21180f;
  --market-muted: #4c3b2c;
  --market-frame: #d5b994;
  --market-ok: #163f2b;
  --market-adjust: #69261b;
  --market-focus: #873a17;
  display: flex;
  flex-direction: column;
  container-type: inline-size;
}
.market-shell[data-display=screen] {
  --market-paper: #14262b;
  --market-ink: #ffeed8;
  --market-muted: #e2ccae;
  --market-frame: #755f4f;
  --market-ok: #a8f5c6;
  --market-adjust: #ffd2b0;
  --market-focus: #ffcd7d;
}
.market-loading { min-height: 500px; }
.market-workspace { display: flex; flex-direction: column; }
.market-shell .puzzle-toolbar { flex-shrink: 0; }
.market-board {
  display: flex;
  flex-direction: column;
  background: #11242d;
  color: var(--market-ink);
}
.market-brief {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 12px 18px;
  background: var(--market-paper);
  border-bottom: 1px solid var(--market-frame);
}
.market-task { min-width: 0; }
.market-wave {
  display: block;
  margin-bottom: 2px;
  font-size: clamp(14px, 1.35cqw, 19px);
  font-weight: 700;
  color: var(--market-muted);
}
.market-task h2 {
  margin: 0;
  color: var(--market-ink);
  font: 700 clamp(24px, 2.85cqw, 43px)/1.1 var(--font-sans);
  overflow-wrap: break-word;
}
.market-task p {
  margin: 5px 0 0;
  color: var(--market-muted);
  font-size: clamp(15px, 1.3cqw, 20px);
  font-weight: 600;
  line-height: 1.35;
}
.market-bridge {
  flex: 0 0 auto;
  max-width: 48%;
  padding: 6px 0 6px 16px;
  border-left: 2px solid var(--market-frame);
}
.market-bridge > * { display: block; }
.market-bridge strong { font-size: clamp(16px, 1.65cqw, 25px); line-height: 1.18; }
.market-bridge span { margin-top: 4px; font-size: clamp(14px, 1.25cqw, 19px); font-weight: 650; line-height: 1.25; }
.market-bridge[data-over=true] { color: var(--market-adjust); border-color: currentColor; }

.market-scene {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: clamp(225px, 31cqw, 345px);
}
.market-quay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 58%;
}
.market-scene::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: linear-gradient(0deg, #0b2029b0, transparent 48%);
  pointer-events: none;
}
.market-quay { z-index: -2; }
.market-stalls {
  position: absolute;
  inset: 0 12px 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(6px, 2.7cqw, 52px);
}
.market-stall {
  display: flex;
  position: relative;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}
.market-stall-art {
  position: absolute;
  inset: 1% 0 19%;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.market-stall-art::before {
  content: "";
  display: block;
  position: absolute;
  inset: auto 15% 8%;
  height: 19%;
  background: radial-gradient(ellipse, #0a1822c7, transparent 68%);
}
.market-stall-art > svg {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 440px;
  min-height: 0;
  filter: drop-shadow(1px 5px 5px #0c161ebf);
}
.market-stall[data-delivery=full] .market-stall-art > svg {
  filter: drop-shadow(1px 4px 5px #0c161ee6) drop-shadow(0 0 9px #ffc170ba);
}
.market-scene[data-complete=true] .market-stall-art > svg {
  filter: drop-shadow(1px 4px 6px #0c161ee6) drop-shadow(0 0 19px #ffbd62dc);
  animation: market-light 1.05s ease-out both;
}
@keyframes market-light {
  0% { opacity: .9; transform: scale(.975); }
  38% { transform: scale(1.025); }
  to { opacity: 1; transform: scale(1); }
}
.market-stall-sign {
  --market-stall-edge: #a75444;
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  align-content: center;
  min-width: 0;
  width: min(92%, 250px);
  padding: 6px 8px 7px;
  border-radius: 11px;
  border: 1px solid var(--market-frame);
  border-top: 4px solid var(--market-stall-edge);
  color: var(--market-ink);
  background: var(--market-paper);
  box-shadow: 0 4px 12px #11171f80;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
[data-stall=B] .market-stall-sign { --market-stall-edge: #34837a; }
[data-stall=C] .market-stall-sign { --market-stall-edge: #be8131; }
.market-stall-sign h3 { margin: 0; color: inherit; font: 700 clamp(15px, 1.8cqw, 25px)/1.18 var(--font-sans); }
.market-stall-sign p { margin: 2px 0 0; line-height: 1.15; }
.market-stall-target { font-size: clamp(16px, 2.25cqw, 32px); font-weight: 700; }
.market-stall-quantity { font-size: clamp(23px, 3.05cqw, 42px); font-weight: 750; }
.market-stall-quantity span { color: var(--market-muted); font-size: .74em; }
.market-delta { display: flex; align-items: center; gap: 4px; font-size: clamp(14px, 1.52cqw, 21px); font-weight: 700; }
.market-delta .svg { width: 1em; height: 1em; }
[data-delivery=full] .market-delta { color: var(--market-ok); }
[data-delivery=adjust] .market-delta { color: var(--market-adjust); }

/* Delivered crates: one per student, grouped under a paper tag with the table
   number, stacked on the quay in front of the stall. */
.market-delivered {
  --crate: clamp(14px, 1.6cqw, 26px);
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 3px clamp(6px, .8cqw, 12px);
  max-width: min(100%, 330px);
  margin-bottom: 3px;
  filter: drop-shadow(1px 3px 3px #071219d0);
}
.market-drop { display: inline-flex; align-items: flex-end; gap: 2px; transition: opacity .2s, transform .2s; }
.market-tag {
  display: grid;
  place-items: center;
  min-width: 1.45em;
  height: 1.45em;
  padding: 0 3px;
  border: 1.5px solid #22160e;
  border-radius: 4px 4px 4px 9px;
  background: #fff3d6;
  color: #22160e;
  font: 800 clamp(13px, 1.25cqw, 20px)/1 var(--font-sans);
  font-variant-numeric: tabular-nums;
}
.market-stack {
  display: inline-grid;
  grid-auto-columns: var(--crate);
  grid-auto-rows: var(--crate);
  gap: 1px;
}
.market-crate { display: block; width: var(--crate); height: var(--crate); overflow: visible; }
.market-delivered .market-crate { animation: market-drop .32s cubic-bezier(.3,1.5,.6,1) calc(var(--crate-i) * 25ms) both; }
@keyframes market-drop { from { opacity: 0; transform: translateY(-9px) scale(.8); } }
.market-scene[data-finding=true] .market-drop { opacity: .32; }
.market-scene[data-finding=true] .market-drop[data-found=true] { opacity: 1; transform: translateY(-3px) scale(1.12); }
.market-drop[data-found=true] .market-tag { background: #ffd36b; box-shadow: 0 0 0 3px #ffd36b88, 0 0 14px #ffc04d; }

/* The dispatcher stands at the head of the bridge, between stalls A and B. */
/* z-index 1 keeps it behind the signs (2), so it never covers their text. */
.market-dispatcher {
  position: absolute;
  z-index: 1;
  left: 33.3%;
  bottom: 2px;
  height: clamp(104px, 13.5cqw, 240px);
  aspect-ratio: 124 / 172;
  transform: translateX(-50%);
  overflow: visible;
  pointer-events: none;
}
.market-dispatcher[data-place=brief] { display: none; }
@container (max-width: 600px) {
  .market-dispatcher[data-place=scene] { display: none; }
  .market-dispatcher[data-place=brief] { display: block; position: static; flex: 0 0 auto; height: 74px; transform: none; margin: -4px 0 -6px -4px; }
  .market-brief { justify-content: flex-start; }
  .market-task { flex: 1 1 0; }
}
.nmd-glow { opacity: .75; transition: opacity .3s; }
.market-dispatcher[data-mood=party] .nmd-glow, .market-dispatcher[data-mood=shipping] .nmd-glow { opacity: 1; }
.market-dispatcher .nmd-body, .market-dispatcher .nmd-wave, .market-dispatcher .nmd-lantern { transform-box: view-box; }
.market-dispatcher[data-mood=ready] .nmd-wave { transform-origin: 79px 80px; animation: nmd-wave 1.1s ease-in-out infinite alternate; }
.market-dispatcher[data-mood=shipping] .nmd-lantern { animation: nmd-swing .5s ease-in-out infinite alternate; }
.market-dispatcher[data-mood=revise] .nmd-body { transform-origin: 62px 160px; animation: nmd-shake .45s ease-in-out 2; }
.market-dispatcher[data-mood=cheer] .nmd-body { transform-origin: 62px 164px; animation: nmd-hop .55s ease-out 2; }
.market-dispatcher[data-mood=party] .nmd-body { transform-origin: 62px 164px; animation: nmd-hop .6s ease-out 4; }
.market-dispatcher[data-mood=party] .nmd-glow { animation: nmd-glow 1.2s ease-in-out infinite alternate; }
@keyframes nmd-wave { from { transform: rotate(-9deg); } to { transform: rotate(12deg); } }
@keyframes nmd-swing { from { transform: rotate(-8deg); } to { transform: rotate(8deg); } }
@keyframes nmd-shake { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
@keyframes nmd-hop { 40% { transform: translateY(-9px); } }
@keyframes nmd-glow { from { opacity: .7; } to { opacity: 1; } }

.market-carts { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.market-cart {
  position: absolute;
  left: 50%;
  top: 76%;
  opacity: 0;
  width: clamp(43px, 8cqw, 125px);
  filter: drop-shadow(0 4px 4px #081821c2);
  animation: market-send 1.08s cubic-bezier(.22,.4,.54,1) var(--cart-delay) both;
}
@keyframes market-send {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.12); }
  18% { opacity: 1; }
  73% { opacity: 1; }
  to { left: var(--cart-end); top: 48%; opacity: 0; transform: translate(-50%, -50%) scale(.7); }
}
[data-motion=false] :is(.market-cart, .market-stall-art > svg, .market-crate, .nmd-body, .nmd-wave, .nmd-lantern, .nmd-glow) { animation: none; }
@media (prefers-reduced-motion: reduce) {
  :is(.market-cart, .market-scene[data-complete=true] .market-stall-art > svg, .market-crate, .nmd-body, .nmd-wave, .nmd-lantern, .nmd-glow) { animation: none; }
}

.market-tables {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
  padding: 8px;
  background: var(--market-paper);
}
.market-table {
  min-width: 0;
  border: 1px solid var(--market-frame);
  border-radius: 8px;
  padding: 8px 7px;
  color: var(--market-ink);
  text-align: center;
}
.market-table[data-reported=true] { box-shadow: inset 0 2px var(--market-ok); }
.market-table h3 {
  margin: 0;
  font: 700 clamp(16px, 1.64cqw, 24px)/1.18 var(--font-sans);
  color: var(--market-ink);
}
.market-table h3 span, .market-table-note {
  display: block;
  margin: 3px 0 0;
  color: var(--market-muted);
  font-size: clamp(14px, 1.15cqw, 18px);
  line-height: 1.18;
  font-weight: 600;
}
/* The student count shares the heading line; the crate row below shows it too. */
.market-table h3 span { display: inline-block; margin: 0 0 0 .3em; white-space: nowrap; }
.market-table[data-found=true] { outline: 3px solid #e7a93a; outline-offset: -1px; }
.market-crates {
  --crate: clamp(14px, 1.25cqw, 20px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 2px 7px;
  margin-top: 5px;
}
.market-cluster { display: inline-flex; align-items: flex-end; gap: 3px; }
.market-letter {
  display: grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 5px;
  border: 2px solid var(--letter, #c0503d);
  color: var(--market-ink);
  font: 800 clamp(12px, 1cqw, 16px)/1 var(--font-sans);
}
.market-letter[data-stall=B] { --letter: #2f8f84; }
.market-letter[data-stall=C] { --letter: #d9a43c; }
.market-route { margin: 4px 0 0; font-size: clamp(17px, 1.64cqw, 24px); line-height: 1.12; font-weight: 700; }
.market-tally { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 5px; font-size: clamp(15px, 1.3cqw, 21px); font-weight: 700; }
.market-tally .input, .market-locked {
  display: inline-grid;
  place-content: center;
  width: 48px;
  height: 40px;
  padding: 0 4px;
  border: 1px solid var(--market-frame);
  border-radius: 8px;
  background: var(--market-paper);
  color: var(--market-ink);
  text-align: center;
  font: 700 clamp(19px, 1.75cqw, 26px)/1 var(--font-sans);
}
.market-tally .input:focus-visible { outline: 2px solid var(--market-focus); outline-offset: 2px; }
.market-tally .input[aria-invalid=true] { border: 2px solid var(--market-adjust); }
.market-locked { border-color: transparent; }
.market-alert { margin: 0; padding: 8px 14px; background: var(--market-paper); color: var(--market-adjust); font-size: 15px; font-weight: 700; }
.market-shell .market-dock {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-end;
  padding: 10px 14px;
  gap: 8px;
}
.market-dock .btn { min-height: 44px; padding: 9px 15px; }
.market-dock [data-market-primary] { min-width: 165px; }
.market-size { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-right: auto; font-weight: 650; font-size: 15px; }
.market-size small { color: var(--ink-soft); font-size: 13px; }
.market-size .input { width: 55px; min-height: 40px; padding: 6px 1px; text-align: center; font-size: 16px; }
.market-progress { margin: 0 auto 0 0; font-size: 15px; line-height: 1.25; font-weight: 700; }
.market-dialog {
  width: min(550px, calc(100% - 24px));
  max-height: 88dvh;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.market-dialog::backdrop { background: #102129b8; }
.market-dialog h2 { margin: 0 0 10px; font-size: 27px; }
.market-dialog p, .market-dialog ol { color: var(--ink); margin: 0; font-size: 16px; line-height: 1.5; }
.market-dialog ol { padding-left: 23px; }
.market-dialog li + li { margin-top: 9px; }
.market-dialog > div { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

.market-shell.market-present { position: fixed; inset: 0; z-index: 1000; height: 100dvh; border: 0; border-radius: 0; }
.market-present .market-workspace { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.market-present .market-board, .market-present .market-scene { flex: 1 0 auto; }
.market-present .market-dock { flex-shrink: 0; }
.market-present .market-scene { min-height: 190px; }

@media (max-width: 760px) {
  .market-brief { padding: 9px 12px; }
  .market-tables { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .market-table { padding: 6px 4px; }
}
@media (max-width: 490px) {
  .market-brief { flex-wrap: wrap; gap: 7px; }
  .market-bridge { max-width: 100%; flex-basis: 100%; padding: 2px 0 2px 8px; }
  .market-scene, .market-present .market-scene { min-height: 172px; }
  .market-stalls { inset-inline: 5px; gap: 4px; }
  .market-stall-sign { width: 100%; padding-inline: 2px; }
  .market-stall-art { inset-inline: -5px; bottom: 22%; }
  .market-dock .btn { min-width: auto; }
  .market-dock [data-market-primary] { min-width: 135px; }
}
@media (max-width: 360px) {
  .market-shell .puzzle-toolbar { column-gap: 4px; }
  .market-shell .puzzle-toolbar .sprout-themes button { padding-inline: 6px; }
  .market-tables { padding: 5px; gap: 4px; }
  .market-tally { gap: 3px; }
  .market-tally .input, .market-locked { width: 40px; }
}
