:root {
  --bg: #0b0d10;
  --bg-elev: #14181d;
  --bg-card: #161b21;
  --line: #232a32;
  --text: #e8ebef;
  --muted: #8b97a5;
  --accent: #6ea8fe;
  --accent-2: #7ee2c0;
  --radius: 16px;
  --maxw: 640px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-elev: #ffffff;
    --bg-card: #ffffff;
    --line: #e6e9ee;
    --text: #131720;
    --muted: #5c6773;
    --accent: #2f6fed;
    --accent-2: #12a97a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: env(safe-area-inset-bottom); }

/* ── Top bar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px calc(14px);
  padding-top: calc(14px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -0.02em; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--accent-2), var(--accent));
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 60%, transparent);
}
.actions { display: flex; gap: 6px; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
  transition: transform .1s ease, border-color .2s ease;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Feed ── */
.feed {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.status {
  color: var(--muted);
  text-align: center;
  padding: 40px 16px;
  line-height: 1.6;
}
.status .big { display: block; font-size: 15px; color: var(--text); margin-bottom: 6px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .12s ease, border-color .2s ease;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.card:active { transform: scale(0.99); }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-body { padding: 16px 18px; }
.card-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted); margin-bottom: 8px;
}
.card-meta .interest {
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 11px;
}

/* Content-type badge */
.badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge.video { color: #ff7a7a; border-color: color-mix(in srgb, #ff7a7a 45%, var(--line)); }
.badge.pick { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 45%, var(--line)); }
.badge.hidden { display: none; }

/* Thumbnail (videos) */
.thumb-wrap { position: relative; display: none; aspect-ratio: 16 / 9; background: var(--bg-elev); overflow: hidden; }
.card.has-thumb .thumb-wrap { display: block; }
.thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.play {
  position: absolute; inset: 0; margin: auto; width: 52px; height: 52px;
  display: grid; place-items: center; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; font-size: 18px; padding-left: 3px;
  pointer-events: none;
}
.card-meta .src::before { content: "·"; margin-right: 8px; color: var(--muted); }
.card-title { margin: 0 0 6px; font-size: 17px; line-height: 1.32; letter-spacing: -0.01em; }
.card-summary { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.5; }
.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px; font-size: 12.5px; color: var(--muted);
}
.card-foot .read { color: var(--accent); font-weight: 600; }

.skeleton { height: 118px; background:
  linear-gradient(100deg, var(--bg-card) 40%, var(--bg-elev) 50%, var(--bg-card) 60%);
  background-size: 200% 100%; animation: sheen 1.3s infinite; border:1px solid var(--line); border-radius: var(--radius); }
@keyframes sheen { to { background-position: -200% 0; } }

/* ── Drawer ── */
.drawer {
  position: fixed; inset: 0; z-index: 30;
  background: color-mix(in srgb, #000 55%, transparent);
  display: flex; justify-content: center; align-items: flex-end;
}
.drawer[hidden] { display: none; }
.drawer-panel {
  width: 100%; max-width: var(--maxw);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: rise .22s ease;
}
@media (min-width: 680px) {
  .drawer { align-items: center; }
  .drawer-panel { border-radius: 20px; }
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.hint { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin: 8px 0 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--line);
  padding: 7px 10px 7px 12px; border-radius: 999px; font-size: 13.5px;
}
.chip button {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0;
}
.chip button:hover { color: #ff6b6b; }

.add-row { display: flex; gap: 8px; margin-bottom: 18px; }
input[type="text"], input[type="number"], select {
  width: 100%; padding: 11px 12px;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; font-size: 15px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; font-size: 14px; color: var(--muted); }
.field span { flex: 0 0 auto; }
.field input, .field select { max-width: 220px; }

.primary {
  background: var(--accent); color: #fff; border: none;
  padding: 11px 16px; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.primary:active { transform: scale(0.98); }
.primary.wide { width: 100%; margin-top: 8px; padding: 13px; }
.primary:disabled { opacity: .6; cursor: default; }

.provider-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 14px 0 4px; padding: 10px 12px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px; }
.provider-note.warn { border-color: color-mix(in srgb, #f5a623 50%, var(--line)); }

/* Reader sheet */
.ghost-btn {
  display: block; text-align: center; text-decoration: none;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; font-size: 15px; font-weight: 600;
}
.ghost-btn:active { transform: scale(0.98); }
.reader-panel .reader-src { font-size: 12px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.reader-title { margin: 6px 0 10px; font-size: 20px; line-height: 1.3; letter-spacing: -0.01em; }
.reader-open-link { display: inline-block; margin-bottom: 14px; color: var(--muted); font-size: 13px; text-decoration: none; border-bottom: 1px solid var(--line); padding-bottom: 1px; }
.reader-open-link:hover { color: var(--accent); }
.reader-choices { display: flex; flex-direction: column; gap: 10px; }
.reader-choices .primary.wide { margin-top: 0; }
.reader-body { margin-top: 4px; }
.reader-body p { margin: 0 0 14px; line-height: 1.62; font-size: 15.5px; color: var(--text); }
.reader-body .reader-loading, .reader-body .reader-error { color: var(--muted); padding: 20px 0; text-align: center; }
.reader-body .reader-origin { display: inline-block; margin-top: 6px; color: var(--accent); font-weight: 600; text-decoration: none; }
.reader-note { font-size: 12px; color: var(--muted); margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

/* Pull-to-refresh indicator */
.pull-indicator {
  position: fixed; top: -46px; left: 0; right: 0; height: 46px; z-index: 8;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 13px; color: var(--muted); opacity: 0; pointer-events: none;
}
.pull-indicator .pull-icon { display: inline-block; font-size: 16px; transition: transform .15s ease; }
.pull-indicator.ready .pull-icon { transform: rotate(180deg); color: var(--accent); }
.pull-indicator.spin .pull-icon { animation: spin .8s linear infinite; }
