/* ══════════════════════════════════════════════════════════════════════════
   The Doodle Bazaar header — ONE header, every page.

   Before this file the site had four different top bars (the town's sticky
   bar, the 3D world's own bar, a floating #world3d-bar injected over the
   iframe, the PDP's .nav, the Observatory's .top) which stacked on top of
   each other and put the cart in a different place on every screen.

   This is the single header: a utility row (brand / search / account / cart)
   and a department row whose mega-panels are built from
   services/storefront_taxonomy.DEPARTMENTS — the same taxonomy the browse
   pages use, so the menu can never drift from what is actually shoppable.

   Self-contained on purpose: it is loaded next to bazaar2.css (light paper),
   dark.css (the video feed) and pages whose CSS is inlined in app.py, so it
   defines its own tokens with fallbacks and namespaces every class `db-`.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  --dbh-ink: #1a1714;
  --dbh-paper: #fbf4e6;
  --dbh-white: #ffffff;
  --dbh-accent: #e10600;
  --dbh-muted: #6b6258;
  --dbh-soft: #f6efe0;
  --dbh-line: rgba(26, 23, 20, 0.16);
  --dbh-row1: 62px;
  --dbh-row2: 44px;
  /* Pages read this to pad their own first element under the fixed header. */
  --dbh-height: calc(var(--dbh-row1) + var(--dbh-row2));
}

/* ── The bar ───────────────────────────────────────────────────────────── */

.db-head {
  position: sticky;
  top: 0;
  /* Above the 3D world overlay (z 60) so the header never gets buried and
     the cart is reachable in every state of the town. */
  z-index: 1200;
  font-family: Nunito, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--dbh-ink);
  background: rgba(251, 244, 230, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid var(--dbh-ink);
}
.db-head *,
.db-head *::before,
.db-head *::after { box-sizing: border-box; }
.db-head a { color: inherit; text-decoration: none; }

/* Fixed variant: used where the page body is its own scroll container (the
   3D world, the video feed) and a sticky bar would scroll away with it. */
.db-head.is-fixed { position: fixed; top: 0; left: 0; right: 0; }

.db-row1 {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--dbh-row1);
  padding: 0 18px;
  max-width: 1600px;
  margin: 0 auto;
}

.db-brand {
  font-family: Fredoka, Nunito, system-ui, sans-serif;
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.2px;
  white-space: nowrap;
  flex: none;
}
.db-brand b { color: var(--dbh-accent); }

/* ── Search ────────────────────────────────────────────────────────────── */

.db-search {
  flex: 1 1 auto;
  max-width: 460px;
  position: relative;
  display: flex;
  align-items: center;
}
.db-search input {
  width: 100%;
  height: 38px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--dbh-ink);
  background: var(--dbh-white);
  border: 2px solid var(--dbh-ink);
  border-radius: 16px 11px 19px 12px / 12px 19px 11px 16px;
  padding: 0 40px 0 14px;
  outline: none;
}
.db-search input::placeholder { color: var(--dbh-muted); font-weight: 600; }
.db-search input:focus { box-shadow: 3px 3px 0 var(--dbh-ink); }
.db-search button {
  position: absolute;
  right: 4px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--dbh-ink);
}
.db-search svg { width: 18px; height: 18px; }

/* ── Utility pills (account / cart / observatory) ──────────────────────── */

.db-util {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex: none;
}

.db-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  /* 44px minimum touch target — the old icon-only pills were 34px. */
  min-height: 40px;
  padding: 0 13px;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  color: var(--dbh-ink);
  background: var(--dbh-white);
  border: 2px solid var(--dbh-ink);
  border-radius: 16px 11px 19px 12px / 12px 19px 11px 16px;
  box-shadow: 3px 3px 0 var(--dbh-ink);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.db-pill:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--dbh-ink); }
.db-pill:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--dbh-ink); }
.db-pill.is-on { background: var(--dbh-accent); color: var(--dbh-white); }
.db-pill svg {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2.1;
  stroke-linecap: round; stroke-linejoin: round;
}
.db-pill.is-icon { padding: 0; width: 40px; }

