:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1d1d1b);
  --hint: var(--tg-theme-hint-color, #8a8a85);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --btn: var(--tg-theme-button-color, #2a7ae2);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #f4f4f2));
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 128, 0.2));
  --hot: #e8590c;
  --warm: #e0a030;
  --cool: #9a9a92;
  --danger: var(--tg-theme-destructive-text-color, #d9480f);
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) { --bg: #17181a; --text: #ecece8; --card: #222326; --hint: #9a9a92; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 16px 0; border-bottom: 1px solid var(--sep); }
.title-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 20px; margin: 0; }
.icon { font-size: 20px; width: 36px; height: 36px; border-radius: 50%; }
.icon:active { background: var(--card); }
.status { color: var(--hint); font-size: 12px; min-height: 16px; }
.tabs { display: flex; gap: 4px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.tabs button { padding: 8px 12px; border-radius: 10px 10px 0 0; color: var(--hint); font-weight: 600; white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--btn); }
.count { font-weight: 500; font-size: 12px; color: var(--hint); }

main { padding: 12px 12px 0; }
.card { background: var(--card); border-radius: 14px; padding: 12px; margin-bottom: 10px; transition: opacity .25s, transform .25s; }
.card.leaving { opacity: 0; transform: translateX(40px); }
.card.highlight { box-shadow: 0 0 0 2px var(--btn); }
.head { display: flex; gap: 10px; align-items: flex-start; }
.score { flex: 0 0 auto; min-width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--cool); }
.score.hot { background: var(--hot); } .score.warm { background: var(--warm); }
.hook { font-weight: 650; font-size: 16px; line-height: 1.3; }
.headline { color: var(--hint); font-size: 14px; margin-top: 3px; }
.meta { color: var(--hint); font-size: 12.5px; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.tag { border: 1px solid var(--sep); border-radius: 6px; padding: 0 6px; }
.quote { margin: 8px 0 0; padding-left: 10px; border-left: 3px solid var(--sep); font-size: 14px; }
.quote cite { display: block; color: var(--hint); font-style: normal; font-size: 12.5px; }
.summary { font-size: 14px; margin-top: 8px; display: none; }
.card.open .summary { display: block; }
.also { margin-top: 8px; font-size: 13px; }
.also summary { color: var(--link); cursor: pointer; list-style: none; }
.also summary::-webkit-details-marker { display: none; }
.also a { display: block; color: var(--text); text-decoration: none; padding: 4px 0; border-top: 1px solid var(--sep); }
.also a span { color: var(--hint); }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions button { flex: 1; padding: 9px 0; border-radius: 10px; font-weight: 600; background: var(--bg); }
.actions .primary { background: var(--btn); color: var(--btn-text); }
.actions button:active { opacity: .7; }

.trend { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.plat { flex: 0 0 auto; font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 6px; color: #fff; background: #c4302b; }
.plat.instagram { background: #c13584; }
.trend .t { font-size: 14px; overflow-wrap: anywhere; }
.trend .nums { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.trend .nums small { display: block; color: var(--hint); font-weight: 400; }

.empty, .error { text-align: center; color: var(--hint); padding: 48px 16px; }
.error { color: var(--danger); }
.skeleton { height: 120px; border-radius: 14px; background: var(--card); margin-bottom: 10px; opacity: .6; }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg);
  border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; z-index: 10; }
.toast[hidden] { display: none; }
.toast button { color: var(--btn); font-weight: 700; filter: brightness(1.3); }

/* list additions */
.brief { font-size: 14px; margin-top: 4px; }
.also-note { color: var(--link); font-size: 13px; margin-top: 6px; }

/* story detail overlay */
body.has-detail { overflow: hidden; }
.detail { position: fixed; inset: 0; z-index: 8; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(32px + env(safe-area-inset-bottom)); }
.detail[hidden] { display: none; }
.back { color: var(--link); font-weight: 600; padding: 6px 2px 10px; }
.box { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.box h2 { font-size: 16px; margin: 0 0 8px; }
.hook.big { font-size: 18px; }
.box .brief { font-size: 15px; margin: 10px 0 0; }
.box .headline { margin: 6px 0 0; }
.explainer h3 { font-size: 14px; margin: 12px 0 4px; }
.explainer h3 small { color: var(--hint); font-weight: 400; }
.explainer p { margin: 0; font-size: 14.5px; }
.explainer ul { margin: 0; padding-left: 18px; font-size: 14px; }
.explainer li { margin: 3px 0; }
.explainer .angle { margin-top: 12px; font-weight: 600; }
.cite, .cite a, .sources a, .explainer a { color: var(--link); text-decoration: none; }
.sources { margin-top: 12px; font-size: 13px; color: var(--hint); }
.hint { color: var(--hint); font-size: 13px; margin: 4px 0 8px; }
textarea { width: 100%; border: 1px solid var(--sep); border-radius: 10px; padding: 10px; font: inherit; font-size: 14.5px;
  color: var(--text); background: var(--bg); resize: vertical; }
button.wide { width: 100%; padding: 11px 0; border-radius: 10px; font-weight: 600; background: var(--btn); color: var(--btn-text); }
button:disabled { opacity: .55; }

/* scripts */
.script { border-top: 1px solid var(--sep); padding: 10px 0 4px; margin-top: 10px; }
.script > summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; gap: 8px; align-items: center; }
.script > summary::-webkit-details-marker { display: none; }
.script-title { font-weight: 650; margin: 8px 0 4px; }
.beat { padding: 8px 0; border-bottom: 1px dashed var(--sep); font-size: 14px; }
.beat .time { font-size: 12px; font-weight: 700; color: var(--hint); }
.beat .vo { margin-top: 2px; }
.beat .onscreen { margin-top: 4px; display: inline-block; font-weight: 700; font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--bg); }
.beat .visual { margin-top: 4px; color: var(--hint); font-style: italic; font-size: 13px; }
.warn { margin-top: 10px; padding: 10px; border-radius: 10px; background: rgba(232, 89, 12, .12); font-size: 13.5px; }
.warn ul { margin: 4px 0 0; padding-left: 18px; }
.caption { font-size: 13.5px; margin: 10px 0 0; }
.skeleton.tall { height: 260px; }
