/* Raw colours and sizes live only in the tokens layer. Mobile first: wide-screen rules sit in min-width queries. */
@layer tokens, base, layout, components, utilities;

@layer tokens {
  :root {
    color-scheme: light;
    --ink: #172b35;
    --ink-muted: #425761;
    --surface: #f5f7f8;
    --card: #ffffff;
    --tint: #eef3f5;
    --line: #cdd7dc;
    --link: #075a78;
    --link-hover: #003d53;
    --on-dark: #ffffff;
    --focus: #b66b00;
    --down: #0b6b3a;
    --down-bg: #e6f3ec;
    --up: #a4361d;
    --up-bg: #fbeae5;
    --low: #7a4a00;
    --low-bg: #fff1d6;
    --disabled: #53646b;
    /* Chart series: passes the dataviz lightness, chroma and contrast checks on --card. */
    --series: #0e6a9e;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --step--1: 0.8125rem;
    --step-0: 1rem;
    --step-1: 1.25rem;
    --step-2: 1.6rem;
    --step-3: 2rem;

    --s1: 0.25rem;
    --s2: 0.5rem;
    --s3: 0.75rem;
    --s4: 1rem;
    --s5: 1.5rem;
    --s6: 2rem;
    --radius: 0.4rem;
    --tap: 44px;
    --wrap: 72rem;
    --measure: 65ch;
  }
}

@layer base {
  * {
    box-sizing: border-box;
  }
  body {
    margin: 0;
    font: var(--step-0) / 1.55 var(--font);
    color: var(--ink);
    background: var(--surface);
  }
  a {
    color: var(--link);
    text-underline-offset: 0.18em;
  }
  a:hover {
    color: var(--link-hover);
  }
  :focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
  }
  h1,
  h2,
  h3 {
    line-height: 1.2;
    text-wrap: balance;
  }
  h1 {
    font-size: var(--step-2);
    margin: 0;
  }
  h2 {
    font-size: var(--step-1);
    margin: 0 0 var(--s3);
  }
  h3 {
    font-size: var(--step-0);
  }
  table {
    border-collapse: collapse;
    width: 100%;
  }
  summary {
    cursor: pointer;
  }
  input,
  button,
  select {
    font: inherit;
  }
  @media (min-width: 640px) {
    h1 {
      font-size: var(--step-3);
    }
  }
}

@layer layout {
  .wrap {
    max-width: var(--wrap);
    margin-inline: auto;
    padding-inline: var(--s4);
  }
  main.wrap {
    padding-block: var(--s4) var(--s6);
  }
  .section {
    margin-top: var(--s6);
  }
  .prose {
    max-width: var(--measure);
  }
}

