:root {
  --bg: #0e0e13;
  --surface: #16161d;
  --surface-2: #1d1d26;
  --line: #2a2a35;
  --text: #f2f2f5;
  --muted: #9a9aab;
  --faint: #6b6b7b;
  --accent: #ff4d6d;
  --accent-soft: rgba(255, 77, 109, 0.14);
  --gold: #ffb84d;
  --good: #3ddc97;
  --warn: #ffb84d;
  --bad: #ff5c5c;
  --tiktok: #25f4ee;
  --instagram: #e1306c;
  --youtube: #ff3b30;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f8;
    --surface: #ffffff;
    --surface-2: #f0f0f4;
    --line: #e2e2ea;
    --text: #15151c;
    --muted: #5f5f70;
    --faint: #8a8a99;
    --accent-soft: rgba(255, 77, 109, 0.1);
    --tiktok: #00b8b3;
    --shadow: 0 10px 30px rgba(20, 20, 40, 0.1);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 22px 14px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 10px 18px; letter-spacing: -0.01em; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); text-decoration: none; color: var(--muted); font-weight: 500; transition: background 0.15s, color 0.15s; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .grow { flex: 1; }
.side .status { font-size: 12px; color: var(--faint); padding: 0 12px; }
main { padding: 26px 30px 60px; max-width: 1400px; width: 100%; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { font-size: 26px; letter-spacing: -0.02em; margin: 0; }
.head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; inset: auto 0 0 0; height: auto; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
  .brand, .side .grow, .side .status { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 4px; flex: 1; text-align: center; }
  .nav a.on { background: none; }
  .nav svg { width: 22px; height: 22px; }
  main { padding: calc(18px + env(safe-area-inset-top)) 16px 100px; }
  .head h1 { font-size: 23px; }
}

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 550; font-size: 14px; transition: transform 0.12s var(--ease), background 0.15s, border-color 0.15s; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--faint); }
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

input[type="text"], input[type="password"], input[type="search"], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 11px; outline: none; transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { width: 100%; resize: vertical; min-height: 80px; }
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.filters input[type="search"] { flex: 1; min-width: 160px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 550; }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }

/* ---------- cards & grids ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 26px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 26px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 13px; }
@media (max-width: 820px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

section.block { margin-bottom: 30px; }
section.block > h2 { font-size: 17px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
section.block > h2 small { color: var(--faint); font-weight: 500; font-size: 13px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 14px; }
@media (max-width: 520px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
.row-scroll { display: grid; grid-auto-flow: column; grid-auto-columns: 168px; gap: 12px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.row-scroll > * { scroll-snap-align: start; }

.card { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--line); cursor: pointer; transition: transform 0.18s var(--ease), box-shadow 0.18s; animation: rise 0.35s var(--ease) both; }
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card:active { transform: scale(0.98); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.thumb { aspect-ratio: 9 / 16; background: var(--surface-2) center / cover no-repeat; position: relative; }
.thumb::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.78) 0%, rgba(0,0,0,0) 45%, rgba(0,0,0,0) 80%, rgba(0,0,0,.35) 100%); }
.badge-x { position: absolute; z-index: 1; top: 8px; left: 8px; padding: 3px 8px; border-radius: 999px; font-weight: 750; font-size: 13px; background: rgba(0,0,0,.6); color: #fff; backdrop-filter: blur(6px); font-variant-numeric: tabular-nums; }
.badge-x.hot { background: var(--accent); }
.badge-x.fire { background: linear-gradient(135deg, var(--accent), var(--gold)); }
.pf { position: absolute; z-index: 1; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; background: rgba(0,0,0,.6); }
.pf svg { width: 13px; height: 13px; }
.saved-dot { position: absolute; z-index: 1; top: 36px; right: 8px; color: var(--gold); }
.overlay { position: absolute; z-index: 1; left: 10px; right: 10px; bottom: 9px; color: #fff; }
.overlay .views { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.overlay .who { font-size: 12px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .cap { padding: 9px 10px 11px; font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 46px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
button.chip { cursor: pointer; }

/* ---------- format leaderboard ---------- */
.lb { display: grid; gap: 8px; }
.lb-row { display: grid; grid-template-columns: minmax(150px, 1.3fr) 2fr auto; gap: 14px; align-items: center; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; transition: border-color 0.15s; }
.lb-row:hover { border-color: var(--faint); }
.lb-row .name { font-weight: 650; }
.lb-row .name small { display: block; color: var(--faint); font-weight: 500; font-size: 12px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; position: relative; }
.bar i { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--gold)); transform-origin: left; animation: grow 0.6s var(--ease) both; }
.bar.base::after { content: ""; position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--faint); left: var(--base); }
@keyframes grow { from { transform: scaleX(0); } }
.lb-row .val { font-weight: 750; font-variant-numeric: tabular-nums; text-align: right; min-width: 56px; }
.lb-row .val small { display: block; font-size: 11.5px; color: var(--faint); font-weight: 500; }
.mini-thumbs { display: flex; gap: 4px; }
.mini-thumbs div { width: 26px; aspect-ratio: 9/16; border-radius: 4px; background: var(--surface-2) center / cover; }
@media (max-width: 820px) { .lb-row { grid-template-columns: 1fr auto; } .lb-row .bar-wrap { grid-column: 1 / -1; order: 3; } }