.db-cart-n {
  display: inline-grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--dbh-accent);
  color: var(--dbh-white);
  font-size: 11px;
  font-weight: 800;
}
.db-pill.is-on .db-cart-n { background: var(--dbh-white); color: var(--dbh-accent); }

/* ── Department row ────────────────────────────────────────────────────── */

.db-row2 {
  border-top: 1.5px solid var(--dbh-line);
  height: var(--dbh-row2);
}
.db-depts {
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 100%;
  padding: 0 12px;
  max-width: 1600px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.db-depts::-webkit-scrollbar { display: none; }

.db-dept { position: relative; display: flex; flex: none; }
.db-dept > a,
.db-dept > button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 100%;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--dbh-ink);
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  cursor: pointer;
}
.db-dept > a:hover,
.db-dept > button:hover,
.db-dept.is-open > a,
.db-dept.is-open > button { border-bottom-color: var(--dbh-accent); }
.db-dept.is-active > a,
.db-dept.is-active > button { border-bottom-color: var(--dbh-ink); }
.db-dept.is-lead > a { color: var(--dbh-accent); font-weight: 800; }
.db-dept .db-caret {
  width: 11px; height: 11px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2.6;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform .16s ease;
}
.db-dept.is-open .db-caret { transform: rotate(180deg); }

/* ── Mega panel ────────────────────────────────────────────────────────── */

/* The panels are authored inside their .db-dept (so the markup reads in
   order and stays associated for assistive tech) but head.js re-parents
   them here on load. They cannot stay inside .db-depts: that row is
   `overflow-x:auto`, and an auto overflow on one axis forces clipping on
   the other — a panel nested in it gets sliced off at the 44px row.
   Anchored to .db-head, which is `position:sticky` and therefore already a
   containing block, so `top:100%` lands exactly under the bar. */
.db-mega {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 5;
  display: none;
  width: max-content;
  min-width: 460px;
  max-width: min(92vw, 780px);
  padding: 18px 20px 20px;
  background: var(--dbh-white);
  border: 2.5px solid var(--dbh-ink);
  border-radius: 4px 22px 6px 20px / 20px 6px 22px 4px;
  box-shadow: 5px 6px 0 var(--dbh-ink);
}
.db-mega.is-open { display: block; }

.db-mega-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px 18px;
}
.db-mega-grid a {
  display: block;
  padding: 7px 9px;
  margin-left: -9px;
  font-size: 14px;
  font-weight: 700;
  color: var(--dbh-ink);
  border-radius: 9px;
}
.db-mega-grid a:hover { background: var(--dbh-soft); color: var(--dbh-accent); }

.db-mega-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 15px;
  padding-top: 13px;
  border-top: 1.5px solid var(--dbh-line);
}
.db-mega-foot p {
  margin: 0;
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--dbh-muted);
}
.db-mega-all {
  flex: none;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--dbh-white);
  background: var(--dbh-accent);
  border-radius: 14px 9px 16px 10px / 10px 16px 9px 14px;
  box-shadow: 2px 2px 0 var(--dbh-ink);
}

/* ── Burger + mobile drawer ────────────────────────────────────────────── */

.db-burger { display: none; }

.db-scrim {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(26, 23, 20, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}
.db-scrim.is-open { opacity: 1; pointer-events: auto; }

.db-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1400;
  width: min(88vw, 360px);
  display: flex;
  flex-direction: column;
  background: var(--dbh-paper);
  border-right: 2.5px solid var(--dbh-ink);
  transform: translateX(-102%);
  transition: transform .26s cubic-bezier(.22, .8, .3, 1);
  font-family: Nunito, ui-sans-serif, system-ui, sans-serif;
  color: var(--dbh-ink);
  overscroll-behavior: contain;
}
.db-drawer.is-open { transform: none; }
.db-drawer a { color: inherit; text-decoration: none; }

.db-drawer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  padding: 13px 14px;
  border-bottom: 2px solid var(--dbh-ink);
}
.db-drawer-body { flex: 1; overflow-y: auto; padding: 6px 0 26px; -webkit-overflow-scrolling: touch; }