@layer components {
  .skip {
    position: absolute;
    left: -999px;
  }
  .skip:focus {
    left: var(--s4);
    top: var(--s2);
    z-index: 3;
    background: var(--card);
    padding: var(--s2);
  }
  .site-header {
    background: var(--ink);
    color: var(--on-dark);
  }
  .site-header__inner {
    max-width: var(--wrap);
    margin-inline: auto;
    padding-inline: var(--s4);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    column-gap: var(--s4);
  }
  .brand {
    display: inline-flex;
    align-items: center;
    min-height: 3.25rem;
    color: var(--on-dark);
    font-weight: 750;
    text-decoration: none;
  }
  .brand:hover {
    color: var(--on-dark);
  }
  .site-nav {
    position: relative;
    display: flex;
    align-items: center;
    margin-inline: calc(-1 * var(--s2));
  }
  .site-nav > a,
  .menu > summary {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding-inline: var(--s2);
    border-radius: var(--radius);
    color: var(--on-dark);
    text-decoration: none;
  }
  .site-nav > a:hover,
  .menu > summary:hover {
    background: rgb(255 255 255 / 0.12);
    color: var(--on-dark);
  }
  .menu > summary {
    list-style: none;
  }
  .menu > summary::-webkit-details-marker {
    display: none;
  }
  .menu > summary::after {
    content: "▾";
    margin-left: var(--s1);
    font-size: var(--step--1);
  }
  .menu__list {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 2;
    list-style: none;
    margin: 0;
    padding: var(--s2);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 6px 18px rgb(23 43 53 / 0.18);
  }
  .menu__list a {
    display: flex;
    align-items: center;
    min-height: var(--tap);
    padding-inline: var(--s2);
  }
  .site-footer {
    border-top: 1px solid var(--line);
    padding-block: var(--s5);
    color: var(--ink-muted);
    font-size: var(--step--1);
  }
  .signup {
    display: grid;
    gap: var(--s2);
    max-width: 28rem;
    margin-block: var(--s4) var(--s2);
  }
  .signup label {
    font-weight: 600;
    color: var(--ink);
  }
  .signup__row {
    display: flex;
    gap: var(--s2);
  }
  .signup input {
    flex: 1;
    min-width: 0;
    min-height: var(--tap);
    padding-inline: var(--s3);
    border: 1px solid var(--ink-muted);
    border-radius: var(--radius);
  }
  .signup button {
    min-height: var(--tap);
    padding-inline: var(--s4);
    border: 0;
    border-radius: var(--radius);
    background: var(--link);
    color: var(--on-dark);
    cursor: pointer;
  }
  .signup button:disabled {
    background: var(--disabled);
    cursor: default;
  }
  .site-footer__links {
    display: flex;
    flex-wrap: wrap;
    column-gap: var(--s4);
  }
  .site-footer__links a {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
  }
  @media (min-width: 640px) {
    .menu__list {
      left: auto;
      min-width: 14rem;
    }
  }

  .crumbs ol {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2);
    margin: 0 0 var(--s3);
    padding: 0;
    list-style: none;
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .crumbs li + li::before {
    content: "/";
    margin-right: var(--s2);
  }

  .page-head {
    margin-bottom: var(--s4);
  }
  .page-head__season {
    display: block;
    margin-top: var(--s1);
    font-size: var(--step-0);
    font-weight: 600;
    color: var(--ink-muted);
  }
  .lede {
    max-width: var(--measure);
    margin: var(--s3) 0 0;
    font-size: var(--step-0);
  }
  .stamp {
    margin: var(--s3) 0 0;
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .stamp__dot {
    display: inline-block;
    margin-right: var(--s2);
    vertical-align: 0.05em;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--down);
  }

  /* Chips are plain links, so filtering works without JavaScript; phones scroll them sideways. */
  .chips {
    display: flex;
    gap: var(--s2);
    margin: 0 calc(-1 * var(--s4)) var(--s3);
    padding: 0 var(--s4) var(--s2);
    overflow-x: auto;
    scrollbar-width: thin;
  }
  @media (min-width: 640px) {
    .chips {
      flex-wrap: wrap;
      margin-inline: 0;
      padding: 0;
      overflow: visible;
    }
  }
  .chip {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    min-height: var(--tap);
    padding-inline: var(--s3);
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
  }
  .chip[aria-current] {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--on-dark);
  }
  .chip__count {
    font-size: var(--step--1);
    font-variant-numeric: tabular-nums;
    opacity: 0.8;
  }
  .compare {
    margin: 0 0 var(--s3);
  }

  .facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s1) var(--s5);
    margin: 0 0 var(--s2);
    padding: 0;
    list-style: none;
  }
  .facts strong {
    font-size: var(--step-1);
  }
  .note {
    max-width: var(--measure);
    margin: 0 0 var(--s4);
    font-size: var(--step--1);
    color: var(--ink-muted);
  }

  .tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: var(--s3);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .tile {
    display: flex;
    flex-direction: column;
    gap: var(--s1);
    padding: var(--s3) var(--s4);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .tile__title {
    font-size: var(--step-0);
    font-weight: 700;
  }
  @media (min-width: 640px) {
    .tile__title {
      font-size: var(--step-1);
    }
  }
  .tile__note {
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .tile__secondary {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    font-size: var(--step--1);
  }

  .empty {
    padding: var(--s3) var(--s4);
    background: var(--tint);
    border-radius: var(--radius);
  }

  .disclosure {
    max-width: var(--measure);
    padding: var(--s3);
    border-left: 3px solid var(--link);
    background: var(--tint);
  }
  .paid-link {
    font-size: var(--step--1);
    color: var(--ink-muted);
    white-space: nowrap;
  }

  .sort-select {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-bottom: var(--s3);
    font-size: var(--step--1);
  }
  .sort-select select {
    min-height: var(--tap);
    padding-inline: var(--s2);
    border: 1px solid var(--ink-muted);
    border-radius: var(--radius);
    background: var(--card);
  }
  .products,
  .products tbody {
    display: block;
  }
  .products thead {
    display: none;
  }
  .products tr {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--s2) var(--s3);
    margin-bottom: var(--s3);
    padding: var(--s3);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .products td {
    display: block;
    padding: 0;
  }
  .product__main,
  .product__history {
    flex: 1 1 100%;
  }
  .product__retailer {
    display: none !important;
  }
  .product__retailer-inline,
  .product__variant {
    display: block;
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .product__title {
    font-weight: 600;
  }
  .product__price,
  .product__stock {
    flex: 1 1 auto;
  }
  .product__off {
    font-weight: 600;
  }
  .product__off--none {
    display: none !important;
  }
  .product__stock {
    align-self: center;
  }
  @media (min-width: 640px) {
    .sort-select {
      display: none;
    }
    .products {
      display: table;
      background: var(--card);
      border: 1px solid var(--line);
      border-radius: var(--radius);
    }
    .products thead {
      display: table-header-group;
    }
    .products tbody {
      display: table-row-group;
    }
    .products tr {
      display: table-row;
      background: none;
      border: 0;
    }
    .products th,
    .products td {
      display: table-cell;
      padding: var(--s3);
      border-bottom: 1px solid var(--line);
      vertical-align: top;
    }
    .products tbody tr:last-child td {
      border-bottom: 0;
    }
    .products th {
      white-space: nowrap;
      padding-block: var(--s2);
      background: var(--tint);
      font-size: var(--step--1);
      font-weight: 600;
      color: var(--ink-muted);
      text-align: left;
    }
    .products th.num,
    .product__price,
    .product__off {
      text-align: right;
    }
    .products th button {
      padding: 0;
      border: 0;
      background: none;
      color: inherit;
      font-weight: inherit;
      cursor: pointer;
    }
    .products th[aria-sort="ascending"] button::after {
      content: " ↑";
    }
    .products th[aria-sort="descending"] button::after {
      content: " ↓";
    }
    .product__retailer {
      display: table-cell !important;
      white-space: nowrap;
    }
    .product__history {
      min-width: 12rem;
    }
    .product__retailer-inline,
    .narrow-only {
      display: none;
    }
    .product__off--none {
      display: table-cell !important;
    }
  }

  .price {
    font-weight: 700;
    font-size: var(--step-1);
    white-space: nowrap;
  }
  .price__from {
    font-weight: 400;
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .price__list {
    margin-left: var(--s2);
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  @media (min-width: 640px) {
    .price {
      font-size: var(--step-0);
    }
    .price__list {
      display: block;
      margin-left: 0;
    }
  }

  /* Each signal pairs its colour with words or a glyph, so colour is never the only cue. */
  .signal {
    display: inline-flex;
    align-items: center;
    gap: var(--s1);
    margin: 0 var(--s1) var(--s1) 0;
    padding: 0.1rem var(--s2);
    border-radius: var(--radius);
    font-size: var(--step--1);
    font-weight: 600;
    white-space: nowrap;
  }
  .signal--down {
    color: var(--down);
    background: var(--down-bg);
  }
  .signal--up {
    color: var(--up);
    background: var(--up-bg);
  }
  .signal--low {
    color: var(--low);
    background: var(--low-bg);
  }
  .signal--stale {
    color: var(--ink-muted);
    background: var(--tint);
  }
  .signal-note {
    display: block;
    font-size: var(--step--1);
    color: var(--ink-muted);
  }

  /* A symbol per stock state, so colour is never the only cue. */
  .stock {
    font-size: var(--step--1);
    white-space: nowrap;
  }
  .stock::before {
    margin-right: var(--s1);
  }
  .stock--in::before {
    content: "●";
    color: var(--down);
  }
  .stock--out {
    color: var(--up);
  }
  .stock--out::before {
    content: "○";
  }
  .stock--part::before {
    content: "◐";
    color: var(--low);
  }
  .stock--unknown,
  .stock--stale {
    color: var(--ink-muted);
  }
  .stock--unknown::before,
  .stock--stale::before {
    content: "?";
  }

  .options {
    margin-top: var(--s1);
    font-size: var(--step--1);
  }
  .options > summary {
    display: flex;
    align-items: center;
    width: max-content;
    max-width: 100%;
    min-height: var(--tap);
    color: var(--link);
  }
  .options ul {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--line);
  }
  .options li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: var(--s3);
    padding: var(--s1) 0;
    border-bottom: 1px dashed var(--line);
  }
  .options__stock {
    color: var(--ink-muted);
    text-align: right;
  }

  .store-button {
    display: inline-block;
    min-height: var(--tap);
    padding: 0.65rem var(--s3);
    line-height: 1.4;
    border: 1px solid var(--link);
    border-radius: var(--radius);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
  }
  .store-button:hover {
    background: var(--link);
    color: var(--on-dark);
  }
  .store-button--compact {
    padding-inline: var(--s2);
    font-weight: 400;
  }
}

@layer utilities {
  .num {
    font-variant-numeric: tabular-nums;
  }
  .muted {
    color: var(--ink-muted);
  }
  .small {
    font-size: var(--step--1);
  }
  .sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

@layer components {
  .change-group {
    margin-top: var(--s5);
  }
  .change-group__count {
    font-weight: 400;
    color: var(--ink-muted);
  }
  .changes {
    margin: 0;
    padding: 0;
    list-style: none;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .change {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s2) var(--s3);
    padding: var(--s3);
    border-bottom: 1px solid var(--line);
  }
  .change:last-child {
    border-bottom: 0;
  }
  .change__what {
    flex: 1 1 100%;
  }
  .change__title {
    font-weight: 600;
  }
  .change__meta {
    display: block;
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .change__detail {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s1) var(--s2);
  }
  .change__detail .signal {
    margin: 0;
  }
  .change__when {
    font-size: var(--step--1);
    font-weight: 600;
    color: var(--ink-muted);
    min-width: 3.5rem;
  }
  @media (min-width: 640px) {
    .change {
      flex-wrap: nowrap;
    }
    .change__what {
      flex: 1 1 50%;
    }
    .change__detail {
      flex: 0 0 auto;
      flex-wrap: nowrap;
      white-space: nowrap;
    }
  }

  /* Positioned so absolutely placed screen-reader text inside the table is clipped with it, not left at page width. */
  .table-scroll {
    position: relative;
    overflow-x: auto;
    margin-bottom: var(--s2);
  }
  .log {
    min-width: 34rem;
    background: var(--card);
    border: 1px solid var(--line);
  }
  .log th,
  .log td {
    padding: var(--s2) var(--s3);
    border-bottom: 1px solid var(--line);
    text-align: left;
  }
  .log thead th {
    background: var(--tint);
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .log .num {
    text-align: right;
  }
  .log tbody th {
    font-weight: 400;
    white-space: nowrap;
  }

  .more-links {
    margin-top: var(--s3);
  }
  .link-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--s4);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .link-list a {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
  }
}

@layer components {
  .buy-box {
    display: grid;
    gap: var(--s2);
    max-width: 36rem;
    margin-bottom: var(--s3);
    padding: var(--s4);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .buy-box .price {
    font-size: var(--step-2);
  }
  .buy-box__off {
    font-weight: 600;
  }
  .buy-box__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--s2) var(--s3);
  }
  .variants {
    min-width: 44rem;
    background: var(--card);
    border: 1px solid var(--line);
    font-size: var(--step--1);
  }
  .variants th,
  .variants td {
    padding: var(--s2) var(--s3);
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
  }
  .variants thead th {
    background: var(--tint);
    color: var(--ink-muted);
    white-space: nowrap;
  }
  .variants .num {
    text-align: right;
    white-space: nowrap;
  }

  .chart {
    margin: 0 0 var(--s4);
    padding: var(--s3);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .chart__title {
    display: block;
    font-weight: 700;
  }
  .chart__summary {
    display: block;
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .chart__plot {
    position: relative;
    height: 10rem;
    margin: var(--s4) 4.5rem var(--s2) 4.25rem;
  }
  .chart__plot svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
  }
  .chart__grid {
    stroke: var(--line);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
  }
  .chart__line {
    fill: none;
    stroke: var(--series);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
  }
  .chart__hit {
    fill: transparent;
  }
  .chart__tick,
  .chart__end {
    position: absolute;
    transform: translateY(-50%);
    font-size: var(--step--1);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  .chart__tick {
    right: 100%;
    padding-right: var(--s2);
    color: var(--ink-muted);
  }
  .chart__end {
    left: 100%;
    padding-left: var(--s3);
    font-weight: 700;
  }
  .chart__dot {
    position: absolute;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 50%;
    background: var(--series);
    box-shadow: 0 0 0 2px var(--card);
    transform: translate(-50%, -50%);
    pointer-events: none;
  }
  .chart__x {
    display: flex;
    justify-content: space-between;
    margin: 0 4.5rem 0 4.25rem;
    font-size: var(--step--1);
    color: var(--ink-muted);
  }
  .chart__cross {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--ink-muted);
    pointer-events: none;
  }
  .chart__tip {
    position: absolute;
    z-index: 1;
    padding: var(--s1) var(--s2);
    background: var(--ink);
    color: var(--on-dark);
    border-radius: var(--radius);
    font-size: var(--step--1);
    white-space: nowrap;
    transform: translate(-50%, calc(-100% - 0.75rem));
    pointer-events: none;
  }
  .chart__tip strong {
    display: block;
    font-variant-numeric: tabular-nums;
  }
  .chart__table {
    margin-top: var(--s3);
    font-size: var(--step--1);
  }
  .chart__table > summary {
    display: flex;
    align-items: center;
    width: max-content;
    min-height: var(--tap);
    color: var(--link);
  }
  .chart__table table {
    max-width: 32rem;
  }
  .chart__table th,
  .chart__table td {
    padding: var(--s1) var(--s2);
    border-bottom: 1px solid var(--line);
    text-align: left;
  }
  .chart__table .num {
    text-align: right;
  }

  .sparkline {
    display: block;
    margin-top: var(--s1);
    overflow: visible;
  }
  .sparkline__line {
    fill: none;
    stroke: var(--series);
    stroke-width: 2;
    stroke-linejoin: round;
  }
  .sparkline__dot {
    fill: var(--series);
    stroke: var(--card);
    stroke-width: 2;
  }
}
