:root {
  --ink: #11100e;
  --ink-soft: #292621;
  --cream: #f4eddf;
  --cream-deep: #e7dbc5;
  --paper: #fbf7ef;
  --rust: #9c3f2f;
  --rust-dark: #6e291f;
  --line: rgba(17, 16, 14, 0.18);
  --shadow: 0 18px 50px rgba(17, 16, 14, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(rgba(17,16,14,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17,16,14,.025) 1px, transparent 1px),
    var(--cream);
  background-size: 24px 24px;
}

button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 20;
  background: var(--ink);
  color: var(--cream);
  padding: .75rem 1rem;
}
.skip-link:focus { top: 1rem; }

.site-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 3rem);
  color: var(--cream);
  background: var(--ink);
  border-bottom: 4px solid var(--rust);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border: 2px solid var(--cream);
  font: 800 1.45rem/1 Georgia, serif;
  transform: rotate(45deg);
}
.brand-mark::first-letter { transform: rotate(-45deg); }
.brand strong { display: block; font: 700 1.2rem/1.1 Georgia, serif; letter-spacing: .04em; }
.brand small { display: block; margin-top: .22rem; color: #d4c8b4; font-size: .78rem; }
.header-links { display: flex; align-items: center; gap: 1.25rem; }
.catalogue-link { font-size: .9rem; font-weight: 700; text-underline-offset: .25rem; }

.layout {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 2.5vw, 2.5rem);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: clamp(1.25rem, 2.5vw, 2.5rem);
  align-items: start;
}

.intro-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  padding-bottom: 1.35rem;
  border-bottom: 2px solid var(--ink);
}
.eyebrow {
  margin: 0 0 .35rem;
  color: var(--rust-dark);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; }
