/*
 * ─────────────────────────────────────────
 *  3-COLOUR SYSTEM
 *  --bg   #0D0D0D   background
 *  --fg   #FFFFFF   text & elements
 *  --ac   #5C5CE0   accent (one colour)
 * ─────────────────────────────────────────
 *
 *  Layout tokens
 *  --topbar-h  44px
 *  --col-w     430px   (mobile column)
 *  --sb-w      260px   (desktop sidebar)
 *  --cx        600px   (half of 1200px max content)
 */

:root {
  --bg:      #0D0D0D;
  --bg2:     #141414;
  --bg3:     #1E1E1E;
  --fg:      #FFFFFF;
  --fg2:     rgba(255,255,255,.5);
  --fg3:     rgba(255,255,255,.08);
  --ac:      #5C5CE0;

  /* Semantic tokens (adapt to theme) */
  --text-body:    rgba(255,255,255,.82);
  --watermark:    rgba(255,255,255,.05);
  --border-hover: rgba(255,255,255,.25);
  --flank-bg:     #080808;

  --topbar-h: 44px;
  --col-w:    430px;
  --sb-w:     260px;
  --cx:       600px;
}

/* ── Light theme overrides ──────────────────── */
[data-theme="light"] {
  --bg:      #F5F5F5;
  --bg2:     #FFFFFF;
  --bg3:     #E2E2E2;
  --fg:      #111111;
  --fg2:     rgba(0,0,0,.5);
  --fg3:     rgba(0,0,0,.06);

  --text-body:    rgba(0,0,0,.82);
  --watermark:    rgba(0,0,0,.04);
  --border-hover: rgba(0,0,0,.2);
  --flank-bg:     #EBEBEB;
}

/* ── Reset ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; background: none; border: none; color: inherit; }
img    { display: block; }

/* ══════════════════════════════════════════
   TOP BAR
══════════════════════════════════════════ */
#topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--bg3);
}

#progress-bar {
  height: 2px;
  width: 0%;
  background: var(--ac);
  transition: width .3s ease;
}

#topbar-inner {
  display: flex;
  align-items: center;
  height: calc(var(--topbar-h) - 2px);
  padding: 0 14px;
  gap: 12px;
}

/* ── Filter pills (topbar — mobile/tablet) */
#product-filter {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
#product-filter::-webkit-scrollbar { display: none; }

.filter-pill {
  padding: 4px 13px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--bg3);
  color: var(--fg2);
  background: transparent;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, background .15s;
}
.filter-pill:hover  { color: var(--fg); border-color: var(--border-hover); }
.filter-pill.active { background: var(--ac); border-color: var(--ac); color: var(--fg); }

/* ── Theme toggle button */
.theme-toggle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg2);
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.theme-toggle:hover {
  color: var(--fg);
  background: var(--fg3);
}
.theme-toggle svg {
  width: 15px;
  height: 15px;
  pointer-events: none;
}

/* Sun shown in dark mode (to switch to light), moon shown in light mode (to switch to dark) */
[data-theme="dark"]  .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun  { display: none; }

/* ── Card counter */
#card-counter {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg2);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ══════════════════════════════════════════
   SIDEBAR  (desktop only — hidden by default)
══════════════════════════════════════════ */
#sidebar {
  display: none;
}

/* ══════════════════════════════════════════
   APP COLUMN  (mobile / tablet)
══════════════════════════════════════════ */
#app {
  position: fixed;
  top: var(--topbar-h);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--col-w);
  bottom: 0;
  overflow: hidden;
}

/* ══════════════════════════════════════════
   SKELETON
══════════════════════════════════════════ */
#skeleton {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.sk-visual {
  height: 42%;
  flex-shrink: 0;
  background: var(--bg2);
  animation: pulse 1.6s ease-in-out infinite;
}

.sk-body {
  flex: 1;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sk {
  background: var(--bg2);
  border-radius: 5px;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: .4; }
  50%       { opacity: .85; }
}