.db-acc { border-bottom: 1.5px solid var(--dbh-line); }
.db-acc > button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  text-align: left;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
.db-acc > button .db-caret { width: 13px; height: 13px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; transition: transform .18s ease; }
.db-acc.is-open > button .db-caret { transform: rotate(180deg); }
.db-acc-panel { display: none; padding: 0 16px 12px; }
.db-acc.is-open .db-acc-panel { display: block; }
.db-acc-panel a {
  display: block;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--dbh-muted);
  border-radius: 10px;
}
.db-acc-panel a:hover,
.db-acc-panel a.db-acc-all { color: var(--dbh-accent); }
.db-acc-panel a.db-acc-all { font-weight: 800; }

.db-drawer-links {
  display: flex;
  flex-direction: column;
  padding: 10px 16px 0;
}
.db-drawer-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-size: 15px;
  font-weight: 700;
}
.db-drawer-links svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.db-drawer-note { padding: 14px 16px 0; font-size: 13px; font-weight: 600; color: var(--dbh-muted); line-height: 1.45; }

/* ── Dark variant (the Observatory video feed) ─────────────────────────── */

.db-head.is-dark {
  background: linear-gradient(rgba(0, 0, 0, .62), rgba(0, 0, 0, .18));
  backdrop-filter: blur(4px);
  border-bottom: 0;
  color: #fff;
}
.db-head.is-dark .db-pill {
  color: #fff;
  background: rgba(0, 0, 0, .34);
  border-color: rgba(255, 255, 255, .5);
  box-shadow: none;
}
.db-head.is-dark .db-pill:hover { background: rgba(0, 0, 0, .5); transform: none; box-shadow: none; }
.db-head.is-dark .db-pill.is-on { background: var(--dbh-accent); border-color: var(--dbh-accent); }
.db-head.is-dark .db-brand b { color: #ff6b6b; }

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 1080px) {
  .db-search { max-width: 300px; }
  .db-dept > a, .db-dept > button { padding: 0 10px; font-size: 13.5px; }
}

@media (max-width: 900px) {
  :root { --dbh-row1: 58px; --dbh-height: var(--dbh-row1); }
  .db-burger { display: inline-flex; }
  /* The department row becomes the drawer on small screens — a horizontally
     scrolling strip of ten departments is not navigation, it is a guessing
     game (this is the "menus are not navigatable" complaint). */
  .db-row2 { display: none; }
  .db-brand { font-size: 19px; }
  .db-util .db-label { display: none; }
  .db-util .db-pill { padding: 0; width: 42px; }
  .db-util .db-pill.db-cart { width: auto; padding: 0 11px; }
}

@media (max-width: 620px) {
  /* Two tidy rows, not three ragged ones: [burger] [brand] … [pills], then
     search full-width underneath. Everything on a baseline, nothing loose. */
  .db-row1 {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "burger brand util" "search search search";
    align-items: center;
    gap: 9px 10px;
    height: auto;
    padding: 9px 12px 10px;
  }
  .db-burger { grid-area: burger; }
  .db-brand  { grid-area: brand; font-size: 18px; }
  .db-util   { grid-area: util; gap: 7px; }
  .db-search { grid-area: search; max-width: none; }
  .db-search input { height: 40px; }
  /* Account and the Observatory live in the drawer on a phone — four pills
     in a 390px row is what made the top read as a pile of buttons. */
  .db-util .db-pill[href="/account"],
  .db-util .db-pill[href="/feed"] { display: none; }
  :root { --dbh-height: 112px; }
}

@media (prefers-reduced-motion: reduce) {
  .db-drawer, .db-scrim, .db-pill, .db-caret { transition: none; }
}

/* ── Park sound toggle (injected by js/park-sound.js on park pages) ─────── */
.db-park-sound .db-wave { transition: opacity .2s ease; }
.db-park-sound.is-on .db-wave { animation: db-sound-wave 1.8s ease-in-out infinite; }
@keyframes db-sound-wave { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .db-park-sound.is-on .db-wave { animation: none; } }
