:root {
  --bg: #0d0d10;
  --bg-2: #141419;
  --bg-3: #1c1c24;
  --card: #16161d;
  --line: #26262f;
  --text: #ececf1;
  --muted: #9a9aa8;
  --faint: #6b6b78;
  --accent: #ff6a00;
  --accent-soft: rgba(255, 106, 0, 0.14);
  --accent-line: rgba(255, 106, 0, 0.4);
  --ig: #e1306c;
  --tt: #25f4ee;
  --ok: #34d17a;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
/* the [hidden] attribute must win over author display rules (e.g. .drawer{display:flex}) */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-top)) 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(13, 13, 16, 0.9);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { font-size: 22px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11px; color: var(--muted); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.stat {
  display: flex; align-items: baseline; gap: 3px;
  padding: 5px 9px; border-radius: 10px; background: var(--bg-3);
  border: 1px solid var(--line); white-space: nowrap;
}
.stat-num { font-weight: 700; font-size: 14px; }
.stat-den { font-size: 10px; color: var(--muted); }
.stat.streak .stat-num { color: var(--accent); }
#stat-ig .stat-num { color: var(--ig); }
#stat-tt .stat-num { color: var(--tt); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--text); font-size: 15px; display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--accent-line); }

/* ---------- Progress ---------- */
.progress-wrap { height: 3px; background: var(--bg-3); position: sticky; top: 0; z-index: 20; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), #ff9d4d); transition: width .4s ease; }

/* ---------- Controls ---------- */
.controls { position: sticky; top: 55px; z-index: 15; background: var(--bg); border-bottom: 1px solid var(--line); }
.control-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; flex-wrap: wrap;
}
.ghost-btn {
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 12px; font-size: 13px; font-weight: 600;
}
.ghost-btn:hover { border-color: var(--accent-line); }
.ghost-btn.danger { color: #ff6b6b; border-color: rgba(255,107,107,.3); }
.today-btn { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.search-box { flex: 1 1 160px; min-width: 140px; }
.search-box input {
  width: 100%; background: var(--bg-3); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 8px 12px; font-size: 13px;
}
.search-box input:focus { outline: none; border-color: var(--accent-line); }
.toggle-inline { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.toggle-inline input { accent-color: var(--accent); }

.day-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px 16px;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.day-strip::-webkit-scrollbar { height: 5px; }
.day-strip::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.day-chip {
  flex: 0 0 auto; min-width: 58px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 7px 8px; color: var(--muted); position: relative;
}
.day-chip .dc-day { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.day-chip .dc-num { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.1; }
.day-chip .dc-wd { font-size: 9px; }
.day-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.day-chip.active .dc-num { color: var(--accent); }
.day-chip.is-today::after {
  content: ""; position: absolute; top: 5px; right: 6px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
.day-chip .dc-dots { display: flex; gap: 2px; justify-content: center; margin-top: 3px; height: 5px; }
.day-chip .dc-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--line); }
.day-chip .dc-dots i.done { background: var(--ok); }

/* ---------- Main ---------- */
main { max-width: 780px; margin: 0 auto; padding: 16px; }
.day-header { margin: 4px 0 14px; }
.day-header h1 { font-size: 22px; margin: 0 0 2px; }
.day-header .dh-sub { color: var(--muted); font-size: 13px; }
.day-header .dh-progress { margin-top: 8px; font-size: 12px; color: var(--faint); }
.day-header .copy-day-btn { margin-top: 10px; }

/* ---------- Post card ---------- */
.post {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 16px; overflow: hidden;
  box-shadow: var(--shadow);
}
.post.posted-ig { border-color: rgba(52, 209, 122, 0.35); }
.post-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 13px 15px; border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.slot-label { display: flex; align-items: center; gap: 9px; min-width: 0; }
.slot-emoji { font-size: 18px; }
.slot-meta { display: flex; flex-direction: column; min-width: 0; }
.slot-meta .sl-name { font-weight: 700; font-size: 14px; }
.slot-meta .sl-sub { font-size: 11px; color: var(--muted); }
.type-badge {
  font-size: 10px; padding: 2px 7px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line);
  white-space: nowrap;
}

.post-toggles { display: flex; gap: 6px; }
.pt {
  display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700;
  padding: 5px 9px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--muted); white-space: nowrap;
}
.pt.on.ig { background: rgba(225,48,108,.16); border-color: rgba(225,48,108,.5); color: #ff85b0; }
.pt.on.tt { background: rgba(37,244,238,.12); border-color: rgba(37,244,238,.45); color: #6ff7f2; }
.pt .pt-check { display: none; }
.pt.on .pt-check { display: inline; }

.post-body { padding: 6px 15px 15px; }

/* Field block */
.block { border-top: 1px solid var(--line); padding: 13px 0 2px; }
.block:first-child { border-top: none; }
.block-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 7px;
}
.block-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 700; }
.block-title .meta { color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 500; margin-left: 6px; }

.copy-btn {
  font-size: 11px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  border-radius: 8px; padding: 4px 10px; display: inline-flex; align-items: center; gap: 5px;
}
.copy-btn:hover { background: rgba(255,106,0,.22); }
.copy-btn.copied { color: var(--ok); border-color: rgba(52,209,122,.5); background: rgba(52,209,122,.14); }

.hook { padding: 9px 11px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 7px; display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.hook p { margin: 0; font-weight: 600; }
.hook .hk-tag { font-size: 10px; color: var(--faint); font-weight: 700; }

.onscreen { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.onscreen b { color: var(--accent); }

.script-box, .caption-box, .prompt-box {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; white-space: pre-wrap; word-wrap: break-word;
}
.script-box { font-size: 14.5px; line-height: 1.6; }
.prompt-box { font-family: var(--mono); font-size: 12.5px; color: #cfcfe0; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: 20px; padding: 3px 9px; }

.cta-line { background: linear-gradient(90deg, var(--accent-soft), transparent); border-left: 3px solid var(--accent); padding: 9px 12px; border-radius: 0 8px 8px 0; font-weight: 600; }

ul.broll { margin: 4px 0 0; padding-left: 18px; }
ul.broll li { margin: 3px 0; color: var(--text); font-size: 13.5px; }

.heygen-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.heygen-grid dt { color: var(--faint); font-weight: 600; }
.heygen-grid dd { margin: 0; }

.note { font-size: 12.5px; color: var(--muted); }
.note b { color: var(--text); }

.post-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.big-copy {
  flex: 1 1 auto; text-align: center; font-weight: 700; font-size: 13px;
  padding: 11px; border-radius: 11px; border: 1px solid var(--accent-line);
  background: var(--accent); color: #1a0f00;
}
.big-copy:hover { filter: brightness(1.05); }
.big-copy.secondary { background: var(--bg-3); color: var(--text); border-color: var(--line); }
.big-copy.copied { background: var(--ok); color: #05230f; }

/* collapsible */
.collapsible .collapse-content { display: none; }
.collapsible.open .collapse-content { display: block; }
.collapse-toggle { cursor: pointer; user-select: none; }
.collapse-toggle::after { content: "▸"; float: right; color: var(--faint); transition: transform .2s; }
.collapsible.open .collapse-toggle::after { transform: rotate(90deg); }

/* ---------- Search results ---------- */
#search-results .sr-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
}
#search-results .sr-item:hover { border-color: var(--accent-line); }
#search-results .sr-meta { font-size: 11px; color: var(--faint); margin-bottom: 4px; }
#search-results .sr-title { font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 90vw);
  background: var(--bg-2); border-left: 1px solid var(--line); z-index: 41;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field input[type=text] { background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 9px 11px; }
.field small { font-size: 11.5px; color: var(--faint); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.muted-block small { line-height: 1.6; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--bg-3); color: var(--text); border: 1px solid var(--accent-line);
  padding: 10px 18px; border-radius: 24px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 60; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.footer { max-width: 780px; margin: 0 auto; padding: 20px 16px 40px; color: var(--faint); font-size: 11.5px; text-align: center; }

@media (min-width: 640px) {
  body { font-size: 15px; }
  .controls { top: 57px; }
}

/* ---------- View tabs ---------- */
.view-tabs {
  display: flex; gap: 6px; padding: 8px 16px 0; max-width: 780px; margin: 0 auto;
}
.view-tab {
  flex: 1; text-align: center; padding: 9px 12px; border-radius: 11px 11px 0 0;
  background: var(--bg-2); border: 1px solid var(--line); border-bottom: none;
  color: var(--muted); font-weight: 700; font-size: 13px;
}
.view-tab.active { background: var(--card); color: var(--accent); border-color: var(--accent-line); }

body.view-trending .controls { display: none; }

/* ---------- Trending ---------- */
#trending { max-width: 780px; margin: 0 auto; padding: 8px 16px 16px; }
.trend-hero h1 { font-size: 22px; margin: 6px 0 2px; }
.card-pad {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; margin-top: 14px;
}
#trend-query {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 13px; font-size: 15px; margin: 8px 0;
}
#trend-query:focus { outline: none; border-color: var(--accent-line); }
.preset-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.preset-chip {
  font-size: 12px; padding: 5px 11px; border-radius: 20px; background: var(--bg-3);
  border: 1px solid var(--line); color: var(--muted); font-weight: 600;
}
.preset-chip:hover, .preset-chip.active { border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }
.engine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.engine-btn {
  display: flex; align-items: center; gap: 7px; padding: 10px 11px; border-radius: 10px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  font-size: 13px; font-weight: 600; text-align: left;
}
.engine-btn:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.engine-btn .eg-ic { font-size: 15px; }

#feed-select {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 6px 9px; font-size: 12px; margin-right: 6px; max-width: 190px;
}
.headline {
  display: block; padding: 11px 12px; border-radius: 10px; background: var(--bg-2);
  border: 1px solid var(--line); margin-bottom: 8px; text-decoration: none; color: var(--text);
}
.headline:hover { border-color: var(--accent-line); }
.headline .hl-title { font-weight: 600; font-size: 14px; line-height: 1.4; }
.headline .hl-meta { font-size: 11px; color: var(--faint); margin-top: 3px; display: flex; justify-content: space-between; gap: 8px; }
.headline .hl-copy { color: var(--accent); font-weight: 700; }

.dir-group { margin-top: 16px; }
.dir-group > h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint);
  margin: 0 0 8px; font-weight: 700;
}
.dir-item {
  display: flex; align-items: baseline; gap: 8px; padding: 9px 12px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); margin-bottom: 7px; text-decoration: none;
}
.dir-item:hover { border-color: var(--accent-line); }
.dir-item .di-name { font-weight: 700; font-size: 13.5px; color: var(--text); white-space: nowrap; }
.dir-item .di-note { font-size: 12px; color: var(--muted); }
.dir-item .di-arrow { margin-left: auto; color: var(--faint); }

.api-item {
  padding: 10px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); margin-bottom: 7px;
}
.api-item a { color: var(--accent); font-weight: 700; text-decoration: none; font-size: 13.5px; }
.api-item .api-free { font-size: 10px; color: var(--ok); border: 1px solid rgba(52,209,122,.4); border-radius: 20px; padding: 1px 7px; margin-left: 6px; }
.api-item .api-use { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
