/* The Shortcut palette: navy-black + red. Light is the base; dark applies for system dark or a forced choice. */
:root {
  --brand-navy: #051826;
  --accent: #ea1b21;
  --accent-press: #c9151b;
  --on-accent: #ffffff;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #e9ecf0;
  --text: #051826;
  --muted: #5b6b7a;
  --line: rgba(5, 24, 38, .10);
  --shadow: 0 1px 2px rgba(5, 24, 38, .06), 0 8px 24px rgba(5, 24, 38, .07);
  --topbar: rgba(244, 245, 247, .82);
  --radius: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #051826;
    --surface: #0c2234;
    --surface-2: #142d43;
    --text: #f3f5f7;
    --muted: #93a4b5;
    --line: rgba(255, 255, 255, .09);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 28px rgba(0, 0, 0, .3);
    --topbar: rgba(5, 24, 38, .82);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #051826;
  --surface: #0c2234;
  --surface-2: #142d43;
  --text: #f3f5f7;
  --muted: #93a4b5;
  --line: rgba(255, 255, 255, .09);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 28px rgba(0, 0, 0, .3);
  --topbar: rgba(5, 24, 38, .82);
  color-scheme: dark;
}

/* Logo swap follows the same rules as the palette */
.logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark { display: block; }
}
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Masthead: big centered logo that tucks into a compact bar on scroll ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: 8px;
  padding: max(16px, env(safe-area-inset-top)) 16px 16px;
  background: var(--topbar);
  -webkit-backdrop-filter: saturate(160%) blur(14px); backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
  transition: padding .2s ease;
}
.topbar::before { content: ""; } /* balances the menu button so the logo sits dead center */
.logo { display: block; justify-self: center; min-width: 0; }
.logo img { height: 42px; width: auto; max-width: 100%; object-fit: contain; transition: height .2s ease; }
@media (min-width: 640px) {
  .topbar { padding-top: max(22px, env(safe-area-inset-top)); padding-bottom: 22px; }
  .logo img { height: 60px; }
}
.topbar.is-compact { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px; }
.topbar.is-compact .logo img { height: 30px; }
.menu-btn {
  display: grid; place-content: center; gap: 4px;
  width: 44px; height: 44px; border-radius: 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  transition: width .2s ease, height .2s ease;
}
.topbar.is-compact .menu-btn { width: 40px; height: 40px; }
@media (prefers-reduced-motion: reduce) { .topbar, .logo img, .menu-btn { transition: none; } }
.menu-btn span { display: block; width: 18px; height: 2px; border-radius: 2px; background: var(--text); }
.menu-btn span:nth-child(2) { width: 12px; justify-self: end; background: var(--accent); }

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 16px max(28px, env(safe-area-inset-bottom));
}

/* ---------- Intro + search ---------- */
.intro { text-align: center; padding: 10px 0 18px; }
.intro h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 7.5vw, 44px); line-height: 1.04; letter-spacing: -.035em; font-weight: 850;
}
.tagline { margin: 0 auto; max-width: 30em; color: var(--muted); }

.search {
  position: sticky; top: calc(max(8px, env(safe-area-inset-top)) + 60px); z-index: 5;
  display: flex; gap: 8px;
  max-width: 560px; margin: 0 auto 14px;
  padding: 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  /* first shadow is a page-colored halo: it fills the strip under the compact bar so cards don't peek through */
  box-shadow: 0 -12px 0 8px var(--bg), var(--shadow);
}
.search-field { flex: 1; display: flex; align-items: center; min-width: 0; padding-left: 14px; }
.hash { font-weight: 850; color: var(--accent); font-size: 20px; margin-right: 4px; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 18px; font-weight: 650; padding: 10px 4px;
}
.search input::placeholder { color: var(--muted); font-weight: 500; }
.search input::-webkit-search-cancel-button { display: none; }
.search-go {
  border: 0; border-radius: 999px; padding: 0 22px;
  background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 750; cursor: pointer;
}
.search:focus-within { outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 2px; }

