@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;900&display=swap');

:root {
  --bg: #080808;
  --surface: #0f0f0f;
  --border: #1a1a1a;
  --border-mid: #242424;
  --text: #f0f0f0;
  --muted: #666;
  --muted2: #444;
  --accent: #e8e8e8;
  --accent-dim: #333;
  --red: #e05252;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --sidebar: 200px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, select { font: inherit; color: inherit; }
svg { display: block; }

/* ── LAYOUT ── */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(320px, 540px) 260px;
  justify-content: center;
  background: var(--bg);
}

/* ── SIDEBAR ── */
.sidebar {
  height: 100vh;
  border-right: 1px solid var(--border);
  padding: 20px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.logo-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
}
.logo-block img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}
.wordmark {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
}
.wordmark span { color: var(--muted); }

.sidebar-label {
  padding: 16px 10px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted2);
}
.nav {
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 10px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.nav:hover { background: var(--surface); color: var(--text); }
.nav.active { color: var(--text); font-weight: 700; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; }
.spacer { flex: 1; }

/* ── FEED SHELL ── */
.feed-shell {
  height: 100vh;
  min-width: 0;
  position: relative;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.topbar {
  position: absolute;
  z-index: 20;
  left: 0; right: 0; top: 0;
  padding: calc(14px + var(--safe-top)) 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(#080808e0 0%, transparent 100%);
  pointer-events: none;
}
.topbar-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.api-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted2);
  transition: background .3s;
}
.api-dot.ok  { background: #3ecf8e; }
.api-dot.bad { background: var(--red); }

/* ── FEED ── */
.feed {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  overscroll-behavior-y: contain;
}
.feed::-webkit-scrollbar { display: none; }

/* ── REEL ── */
.reel, .loader-reel {
  height: 100vh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}
.reel { position: relative; background: #040404; overflow: hidden; }

.video-wrap {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #040404;
}
.cover-blur {
  position: absolute; inset: -20px;
  background-size: cover; background-position: center;
  filter: blur(40px) brightness(.15) saturate(.4);
  transform: scale(1.15);
  opacity: .95;
}
video {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  object-fit: contain;
  background: #040404;
}
.shade {
  position: absolute; z-index: 2; inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(8,8,8,.5) 0%,
    transparent 18%,
    transparent 55%,
    rgba(8,8,8,.9) 100%
  );
}
.tap { position: absolute; z-index: 4; inset: 70px 72px 110px 0; cursor: pointer; }

.play-indicator {
  position: absolute; z-index: 5;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(8,8,8,.7);
  border: 1px solid rgba(255,255,255,.12);
  display: grid; place-items: center;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
  backdrop-filter: blur(8px);
}
.reel.paused .play-indicator { opacity: 1; }
.play-indicator svg { width: 22px; margin-left: 3px; fill: #fff; }

/* ── META ── */
.meta {
  position: absolute; z-index: 7;
  left: 14px; right: 76px;
  bottom: 30px;
}
.userline { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.userline strong { font-size: 13px; font-weight: 700; color: var(--text); letter-spacing: .01em; }
.caption { font-size: 13px; line-height: 1.4; max-height: 52px; overflow: hidden; color: rgba(240,240,240,.85); font-weight: 400; }
.music-line { margin-top: 7px; font-size: 11px; font-weight: 500; color: var(--muted); display: flex; gap: 5px; overflow: hidden; white-space: nowrap; }
.music-line span { overflow: hidden; text-overflow: ellipsis; }

/* ── ACTIONS ── */
.actions {
  position: absolute; z-index: 8;
  right: 6px; bottom: 26px;
  width: 62px;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
}
.action {
  border: 0; background: none; padding: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  gap: 4px;
  font-size: 10px; font-weight: 700;
  color: rgba(240,240,240,.9);
}
.bubble {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(15,15,15,.75);
  border: 1px solid rgba(255,255,255,.07);
  display: grid; place-items: center;
  backdrop-filter: blur(6px);
  transition: background .12s;
}
.action:hover .bubble { background: rgba(30,30,30,.9); }
.action svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 1.8; }
.action.liked .bubble { background: rgba(224,82,82,.18); border-color: rgba(224,82,82,.3); }
.action.liked svg { stroke: var(--red); fill: var(--red); }

.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.25);
  background: var(--surface);
  object-fit: cover;
}
.avatar-fallback {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.2);
  background: var(--accent-dim);
  display: grid; place-items: center;
  font-weight: 800; font-size: 11px;
  color: var(--muted);
  letter-spacing: .04em;
}

