/* /<game>/trading (pages/trading.js, markup pages/trading-markup.js), prefix tp-. spec/nav/UX.md: the page title, one row
   of filter chips (the item picker under the chip that opened it), both on the brand band, the feed: one trade per row
   resting on the band's foot (the rows are
   app/components/adcard.css). Sizes follow the page's own width (a container), so it looks right in any frame. Colours
   only from tokens.css. */

.tp { container: tp / inline-size; }
/* the picker's rows and the chips' parts take quick taps as taps, never a zoom */
.tp :is(.tp-opt, .tp-x, .tp-chip__btn, .tp-new, .tp-more) { touch-action: manipulation; }

/* ================================================================ the band
   The title and the filters stand on a band of the brand green that runs edge to edge under the top bar, tiled with the
   values.io flame in a lighter green (the way Duolingo's promotional pictures tile their own marks on their green);
   it ends in the tree-frog lip, and the list of trades rests 48px into it like a card. The band is the wrapper's
   ::before (the green, the lip) and ::after (the flames, a mask over a lighter green), as wide as the window
   (100vw: the page clips the scrollbar's few pixels, .f-page below), drawn under the page's own content (z-index -1 in
   the page's one layer: never its own layer, which put the item picker's list, opening down over the feed, under the
   feed). The flames drift one tile (480px) a minute: the page's one moving part, still with reduced motion. */
.tp-band { --tp-band-top: 28px; position: relative; padding-bottom: 16px; }
@media (max-width: 899px) { .tp-band { --tp-band-top: 20px; } }   /* the phone frame's page starts 20px under the bar */
.tp-band > .tp-tools { margin-bottom: 0; }
.f-page:has(.tp-band) { overflow-x: clip; }
.tp-band::before, .tp-band::after { content: ""; position: absolute; z-index: -1; left: 50%; top: calc(-1 * var(--tp-band-top)); pointer-events: none; }
.tp-band::before {
  bottom: -48px; width: calc(100vw / var(--zoom, 1)); transform: translateX(-50%);
  background: var(--color-band); border-bottom: 4px solid var(--color-band-lip);
}
/* the flames: one 480 x 128 tile of four in two staggered rows, each turned a little, 240px apart, the first one 44px
   left of the page column so the title and Post sit in the gaps. The layer is a tile wider than the window on its
   left, so it can slide one tile to the right and start again with no seam */
.tp-band::after {
  --tp-flames: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='480' height='128' viewBox='0 0 480 128'%3E%3Cdefs%3E%3Cpath id='f' transform='scale(2.9) translate(-4.05 -5.5)' d='M4.089 11C-0.311 11 -0.902 5.19 1.089 2C1.089 2 1.089 6 3.749 6C2.377 2.5 5.589 0 5.589 0C5.589 0 5.45 2.379 6.839 4C9.751 7.397 7.089 11 4.089 11Z'/%3E%3C/defs%3E%3Cuse href='%23f' transform='translate(60 40) rotate(-12)'/%3E%3Cuse href='%23f' transform='translate(180 104) rotate(9)'/%3E%3Cuse href='%23f' transform='translate(300 40) rotate(6)'/%3E%3Cuse href='%23f' transform='translate(420 104) rotate(-8)'/%3E%3C/svg%3E");
  --tp-flames-at: calc(max(var(--f-gutter, 24px), 50% - 560px) - 104px) calc(var(--tp-band-top) - 28px);
  bottom: -44px; width: calc(100vw / var(--zoom, 1) + 480px); transform: translateX(calc(-50% - 240px));
  background: var(--color-band-flame);
  -webkit-mask: var(--tp-flames) var(--tp-flames-at) / 480px 128px repeat; mask: var(--tp-flames) var(--tp-flames-at) / 480px 128px repeat;
}
@media (prefers-reduced-motion: no-preference) {
  .tp-band::after { animation: tp-flames 60s linear infinite; }
}
@keyframes tp-flames { to { translate: 480px 0; } }
/* its colours are tokens (tokens.css, dark.css: one band per theme); the title on it reads 4.5:1 and more on each; the
   chips and Post keep their own faces */
