:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.12);
  --est: #b25000;
  --est-soft: rgba(178, 80, 0, 0.1);
  --iphone: #0071e3;
  --ipad: #8e44ad;
  --laptop: #1a8a4a;
  --desktop: #c0392b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --line: #38383a;
    --accent: #2997ff;
    --accent-soft: rgba(41, 151, 255, 0.16);
    --est: #ff9f0a;
    --est-soft: rgba(255, 159, 10, 0.14);
    --iphone: #2997ff;
    --ipad: #bf5af2;
    --laptop: #30d158;
    --desktop: #ff6961;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --line: #38383a;
    --accent: #2997ff;
    --accent-soft: rgba(41, 151, 255, 0.16);
    --est: #ff9f0a;
    --est-soft: rgba(255, 159, 10, 0.14);
    --iphone: #2997ff;
    --ipad: #bf5af2;
    --laptop: #30d158;
    --desktop: #ff6961;
    --shadow: none;
    color-scheme: dark;
  }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

/* ---------- header / controls ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  padding: 18px 0 14px;
}
.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 26px; letter-spacing: -0.02em; margin: 0; }
.meta { margin: 0; color: var(--muted); font-size: 13px; }

.controls { margin-top: 14px; display: grid; gap: 12px; }
.range-labels { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; }
.range-labels output { font-weight: 600; font-size: 17px; }
.range-count { color: var(--muted); font-size: 13px; }

.histogram { display: flex; align-items: flex-end; gap: 2px; height: 34px; margin: 8px 0 0; }
.histogram span { flex: 1; background: var(--line); border-radius: 2px 2px 0 0; min-height: 2px; transition: background .15s; }
.histogram span.in { background: var(--accent); opacity: .55; }

.dual-range { position: relative; height: 28px; }
.track { position: absolute; left: 0; right: 0; top: 12px; height: 4px; border-radius: 2px; background: var(--line); }
.track-fill { position: absolute; top: 0; bottom: 0; background: var(--accent); border-radius: 2px; }
.dual-range input[type=range] {
  position: absolute; inset: 0; width: 100%; margin: 0;
  background: none; pointer-events: none; -webkit-appearance: none; appearance: none;
}
.dual-range input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 1px solid rgba(0,0,0,.08);
  box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: grab;
}
.dual-range input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 1px solid rgba(0,0,0,.08); box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: grab;
}
.dual-range input[type=range]::-moz-range-track { background: none; }
.dual-range input[type=range]:focus-visible::-webkit-slider-thumb { outline: 3px solid var(--accent-soft); }

.filters { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 5px 12px 5px 10px; font: inherit; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip[aria-pressed=false] { opacity: .45; }
.chip[aria-pressed=false] .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.toggles { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.toggle { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); cursor: pointer; }
.sort {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 5px 10px; font: inherit; font-size: 13px; cursor: pointer;
}

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 24px 0; padding: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 86px; top: 6px; bottom: 6px; width: 2px; background: var(--line);
}
.stop { display: grid; grid-template-columns: 74px 1fr; gap: 24px; padding: 6px 0 14px; position: relative; }
.stop::before {
  content: ""; position: absolute; left: 81px; top: 13px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--accent);
}
.stop-price {
  text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; padding-top: 6px; font-size: 15px;
}
.stop-items { display: grid; gap: 8px; min-width: 0; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px 12px 12px; border-left: 4px solid var(--c); min-width: 0;
  display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: center;
  color: inherit; text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.card:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 10px 28px rgba(0,0,0,.08); }
.card:hover .go { text-decoration: underline; }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card.est { border-left-style: dashed; }
.thumb {
  width: 64px; height: 64px; object-fit: contain; border-radius: 10px;
  background: #fff; /* Apple's product shots are on white */
}
.body { display: grid; gap: 6px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card .cat { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.specs { display: flex; gap: 4px; flex-wrap: wrap; min-width: 0; }
.spec { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--bg); color: var(--text); }
.spec.hl { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.spec.add { background: var(--est-soft); color: var(--est); font-weight: 500; }
.card .go { font-size: 13px; white-space: nowrap; color: var(--accent); }
.card .sub { font-size: 12px; color: var(--muted); }
.card .sub b { color: var(--est); font-weight: 600; }

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

.notes { border-top: 1px solid var(--line); margin: 32px 0 48px; padding-top: 16px; color: var(--muted); font-size: 13px; }
.notes h2 { font-size: 14px; color: var(--text); margin: 0 0 8px; }
.notes ul { margin: 0 0 12px; padding-left: 18px; }
.notes li { margin: 2px 0; }

@media (max-width: 600px) {
  h1 { font-size: 21px; }
  .timeline::before { left: 62px; }
  .stop { grid-template-columns: 52px 1fr; gap: 20px; }
  .stop::before { left: 57px; }
  .stop-price { font-size: 13px; }
  .card { grid-template-columns: 44px 1fr; gap: 10px; padding: 10px; align-items: start; }
  .thumb { width: 44px; height: 44px; }
  .head { flex-direction: column; gap: 0; }
  .filters { align-items: flex-start; }
}

/* ---------- product-type chips ---------- */
.chips.models { gap: 5px; }
.chip.small { font-size: 12px; padding: 3px 10px; border-color: color-mix(in srgb, var(--c) 35%, var(--line)); }
.chip.small[aria-pressed=true] { background: color-mix(in srgb, var(--c) 12%, var(--surface)); }
.chip.small[aria-pressed=false] { opacity: .5; text-decoration: line-through; }

/* ---------- card: whole tile is a link, compare button sits above it ---------- */
.card { position: relative; }
.card-link { position: absolute; inset: 0; border-radius: inherit; z-index: 1; }
.card-link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card .cmp-btn { position: relative; z-index: 2; }
.card:hover { cursor: pointer; }
.card.picked { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.actions { display: flex; gap: 10px; align-items: center; }
.cmp-btn {
  font: inherit; font-size: 12px; border-radius: 999px; padding: 3px 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}
.cmp-btn:hover { color: var(--accent); border-color: var(--accent); }
.cmp-btn[aria-pressed=true] { background: var(--accent); color: #fff; border-color: var(--accent); }
.card h3 .size { font-weight: 600; }
.card h3 .size.diff, .spec.diff, .detail.diff-text {
  background: var(--diff-bg); color: var(--diff-fg); border-radius: 6px;
}
.card h3 .size.diff { padding: 0 6px; }
.spec.diff { box-shadow: inset 0 0 0 1.5px var(--diff-fg); font-weight: 600; }
.detail { font-size: 13px; color: var(--text); }
.detail.diff-text { display: inline-block; padding: 1px 6px; justify-self: start; }

:root { --diff-bg: #fff4c2; --diff-fg: #7a5200; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --diff-bg: #3d3210; --diff-fg: #ffd60a; }
}
:root[data-theme="dark"] { --diff-bg: #3d3210; --diff-fg: #ffd60a; }

/* ---------- compare tray ---------- */
.tray {
  position: sticky; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 20px rgba(0,0,0,.08);
}
.tray-inner { max-width: 920px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.tray-items { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.tray-item {
  font-size: 12px; border-radius: 8px; padding: 4px 4px 4px 10px; border-left: 3px solid var(--c);
  background: var(--bg); display: inline-flex; align-items: center; gap: 6px;
}
.tray-item .x { border: 0; background: none; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; padding: 0 4px; }
.tray-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tray-note { font-size: 12px; color: var(--est); }
.link { font-size: 13px; }
.primary {
  font: inherit; font-size: 13px; font-weight: 500; border: 0; border-radius: 999px; padding: 7px 16px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.primary:disabled { background: var(--line); color: var(--muted); cursor: default; }

/* ---------- compare dialog ---------- */
.compare-dialog {
  width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.compare-dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-head {
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  display: flex; gap: 16px; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.dialog-head h2 { font-size: 18px; margin: 0; margin-right: auto; }
.close { border: 0; background: var(--bg); color: var(--text); width: 30px; height: 30px; border-radius: 50%; font-size: 18px; cursor: pointer; }
.table-wrap { overflow: auto; max-height: calc(100vh - 120px); }
.compare-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.compare-table th, .compare-table td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.compare-table thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; font-size: 14px; min-width: 160px; }
.compare-table thead img { width: 72px; height: 72px; object-fit: contain; background: #fff; border-radius: 10px; display: block; margin-bottom: 6px; }
.compare-table thead a { font-weight: 400; font-size: 12px; }
.compare-table tbody th { color: var(--muted); font-weight: 500; width: 170px; white-space: nowrap; }
.compare-table tr.differs td { background: var(--diff-bg); color: var(--diff-fg); }
.compare-table tr.differs th { color: var(--text); }
.compare-table tr.model-row:first-of-type th { padding-top: 16px; }

@media (max-width: 600px) {
  .tray-inner { padding: 8px 12px; }
  .compare-table tbody th { white-space: normal; width: 110px; }
  .compare-table thead th { min-width: 130px; }
}

/* ---------- per-product colors (cycled within each category) ---------- */
:root {
  --m0: #0071e3; --m1: #c35a00; --m2: #1a8a4a; --m3: #8e44ad; --m4: #d70015;
  --m5: #0a7f86; --m6: #c2185b; --m7: #4b4fc4; --m8: #8a6d3b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --m0: #2997ff; --m1: #ff9f0a; --m2: #30d158; --m3: #bf5af2; --m4: #ff6961;
    --m5: #40c8e0; --m6: #ff6fae; --m7: #7d7aff; --m8: #c8a26b;
  }
}
:root[data-theme="dark"] {
    --m0: #2997ff; --m1: #ff9f0a; --m2: #30d158; --m3: #bf5af2; --m4: #ff6961;
    --m5: #40c8e0; --m6: #ff6fae; --m7: #7d7aff; --m8: #c8a26b;
  }
.chip.small { gap: 6px; padding-left: 8px; border-color: color-mix(in srgb, var(--c) 45%, var(--line)); }
.chip.small .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip.small[aria-pressed=true] { background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--text); }
.chip.small[aria-pressed=false] .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.card .cat::before { content: "· "; }
.card h3 { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.card h3::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); align-self: center; flex: none; }
.card .cat { margin-left: 0; }

/* ---------- display-size chips ---------- */
.row-label { font-size: 12px; color: var(--muted); align-self: center; margin-right: 2px; }
.chip.size-chip { --c: var(--muted); padding-left: 10px; font-variant-numeric: tabular-nums; }
.chip.size-chip[aria-pressed=true] { background: var(--surface); border-color: var(--text); }
#sizeChips:empty { display: none; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 20px 0 32px; color: var(--muted); font-size: 12px; }
.site-footer p { margin: 0 0 6px; max-width: 720px; }
.site-footer b { color: var(--text); }

/* ---------- header controls: view toggles + theme switch ---------- */
.title-row { align-items: center; }
.title-text { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-width: 0; }
.view-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.pill {
  font: inherit; font-size: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center;
}
.pill[aria-pressed=false] { color: var(--muted); }
.pill .badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; line-height: 16px; }
.controls[hidden], .control-block[hidden] { display: none !important; }
.control-block { display: grid; gap: 12px; }
.collapsed-summary { font-size: 12px; color: var(--muted); }
@media (max-width: 600px) {
  .view-controls { margin-left: 0; width: 100%; }
}

/* ---------- theme switch (same component as innovatory.xyz) ---------- */
.theme-mount { display: inline-flex; }
.theme-switch {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.theme-switch button {
  appearance: none; -webkit-appearance: none; border: 0; margin: 0; padding: 0;
  width: 32px; height: 26px; border-radius: 999px; background: transparent; color: var(--muted);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: background .16s ease, color .16s ease;
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-checked="true"] { background: var(--bg); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.theme-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-switch svg { width: 15px; height: 15px; display: block; }

/* title on the left, controls pinned top right */
.title-row { flex-wrap: nowrap; align-items: flex-start; }
.title-text { flex-direction: column; gap: 2px; align-items: flex-start; }
.view-controls { flex-wrap: nowrap; }
@media (max-width: 600px) {
  .title-row { flex-wrap: wrap; }
  .view-controls { width: auto; margin-left: auto; }
  .theme-switch button { width: 27px; height: 24px; }
}

/* ---------- intro, select ---------- */
.tagline { margin: 2px 0 0; font-size: 15px; color: var(--text); }
.meta { font-size: 12px; }
.select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; margin-left: 4px;
}

/* ---------- grouped Mac upgrades ---------- */
.upgrades { position: relative; z-index: 2; margin-top: 2px; font-size: 13px; }
.upgrades summary {
  cursor: pointer; color: var(--accent); font-weight: 500; list-style: none; width: fit-content;
  padding: 3px 10px; border-radius: 999px; background: var(--accent-soft);
}
.upgrades summary::-webkit-details-marker { display: none; }
.upgrades summary::before { content: "▸ "; }
.upgrades[open] summary::before { content: "▾ "; }
.upgrades ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.upgrades li {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 12px; align-items: center;
  padding: 5px 8px; border-radius: 8px; background: var(--bg);
}
.upgrades li.out { opacity: .45; }
.upgrades li a { color: var(--text); }
.upgrades li a:hover { color: var(--accent); }
.up-delta { color: var(--muted); font-variant-numeric: tabular-nums; }
.up-price { font-variant-numeric: tabular-nums; }

/* ---------- sticky price labels ---------- */
.stop { align-items: start; }
.stop-price { position: sticky; top: calc(var(--header-h, 0px) + 10px); }

/* ---------- fade-in on filter changes ---------- */
@keyframes stopIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.timeline.animate .stop { animation: stopIn .28s ease both; }
.timeline.animate .stop:nth-child(n+2) { animation-delay: .03s; }
.timeline.animate .stop:nth-child(n+4) { animation-delay: .06s; }
.timeline.animate .stop:nth-child(n+8) { animation-delay: .09s; }
@media (prefers-reduced-motion: reduce) { .timeline.animate .stop { animation: none; } }

/* ---------- compact view ---------- */
body.compact .card { grid-template-columns: 1fr; padding: 8px 12px; }
body.compact .thumb, body.compact .card .sub { display: none; }
body.compact .body { gap: 4px; }
body.compact .stop { padding-bottom: 8px; }
.pill[aria-pressed=true]#toggleCompact { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- tip jar ---------- */
.tip-jar {
  display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 16px; color: var(--text); font-size: 14px;
}
.tip-jar p { margin: 0; max-width: 560px; }
.tip-btn { text-decoration: none; display: inline-block; }
.tip-btn:hover { text-decoration: none; filter: brightness(1.08); }
@media (max-width: 600px) {
  .upgrades li { grid-template-columns: 1fr auto; }
  .upgrades li .up-delta { display: none; }
  .tagline { font-size: 14px; }
}
.card { align-items: start; }

/* ---------- tip button (header) ---------- */
.tip-icon {
  display: inline-flex; align-items: center; gap: 5px; height: 34px; padding: 0 12px 0 10px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--text); font-size: 12px; font-weight: 500; text-decoration: none;
  transition: color .16s ease, border-color .16s ease;
}
.tip-icon[hidden] { display: none; }
.tip-icon:hover { text-decoration: none; color: #c35a00; border-color: #c35a00; }
.tip-icon svg { width: 16px; height: 16px; display: block; }
@media (max-width: 600px) { .tip-icon span { display: none; } .tip-icon { padding: 0 9px; } }
.pill, .tip-icon { white-space: nowrap; }
.title-text { min-width: 0; flex: 1; }
.tip-icon { height: 30px; }