.disc {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #111;
  border: 5px solid #0c0c0c;
  box-shadow: 0 0 0 1px var(--border-mid);
  animation: spin 6s linear infinite;
  position: relative;
}
.disc::after {
  content: '';
  display: block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--surface);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── PROGRESS ── */
.progress {
  position: absolute; z-index: 9;
  bottom: 0; left: 0; right: 0;
  height: 1.5px;
  background: rgba(255,255,255,.1);
}
.progress i { display: block; height: 100%; width: 0; background: rgba(255,255,255,.5); transition: width .1s linear; }

/* ── LOADER / ERROR ── */
.loader-reel {
  display: grid; place-items: center;
  text-align: center; padding: 30px;
  background: var(--bg);
}
.spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border-mid);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  margin: 0 auto 14px;
}
.errorbox { max-width: 320px; color: var(--muted); line-height: 1.55; }
.errorbox h2 { color: var(--text); margin-bottom: 8px; font-size: 16px; font-weight: 700; }
.errorbox button {
  border: 1px solid var(--border-mid);
  background: transparent; color: var(--text);
  border-radius: 6px; padding: 9px 16px;
  font-size: 12px; font-weight: 700;
  cursor: pointer; margin-top: 12px;
  transition: background .12s;
}
.errorbox button:hover { background: var(--surface); }

/* ── RIGHT PANEL ── */
.rightbar {
  height: 100vh;
  padding: 28px 16px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.panel-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted2);
  margin-bottom: 10px;
}
.card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 14px;
  margin-bottom: 14px;
}
select {
  width: 100%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-mid);
  border-radius: 6px; padding: 8px 10px;
  outline: none; font-size: 12px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}
select:focus { border-color: var(--muted); }
.btn {
  border: 0;
  border-radius: 6px;
  padding: 8px 13px;
  font-size: 12px; font-weight: 700;
  cursor: pointer;
  transition: opacity .12s;
}
.btn:hover { opacity: .8; }
.btn-primary { background: var(--text); color: var(--bg); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border-mid); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted2); }
.row { display: flex; gap: 7px; align-items: center; margin-top: 9px; }

/* ── MOBILE NAV ── */
.mobile-nav { display: none; }

/* ── TOAST ── */
.toast {
  position: fixed; z-index: 200;
  left: 50%; bottom: 24px;
  transform: translate(-50%, 16px);
  background: var(--text); color: var(--bg);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px; font-weight: 700;
  opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s;
  letter-spacing: .02em;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── DRAWERS ── */
.backdrop {
  position: fixed; z-index: 90; inset: 0;
  background: rgba(0,0,0,.7);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  backdrop-filter: blur(2px);
}
.backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; z-index: 91;
  right: 0; top: 0; bottom: 0;
  width: min(400px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border-mid);
  transform: translateX(100%);
  transition: transform .22s;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }

.drawer-head {
  height: 52px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}
.close {
  border: 0; background: none; cursor: pointer;
  padding: 8px; color: var(--muted);
  border-radius: 6px;
  transition: color .12s;
}
.close:hover { color: var(--text); }
.close svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