.active-filter {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 0 auto 12px; font-size: 14px; color: var(--muted);
}
.active-filter b { color: var(--text); }
.clear-filter {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); text-decoration: none; font-size: 12px; font-weight: 700;
}

/* ---------- Cards: photo + title on top, store buttons underneath ---------- */
.grid {
  list-style: none; margin: 6px 0 0; padding: 0;
  display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 680px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 1000px) { .wrap { max-width: 1120px; } .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card {
  display: grid; grid-template-columns: 104px minmax(0, 1fr); grid-template-rows: auto 1fr;
  column-gap: 14px; row-gap: 12px; height: 100%;
  padding: 12px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.thumb {
  position: relative; display: block; grid-row: 1; aspect-ratio: 1; overflow: hidden;
  border-radius: 14px; background: #fff;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 7%; }
.thumb:has(.thumb-fallback) { background: var(--surface-2); }
.thumb-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 22px; font-weight: 850; color: var(--muted); letter-spacing: -.03em;
}
.code-tag {
  position: absolute; left: 6px; top: 6px;
  background: rgba(5, 24, 38, .9); color: #fff;
  font-weight: 800; font-size: 12px; padding: 3px 8px; border-radius: 999px; letter-spacing: .01em;
}
.badge {
  position: absolute; right: 8px; top: 8px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 750; font-size: 12px; padding: 4px 9px; border-radius: 999px;
}
.card-head { align-self: center; min-width: 0; }
.card-head h2 { margin: 0; font-size: 16.5px; line-height: 1.22; font-weight: 800; letter-spacing: -.015em; }
.card-head h2 a {
  text-decoration: none;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
@media (hover: hover) { .card-head h2 a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; } }
.card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0 0 4px; font-size: 12.5px; color: var(--muted); }
.badge-inline {
  background: var(--accent); color: var(--on-accent);
  font-weight: 750; font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
}
.pin { color: var(--accent); font-weight: 750; }

.card-buttons { grid-column: 1 / -1; display: grid; gap: 8px; align-self: end; }
.cbtn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 48px; padding: 10px 14px; border-radius: 14px;
  text-decoration: none; font-weight: 750; font-size: 15.5px;
  transition: transform .12s ease;
}
.cbtn:active { transform: scale(.98); }
.cbtn-lead { background: var(--accent); color: var(--on-accent); }
.cbtn-lead:active { background: var(--accent-press); }
@media (hover: hover) { .cbtn-lead:hover { background: var(--accent-press); } }
.cbtn-lead::after { content: "→"; font-size: 18px; margin-left: 2px; }
.cbtn-alt { background: var(--surface-2); color: var(--text); min-height: 42px; font-size: 14.5px; }
.cbtn-label, .btn-label { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; }
/* Label and price share a line when they fit; otherwise the price drops neatly underneath */
.cbtn-main { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; column-gap: 10px; row-gap: 2px; }
.store-icon { flex: none; font-size: 17px; line-height: 1; width: 20px; text-align: center; }
.store-icon-img { width: 20px; height: 20px; object-fit: contain; }
/* On the red lead button the red S would disappear, so it turns white there */
.cbtn-lead .store-icon-img, .btn-lead .store-icon-img { filter: brightness(0) invert(1); }
.cbtn-note { margin-left: auto; font-weight: 600; font-size: 13.5px; opacity: .9; text-align: right; white-space: nowrap; }
.cbtn-more { text-align: center; font-size: 13.5px; font-weight: 700; color: var(--muted); text-decoration: none; padding: 2px 0; }

.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* ---------- Item page ---------- */
.back { display: inline-block; text-decoration: none; font-weight: 650; color: var(--muted); padding: 2px 0 14px; }

.item { max-width: 520px; margin: 0 auto; }
.hero {
  position: relative; display: block; border-radius: 26px; overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.hero img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; }