h1 { font-size: clamp(2rem, 5vw, 3.4rem); line-height: .98; }
h2 { font-size: 1.7rem; }
.lede { max-width: 670px; margin: .8rem 0 0; color: #4f4940; font-size: 1rem; line-height: 1.55; }

.pack-control > span { display: block; margin-bottom: .45rem; font-size: .82rem; font-weight: 800; }
.segment { display: flex; padding: 4px; background: var(--ink); border-radius: 999px; }
.segment button {
  width: 54px;
  border: 0;
  border-radius: 999px;
  padding: .58rem .75rem;
  color: var(--cream);
  background: transparent;
  font-weight: 800;
}
.segment button[aria-checked="true"] { color: var(--ink); background: var(--cream); }

.toolbar { display: flex; align-items: center; gap: 1rem; margin: 1.25rem 0; }
.search { position: relative; flex: 1; }
.search svg {
  position: absolute;
  left: .95rem;
  top: 50%;
  width: 20px;
  transform: translateY(-50%);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}
.search input {
  width: 100%;
  min-height: 48px;
  padding: .72rem 1rem .72rem 2.8rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  background: var(--paper);
  outline: none;
}
.search input:focus { box-shadow: 0 0 0 3px var(--rust); }
.result-count { flex: none; margin: 0; color: #5f584e; font-size: .9rem; }

.token-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.token-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 2px solid var(--ink);
  background: var(--paper);
  box-shadow: 5px 5px 0 rgba(17,16,14,.12);
}
.token-image-wrap { position: relative; aspect-ratio: 5 / 7; overflow: hidden; background: var(--ink-soft); }
.token-image-wrap img { display: block; width: 100%; height: 100%; object-fit: cover; }
.token-code {
  position: absolute;
  top: .55rem;
  left: .55rem;
  padding: .28rem .48rem;
  color: var(--cream);
  background: var(--ink);
  border: 1px solid var(--cream);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .06em;
}
.token-body { display: flex; flex: 1; flex-direction: column; padding: .75rem; }
.token-body h3 { margin: 0; font: 700 1.05rem/1.1 Georgia, serif; }
.token-meta { margin: .35rem 0 0; color: #625b51; font-size: .78rem; line-height: 1.35; }
.token-rule { margin: .45rem 0 0; color: #39352f; font-size: .78rem; line-height: 1.35; }
.token-foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: auto; padding-top: .75rem; }
.reference-link { font-size: .75rem; font-weight: 800; text-underline-offset: .2rem; }
.qty-control { display: flex; align-items: center; border: 2px solid var(--ink); }
.qty-control button { width: 34px; height: 34px; border: 0; color: var(--cream); background: var(--ink); font-size: 1.15rem; font-weight: 900; }
.qty-control button:disabled { cursor: not-allowed; opacity: .35; }
.qty-control output { min-width: 31px; text-align: center; font-size: .84rem; font-weight: 900; }
.token-card.is-selected { outline: 4px solid var(--rust); outline-offset: -4px; }

.basket {
  position: sticky;
  top: 1.25rem;
  padding: 1.25rem;
  color: var(--cream);
  background: var(--ink);
  border: 4px double var(--cream-deep);
  box-shadow: var(--shadow);
}
.basket-head { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.basket .eyebrow { color: #df9c87; }
.count-badge { padding: .5rem .65rem; color: var(--ink); background: var(--cream); font-weight: 900; }
.progress { height: 8px; margin: 1.2rem 0 .75rem; overflow: hidden; background: #403b35; }
.progress span { display: block; width: 0; height: 100%; background: var(--rust); transition: width .2s ease; }
.basket-status { min-height: 2.6em; margin: 0 0 1rem; color: #d9cebb; font-size: .88rem; line-height: 1.45; }
.basket-items { max-height: min(48vh, 500px); overflow: auto; border-top: 1px solid #4a453e; border-bottom: 1px solid #4a453e; }
.empty-state { display: grid; place-items: center; min-height: 190px; padding: 2rem; color: #b8ad9c; text-align: center; }
.empty-state span { font-size: 2.4rem; }
.empty-state p { margin: .4rem 0 0; }
.basket-row { display: grid; grid-template-columns: 52px minmax(0,1fr) auto; gap: .75rem; align-items: center; padding: .75rem 0; border-bottom: 1px solid #3d3933; }
.basket-row:last-child { border-bottom: 0; }
.basket-row img { display: block; width: 52px; aspect-ratio: 5/7; object-fit: cover; border: 1px solid var(--cream-deep); }
.basket-row strong, .basket-row small { display: block; }
.basket-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 .9rem/1.2 Georgia, serif; }
.basket-row small { margin-top: .22rem; color: #bdb2a1; font-size: .72rem; }
.basket-qty { display: flex; align-items: center; gap: .35rem; }
.basket-qty button { width: 28px; height: 28px; border: 1px solid #81786b; color: var(--cream); background: transparent; font-weight: 900; }
.basket-qty output { min-width: 1.1rem; text-align: center; font-weight: 800; }
.basket-actions { display: grid; gap: .6rem; margin-top: 1rem; }
.basket-actions button { min-height: 46px; border: 2px solid var(--cream); font-weight: 900; }
.basket-actions button:disabled { cursor: not-allowed; opacity: .4; }
.primary { color: var(--ink); background: var(--cream); }
.secondary { color: var(--cream); background: transparent; }
.format-note { margin: .85rem 0 0; color: #aba08f; font-size: .73rem; line-height: 1.45; }

.load-more { display: block; min-width: 220px; margin: 1.5rem auto 0; padding: .8rem 1rem; border: 2px solid var(--ink); color: var(--cream); background: var(--ink); font-weight: 900; }
.no-results { grid-column: 1 / -1; padding: 4rem 1rem; border: 2px dashed var(--line); text-align: center; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; z-index: 30; transform: translate(-50%, 150%); padding: .8rem 1rem; color: var(--cream); background: var(--rust-dark); box-shadow: var(--shadow); font-weight: 800; transition: transform .2s ease; }
.toast.show { transform: translate(-50%, 0); }
.visually-hidden { position: absolute!important; width: 1px!important; height: 1px!important; padding: 0!important; margin: -1px!important; overflow: hidden!important; clip: rect(0,0,0,0)!important; white-space: nowrap!important; border: 0!important; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .basket { position: relative; top: auto; grid-row: 1; }
  .basket-items { max-height: 280px; }
}

@media (max-width: 620px) {
  .site-header { min-height: 68px; }
  .brand small, .catalogue-link { display: none; }
  .layout { padding: 1rem; }
  .intro-row { align-items: start; flex-direction: column; gap: 1rem; }
  .pack-control { width: 100%; }
  .segment button { flex: 1; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .result-count { padding-left: .1rem; }
  .token-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  .token-body { padding: .6rem; }
  .token-body h3 { font-size: .9rem; }
  .token-meta, .token-rule, .reference-link { font-size: .69rem; }
  .token-foot { align-items: end; flex-direction: column; }
  .reference-link { align-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto!important; transition: none!important; }
}
