/* Market picker, bar and header switcher (v1.3, WP4; design §2.2–§2.5). Loaded only while the market UI is active,
   and always on /markets and /markets/switch. Every accent colour is derived from --accent-rgb so a custom theme
   (ADR-020) recolours the map and the cards; forced-colors mode gets explicit system colours at the end. */

/* ── Header switcher ─────────────────────────────────────────────────────────────────────────────────────────── */
/* position:absolute, never fixed: .site-header.glass has a backdrop-filter, which makes a fixed child position
   against the header instead of the viewport (design §2.5). */
.market-switch{position:relative}
.market-switch>summary{list-style:none}
.market-switch>summary::-webkit-details-marker{display:none}
.market-switch__pill{display:inline-flex;align-items:center;gap:6px;min-height:36px;padding:0 10px;border:1px solid var(--border-control,#6B7A99);border-radius:var(--r-pill);background:var(--surface-1);color:var(--text-2);font-size:var(--fs-sm);font-weight:700;cursor:pointer;user-select:none}
.market-switch__pill:hover,.market-switch[open]>.market-switch__pill{background:var(--surface-2);color:var(--text);border-color:var(--border-accent)}
.market-switch__pill .icon:first-child{color:var(--accent)}
.market-switch[open]>.market-switch__pill .icon:last-child{transform:rotate(180deg)}
.market-switch__panel{position:absolute;right:0;top:calc(100% + 8px);width:min(360px,calc(100vw - 32px));max-height:70dvh;overflow:auto;padding:var(--s-2);z-index:65;box-shadow:var(--shadow-3)}
.market-switch__form{display:flex;flex-direction:column;gap:2px;margin:0}
.market-opt{display:flex;align-items:flex-start;gap:var(--s-3);width:100%;min-height:44px;padding:10px 12px;border:0;border-radius:var(--r-md);background:transparent;color:var(--text);text-align:left;font:inherit;cursor:pointer}
.market-opt:hover{background:var(--surface-hover)}
.market-opt.is-current{background:rgb(var(--accent-rgb) / .10)}
.market-opt__code{flex:none;min-width:40px;padding:2px 6px;border-radius:var(--r-sm);background:var(--surface-3);color:var(--accent-text);font-size:var(--fs-xs);font-weight:800;text-align:center}
.market-opt__body{display:flex;flex-direction:column;gap:2px;flex:1;min-width:0}
.market-opt__name{font-weight:600;font-size:var(--fs-sm)}
.market-opt__meta{color:var(--text-muted);font-size:var(--fs-xs)}
.market-opt__check{flex:none;color:var(--accent);margin-top:2px}
.market-switch__warn{display:flex;gap:6px;align-items:flex-start;margin:var(--s-2) var(--s-2) 0;padding:8px 10px;border-radius:var(--r-md);background:var(--warning-bg);color:var(--text-2);font-size:var(--fs-xs)}
.market-switch__map{display:flex;align-items:center;gap:6px;margin-top:var(--s-2);padding:10px 12px;border-top:1px solid var(--divider);color:var(--text-link);font-size:var(--fs-sm);font-weight:600}
.market-navlink{display:inline-flex!important;align-items:center;gap:6px;border:0!important;padding:8px 0!important}
.market-navlink .icon{color:var(--accent)}
@media (max-width:1023px){.site-tools .market-switch__code{max-width:4ch;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}}
/* Phones: the pill sits left of the cart and menu buttons, so a panel right-aligned to the pill and up to 360 px wide
   starts off-screen (measured at 390 px: x = -72). Anchor it to the sticky header instead (still absolute, never
   fixed), 16 px from the right edge, just under the tools row (8 px padding + 36–44 px row). */
@media (max-width:599px){
  .market-switch{position:static}
  .market-switch__panel{right:16px;top:52px}
}

/* ── Market bar (in flow, never sticky) ──────────────────────────────────────────────────────────────────────── */
.market-bar{border-bottom:1px solid var(--border);background:linear-gradient(90deg,rgb(var(--accent-rgb) / .10),transparent 70%),var(--surface-1);font-size:var(--fs-sm)}
.market-bar__inner{display:flex;align-items:center;flex-wrap:wrap;gap:var(--s-2) var(--s-3);padding-block:10px}
.market-bar__icon{display:inline-flex;color:var(--accent)}
.market-bar__text{flex:1;min-width:220px;margin:0;color:var(--text-2)}
.market-bar__text strong{color:var(--text)}
.market-bar__actions{display:flex;align-items:center;flex-wrap:wrap;gap:var(--s-2);margin:0}
.market-bar__close{display:inline-flex;align-items:center;justify-content:center;width:44px;height:44px;border:0;border-radius:var(--r-md);background:transparent;color:var(--text-2);cursor:pointer}
.market-bar__close:hover{background:var(--surface-2);color:var(--text)}
.market-bar__compact{display:none}
.market-bar--link{background:linear-gradient(90deg,var(--warning-bg),transparent 70%),var(--surface-1)}
.market-bar--gone{background:var(--info-bg)}
.market-dialog-open .market-bar{display:none}
@media (max-width:599px){
  /* The one-time "market no longer offered" notice (.market-bar--gone) is text only: it must stay readable on phones. */
  /* A link bar keeps its "Choose a market" link: for a visitor who has not answered yet it is the way to another region. */
  .market-bar__more,.market-bar__show,.market-bar:not(.market-bar--link) .market-bar__choose,.market-bar:not(.market-bar--link):not(.market-bar--gone) .market-bar__text{display:none}
  .market-bar__compact{display:inline-flex;flex:1;align-items:center;min-height:44px;color:var(--text);font-weight:600}
}

/* ── Region step (ADR-040, ADR-067) and the inline region chooser (market-controls.js marketChooser) ────────── */
/* A gated response carries the step (`hidden`) AND the page. The inline <style id="arrival-step"> in <head> reveals the
   step and hides the page ONLY under ARRIVAL_STEP_MEDIA (a computer); nothing in this file may show the step, so a
   phone, a tablet, print or a failed stylesheet always gets the page with its bar. The step reuses .mpk without the map
   and is sized so a 1366×768 laptop sees every region card and the worldwide option without scrolling (§2.7). */
.market-gate{padding-block:var(--s-5) var(--s-6)}
.market-gate__inner{max-width:var(--container-narrow)}
.market-gate .mpk{gap:var(--s-3);padding:0}
.market-gate .mpk__title{margin:var(--s-1) 0 var(--s-1);font-size:var(--fs-2xl)}
.market-gate .market-card{padding:var(--s-3) var(--s-4)}
/* ADR-147: the map is back on the step, so it may not eat the screen — at 1366×768 every card stays visible. */
.market-gate .mpk-map__svg{max-height:min(24vh,185px)}
.market-gate .mpk__map{background-position:center}
/* ADR-148: the step is the whole screen. It covers the header, the bar and the footer, so the question is the only
   thing on it — the same media query as the inline reveal rule, so a phone or a failed stylesheet is never trapped
   behind a fixed layer. The inline rule's display:block!important stands; centring is the inner block's margin. */
@media screen and (min-width:1024px) and (hover:hover) and (pointer:fine){
  .market-gate[data-market-gate]{position:fixed;inset:0;z-index:1000;overflow-y:auto;padding-block:var(--s-5);background:var(--bg-0) radial-gradient(120% 90% at 50% -10%,var(--bg-2),var(--bg-0)) fixed}
  .market-gate__inner{margin-inline:auto}
}
.market-gate .market-card__countries summary{min-height:28px}
.market-gate > .container:first-child{padding-top:0}
.mpk__next{margin:0 0 var(--s-2);color:var(--text-2);font-size:var(--fs-sm);font-weight:600}

.market-chooser{margin:var(--s-3) 0}
/* The group (visual 10): an unstyled fieldset carries the flex row; the floated legend is not the "rendered legend",
   so it lays out as an ordinary flex item in that row instead of sitting on the fieldset border. */
.market-chooser__set{display:flex;align-items:center;flex-wrap:wrap;gap:var(--s-2);min-width:0;margin:0;padding:0;border:0}
.market-chooser__legend{float:left;flex:none;margin:0;padding:0;color:var(--text-2);font-size:var(--fs-xs);font-weight:700;text-transform:uppercase;letter-spacing:.04em}
.market-chooser__opt{display:inline-flex;align-items:center;gap:6px;min-height:36px;padding:0 12px;border:1px solid var(--border-control,#6B7A99);border-radius:var(--r-pill);background:var(--surface-1);color:var(--text-2);font:inherit;font-size:var(--fs-sm);font-weight:600;cursor:pointer}
.market-chooser__opt:hover{background:var(--surface-2);color:var(--text);border-color:var(--border-accent)}
.market-chooser__opt small{color:var(--text-muted);font-size:var(--fs-xs);font-weight:700}
.market-chooser__opt.is-current{background:rgb(var(--accent-rgb) / .12);border-color:var(--border-accent);color:var(--text)}
.market-chooser__opt.is-current small{color:var(--accent-text)}
.market-chooser--compact{margin:0 0 var(--s-3)}
.market-chooser--compact .market-chooser__set{gap:6px}
.market-chooser--compact .market-chooser__opt{min-height:32px;padding:0 10px;font-size:var(--fs-xs)}
@media (max-width:599px){.market-chooser__set{gap:6px}.market-chooser__legend{flex:1 0 100%}}

/* ── Scope line (market-controls.js marketScopeLine, rendered by catalogue and commerce views) ───────────────── */
/* One sentence, not three flex items. As a flex container this line collected the globe, the bare text node and the
   "change" link as three items: on a 400px phone the sentence ("…follow your market: All markets — worldwide. ·") was
   wider than the row, so the globe sat alone on line 1, the sentence took line 2 ending in a dangling "·", and
   "change" landed on line 3. Inline text wraps where a sentence should. */
.market-scope{display:block;margin:var(--s-2) 0;color:var(--text-muted);font-size:var(--fs-sm)}
/* base.css makes every svg display:block, which is what pushed the icon out of the sentence. */
.market-scope .icon{display:inline-block;vertical-align:-2px;color:var(--accent)}
.market-switch-form{display:inline;margin:0}

/* ── Dialog (first visit on /, and the picker fetched as a fragment) ─────────────────────────────────────────── */
.market-dialog{width:min(980px,calc(100vw - 32px));max-height:min(92dvh,900px);padding:0;border:1px solid var(--border-strong);border-radius:var(--r-xl);background:var(--surface-solid);color:var(--text);box-shadow:var(--shadow-3);overflow:auto}
.market-dialog::backdrop{background:rgba(3,6,14,.72);backdrop-filter:blur(4px)}
.market-dialog[open]{animation:mpk-in .22s var(--ease)}
.market-dialog__closer{position:sticky;top:0;display:flex;justify-content:flex-end;height:0;margin:0;z-index:3}
.market-dialog__close{display:inline-flex;align-items:center;justify-content:center;width:44px;height:44px;margin:10px 10px 0 0;border:1px solid var(--border);border-radius:var(--r-pill);background:var(--surface-2);color:var(--text);cursor:pointer}
.market-dialog__close:hover{background:var(--surface-hover)}
.market-dialog .mpk{padding:var(--s-6)}
@keyframes mpk-in{from{opacity:0;transform:translateY(8px) scale(.985)}to{opacity:1;transform:none}}

/* ── Picker body ─────────────────────────────────────────────────────────────────────────────────────────────── */
.mpk{display:grid;gap:var(--s-4)}
.mpk__head{max-width:62ch}
.mpk__eyebrow{display:inline-flex;align-items:center;gap:6px;margin:0}
.mpk__title{margin:var(--s-1) 0 var(--s-2);font-size:var(--fs-xl)}
.mpk__title:focus{outline:none;box-shadow:none}
.mpk__intro{margin:0;color:var(--text-2)}
.mpk__map{position:relative;border-radius:var(--r-lg);background:radial-gradient(ellipse at 54% 20%,rgb(var(--accent-rgb) / .10),transparent 60%),var(--surface-sunken);border:1px solid var(--divider);overflow:hidden}
.mpk__cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:var(--s-3);margin:0}
.mpk__foot{display:flex;flex-wrap:wrap;justify-content:space-between;gap:var(--s-2);color:var(--text-muted);font-size:var(--fs-xs)}
.mpk__foot p{margin:0}

.market-card{position:relative;display:flex;flex-direction:column;gap:6px;padding:var(--s-4);border:1px solid var(--border-control,#6B7A99);border-radius:var(--r-lg);background:var(--surface-1);transition:border-color var(--dur) var(--ease),background var(--dur) var(--ease)}
.market-card:hover,.market-card:focus-within,.market-card.is-hot{border-color:var(--border-accent);background:var(--surface-2)}
.market-card.is-current{border-color:rgb(var(--accent-rgb) / .6)}
.market-card--all{grid-column:1/-1;flex-direction:row;flex-wrap:wrap;align-items:center;column-gap:var(--s-4)}
/* The way past the question: dashed, quieter than a region, still a real button. */
.market-card--skip{border-style:dashed;background:transparent}
.market-card--skip:hover,.market-card--skip:focus-within,.market-card--skip.is-hot{border-style:solid}
.market-card--all .market-card__note{flex-basis:100%}
.market-card[aria-busy="true"]{opacity:.65}
.market-card__pick{display:flex;align-items:center;gap:var(--s-2);min-height:44px;padding:0;border:0;background:transparent;color:var(--text);font:inherit;font-size:var(--fs-md);font-weight:700;text-align:left;cursor:pointer}
/* The stretched ::after makes the whole card the button; the focus ring sits on it so it survives forced colours. */
.market-card__pick::after{content:"";position:absolute;inset:0;border-radius:inherit;border-radius:var(--r-lg)}
.market-card__pick:focus{outline:none;box-shadow:none}
.market-card__pick:focus-visible::after{outline:2px solid var(--accent);outline-offset:2px}
.market-card__code{display:inline-flex;align-items:center;justify-content:center;min-width:40px;height:28px;padding:0 8px;border-radius:var(--r-sm);background:rgb(var(--accent-rgb) / .14);color:var(--accent-text);font-size:var(--fs-sm);font-weight:800}
.market-card__badge{align-self:flex-start;padding:2px 8px;border-radius:var(--r-pill);background:rgb(var(--accent-rgb) / .16);color:var(--accent-text);font-size:var(--fs-xs);font-weight:700}
.market-card--all .market-card__badge{align-self:center}
.market-card__meta{margin:0;color:var(--text);font-size:var(--fs-sm)}
.market-card__note{margin:0;color:var(--text-muted);font-size:var(--fs-xs)}
/* Above the stretched button so the countries list opens instead of submitting the card. */
.market-card__countries{position:relative;z-index:1;font-size:var(--fs-xs);color:var(--text-muted)}
.market-card__countries summary{display:inline-flex;min-height:32px;align-items:center;cursor:pointer;color:var(--text-link)}
.market-card__countries p{margin:4px 0 0}

/* ── Map ─────────────────────────────────────────────────────────────────────────────────────────────────────── */
.mpk-map__svg{display:block;width:100%;height:auto;max-height:260px}
.mpk-map__pat-land{color:var(--text-muted)}
.mpk-map__pat-market{color:var(--accent-text)}
.mpk-map__land{opacity:.28;transition:opacity var(--dur) var(--ease)}
/* While one region is lit, ordinary land steps back so the answer is obvious at a glance (ADR-147). Written as a
   filter, not as opacity: the market regions keep the contrast floor brand.test measures from the base rules, and a
   market region is never dimmed — every offered region stays ≥ 3:1 against the map in every state. */
.mpk__map:has(.mpk-map__market:hover) .mpk-map__land{filter:opacity(.55)}
.mpk-map__area{opacity:.7;transition:opacity var(--dur) var(--ease),filter var(--dur) var(--ease)}
.mpk-map__market{cursor:pointer}
.mpk-map__hit{fill:transparent}
.mpk-map__arc{fill:none;stroke:rgb(var(--accent-rgb) / .8);stroke-width:1.6;stroke-dasharray:4 5;opacity:0;transition:opacity var(--dur) var(--ease)}
.mpk-map__pill rect{fill:var(--surface-solid);stroke:rgb(var(--accent-rgb) / .35);stroke-width:1}
.mpk-map__pill text{fill:var(--text);font:700 11px var(--font)}
.mpk-map__market.is-current .mpk-map__pill rect{stroke:rgb(var(--accent-rgb) / .8)}
/* :hover is the no-JavaScript half of the glow — the SVG regions are real hit targets. .is-hot is the same state
   driven from the cards (and from a hovered region back onto its card) by public/js/markets.js. */
.mpk-map__market.is-hot .mpk-map__area,.mpk-map__market:hover .mpk-map__area{opacity:1;filter:drop-shadow(0 0 14px rgb(var(--accent-rgb) / .9)) drop-shadow(0 0 4px rgb(var(--accent-rgb) / .8)) brightness(1.4)}
.mpk-map__market.is-hot .mpk-map__arc,.mpk-map__market:hover .mpk-map__arc{opacity:1;animation:mpk-flow 1.2s linear infinite}
.mpk-map__market.is-hot .mpk-map__pill rect,.mpk-map__market:hover .mpk-map__pill rect{stroke:var(--accent);stroke-width:1.5}
.mpk-map__market.is-hot .mpk-map__pill text,.mpk-map__market:hover .mpk-map__pill text{fill:var(--accent-text)}
.mpk-map__hubdot{fill:var(--accent)}
.mpk-map__pulse{fill:none;stroke:var(--accent);stroke-width:1.5;transform-origin:541px 57px;transform-box:view-box;animation:mpk-pulse 1.8s var(--ease) 3}
.mpk-map__hublabel{fill:var(--text-2);font:600 11px var(--font)}
@keyframes mpk-flow{to{stroke-dashoffset:-18}}
@keyframes mpk-pulse{from{transform:scale(1);opacity:.9}to{transform:scale(3.2);opacity:0}}

/* ── /markets and /markets/switch ────────────────────────────────────────────────────────────────────────────── */
.markets-page .container--narrow,.markets-switch .container--narrow{max-width:1040px}
.markets-page__title{margin:0 0 var(--s-4);font-size:var(--fs-2xl)}
.markets-page__picker{margin-bottom:var(--s-5)}
.markets-page__picker .mpk__title{font-size:var(--fs-lg)}
.markets-table th[scope="row"]{text-align:left;font-weight:600}
.market-code{display:inline-block;min-width:36px;padding:1px 6px;border-radius:var(--r-sm);background:rgb(var(--accent-rgb) / .14);color:var(--accent-text);font-size:var(--fs-xs);font-weight:800;text-align:center}
.markets-switch__table{margin-block:var(--s-4)}
.markets-switch__table tr.is-unavailable td:last-child{color:var(--warning)}
.markets-switch__actions{display:flex;flex-wrap:wrap;gap:var(--s-3);align-items:center;margin-top:var(--s-4)}

/* ── Small screens: bottom sheet, compact map. The worldwide card stays LAST at every width: DOM order is visual
   order (visual 5, WCAG 2.4.3), so nothing here reorders the cards. ─────────────────────────────────────────── */
@media (max-width:639px){
  .market-dialog{inset:auto 0 0 0;width:100%;max-width:100%;max-height:92dvh;margin:0;border-radius:var(--r-xl) var(--r-xl) 0 0;border-bottom:0}
  .market-dialog .mpk{padding:var(--s-5) var(--s-4)}
  .mpk-map__svg{max-height:130px}
  .mpk-map__pill,.mpk-map__hublabel{display:none}
  .mpk__cards{grid-template-columns:1fr}
  .mpk__title{font-size:var(--fs-lg);padding-right:48px}
}
@media (max-width:399px){.mpk__map{display:none}}

/* ── Print (ADR-067): a printed gated page prints the page. The inline step rule is screen-only; this is the backstop. */
@media print{
  [data-market-gate],.market-bar{display:none!important}
  [data-arrival-page]{display:block!important}
}

/* ── Reduced motion and forced colours ───────────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion:reduce){
  .market-dialog[open]{animation:none}
  .mpk-map__market.is-hot .mpk-map__arc,.mpk-map__market:hover .mpk-map__arc,.mpk-map__pulse{animation:none}
  .market-card,.mpk-map__area,.mpk-map__arc{transition:none}
}
@media (forced-colors:active){
  .market-chooser__opt{border-color:CanvasText}
  .market-chooser__opt.is-current{outline:2px solid Highlight}
  .mpk-map__pat-land,.mpk-map__pat-market{color:CanvasText}
  .mpk-map__market.is-hot .mpk-map__area,.mpk-map__market:hover .mpk-map__area{filter:none;opacity:1}
  .mpk-map__arc,.mpk-map__pulse{stroke:Highlight}
  .mpk-map__hubdot{fill:Highlight}
  .mpk-map__pill rect{fill:Canvas;stroke:CanvasText}
  .mpk-map__pill text,.mpk-map__hublabel{fill:CanvasText}
  .market-card{border-color:CanvasText}
  .market-card__pick:focus-visible::after{outline-color:Highlight}
  .market-opt.is-current{outline:2px solid Highlight}
}