/* ---------- lessons / digest ---------- */
.lessons { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.lessons li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.lessons li::before { content: "→"; color: var(--accent); font-weight: 800; }
.ai { line-height: 1.6; }
.ai h1, .ai h2, .ai h3 { font-size: 16px; margin: 18px 0 6px; }
.ai p, .ai ul, .ai ol { margin: 6px 0; }
.hooks { display: grid; gap: 8px; }
.hook { padding: 10px 14px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.hook small { display: block; color: var(--faint); font-size: 12px; margin-top: 3px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 960px) { .cols { grid-template-columns: 1fr; } }

/* ---------- tables (accounts) ---------- */
.list { display: grid; gap: 8px; }
.acc { display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.acc .pfbig { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); }
.acc .pfbig svg { width: 18px; height: 18px; }
.acc .meta { min-width: 0; }
.acc .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc .meta span { font-size: 12.5px; color: var(--muted); }
.acc .err { color: var(--bad); font-size: 12px; display: block; margin-top: 2px; }
.acc .nums { text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.acc .nums b { color: var(--text); }
.acc.off { opacity: 0.5; }
@media (max-width: 820px) { .acc { grid-template-columns: auto 1fr auto; } .acc .nums { display: none; } }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; background: rgba(0,0,0,.5); animation: fade 0.2s ease both; }
.drawer .sheet { width: min(560px, 100%); height: 100%; overflow-y: auto; background: var(--bg); border-left: 1px solid var(--line); padding: 20px 22px calc(40px + env(safe-area-inset-bottom)); animation: slide 0.32s var(--ease) both; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@media (max-width: 820px) {
  .drawer { align-items: flex-end; }
  .drawer .sheet { height: 92vh; border-radius: 18px 18px 0 0; border-left: 0; padding-top: calc(16px); animation-name: up; }
  @keyframes up { from { transform: translateY(60px); opacity: 0; } }
}
.sheet-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.detail { display: grid; grid-template-columns: 150px 1fr; gap: 18px; }
.detail .thumb { border-radius: var(--radius-sm); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); }
.caption { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; margin: 16px 0; }
.spark { width: 100%; height: 90px; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark path.area { fill: var(--accent-soft); }
.sub { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 13px; }
.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); animation: rise 0.25s var(--ease) both; max-width: calc(100% - 32px); }
.pill-run { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.pill-run i { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.pill-run.busy i { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(360px, 100%); display: grid; gap: 14px; text-align: center; }
.login img { width: 56px; height: 56px; margin: 0 auto; border-radius: 14px; }
.login h1 { margin: 6px 0 0; font-size: 24px; letter-spacing: -0.02em; }
.login input { text-align: center; padding: 12px; font-size: 17px; }
.login .btn { justify-content: center; padding: 12px; }
.login .error { color: var(--bad); font-size: 14px; min-height: 20px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