.hero .badge { font-size: 13px; right: 12px; top: 12px; padding: 5px 11px; }
.item-meta { display: flex; align-items: center; gap: 8px; margin: 18px 0 4px; color: var(--muted); font-size: 14px; }
.code-pill { background: var(--text); color: var(--bg); font-weight: 800; font-size: 13px; padding: 3px 9px; border-radius: 999px; }
.item-title { margin: 0 0 8px; font-size: clamp(24px, 6.5vw, 32px); line-height: 1.12; letter-spacing: -.03em; font-weight: 850; }
.blurb { margin: 0 0 6px; color: var(--muted); }

.buttons { display: grid; gap: 10px; margin: 18px 0 8px; }
.btn {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 12px 20px; border-radius: 18px;
  text-decoration: none; font-weight: 750; font-size: 17px;
  transition: transform .12s ease;
}
.btn:active { transform: scale(.98); }
.btn-lead {
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 22%, transparent);
}
.btn-lead::after { content: "→"; font-size: 20px; }
.btn-alt { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.btn-note { font-weight: 600; font-size: 14px; opacity: .88; margin-left: auto; text-align: right; white-space: nowrap; }
.watch { text-align: center; margin: 18px 0 0; }
.watch a { color: var(--muted); font-weight: 650; text-decoration: none; }
.draft-note {
  max-width: 520px; margin: 0 auto 12px; text-align: center; font-weight: 650;
  background: var(--surface-2); padding: 8px; border-radius: 12px;
}

/* ---------- 404 ---------- */
.notfound { text-align: center; padding: 20px 0; }
.notfound .big { font-size: 64px; font-weight: 850; letter-spacing: -.04em; margin: 0; color: var(--accent); }
.notfound h1 { margin: 4px 0 8px; letter-spacing: -.02em; }
.notfound p { color: var(--muted); }
.notfound .search { position: static; margin-top: 18px; box-shadow: var(--shadow); }

/* ---------- Menu drawer ---------- */
.drawer {
  position: fixed; inset: 0 0 0 auto; margin: 0;
  width: min(340px, 88vw); height: 100%; max-height: none; max-width: none;
  padding: max(14px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  border: 0; border-left: 1px solid var(--line);
  background: var(--bg); color: var(--text);
  overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(100%); transition: transform .25s ease, display .25s allow-discrete, overlay .25s allow-discrete;
}
.drawer[open] { transform: none; }
@starting-style { .drawer[open] { transform: translateX(100%); } }
.drawer::backdrop {
  background: rgba(5, 24, 38, 0); transition: background .25s ease, display .25s allow-discrete, overlay .25s allow-discrete;
}
.drawer[open]::backdrop { background: rgba(5, 24, 38, .5); }
@starting-style { .drawer[open]::backdrop { background: rgba(5, 24, 38, 0); } }
@media (prefers-reduced-motion: reduce) { .drawer, .drawer::backdrop { transition: none; } }

.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.drawer-title { font-weight: 850; font-size: 20px; letter-spacing: -.02em; }
.drawer-close {
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 15px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.drawer-section { padding: 10px 0; border-bottom: 1px solid var(--line); }
.drawer-section:last-child { border-bottom: 0; }
.drawer-label {
  margin: 12px 4px 6px; font-size: 12px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.drawer-link {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px; border-radius: 14px; text-decoration: none; font-weight: 650;
}
.drawer-link:hover { background: var(--surface); }
.drawer-link.is-on { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
.drawer-link.is-on .count { background: var(--accent); color: #fff; }
.count {
  min-width: 26px; padding: 2px 8px; border-radius: 999px; text-align: center;
  font-size: 12.5px; font-weight: 750; background: var(--surface-2); color: var(--muted);
}
.theme-switch {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  padding: 4px; border-radius: 14px; background: var(--surface-2);
}
.theme-switch button {
  border: 0; border-radius: 10px; padding: 9px 0; cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 700; background: transparent; color: var(--muted);
}
.theme-switch button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.drawer-foot .drawer-link { color: var(--accent); }

/* ---------- Footer ---------- */
.foot { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); text-align: center; font-size: 13px; color: var(--muted); }
.foot p { margin: 0 auto 8px; max-width: 40em; }
.foot a { font-weight: 750; color: var(--text); text-decoration: none; }