.tp-band .tp-title { color: var(--color-band-title); }
/* ================================================================ title */
.tp-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; margin-bottom: 16px; }
.tp-title { margin: 0; color: var(--color-eel); font: 700 28px/34px var(--font); }   /* the app's page title (pop.css) */
/* Post a trade: a chip like the filters under it, its + green like Can do's tick */
.tp-post { flex: none; gap: 6px; padding: 0 14px 0 10px; }
.tp-post > svg { flex: none; color: var(--color-owl); }

/* ================================================================ the toolbar: filter chips */
/* one row of chips (they flow straight into it: display: contents) that wraps on a wide page; under 760px they keep
   one row that scrolls sideways when picked items make it too long (the Values page's tier strip, its fades), the bell
   at its end. On a phone Saved, Yours and the bell are their icons alone (their words are still read out) */
.tp-tools { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.tp-chips { display: contents; }
.tp-chip { gap: 6px; padding: 0 12px; }
.tp-chip > svg { flex-shrink: 0; }
.tp-chip--can_do > svg { color: var(--color-owl); }
.tp-chip--saved > svg { color: var(--color-macaw); }
.tp-chip--mine > svg { color: var(--color-beetle); }
.tp-chip.is-on > svg { color: inherit; }
/* the chip whose picker is open looks pressed in, like a picked chip */
.tp-chip[aria-expanded="true"], .tp-chip:has(> [aria-expanded="true"]) { color: var(--color-whale); }
.tp-chip[aria-expanded="true"]::before, .tp-chip:has(> [aria-expanded="true"])::before { background: var(--color-iguana); border-color: var(--color-blue-jay); box-shadow: 0 2px 0 var(--color-blue-jay); }
/* a picked filter: the chip itself reopens the picker, its × removes it (all of its items). Its picture is 6px in from
   the chip's edge, as a tile's is; a name in words alone starts where an unpicked chip's word does */
.tp-chip.tp-chip--set { padding: 0 4px 0 0; cursor: default; }
.tp-chip__btn { display: inline-flex; align-items: center; gap: 8px; height: 100%; padding: 0 4px 0 6px; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
.tp-chip__btn:not(:has(> .tp-pics)) { padding-left: 12px; }
/* several items: their pictures overlap (three at most), each ringed in the chip's colour; "+2" after the first name */
.tp-pics > .u-pic + .u-pic { margin-left: -10px; }
.tp-pics > .u-pic[data-tier] + .u-pic[data-tier] { outline-color: var(--color-iguana); }
.tp-chip__more { margin-left: 2px; }
.tp-x { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--color-hare); cursor: pointer; }
@media (hover: hover) { .tp-x:hover { color: var(--color-whale); } }
/* the keyboard's ring goes round the whole chip (its painted face, ::before), never a box inside it; the × keeps a
   ring of its own, inside the chip */
.tp-chip:focus-visible, .tp-chip__btn:focus-visible { outline: none; }
.tp-chip:is(:focus-visible, :has(> .tp-chip__btn:focus-visible))::before { outline: 2px solid var(--color-macaw); outline-offset: 2px; }
.tp-x:focus-visible { outline: 2px solid var(--color-macaw); outline-offset: -2px; }
/* the bell (an alert for exactly these filters, app/components/tradealert.css .ta-chip): the row's one action, at its
   end */
.tp-bell { display: contents; }
.tp-bell > .ta-chip { flex: none; margin-left: auto; }
@container tp (max-width: 759.98px) {
  .tp-tools { flex-wrap: nowrap; }
  /* 4px room around the chips inside the strip: their lips, a press and the focus ring aren't cut off */
  .tp-chips { display: flex; flex: 1 1 auto; align-items: center; gap: inherit; min-width: 0; margin: -4px -4px -6px; padding: 4px 4px 6px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
  .tp-chips::-webkit-scrollbar { display: none; }
  .tp-chips > * { flex: none; }
  .tp-chips.has-right { -webkit-mask-image: linear-gradient(to left, transparent, #000 32px); mask-image: linear-gradient(to left, transparent, #000 32px); }
  .tp-chips.has-left { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px); mask-image: linear-gradient(to right, transparent, #000 32px); }
  .tp-chips.has-left.has-right {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
  }
}

/* the item picker: a field with Done at its right, and the list, under the chip that opened it */
.tp-picker { position: absolute; z-index: 40; top: calc(100% + 8px); left: var(--left, 0px); width: min(420px, 100%); padding: 8px; border: 2px solid var(--color-swan); border-radius: 16px; background: var(--color-snow); box-shadow: 0 2px 0 var(--color-swan); }
.tp-picker__top { display: flex; align-items: center; gap: 8px; }
.tp-picker__top > .tp-field { flex: 1 1 auto; min-width: 0; }
.tp-done { --h: 48px; --pad: 0 14px; }
.tp-picker[hidden] { display: none; }
/* it comes out of its chip like a popover (ui.css .u-pop): a fade and a 4px glide, and goes the same way (trading.js) */
.tp-picker:not([hidden]) { animation: tp-pick-in var(--m-fast) var(--m-ease-out) both; }
.tp-picker.is-leaving { animation: tp-pick-out var(--m-fast) var(--m-ease-in) both; pointer-events: none; }
@keyframes tp-pick-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes tp-pick-out { to { opacity: 0; transform: translateY(-4px); } }
.tp-field { height: 48px; }
.tp-field > input { font-size: 17px; }
.tp-suggest { max-height: min(400px, calc(56vh / var(--zoom, 1))); overflow-y: auto; margin-top: 6px; }
.tp-sugg__head { margin: 8px 8px 4px; color: var(--color-label); font: 700 13px/16px var(--font); letter-spacing: .06em; text-transform: uppercase; }
.tp-sugg__none { margin: 0; padding: 12px 8px; color: var(--color-wolf); font: 400 17px/24px var(--font); }
/* the side has its ITEMS_MAX: said once on top, the items not picked greyed (a tap on one does nothing) */
.tp-sugg__full { margin: 8px 8px 4px; color: var(--color-wolf); font: 700 15px/20px var(--font); }
.tp-opt[aria-disabled="true"] { opacity: .45; cursor: default; }
@media (hover: hover) { .tp-opt[aria-disabled="true"]:hover { background: none; } }
.tp-sugg__skel { display: block; height: 52px; margin: 6px 0; border-radius: 12px; }
.tp-opt { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; column-gap: 12px; width: 100%; min-height: 52px; padding: 6px 10px 6px 6px; border: 0; border-radius: 12px; background: none; color: var(--color-eel); font: 400 17px/22px var(--font); text-align: left; cursor: pointer; }
@media (hover: hover) { .tp-opt:hover { background: var(--color-polar); } }
.tp-opt.is-active { background: var(--color-iguana); }
.tp-opt__name { min-width: 0; overflow-wrap: anywhere; }   /* the tier is the picture's colour: no second line */
.tp-opt.is-picked b, .tp-opt.is-active b { color: var(--color-whale); }
.tp-opt__val { display: flex; color: var(--color-eel); font-weight: 700; white-space: nowrap; }
.tp-opt.is-picked .tp-opt__val { color: var(--color-macaw); }

/* ================================================================ the feed */
.tp-results { position: relative; }   /* scrolled to under the top bar: the frame's scroll-padding */
/* "N new trades": a small round pill that floats, so nothing moves until it is tapped. At the top of the page it sits
   centred on the list's top line, in the gap under the filters: half of it in the gap, half in the first row's top
   padding, over no words or tiles (16px of gap, 2px line, 20px padding round a 32px pill). Scrolled, it stays under
   the top bar (the wrapper sticks 15px lower, as the pill sits 15px above it). Its soft shadow says it floats. */
.tp-newwrap { position: sticky; top: calc(var(--f-top-h, 64px) + 12px + 15px); z-index: 30; display: flex; justify-content: center; height: 0; pointer-events: none; }
.tp-new { pointer-events: auto; margin-top: -15px; --h: 32px; --pad: 0 14px 0 10px; --r: 16px; --lip: 3px; --fs: 13px; --ls: .6px; gap: 6px; }
.tp-new::before { box-shadow: 0 var(--lip) 0 var(--edge), 0 6px 16px rgba(var(--color-black-rgb), .16); }
.tp-new::after { content: ""; position: absolute; inset: -6px -4px; }   /* a 44px target round the 32px pill */
.tp-new > svg { width: 16px; height: 16px; }
.tp-new[hidden] { display: none; }
/* new trades opening up on top of the list (trading.js arrive): drawn in full while they come (a row's off-screen
   estimate would open the box to the wrong height); the line under the last one is the line the rows have between
   them, so nothing shifts when they become the list's own rows again */
.tp-arrive { overflow: clip; }
.tp-arrive > .ac-row { content-visibility: visible; }
.tp-arrive > .ac-row:last-child { border-bottom: 2px solid var(--color-swan); }

/* a feed of 20 rows and more: the ones off screen skip layout and paint (a filter's redraw took 50-64 ms frames in
   WebKit), each keeping the height it last had so the scrollbar stays put
   (the sizes are of the rows' insides, their padding and line come on top: a row on one line is 210-229px in all, on
   two lines 274-293, a phone's card 467-518 with its 16px padding and 2px lines, most 482). The first screen's rows
   are always drawn: a row drawn a frame late at its real height pushed the ones under it down as the page showed. */
.tp-list .ac-row:not(.tp-skel) { content-visibility: auto; contain-intrinsic-block-size: auto 176px; }
@container tp (max-width: 1069.98px) { .tp-list .ac-row:not(.tp-skel) { contain-intrinsic-block-size: auto 233px; } }
@media (max-width: 699px) { .tp-list .ac-row:not(.tp-skel) { contain-intrinsic-block-size: auto 444px; } }
.tp-list .ac-row:nth-child(-n + 6) { content-visibility: visible; }

/* placeholder rows: the row's own grid (adcard.css), grey shapes where the who, the tiles and the button come. Not in
   the first 300 ms (--tp-late, trading.js skeleton()): a quick answer never flashes them. Until then the list's box
   takes no room at all: no empty box with its line (it showed alone before the trades came), and no page taller than
   the window, so a short answer ("No trades yet.") comes with nothing else moving (the scrollbar came and went) */
.tp-skel { cursor: default; }
.tp-list .ac-rows:has(> .tp-skel):not([data-now]) { animation: tp-late 1ms var(--tp-late, 300ms) backwards; }
@keyframes tp-late { from { visibility: hidden; max-height: 0; overflow: hidden; border-width: 0; } }
/* while the placeholders show, the list holds a window's height: the footer never shows under them and then jumps down
   when the trades (taller rows) come. Not while they are hidden (above), unless the list holds a reload's old height
   (an inline min-height: index.html, trading.js hold), so the place it kept lands */
.tp-list:has(.tp-skel) { min-height: calc(100vh / var(--zoom, 1)); min-height: calc(100svh / var(--zoom, 1)); }
.tp-list:has(.tp-skel):not([style*="min-height"]):not(:has(> .ac-rows[data-now])) { animation: tp-late-room 1ms var(--tp-late, 300ms) backwards; }
@keyframes tp-late-room { from { min-height: 0; } }
.tp-skel .ac-who > .m-skel--text + .m-skel--text { margin-top: 8px; }
.tp-skel__tile { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tp-skel__tile > .m-skel:first-child { width: 100%; height: auto; aspect-ratio: 1; border-radius: 16px; }   /* a square like the tile (.m-skel's own 16px height would win over the ratio) */
.tp-skel__tile > .m-skel--text { height: 12px; margin: 0; }
.tp-skel__btn { display: block; height: 48px; border-radius: 12px; }
.tp-note { margin-bottom: 16px; }
.tp-after { display: flex; justify-content: center; margin-top: 24px; }
.tp-after:empty { display: none; }
.tp-more { min-width: 240px; }
/* nothing here: one line and one button (it rests on the band's foot like the list: its own face) */
.tp-none { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 16px; padding: 16px 16px 16px 20px; border: 2px solid var(--color-swan); border-radius: 16px; background: var(--color-snow); }   /* a card on the band's foot */
.tp-none__text { flex: 1 1 240px; margin: 0; color: var(--color-eel); font: 700 17px/24px var(--font); text-wrap: pretty; }   /* no lone word on its last line */

/* ================================================================ phones: the feed snaps like a reel
   On a phone (one card a trade, adcard.css) a swipe moves exactly one trade: the page snaps the next card to the top,
   just under the bar, the way Reels and Shorts move one at a time (snap-stop: a hard flick still stops at the next
   one). The band's top and the footer's end are snap points too, so the filters and the footer are always reachable.
   The cards sit 12px apart, so they snap 12px under the bar (not the frame's 16px): the card above hides wholly under
   the bar, never a sliver of its edge. Never while typing (html.kb, app/viewport.js: the keyboard moves the page),
   while the item picker is open (its list scrolls on its own), on a phone held sideways (under 560px tall a card can be
   taller than the screen), nor on tablets and computers (their rows are a list to read down). */
@media (max-width: 699px) and (min-height: 560px) {
  html:has(.tp-list) { scroll-snap-type: y mandatory; scroll-padding-top: calc(var(--f-top-h) + 12px); }
  html.kb:has(.tp-list), html:has(.tp-picker:not([hidden])) { scroll-snap-type: none; }
  .tp-band { scroll-snap-align: start; scroll-margin-top: var(--tp-band-top); }
  .tp-list .ac-row:not(.tp-skel) { scroll-snap-align: start; scroll-snap-stop: always; }
  .f-page:has(.tp-list) .f-foot { scroll-snap-align: end; }
}

/* ================================================================ narrower pages */
@container tp (max-width: 559px) {
  .tp-picker { left: 0; width: 100%; }
}
@container tp (max-width: 519px) {
  .tp-head { margin-bottom: 12px; }
  .tp-tools { gap: 8px; }   /* the 16px under it kept: the new-trades pill sits in it, on the list's line */
  .tp-none { padding: 14px; }
  .tp-none > .u-btn { width: 100%; }
}
/* a phone: the five chips fit one row, none cut at its edge: Saved is its bookmark alone, Yours its person, the bell
   its bell; under 376px of row (390px and smaller phones: they were 13 to 43px short) I want / I have drop their
   arrows too (a tap opens the picker all the same) */
@container tp (max-width: 399px) {
  .tp-tools { gap: 6px; }
  .tp-chip:not(.tp-chip--set) { gap: 5px; padding: 0 10px; }
  .tp-chip--saved, .tp-chip--mine, .tp-bell > .ta-chip { padding: 0 10px; }
  :is(.tp-chip--saved > span, .tp-chip--mine > span, .tp-bell > .ta-chip > .ta-btn__label) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
@container tp (max-width: 375px) {
  .tp-chip[data-pick] > svg { display: none; }
}
/* a phone's row: two pictures of a chip's items at most ("+2" says the rest) */
@container tp (max-width: 399px) {
  .tp-pics > .u-pic:nth-child(n + 3) { display: none; }
}
/* a 320px phone: Can do is its check alone too */
@container tp (max-width: 303px) {
  .tp-chip--can_do { padding: 0 10px; }
  .tp-chip--can_do > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