.profile-drawer {
  position: fixed; z-index: 92;
  right: 0; top: 0; bottom: 0;
  width: min(440px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border-mid);
  transform: translateX(100%);
  transition: transform .22s;
  display: flex; flex-direction: column;
}
.profile-drawer.open { transform: none; }
.profile-content { flex: 1; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.profile-loading { padding: 48px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.profile-loading .spinner { margin-bottom: 12px; }

.profile-hero { padding: 22px 18px 18px; border-bottom: 1px solid var(--border); }
.profile-identity { display: flex; align-items: center; gap: 14px; }
.profile-big-avatar {
  width: 76px; height: 76px; border-radius: 50%;
  object-fit: cover; background: var(--surface);
  flex: 0 0 auto; border: 2px solid var(--border-mid);
}
.profile-big-fallback {
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-dim);
  font-size: 20px; font-weight: 900;
  flex: 0 0 auto; color: var(--muted);
  border: 2px solid var(--border-mid);
  letter-spacing: .04em;
}
.profile-names { min-width: 0; }
.profile-names h2 { margin: 0; font-size: 18px; line-height: 1.15; font-weight: 800; }
.profile-names .handle { margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 500; }
.verified {
  display: inline-grid; place-items: center;
  width: 14px; height: 14px; border-radius: 50%;
  background: #3ecf8e; color: #000;
  font-size: 8px; font-weight: 900;
  margin-left: 4px; vertical-align: 2px;
}
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; text-align: center; }
.profile-stat { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 10px 5px; }
.profile-stat b { display: block; font-size: 14px; font-weight: 800; }
.profile-stat span { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; text-transform: uppercase; letter-spacing: .06em; }
.profile-bio { font-size: 12px; line-height: 1.5; color: rgba(240,240,240,.7); margin-top: 14px; }
.profile-posts-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
}
.profile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5px; background: var(--bg); }
.profile-post { position: relative; aspect-ratio: 9/12; border: 0; padding: 0; background: var(--surface); overflow: hidden; cursor: pointer; }
.profile-post img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.profile-post:hover img { transform: scale(1.04); }
.profile-post-shade {
  position: absolute; inset: auto 0 0;
  padding: 20px 6px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  font-size: 10px; font-weight: 700;
  color: rgba(240,240,240,.85);
}
.profile-empty { padding: 36px 20px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.6; }

/* ── COMMENTS ── */
.comment-user { appearance: none; border: 0; background: none; color: inherit; padding: 0; display: flex; gap: 10px; text-align: left; cursor: pointer; max-width: 100%; }
.comment-user:hover b { text-decoration: underline; }
.comments { flex: 1; overflow: auto; padding: 14px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.comment { display: flex; gap: 10px; margin-bottom: 16px; }
.comment img, .cavi {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; background: var(--accent-dim);
  flex: 0 0 auto; border: 1px solid var(--border);
}
.cavi { display: grid; place-items: center; font-size: 9px; font-weight: 800; color: var(--muted); letter-spacing: .04em; }
.ctext { font-size: 12px; line-height: 1.4; }
.ctext b { display: block; margin-bottom: 3px; font-size: 12px; color: var(--text); }
.ctext small { display: block; color: var(--muted); margin-top: 4px; font-size: 10px; }

/* ── RESPONSIVE ── */
@media (max-width: 1020px) {
  :root { --sidebar: 60px; }
  .app { grid-template-columns: var(--sidebar) minmax(320px, 520px) 0; }
  .sidebar { padding: 20px 10px; }
  .logo-block { padding: 0 0 20px; justify-content: center; }
  .logo-block img { width: 26px; height: 26px; }
  .wordmark { display: none; }
  .sidebar-label, .nav span { display: none; }
  .nav { justify-content: center; padding: 11px; }
  .rightbar { display: none; }
}
@media (max-width: 660px) {
  .app { display: block; }
  .sidebar { display: none; }
  .feed-shell, .reel, .loader-reel { height: 100dvh; }
  .meta { bottom: calc(62px + var(--safe-bottom)); }
  .actions { bottom: calc(62px + var(--safe-bottom)); }
  .progress { bottom: calc(50px + var(--safe-bottom)); }
  .mobile-nav {
    display: flex;
    position: absolute; z-index: 30;
    left: 0; right: 0; bottom: 0;
    height: calc(52px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(8,8,8,.95);
    border-top: 1px solid var(--border);
    justify-content: space-around; align-items: center;
    backdrop-filter: blur(8px);
  }
  .mobile-nav button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); }
  .mobile-nav button svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
  .toast { bottom: calc(66px + var(--safe-bottom)); }
}