.sk-row   { display: flex; gap: 10px; align-items: center; }
.sk-badge { width: 76px; height: 19px; border-radius: 999px; }
.sk-date  { width: 56px; height: 13px; }
.sk-title { height: 24px; width: 85%; }
.sk-short { width: 55%; }
.sk-block {
  border: 1px solid var(--bg3);
  border-radius: 10px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sk-tag  { width: 80px; height: 11px; border-radius: 999px; }
.sk-line { height: 13px; width: 100%; }
.sk-med  { width: 68%; }

/* ══════════════════════════════════════════
   FEED
══════════════════════════════════════════ */
#feed {
  position: absolute;
  inset: 0;
  scroll-snap-type: y mandatory;
  overflow-y: scroll;
  scrollbar-width: none;
}
#feed::-webkit-scrollbar { display: none; }

/* ══════════════════════════════════════════
   CARD  (mobile / tablet — vertical stack)
══════════════════════════════════════════ */
.card {
  height: 100%;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--bg3);
  background: var(--bg);
  overflow: hidden;
}

/* Visual area */
.card-visual {
  height: 42%;
  flex-shrink: 0;
  position: relative;
  background: var(--bg2);
  border-top: 3px solid var(--ac);
  overflow: hidden;
}

.card-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-visual-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 9vw, 52px);
  font-weight: 900;
  color: var(--watermark);
  text-transform: uppercase;
  letter-spacing: .04em;
  pointer-events: none;
  text-align: center;
  padding: 12px;
}

/* Body */
.card-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 14px 70px 12px 16px;   /* right clears mobile FABs */
  gap: 10px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.product-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--ac);
  color: var(--fg);
  white-space: nowrap;
}

.new-chip {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  padding: 3px 8px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid #EF4444;
  color: #EF4444;
  text-transform: uppercase;
  white-space: nowrap;
}

.card-date {
  font-size: 12px;
  color: var(--fg2);
  margin-left: auto;
  white-space: nowrap;
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--fg);
  flex-shrink: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* Info blocks */
.info-block {
  border: 1px solid var(--bg3);
  border-radius: 10px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}

.info-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ac);
}
.info-tag.impact { color: var(--fg2); }

.info-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-body);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

/* Inline card actions (desktop only — hidden on mobile) */
.card-actions {
  display: none;
}

/* Scroll hint */
.scroll-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
  color: var(--fg2);
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
  transition: opacity .35s ease;
}
.scroll-hint.hidden { opacity: 0; pointer-events: none; }
.scroll-hint svg    { width: 14px; height: 14px; flex-shrink: 0; }

/* Empty / error state */
.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--fg2);
  font-size: 14px;
  text-align: center;
  padding: 40px;
}
.empty-state .empty-title { font-size: 16px; font-weight: 600; color: var(--fg); }

/* ══════════════════════════════════════════
   FLOATING BUTTONS  (mobile / tablet)
══════════════════════════════════════════ */
.fabs {
  position: fixed;
  right: 8px;
  bottom: 80px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fab {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: background .15s, transform .15s;
}
.fab:hover  { background: var(--bg3); transform: scale(1.07); }
.fab:active { transform: scale(.95); }
.fab-ico { width: 18px; height: 18px; }
.fab-lbl {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fg2);
}
.fab.saved .fab-ico { stroke: #EF4444; }

/* Install FAB — accent coloured to stand out */
.fab--install            { border-color: var(--ac); }
.fab--install .fab-ico   { stroke: var(--ac); }
.fab--install .fab-lbl   { color: var(--ac); }

/* ══════════════════════════════════════════
   TOAST
══════════════════════════════════════════ */
#toast {
  position: fixed;
  top: 54px;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  opacity: 0;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  z-index: 200;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ══════════════════════════════════════════
   BRANDING (mobile only)
══════════════════════════════════════════ */
#branding {
  position: fixed;
  bottom: 8px;
  left: 14px;
  font-size: 11px;
  color: var(--fg);
  opacity: 0.28;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
  letter-spacing: .04em;
}

/* ══════════════════════════════════════════
   SEARCH BAR  (mobile / tablet — topbar)
══════════════════════════════════════════ */
#search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: 0;
  overflow: hidden;
  transition: height .2s ease, padding-bottom .2s ease;
}
body.search-open #search-bar {
  height: 40px;
  padding-bottom: 6px;
}
/* Push #app down to clear the extra search row */
body.search-open #app {
  top: calc(var(--topbar-h) + 40px);
}

