:root {
      --bg: #000;
      --surface: #111;
      --surface-2: #1a1a1a;
      --text: #fff;
      --text-muted: #aaa;
      --accent: #fe2c55;
      --accent-2: #25f4ee;
      --safe-top: env(safe-area-inset-top, 0px);
      --safe-bottom: env(safe-area-inset-bottom, 0px);
      --top-h: 52px;
      --bottom-h: 64px;
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      -webkit-tap-highlight-color: transparent;
      user-select: none;
    }

    html, body {
      width: 100%;
      height: 100%;
      min-width: 0;
      min-height: 0;
      background: var(--bg);
      color: var(--text);
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
      overflow: hidden;
    }

    #app {
      height: var(--app-height, 100dvh);
      min-height: 0;
      max-height: var(--app-height, 100dvh);
      width: min(100%, 480px);
      min-width: 0;
      max-width: 480px;
      margin: 0 auto;
      position: relative;
      background: var(--bg);
      display: flex;
      flex-direction: column;
    }

    /* ========== TOP NAV ========== */
    .top-nav {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: calc(var(--top-h) + var(--safe-top));
      padding-top: var(--safe-top);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 100;
      background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
      pointer-events: none;
    }

    .top-nav .tabs {
      display: flex;
      gap: clamp(10px, 2.6vw, 18px);
      max-width: calc(100% - 66px);
      margin-right: 34px;
      pointer-events: auto;
    }

    .top-nav .tab {
      font-size: clamp(13px, 3.7vw, 16px);
      font-weight: 600;
      color: var(--text-muted);
      white-space: nowrap;
      cursor: pointer;
      position: relative;
      padding: 6px 0;
      transition: color 0.2s;
    }

    .top-nav .tab.active {
      color: #fff;
    }
    .top-nav .tab:focus-visible { outline: 2px solid rgba(255,255,255,.7); outline-offset: 5px; border-radius: 2px; }

    .top-nav .refresh-btn {
      position: absolute;
      right: 12px;
      top: calc(var(--safe-top) + 8px);
      width: 38px;
      height: 38px;
      border: 1px solid rgba(255,255,255,.12);
      border-radius: 50%;
      background: rgba(0,0,0,.34);
      color: #fff;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      pointer-events: auto;
      backdrop-filter: blur(10px);
      box-shadow: 0 8px 24px rgba(0,0,0,.18);
    }
    .top-nav .refresh-btn:hover { background: rgba(255,255,255,.08); }
    .top-nav .refresh-btn:active { transform: scale(.92); }
    .top-nav .refresh-btn.spinning svg { animation: spin .65s linear infinite; }

    .top-nav .tab.active::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      width: 24px;
      height: 3px;
      background: #fff;
      border-radius: 2px;
    }

    /* ========== BOTTOM NAV ========== */
    .bottom-nav {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      height: calc(var(--bottom-h) + var(--safe-bottom));
      padding-bottom: var(--safe-bottom);
      display: flex;
      align-items: center;
      justify-content: space-around;
      background: rgba(0,0,0,0.85);
      backdrop-filter: blur(12px);
      z-index: 100;
      border-top: 1px solid rgba(255,255,255,0.08);
    }

    .bottom-nav .btn {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2px;
      color: var(--text-muted);
      font-size: 10px;
      cursor: pointer;
      padding: 6px 8px;
      min-width: 56px;
      transition: color 0.2s;
    }

    .bottom-nav .btn.active,
    .bottom-nav .btn:active {
      color: #fff;
    }

    .bottom-nav .btn .icon {
      font-size: 24px;
      line-height: 1;
    }

    .bottom-nav .btn.create .icon {
      width: 44px;
      height: 30px;
      background: linear-gradient(135deg, var(--accent-2), var(--accent));
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 22px;
      color: #fff;
      border: 2px solid #fff;
    }

    .bottom-nav .btn.create.press-animation {
      animation: createButtonPulse .42s cubic-bezier(.2,.8,.25,1);
    }
    .bottom-nav .btn.create.press-animation .icon {
      animation: createIconPop .42s cubic-bezier(.2,.8,.25,1);
    }
    @keyframes createButtonPulse {
      0% { transform: scale(1); }
      38% { transform: scale(.90); }
      72% { transform: scale(1.07); }
      100% { transform: scale(1); }
    }
    @keyframes createIconPop {
      0% { transform: rotate(0deg) scale(1); }
      45% { transform: rotate(-7deg) scale(1.16); }
      100% { transform: rotate(0deg) scale(1); }
    }


    /* ========== GLOBAL MOTION ========== */
    html { scroll-behavior: smooth; }
    button, input, textarea, select, .btn, .tab, .itab, .ptab, .user-row, .icon-btn,
    .subscribe-btn, .profile-actions button, .setting-row, .settings-tab {
      transition: transform .18s ease, opacity .18s ease, background-color .18s ease,
                  border-color .18s ease, color .18s ease, box-shadow .18s ease;
    }
    .screen.active { animation: screenIn .24s cubic-bezier(.22,.8,.25,1); }
    @keyframes screenIn { from { opacity:0; transform:translateY(8px) scale(.995); } to { opacity:1; transform:translateY(0) scale(1); } }
    .video-card { animation: cardIn .32s cubic-bezier(.22,.8,.25,1); }
    @keyframes cardIn { from { opacity:.5; transform:scale(.985); } to { opacity:1; transform:scale(1); } }
    .modal-sheet { animation: sheetIn .22s cubic-bezier(.22,.8,.25,1); }
    @keyframes sheetIn { from { opacity:0; transform:translateY(18px) scale(.985); } to { opacity:1; transform:translateY(0) scale(1); } }
    .sticker-picker { animation: pickerIn .18s cubic-bezier(.22,.8,.25,1); }
    @keyframes pickerIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }
    .setting-row:active, .settings-tab:active, .user-row:active { transform:scale(.992); }

    /* ========== PROFILE CONNECTIONS ========== */
    .profile-stat-button { border:0; background:transparent; color:#fff; cursor:pointer; padding:4px 8px; border-radius:10px; }
    .profile-stat-button:hover { background:rgba(255,255,255,.06); }
    .connections-sheet { width:min(100%, 520px); max-height:78%; }
    .connections-tabs { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:4px; min-width:0; padding:4px; background:#191919; border-radius:10px; margin-bottom:10px; }
    .connection-tab { border:0; background:transparent; color:#8f8f95; padding:10px; border-radius:8px; font-weight:750; cursor:pointer; }
    .connection-tab.active { background:#2a2a2c; color:#fff; }
    .connections-list { max-height:52vh; overflow:auto; }
    .connection-empty { padding:36px 14px; text-align:center; color:var(--text-muted); }

    /* ========== SETTINGS ========== */
    #settings-screen { background:#09090a; padding-bottom:calc(var(--bottom-h) + var(--safe-bottom)); }
    .settings-layout { flex:1; display:flex; min-height:0; padding-top:calc(var(--top-h) + var(--safe-top)); }
    .settings-sidebar { width:220px; flex:0 0 220px; border-right:1px solid rgba(255,255,255,.07); padding:14px 10px; overflow:auto; background:rgba(255,255,255,.015); }
    .settings-tab { width:100%; border:0; background:transparent; color:#a1a1a8; text-align:left; padding:11px 12px; border-radius:10px; cursor:pointer; display:flex; align-items:center; gap:10px; font-weight:650; }
    .settings-tab.active { color:#fff; background:rgba(255,255,255,.08); }
    .settings-content { flex:1; min-width:0; overflow:auto; padding:24px 20px 40px; }
    .settings-inner { width:min(860px,100%); margin:0 auto; }
    .settings-title { font-size:22px; font-weight:820; margin-bottom:4px; }
    .settings-subtitle { color:#8f8f95; font-size:13px; margin-bottom:20px; }
    .settings-card { background:#111113; border:1px solid rgba(255,255,255,.07); border-radius:16px; overflow:hidden; margin-bottom:14px; }
    .settings-card-title { padding:14px 16px 8px; font-weight:780; font-size:13px; color:#fff; }
    .setting-row { display:flex; align-items:center; gap:16px; padding:15px 16px; border-top:1px solid rgba(255,255,255,.06); min-height:66px; }
    .setting-icon { width:36px; height:36px; border-radius:10px; background:rgba(255,255,255,.05); display:flex; align-items:center; justify-content:center; flex:0 0 auto; color:#fff; }
    .setting-main { flex:1; min-width:0; }
    .setting-label { font-size:14px; font-weight:700; }
    .setting-help { color:#77777e; font-size:12px; line-height:1.35; margin-top:3px; }
    .setting-control { flex:0 0 auto; }
    .setting-control select, .setting-control input[type=text], .setting-control input[type=time], .setting-control input[type=number] { min-width:132px; background:#1a1a1c; border:1px solid rgba(255,255,255,.08); color:#fff; border-radius:9px; padding:9px 10px; outline:none; }
    .switch { position:relative; width:46px; height:28px; display:inline-block; }
    .switch input { opacity:0; width:0; height:0; }
    .switch-track { position:absolute; inset:0; background:#343438; border-radius:99px; cursor:pointer; }
    .switch-track::after { content:""; position:absolute; width:22px; height:22px; top:3px; left:3px; background:#fff; border-radius:50%; box-shadow:0 1px 4px rgba(0,0,0,.35); transition:transform .18s ease; }
    .switch input:checked + .switch-track { background:var(--accent); }
    .switch input:checked + .switch-track::after { transform:translateX(18px); }
    .settings-back { position:absolute; top:calc(var(--safe-top) + 10px); left:12px; z-index:30; width:36px; height:36px; border-radius:50%; border:1px solid rgba(255,255,255,.08); background:rgba(0,0,0,.3); color:#fff; display:flex; align-items:center; justify-content:center; cursor:pointer; }
    .settings-mobile-tabs { display:none; }
    .settings-save-note { color:#6f6f76; font-size:11px; text-align:right; padding:0 2px 6px; min-height:17px; }
    body.light-theme { background:#f5f5f7; color:#161616; }
    body.light-theme #app, body.light-theme .screen { background:#f5f5f7; }
    body.light-theme .settings-card { background:#fff; border-color:#dedee4; }
    body.light-theme .settings-sidebar { background:#fff; border-color:#dedee4; }
    body.light-theme .setting-row { border-color:#ececf0; }
    body.light-theme .setting-icon { background:#f0f0f2; color:#202024; }
    body.light-theme .setting-label, body.light-theme .settings-title { color:#161616; }
    body.light-theme .settings-tab { color:#73737b; }
    body.light-theme .settings-tab.active { color:#161616; background:#ededf0; }
    body.light-theme .top-nav { background:linear-gradient(to bottom, rgba(255,255,255,.86), transparent); }
    body.light-theme .top-nav .tab.active { color:#161616; }
    body.light-theme .top-nav .refresh-btn { background:rgba(255,255,255,.75); color:#161616; border-color:rgba(0,0,0,.08); }
    body.light-theme .bottom-nav { background:rgba(255,255,255,.92); color:#161616; border-top-color:rgba(0,0,0,.08); }
    body.light-theme .bottom-nav .btn { color:#707078; }
    body.light-theme .bottom-nav .btn.active { color:#161616; }
    body.light-theme .settings-save-note { color:#66666d; }
    body.light-theme .setting-control select, body.light-theme .setting-control input[type=text], body.light-theme .setting-control input[type=time], body.light-theme .setting-control input[type=number] { background:#f4f4f6; color:#161616; border-color:#dedee4; }
    body.light-theme .settings-back { background:rgba(255,255,255,.75); color:#161616; border-color:#dedee4; }

    /* ========== CONTRAST / READABILITY ========== */
    .video-card::after {
      content:"";
      position:absolute;
      left:0; right:0; bottom:0;
      height:38%;
      pointer-events:none;
      z-index:6;
      background:linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,.34) 42%, transparent 100%);
    }
    .video-info {
      text-shadow:0 2px 10px rgba(0,0,0,.72), 0 1px 3px rgba(0,0,0,.95);
    }
    .video-info .author { color:#fff; }
    .video-info .desc { color:#fff; }
    .video-info .hashtags { color:#f1f1f1; }
    .video-info .music { color:#f5f5f5; }

    .field {
      border:1px solid rgba(255,255,255,.075);
      box-shadow:0 8px 24px rgba(0,0,0,.12);
    }
    .field input,
    .field textarea { color:var(--text); }
    .field input::placeholder,
    .field textarea::placeholder { color:var(--text-muted); opacity:1; }

    .profile-edit-field input,
    .auth-field input,
    .comment-input-row input,
    .search-input { color:var(--text); }
    .search-safety-card{margin:18px 14px;padding:22px 18px;border:1px solid rgba(255,255,255,.09);border-radius:20px;background:var(--surface);text-align:center;box-shadow:0 10px 30px rgba(0,0,0,.14)}
    .search-safety-card--support{border-color:rgba(76,175,80,.28)}
    .search-safety-card--adult{border-color:rgba(255,193,7,.25)}
    .search-safety-icon{width:46px;height:46px;margin:0 auto 12px;border-radius:15px;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,.06);font-weight:900;font-size:15px}
    .search-safety-title{font-size:19px;font-weight:850;margin-bottom:8px}
    .search-safety-text{font-size:14px;line-height:1.5;color:var(--text-muted);max-width:520px;margin:0 auto}
    .search-safety-action{display:inline-flex;align-items:center;justify-content:center;margin:16px auto 8px;min-height:42px;padding:0 16px;border-radius:12px;background:var(--accent);color:#fff;text-decoration:none;font-weight:800}
    .search-safety-help{font-size:12px;line-height:1.45;color:var(--text-muted)}
    .search-safety-query{margin-top:13px;font-size:12px;color:var(--text-muted);opacity:.8;overflow-wrap:anywhere}

    .profile-edit-field input::placeholder,
    .auth-field input::placeholder,
    .comment-input-row input::placeholder,
    .search-input::placeholder { color:var(--text-muted); opacity:1; }

    body.light-theme .profile-header,
    body.light-theme .profile-screen,
    body.light-theme .settings-content,
    body.light-theme #publish-screen,
    body.light-theme #search-screen,
    body.light-theme #inbox-screen {
      color:#161616;
    }
    body.light-theme #profile-screen { background:#f5f5f7; }
    body.light-theme .profile-header { background:linear-gradient(180deg,#ffffff 0%,#f3f3f6 100%); }
    body.light-theme .profile-name,
    body.light-theme .profile-stats .stat .num,
    body.light-theme .profile-actions button,
    body.light-theme .profile-tabs .ptab.active,
    body.light-theme .settings-card-title,
    body.light-theme .setting-label,
    body.light-theme .publish-header,
    body.light-theme .field input,
    body.light-theme .field textarea { color:#161616; }
    body.light-theme .profile-username,
    body.light-theme .profile-bio,
    body.light-theme .profile-stats .stat .label,
    body.light-theme .settings-subtitle,
    body.light-theme .setting-help,
    body.light-theme .profile-edit-subtitle,
    body.light-theme .profile-edit-field label { color:#5f6068; }
    body.light-theme .profile-tabs { background:rgba(255,255,255,.94); border-color:#dedee4; }
    body.light-theme .field { background:#fff; border-color:#dedee4; box-shadow:0 5px 18px rgba(20,20,30,.06); }
    body.light-theme .field input,
    body.light-theme .field textarea,
    body.light-theme .profile-edit-field input,
    body.light-theme .auth-field input,
    body.light-theme .comment-input-row input,
    body.light-theme .search-input { background:#fff; color:#161616; }
    body.light-theme .field label,
    body.light-theme .profile-edit-field label { color:#666872; }
    body.light-theme .profile-edit-sheet,
    body.light-theme .modal-sheet { background:linear-gradient(180deg,#ffffff 0%,#f5f5f7 100%); color:#161616; border-color:#dedee4; }
    body.light-theme .profile-edit-close { color:#161616; background:#f0f0f2; border-color:#dedee4; }
    body.light-theme .profile-edit-field input { border-color:#d8d8df; background:#f8f8fa; }
    body.light-theme .profile-edit-field input:disabled { color:#777983; background:#ededf0; }
    body.light-theme .auth-field,
    body.light-theme .comment-input-row input { background:#f0f0f3; }
    body.light-theme .modal-sheet h3,
    body.light-theme .speed-options button,
    body.light-theme .menu-options button { color:#161616; }
    .menu-options button.danger-action { color:#ff6b85; font-weight:700; }
    .menu-options button.danger-action:hover { background:rgba(255,107,133,.10); }
    body.light-theme .menu-options button.danger-action { color:#c51f45; }
    body.light-theme .speed-options button:active,
    body.light-theme .menu-options button:active,
    body.light-theme .speed-options button.active { background:#ececf0; }

    /* ========== SCREENS ========== */
    .screen {
      position: absolute;
      inset: 0;
      width: 100%;
      min-width: 0;
      max-width: 100%;
      height: var(--app-height, 100dvh);
      min-height: 0;
      max-height: var(--app-height, 100dvh);
      display: none;
      flex-direction: column;
      overflow: hidden;
    }

    .screen.active {
      display: flex;
    }


    /* ========== VIRTUAL BACK / HISTORY NAVIGATION ========== */
    .virtual-back {
      position:absolute;
      top:calc(var(--safe-top) + 12px);
      left:12px;
      z-index:180;
      width:42px;
      height:42px;
      border-radius:50%;
      border:1px solid rgba(255,255,255,.14);
      background:rgba(18,18,19,.72);
      color:#fff;
      display:none;
      align-items:center;
      justify-content:center;
      cursor:pointer;
      backdrop-filter:blur(12px);
      -webkit-backdrop-filter:blur(12px);
      box-shadow:0 8px 24px rgba(0,0,0,.25);
      touch-action:manipulation;
    }
    .virtual-back.visible { display:flex; }
    .virtual-back:active { transform:scale(.94); background:rgba(40,40,42,.9); }
    .virtual-back svg { width:21px; height:21px; }
    body.light-theme .virtual-back {
      background:rgba(255,255,255,.82);
      color:#161616;
      border-color:rgba(0,0,0,.1);
    }
    @media (min-width:860px) {
      .virtual-back { left:258px; }
    }

    /* ========== FEED ========== */


/* ========== LOW-END DEVICE MODE ========== */
.low-performance .screen.active,
.low-performance .video-card,
.low-performance .modal-sheet,
.low-performance .sticker-picker,
.low-performance .recovery-step.active {
  animation: none !important;
}
.low-performance .top-nav .refresh-btn,
.low-performance .virtual-back,
.low-performance .profile-tabs,
.low-performance .bottom-nav {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
.low-performance .feed-container {
  scroll-behavior: auto;
}

/* Multi-file gallery upload */
.pending-media-summary {
  margin: 0 0 10px;
  padding: 11px 13px;
  border: 1px solid rgba(125, 92, 255, .28);
  border-radius: 13px;
  background: rgba(125, 92, 255, .09);
  color: var(--text, #f5f5f7);
  font-size: 12px;
  line-height: 1.45;
}
.pending-media-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 164px;
  overflow: auto;
  margin: 0 0 14px;
  padding: 2px 2px 6px;
}
.pending-media-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 11px;
  background: rgba(255,255,255,.035);
}
.pending-media-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(135deg, #7657ff, #a044ff);
  font-size: 12px;
}
.pending-media-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text, #f5f5f7);
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pending-media-size {
  flex: 0 0 auto;
  color: var(--text-muted, #999);
  font-size: 10px;
}
.pending-media-summary[hidden],
.pending-media-list[hidden] { display: none !important; }
body.light-theme .pending-media-row { background: #fff; border-color: #e6e6ed; }
body.light-theme .pending-media-name { color: #17171b; }
