:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #11151c;
  --muted: #5d6675;
  --border: #e2e5eb;
  --ai: #6d4aff;
  --hw: #d97706;
  --tech: #0891b2;
  --deal: #059669;
  --deal-bg: #e7f8f1;
  --price: #b45309;
  --danger: #dc2626;
  --accent: var(--ai);
  --on-accent: #fff;
  --radius: 14px;
  --content: 760px; /* page content width; wider on large screens */
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --safe-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d12; --surface: #151922; --surface-2: #1e2330; --text: #e9ecf2; --muted: #8e97a8;
    --border: #262c3a; --ai: #9d87ff; --hw: #f59e0b; --tech: #22d3ee; --deal: #34d399; --deal-bg: #10291f;
    --price: #fbbf24; --on-accent: #0b0d12; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d12; --surface: #151922; --surface-2: #1e2330; --text: #e9ecf2; --muted: #8e97a8;
  --border: #262c3a; --ai: #9d87ff; --hw: #f59e0b; --tech: #22d3ee; --deal: #34d399; --deal-bg: #10291f;
  --price: #fbbf24; --on-accent: #0b0d12; --shadow: none; color-scheme: dark;
}

body[data-tab="hardware"] { --accent: var(--hw); }
body[data-tab="tech"] { --accent: var(--tech); }
body[data-tab="saved"] { --accent: var(--text); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: calc(var(--safe-top) + 8px) calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: var(--content); margin: 0 auto; }
.topnav-wrap { display: none; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; flex: none; }
.brand h1 { margin: 0; font-size: 19px; line-height: 1.2; letter-spacing: -.01em; }
.status { background: none; border: 0; padding: 0; color: var(--muted); font-size: 12px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.status.warn::after { content: " ⚠"; color: var(--hw); }
.actions { display: flex; gap: 2px; flex: none; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: none; border: 0; color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.search-row { max-width: var(--content); margin: 8px auto 0; }
.search-row input {
  width: 100%; height: 40px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
}
.search-row input:focus { border-color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0; max-width: var(--content); margin: 0 auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chips-sub { padding-top: 0; }
.chip {
  flex: none; height: 32px; padding: 0 13px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
.chips-sub .chip { height: 28px; font-size: 12.5px; padding: 0 11px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }
select.chip { padding-right: 8px; max-width: 180px; }

.progress { height: 2px; margin: 0 calc(-16px - var(--safe-right)) 0 calc(-16px - var(--safe-left)); background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ── Pull to refresh ─────────────────────────────────── */
.ptr { height: 0; overflow: hidden; text-align: center; color: var(--muted); font-size: 13px; line-height: 44px; transition: height .2s; }
.ptr.pulling { transition: none; }

/* ── Cards ───────────────────────────────────────────── */
.list {
  max-width: var(--content); margin: 0 auto;
  padding: 12px calc(16px + var(--safe-right)) calc(96px + var(--safe-bottom)) calc(16px + var(--safe-left));
  display: grid; gap: 10px;
}
.day { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 2px 0; }
.card {
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 14px 10px; box-shadow: var(--shadow);
}
.card.read .title { color: var(--muted); font-weight: 500; }
.card .meta { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.card .src { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; white-space: nowrap; }
.badge.official { background: color-mix(in srgb, var(--ai) 14%, transparent); color: var(--ai); }
.badge.release { background: var(--ai); color: var(--on-accent); }
.badge.research { background: var(--surface-2); color: var(--muted); }
.badge.deal { background: var(--deal); color: var(--on-accent); }
.badge.price { background: color-mix(in srgb, var(--price) 16%, transparent); color: var(--price); }
.card .title {
  font-size: 15.5px; font-weight: 650; line-height: 1.35; color: var(--text); text-decoration: none;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card .title::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); } /* whole card is tappable */
.card .summary { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .thumb { grid-row: 2 / span 2; grid-column: 2; width: 84px; height: 84px; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.card .body { min-width: 0; }
.dealbox { display: flex; align-items: flex-start; gap: 12px; margin-top: 8px; padding: 10px; border-radius: 12px; background: var(--deal-bg); }
.dealprice { min-width: 0; display: grid; gap: 2px; }
.dealprice > div:first-child { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.dealbox .was { color: var(--muted); font-size: 13px; }
.rlabel { font-size: 12px; font-weight: 650; color: var(--text); }
.dealbox .save { font-size: 13px; font-weight: 600; color: var(--deal); }
.dealbox .hist { font-size: 12px; color: var(--muted); }
.dealbox .hist .good { color: var(--deal); }
.rating {
  --c: var(--muted); --pct: 0;
  flex: none; width: 54px; height: 54px; border-radius: 50%; display: grid; place-content: center; text-align: center; line-height: 1;
  background: radial-gradient(closest-side, var(--surface) 76%, transparent 78%), conic-gradient(var(--c) calc(var(--pct) * 1%), var(--surface-2) 0);
}
.rating b { font-size: 17px; font-weight: 750; color: var(--c); font-variant-numeric: tabular-nums; }
.rating small { font-size: 10px; color: var(--muted); }
.rating.none b { color: var(--muted); }
.rating.r5 { --c: #16a34a; } .rating.r4 { --c: #22c55e; } .rating.r3 { --c: #eab308; } .rating.r2 { --c: #f97316; } .rating.r1 { --c: #ef4444; }
.offers { position: relative; z-index: 1; margin-top: 8px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.offers-title { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 7px 10px; background: var(--surface-2); }
.offer { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; padding: 8px 10px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: 13.5px; }
.offer .store { font-weight: 600; }
.offer .oprice { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.offer .osave { font-size: 12px; color: var(--deal); }
.offer .ago { font-size: 12px; color: var(--muted); text-align: right; }
.offer.best .oprice { color: var(--deal); }
.offer.best .store::after { content: " · best price"; font-weight: 500; font-size: 11.5px; color: var(--deal); }
.offer:active { background: var(--surface-2); }
.card .meta .at { white-space: nowrap; }
.dealbox .amount { color: var(--deal); font-weight: 750; font-size: 16px; font-variant-numeric: tabular-nums; }
.dealbox .off { color: var(--deal); font-weight: 600; font-size: 12.5px; }
.card .foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.card .foot .spacer { flex: 1; }
.card .act { position: relative; z-index: 1; width: 34px; height: 34px; display: grid; place-items: center; background: none; border: 0; border-radius: 10px; color: var(--muted); }
.card .act svg { width: 19px; height: 19px; }
.card .act:active { background: var(--surface-2); }
.card .act.saved { color: var(--accent); }
.card .act.saved svg { fill: currentColor; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 6px; }
.more { justify-self: center; margin: 8px 0; }

/* ── Tab bar ─────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px var(--safe-right) calc(6px + var(--safe-bottom)) var(--safe-left);
}
.tabbar button {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 6px 0; border: 0; background: none;
  color: var(--muted); font-size: 11.5px; font-weight: 500;
}
.tabbar button svg { width: 24px; height: 24px; padding: 2px 14px; box-sizing: content-box; border-radius: 999px; }
.tabbar button.active { color: var(--text); }
.tabbar button[data-tab="ai"].active svg { background: color-mix(in srgb, var(--ai) 18%, transparent); color: var(--ai); }
.tabbar button[data-tab="hardware"].active svg { background: color-mix(in srgb, var(--hw) 18%, transparent); color: var(--hw); }
.tabbar button[data-tab="tech"].active svg { background: color-mix(in srgb, var(--tech) 18%, transparent); color: var(--tech); }
.tabbar button[data-tab="saved"].active svg { background: var(--surface-2); }
.dot { position: absolute; top: 2px; left: calc(50% + 10px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font: 700 10.5px/17px system-ui, sans-serif; font-style: normal; }
.dot:empty { display: none; }

/* ── Settings sheet ──────────────────────────────────── */
.sheet {
  width: 100%; max-width: 640px; max-height: 88vh; margin: auto auto 0; padding: 0;
  border: 1px solid var(--border); border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 8px 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
.sheet-head h2 { font-size: 17px; margin: 0; }
.sheet-body { padding: 8px 18px calc(24px + var(--safe-bottom)); }
.sheet h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 6px; }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 550; }
.row .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub.err { color: var(--danger); }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); transition: .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: .15s; }
.switch input:checked + span { background: var(--deal); border-color: var(--deal); }
.switch input:checked + span::after { transform: translateX(18px); }
.field { display: grid; gap: 8px; margin-top: 8px; }
.field input, .field select { height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.btn { height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.danger { color: var(--danger); }
.btn-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.note { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 7px 12px; font-size: 13px; }
.seg button.active { background: var(--text); color: var(--bg); }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); transform: translate(-50%, 20px); z-index: 20;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Wide screens: tabs in the top bar, stories in a grid ───────────── */
@media (min-width: 900px) {
  :root { --content: 1180px; }
  .tabbar { display: none; }
  .topbar { padding-left: calc(32px + var(--safe-left)); padding-right: calc(32px + var(--safe-right)); }
  .topbar-row { gap: 24px; }
  .brand { flex: 0 1 auto; min-width: 200px; }
  .status { max-width: 260px; }
  .topnav-wrap { flex: 1; display: flex; justify-content: center; }
  .topnav {
    display: inline-flex; gap: 4px; padding: 4px; border-radius: 16px;
    background: var(--surface); border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25), inset 0 1px 0 color-mix(in srgb, var(--text) 6%, transparent);
  }
  .topnav button {
    --c: var(--text);
    position: relative; display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px;
    border: 0; border-radius: 12px; background: none; color: var(--text); font-size: 14px; font-weight: 650; white-space: nowrap;
    transition: background .15s, color .15s, box-shadow .15s;
  }
  .topnav button[data-tab="ai"] { --c: var(--ai); }
  .topnav button[data-tab="hardware"] { --c: var(--hw); }
  .topnav button[data-tab="tech"] { --c: var(--tech); }
  .topnav button svg { width: 19px; height: 19px; color: var(--c); stroke-width: 2; }
  .topnav button:hover { background: color-mix(in srgb, var(--c) 14%, var(--surface-2)); }
  .topnav button:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; }
  .topnav button.active {
    background: var(--c); color: var(--on-accent);
    box-shadow: 0 2px 10px color-mix(in srgb, var(--c) 45%, transparent);
  }
  .topnav button.active svg { color: var(--on-accent); }
  .topnav button[data-tab="saved"].active { background: var(--text); color: var(--bg); box-shadow: 0 2px 10px rgba(0, 0, 0, .3); }
  .topnav button[data-tab="saved"].active svg { color: var(--bg); }
  .topnav .dot { position: static; margin-left: -2px; }
  .progress { margin-left: calc(-32px - var(--safe-left)); margin-right: calc(-32px - var(--safe-right)); }
  .search-row { max-width: 560px; }
  .list {
    grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); align-items: start; gap: 14px;
    padding: 16px calc(32px + var(--safe-right)) 48px calc(32px + var(--safe-left));
    max-width: calc(var(--content) + 64px);
  }
  .list > .empty, .list > .more { grid-column: 1 / -1; }
  /* Day headings would leave half-empty rows in a grid; each card shows its age instead. */
  .list > .day { display: none; }
  .card .title::after { cursor: pointer; }
  .card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
  .toast { bottom: 32px; }
  .ptr { display: none; }
  .sheet { margin: auto; border-radius: 20px; }
}
@media (min-width: 900px) and (max-width: 1040px) {
  .topnav button { padding: 0 10px; gap: 6px; font-size: 13.5px; }
  .brand { min-width: 0; }
  .status { max-width: 170px; }
}
@media (min-width: 1600px) {
  :root { --content: 1520px; }
}

/* ── Store button, disclosure, footer ─────────────────────────────────── */
.storebar { position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; margin: 10px 0 6px; flex-wrap: wrap; }
.storebtn {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 16px; border-radius: 10px;
  background: var(--deal); color: var(--on-accent); font-size: 14px; font-weight: 700; text-decoration: none;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--deal) 35%, transparent);
}
.storebtn:hover { filter: brightness(1.08); }
.storebtn:active { transform: translateY(1px); }
.disclose { font-size: 11.5px; color: var(--muted); }
.offers-note { font-size: 11.5px; color: var(--muted); padding: 7px 10px; border-top: 1px solid var(--border); }
.site-footer { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; padding: 20px 2px 8px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border); margin-top: 8px; }
.site-footer nav { display: flex; gap: 16px; }
.site-footer a, .note a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.site-footer a:hover, .note a:hover { color: var(--text); }