#search-input {
  flex: 1;
  height: 30px;
  background: var(--bg3);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--fg);
  outline: none;
  font-family: inherit;
  transition: border-color .15s;
  -webkit-appearance: none;
}
#search-input::placeholder         { color: var(--fg2); }
#search-input:focus                 { border-color: var(--ac); }
#search-input::-webkit-search-cancel-button { display: none; }

#search-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--fg2);
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
#search-clear:hover { color: var(--fg); background: var(--fg3); }
#search-clear svg   { width: 14px; height: 14px; pointer-events: none; }

/* Accent the search toggle icon when the bar is open */
body.search-open #search-toggle { color: var(--ac); }

/* ══════════════════════════════════════════
   TABLET  ≥ 600px  (same card, wider column)
══════════════════════════════════════════ */
@media (min-width: 600px) {
  .card-title  { font-size: 20px; }
  .info-text   { font-size: 14px; }
}

/* FABs fall into the gutter when viewport > 542px */
@media (min-width: 542px) {
  .card-body { padding-right: 16px; }
}

/* ══════════════════════════════════════════
   DESKTOP  ≥ 1024px
   Layout: sidebar (260px) + main feed
   Content max: 1200px, centred in 1440px
══════════════════════════════════════════ */
@media (min-width: 1024px) {

  /* ── Topbar ── */
  #topbar-inner {
    padding: 0 24px;
    justify-content: flex-end;   /* counter right-aligned on desktop */
  }
  /* Hide mobile filter pills — sidebar handles it */
  #product-filter { display: none; }

  /* Hide mobile branding — sidebar shows it */
  #branding { display: none; }

  /* Hide mobile FABs — inline card actions used instead */
  .fabs { display: none; }

  /* ── Sidebar ── */
  #sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--topbar-h);
    /* left edge = half-viewport minus half-content */
    left: max(0px, calc(50% - var(--cx)));
    width: var(--sb-w);
    height: calc(100vh - var(--topbar-h));
    padding: 28px 20px 24px;
    border-right: 1px solid var(--bg3);
    overflow-y: auto;
    scrollbar-width: none;
    z-index: 60;
    gap: 0;
  }
  #sidebar::-webkit-scrollbar { display: none; }

  .sb-brand {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 24px;
  }

  .sb-title {
    font-size: 18px;
    font-weight: 800;
    line-height: 1.2;
    color: var(--fg);
    letter-spacing: -.01em;
  }

  .sb-tagline {
    font-size: 11px;
    color: var(--fg2);
    letter-spacing: .03em;
  }

  .sb-divider {
    height: 1px;
    background: var(--bg3);
    margin-bottom: 24px;
  }

  .sb-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 28px;
  }

  .sb-section--push {
    margin-top: auto;
    margin-bottom: 0;
    padding-top: 24px;
    border-top: 1px solid var(--bg3);
  }

  .sb-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--fg2);
    margin-bottom: 4px;
  }

  /* Sidebar category buttons */
  #sidebar-filter {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .sb-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--fg2);
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background .15s, color .15s;
  }
  .sb-item:hover  { background: var(--bg2); color: var(--fg); }
  .sb-item.active { background: var(--ac); color: var(--fg); }
  .sb-item.active .sb-count { color: rgba(255,255,255,.7); }

  .sb-count {
    font-size: 12px;
    color: var(--fg2);
    font-variant-numeric: tabular-nums;
    font-weight: 400;
  }

  /* Keyboard hint */
  .sb-keys {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--fg2);
  }

  .sb-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: var(--bg2);
    border: 1px solid var(--bg3);
    font-size: 13px;
    font-family: inherit;
    color: var(--fg);
    font-style: normal;
  }

  .sb-key-hint {
    font-size: 12px;
    color: var(--fg2);
  }

  /* ── App column: right of sidebar ── */
  #app {
    position: fixed;
    top: var(--topbar-h);
    /* left edge = sidebar right edge */
    left: calc(max(0px, calc(50% - var(--cx))) + var(--sb-w));
    /* right edge = symmetric to left of content */
    right: max(0px, calc(50% - var(--cx)));
    bottom: 0;
    max-width: none;
    width: auto;
    transform: none;
  }

  /* ── Skeleton: horizontal split to match desktop card ── */
  #skeleton {
    flex-direction: row;
  }

  .sk-visual {
    width: 45%;
    height: 100%;
    flex-shrink: 0;
  }

  .sk-body {
    flex: 1;
    padding: 32px 40px;
    gap: 16px;
  }

  .sk-title { height: 32px; }

  /* ── Card: horizontal layout on desktop ── */
  .card {
    flex-direction: row;
  }

  .card-visual {
    width: 45%;
    height: 100%;
    flex-shrink: 0;
    border-top: none;
    border-right: 3px solid var(--ac);
  }

  .card-visual-label {
    font-size: clamp(32px, 4vw, 64px);
  }

  /* Body: right pane, scrollable if overflow */
  .card-body {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    scrollbar-width: none;
    padding: 36px 48px 32px 40px;
    gap: 16px;
  }
  .card-body::-webkit-scrollbar { display: none; }

  .card-meta  { gap: 10px; }

  .product-badge {
    font-size: 11px;
    padding: 4px 12px;
  }

  .card-title {
    font-size: 30px;
    font-weight: 800;
    line-height: 1.25;
    -webkit-line-clamp: unset;
    display: block;
    overflow: visible;
  }

  .info-block {
    padding: 16px 18px;
    border-radius: 12px;
    gap: 8px;
    flex-shrink: 0;
  }

  .info-tag  { font-size: 11px; }

  .info-text {
    font-size: 15px;
    line-height: 1.65;
    -webkit-line-clamp: unset;
    display: block;
    overflow: visible;
  }

  /* Inline card actions (shown on desktop) */
  .card-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: auto;
    padding-top: 20px;
    flex-shrink: 0;
  }

  .card-act {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--fg2);
    background: var(--bg2);
    border: 1px solid var(--bg3);
    cursor: pointer;
    transition: background .15s, color .15s, transform .12s;
  }
  .card-act:hover  { background: var(--bg3); color: var(--fg); transform: translateY(-1px); }
  .card-act:active { transform: translateY(0); }

  .act-ico {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }

  .card-act.act-saved .act-ico { stroke: #EF4444; }

  /* Scroll hint: hidden on desktop (sidebar shows keyboard nav) */
  .scroll-hint { display: none; }

  /* ── Hide mobile search toggle + bar on desktop ── */
  #search-toggle,
  #search-bar { display: none; }
  /* Also undo any body.search-open top shift on desktop */
  body.search-open #app { top: var(--topbar-h); }

  /* ── Sidebar search input ── */
  .sb-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
  }

  .sb-search-icon {
    position: absolute;
    left: 10px;
    width: 14px;
    height: 14px;
    color: var(--fg2);
    pointer-events: none;
    flex-shrink: 0;
  }

  #sb-search-input {
    width: 100%;
    height: 34px;
    background: var(--bg3);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 32px 0 30px;
    font-size: 13px;
    color: var(--fg);
    outline: none;
    font-family: inherit;
    transition: border-color .15s;
    -webkit-appearance: none;
  }
  #sb-search-input::placeholder { color: var(--fg2); }
  #sb-search-input:focus         { border-color: var(--ac); }
  #sb-search-input::-webkit-search-cancel-button { display: none; }

  #sb-search-clear {
    position: absolute;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    color: var(--fg2);
    transition: color .15s, background .15s;
  }
  #sb-search-clear:hover { color: var(--fg); background: var(--fg3); }
  #sb-search-clear svg   { width: 12px; height: 12px; pointer-events: none; }

  /* ── PWA Install button ── */
  .sb-install-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ac);
    background: var(--bg2);
    border: 1px solid var(--ac);
    cursor: pointer;
    transition: background .15s, opacity .15s;
    letter-spacing: .01em;
  }
  .sb-install-btn:hover { background: var(--bg3); }
  .sb-install-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    stroke: var(--ac);
  }
}

/* ══════════════════════════════════════════
   LARGE DESKTOP  ≥ 1440px
   (dark flanks appear outside 1200px content)
══════════════════════════════════════════ */
@media (min-width: 1440px) {
  body { background: var(--flank-bg); }
  #sidebar { border-left: 1px solid var(--bg3); }
  #app     { border-right: 1px solid var(--bg3); }
}

/* ══════════════════════════════════════════
   REDUCED MOTION
══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
