:root {
  --bg: #0b0b10;
  --surface: #15151d;
  --surface-2: #1d1d27;
  --line: #2a2a36;
  --text: #f2f2f7;
  --muted: #8e8e9c;
  --accent: #8b5cf6;
  --accent-2: #ec4899;
  --a: #8b5cf6;
  --b: #14b8a6;
  --danger: #ef4444;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -0.02em; }
button, input { font: inherit; color: inherit; }
a { color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: #fca5a5; min-height: 1.4em; margin: 0; font-size: 14px; }

/* ---------- Screens ---------- */
.screen { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 24px); }
.screen.center { min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; }
.logo { border-radius: 18px; box-shadow: 0 10px 40px rgba(139, 92, 246, 0.35); margin-bottom: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100%); margin-top: 12px; }
.stack input { text-align: center; letter-spacing: 0.3em; font-size: 22px; }

input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #6b6b78; letter-spacing: normal; }

/* ---------- Buttons ---------- */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.08s, opacity 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: rgba(239, 68, 68, 0.14); color: #fca5a5; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 11px; }
.icon-btn, .avatar-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  cursor: pointer; position: relative; padding: 0;
}
.icon-btn.on { color: var(--accent); border-color: rgba(139, 92, 246, 0.5); }
.icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }
.avatar-btn { border: 0; background: none; }

/* ---------- Avatars ---------- */
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
  background: var(--surface-2); flex: none;
}
.avatar.a { background: linear-gradient(135deg, #8b5cf6, #6366f1); }
.avatar.b { background: linear-gradient(135deg, #14b8a6, #0ea5e9); }

/* ---------- Identity picker ---------- */
.who-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: min(360px, 100%); margin-top: 16px; }
.who-btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 10px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  cursor: pointer; font-weight: 600;
}
.who-btn .avatar { width: 56px; height: 56px; font-size: 22px; }
.who-btn:active { transform: scale(0.98); }

/* ---------- Top bar & composer ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  margin: calc(-1 * (var(--safe-top) + 12px)) -16px 0;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: rgba(11, 11, 16, 0.82);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
}
.topbar h1 { font-size: 24px; font-weight: 800; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.composer { display: flex; gap: 8px; margin: 8px 0 14px; }
.composer input { flex: 1; min-width: 0; }
.composer .btn { padding: 12px 14px; }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.16), rgba(236, 72, 153, 0.12));
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 14px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px;
}

/* ---------- Feed ---------- */
.feed { display: flex; flex-direction: column; gap: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
  animation: pop 0.25s ease-out;
}
.card.highlight { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.card-head .who { font-weight: 600; }
.card-head .meta { color: var(--muted); font-size: 13px; }
.card-head .spacer { flex: 1; }
.pill { font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.tiktok { color: #67e8f9; }
.pill.instagram { color: #f9a8d4; }

.embed {
  position: relative; width: 100%; background: #000;
  height: min(740px, 82svh);
}
.embed.instagram { background: #fff; height: min(720px, 80svh); }
.embed::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, #111 30%, #1c1c24 50%, #111 70%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
.embed.loaded::before { display: none; }
@keyframes shimmer { to { background-position: -200% 0; } }
.embed iframe { position: relative; width: 100%; height: 100%; border: 0; display: block; }

.card-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.card-foot .spacer { flex: 1; }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  font-size: 14px; color: var(--muted); padding: 8px 10px; border-radius: 10px; background: none; border: 0; cursor: pointer;
}
.link-btn:active { background: var(--surface-2); }
.link-btn.archive:active { color: #fca5a5; }

.empty { text-align: center; padding: 48px 16px; }
.empty .big { font-size: 42px; margin: 0; }
.sentinel { height: 64px; display: grid; place-items: center; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Settings sheet ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  background: var(--surface); color: var(--text);
  border-radius: 22px 22px 0 0;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet-body { padding: 20px 18px calc(var(--safe-bottom) + 18px); display: flex; flex-direction: column; gap: 8px; }
.sheet-body h2 { font-size: 20px; margin-bottom: 4px; }
.label { margin: 12px 0 2px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 14px; padding: 4px; gap: 4px; }
.seg-btn { border: 0; background: none; padding: 10px; border-radius: 11px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg-btn.active { background: var(--surface-2); color: var(--text); }
.btn.close { margin-top: 14px; background: var(--surface-2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 18px); z-index: 50;
  background: #26262f; border: 1px solid var(--line); color: var(--text);
  padding: 11px 14px; border-radius: 14px; font-size: 14px;
  display: flex; gap: 14px; align-items: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  max-width: calc(100% - 32px);
}
.toast-action { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 0; }
