/* 萤火直播 Firefly Live · App 外壳（对标 BIGO Live 手机端观感）
   ────────────────────────────────────────────────────────────
   目标：桌面浏览器打开不是「网页缩小版」，而是一台手机里跑 App。
   - 宽屏（≥600px）：居中 393×852 手机外框，含灵动岛、状态栏、圆角屏体、外投影；
   - 窄屏/真机：自动铺满，无外框（Android WebView 里不会出现「框中框」）。
   内容区 .app-main 独立滚动，底部 tabbar 固定 —— 与原生 App 的滚动模型一致。

   全站生效（除 admin/ 后台，后台走独立 admin/base.html）。 */

/* ══════════ 外壳：桌面端手机框 ══════════ */
@media (min-width: 600px) {
  html { height: 100%; }
  body {
    height: 100%;
    display: grid;
    place-items: center;
    background:
      radial-gradient(900px 520px at 50% -8%, rgba(254, 44, 85, .10), transparent 62%),
      radial-gradient(700px 460px at 88% 108%, rgba(90, 120, 255, .07), transparent 60%),
      #06070a;
    overflow: hidden;
  }

  .app-shell {
    position: relative;
    width: 393px;
    /* ★ 必须给确定高度：老内核（华为浏览器/微信 X5，Chromium 70 及更早）不支持
       CSS min()（需 79+）与 dvh（需 108+），若只写下面那行，高度会退化成 auto，
       .app-main 就不再是滚动容器，再叠加 body{overflow:hidden} → 整页卡死不能滑动。
       这里先给 calc + max-height 的老语法兜底，两条声明结果等价。 */
    height: calc(100vh - 36px);
    max-height: 852px;
    height: min(852px, calc(100vh - 36px));
    padding: 9px;
    border-radius: 54px;
    background: linear-gradient(155deg, #33363f 0%, #14161c 34%, #0a0b0f 68%, #262932 100%);
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, .09),
      0 2px 3px rgba(255, 255, 255, .06) inset,
      0 34px 80px rgba(0, 0, 0, .78),
      0 8px 24px rgba(0, 0, 0, .6);
  }
  /* 侧键：音量 + 电源（纯装饰，增强「这是手机」的直觉） */
  .app-shell::before,
  .app-shell::after {
    content: "";
    position: absolute;
    width: 3px;
    border-radius: 3px;
    background: linear-gradient(180deg, #3a3d47, #1b1d24);
  }
  .app-shell::before { left: -3px; top: 168px; height: 62px; box-shadow: 0 78px 0 #2c2f38; }
  .app-shell::after  { right: -3px; top: 196px; height: 96px; }

  .app-screen {
    position: relative;
    height: 100%;
    border-radius: 46px;
    overflow: hidden;
    background: #0a0b0f;
    display: flex;
    flex-direction: column;
    isolation: isolate;
    /* 建立 containing block：壳内 fixed 弹层（登录弹窗/下载弹窗/Cookie 条/toast）
       以手机屏为定位基准，而不是整个浏览器窗口 */
    transform: translateZ(0);
  }
  /* 灵动岛 */
  .app-screen::before {
    content: "";
    position: absolute;
    top: 11px; left: 50%;
    transform: translateX(-50%);
    width: 104px; height: 27px;
    border-radius: 999px;
    background: #000;
    z-index: 90;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .06);
  }

  /* 状态栏：时间居左，信号/WiFi/电量居右（灵动岛两侧留空） */
  .app-status {
    flex: none;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 26px 0 30px;
    font-size: 13.5px;
    font-weight: 700;
    letter-spacing: .2px;
    color: #fff;
    background: transparent;
    position: relative;
    z-index: 80;
    pointer-events: none;
  }
  .app-status .st-time { font-variant-numeric: tabular-nums; }
  .app-status .st-right { display: flex; align-items: center; gap: 5px; }
  .app-status .st-right svg { display: block; }

  /* 底部 Home 指示条 */
  .app-screen::after {
    content: "";
    position: absolute;
    bottom: 8px; left: 50%;
    transform: translateX(-50%);
    width: 134px; height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .55);
    z-index: 120;
    pointer-events: none;
  }

  /* 手机内滚动模型：中间区独立滚动，tabbar 常驻 */
  .app-screen .app-main {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .app-screen .app-main::-webkit-scrollbar { width: 0; height: 0; }

  /* 壳内不出现 PC 页脚；tabbar 承担导航 */
  .app-screen .site-footer { display: none; }

  /* Cookie 条在壳内改为贴底（不与 tabbar 重叠） */
  .app-screen .cookie {
    left: 9px; right: 9px; bottom: 9px;
    border-radius: 0 0 46px 46px;
    padding: 12px 16px;
  }
}

/* ══════════ 窄屏 / 真机：全屏铺满，不画外框 ══════════ */
@media (max-width: 599px) {
  html, body { height: 100%; }
  body { overflow: hidden; }
  /* 100vh 先兜底，dvh 只在支持的内核上覆盖（Chromium 108+）。
     顺序不能反，否则老内核两条全废、高度退化成 auto → 页面不能滚动。 */
  .app-shell { height: 100vh; height: 100dvh; }
  .app-screen { height: 100%; display: flex; flex-direction: column; background: var(--bg); }
  .app-screen .app-main { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .app-screen .site-footer { display: none; }
  /* 真机有系统状态栏，模拟状态栏隐藏 */
  .app-status { display: none; }
  .app-screen::before,
  .app-screen::after { display: none; }
}

/* ══════════ 壳内顶栏：App 化（替换 PC 导航） ══════════
   桌面宽屏也不需要横排六个文字导航 —— 手机 App 的顶栏是
   「品牌/搜索 + 少量图标」，分类靠首页横滑 chip 与底部 tabbar。 */
.app-screen .site-header {
  position: sticky;
  top: 0;
  height: 50px;
  padding: 0 14px;
  gap: 10px;
  background: rgba(10, 11, 15, .86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  z-index: 70;
}
.app-screen .site-header nav.top,
.app-screen .site-header .btn-burger,
.app-screen .site-header .mnav { display: none !important; }
.app-screen .brand { font-size: 16px; gap: 7px; }
.app-screen .brand .m { width: 26px; height: 26px; border-radius: 8px; font-size: 13px; }
.app-screen .brand small { display: none; }
.app-screen .hdr-user { gap: 7px; }
.app-screen .hdr-user .btn-login { height: 30px; padding: 0 12px; font-size: 12px; white-space: nowrap; }
.app-screen .hdr-user .coin { height: 28px; padding: 0 10px; font-size: 12px; white-space: nowrap; }
.app-screen .btn-dl { display: none; }   /* 手机观感顶栏不放下载按钮（BIGO 同） */
.app-screen .lang-full { display: none; }
.app-screen .lang-short { display: inline; }
.app-screen .lang { padding: 6px 8px; font-size: 12px; }
/* 顶栏里「主播中心 / 昵称 / 退出」三个文字按钮在手机上太挤 → 只留头像进 me 页 */
.app-screen .hdr-user .btn-login,
.app-screen .hdr-user #btnLogout { display: none; }
.app-screen .hdr-user .im-entry { width: 32px; height: 32px; }
.app-screen .notice { padding: 8px 14px; font-size: 12px; }
.app-screen .toast { top: 64px; }

/* ══════════ 底部 Tabbar（BIGO 式五栏 + 中间开播） ══════════ */
.app-tabbar {
  flex: none;
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  height: 58px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(10, 11, 15, .96);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, .07);
  z-index: 75;
}
@media (min-width: 600px) {
  /* 桌面壳内：给 Home 指示条留出空间 */
  .app-tabbar { height: 70px; padding-bottom: 20px; }
}
.app-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 58px;
  color: rgba(255, 255, 255, .46);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .2px;
  transition: color .16s;
  -webkit-tap-highlight-color: transparent;
}
.app-tab svg { width: 23px; height: 23px; display: block; }
.app-tab:hover { color: rgba(255, 255, 255, .8); }
.app-tab.on { color: #fff; }
.app-tab.on svg { filter: drop-shadow(0 0 8px rgba(254, 44, 85, .55)); }
.app-tab.on .dot { opacity: 1; }
.app-tab .dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--brand); opacity: 0; transition: .16s;
}
/* 中间开播按钮：凸起的渐变圆 */
.app-tab-go {
  position: relative;
  justify-content: flex-end;
  padding-bottom: 0;
}
.app-tab-go .plus {
  position: absolute;
  bottom: 26px;
  width: 50px; height: 50px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--grad);
  box-shadow: 0 8px 22px rgba(254, 44, 85, .48), 0 0 0 3px rgba(10, 11, 15, .95);
  color: #fff;
  transition: transform .18s;
}
.app-tab-go .plus svg { width: 24px; height: 24px; }
.app-tab-go:active .plus { transform: scale(.94); }
.app-tab-go .lbl { margin-top: 34px; }
.app-tab .badge {
  position: absolute;
  top: 8px;
  margin-left: 16px;
  min-width: 15px; height: 15px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 9.5px;
  font-weight: 800;
  line-height: 15px;
  text-align: center;
}
.app-tab .badge[hidden] { display: none !important; }

/* ══════════ Android 原生壳专用布局 ══════════
   原生层已经提供系统状态栏和底部五栏，因此 WebView 内只渲染内容页面。
   这一分支由服务端 UA 检测首屏输出，避免 onPageFinished 注入造成的闪烁。 */
html.in-firefly-app,
html.in-firefly-app body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: #090a0e;
}
html.in-firefly-app body {
  display: block;
  color: #f7f8fb;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
.native-app-page {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #090a0e;
  transform: translateZ(0);
  /* 底部 tabbar（网页版五栏）作为 flex 兄弟节点常驻，native-main 独立滚动 */
  display: flex;
  flex-direction: column;
}
.native-app-page .native-main {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.native-app-page .native-main::-webkit-scrollbar { width: 0; height: 0; }
html.in-firefly-app body[data-page="room"] .native-main,
html.in-firefly-app body[data-page="im"] .native-main { overflow: hidden; }
html.in-firefly-app .toast { top: max(14px, env(safe-area-inset-top, 0px)); }
html.in-firefly-app .modal-mask,
html.in-firefly-app .im-mask,
html.in-firefly-app .lightbox { position: absolute; }

/* App 页面通用顶栏：各 Tab 自己拥有上下文，不复用网页品牌导航。 */
.app-page-head {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(8px, env(safe-area-inset-top, 0px)) 16px 8px;
  background: rgba(9, 10, 14, .94);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.app-page-head h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 850;
  letter-spacing: -.5px;
}
.app-page-head .app-head-actions { display: flex; align-items: center; gap: 8px; }
.app-page-head .app-head-action {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #f7f8fb;
  background: rgba(255, 255, 255, .08);
}
.app-page-head .app-head-action:active { transform: scale(.94); }

@media (prefers-reduced-motion: reduce) {
  html.in-firefly-app *,
  html.in-firefly-app *::before,
  html.in-firefly-app *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ══════════ 桌面宽屏版式（≥900px）：解除手机外框，切换为真正的桌面布局 ══════════
   - <900px（真机 <600px 全屏 / 600~899px 手机框预览）完全不受影响；
   - ≥900px：body 恢复整页滚动，.app-shell 变为普通页面容器，
     .app-main 限宽 1200px 居中，顶栏随容器限宽，底部 tabbar 改为居中悬浮胶囊。
     fixed 弹层（登录/下载弹窗、Cookie 条、toast）恢复以浏览器视口为定位基准。 */
@media (min-width: 900px) {
  html, body { height: auto; }
  body { display: block; overflow: auto; }

  .app-shell {
    width: 100%;
    height: auto;
    min-height: 100vh;
    padding: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
  }
  .app-shell::before,
  .app-shell::after { content: none; }

  .app-screen {
    height: auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    overflow: visible;
    background: var(--bg);
    transform: none;
  }
  .app-screen::before,
  .app-screen::after { display: none; }   /* 灵动岛 / Home 指示条 */
  .app-status { display: none; }          /* 模拟状态栏 */

  /* 主容器：居中限宽（首页信息流 / 直播间 / 我的 / 钱包 / 主播中心等共用） */
  .app-screen .app-main {
    flex: 1 0 auto;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    overflow: visible;
    padding-bottom: 86px;   /* 给悬浮 tabbar 留出高度，避免内容压底 */
  }

  /* 顶栏随容器限宽居中（底色与页面同色，视觉上仍是通栏） */
  .app-screen .site-header {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
  }

  /* 底部 Tab 栏：居中悬浮胶囊，不再贴满全宽 */
  .app-screen .app-tabbar {
    position: fixed;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 1200px;
    height: 62px;
    padding-bottom: 0;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-top: 1px solid rgba(255, 255, 255, .08);
    box-shadow: 0 18px 44px rgba(0, 0, 0, .55);
  }
  .app-screen .app-tab { height: 62px; }
  .app-screen .app-tab-go .plus { bottom: 22px; }
  .app-screen .app-tab-go .lbl { margin-top: 30px; }

  /* Cookie 条：底部居中限宽，避让悬浮 tabbar */
  .app-screen .cookie {
    left: 50%;
    right: auto;
    bottom: 86px;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 1200px;
    border-radius: 14px;
  }

  /* 直播间是全屏沉浸页：隐藏悬浮 tabbar，播放器 + 侧栏占满主容器 */
  body[data-page="room"] .app-screen .app-main { padding-bottom: 0; }
  body[data-page="room"] .app-tabbar { display: none; }
}

/* ══════════ App 语言切换底部弹层（partials/lang_sheet.html；仅 App 模式渲染） ══════════ */
.lang-sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 220;                     /* 高于 tabbar(75) 与页面顶栏(40)，低于 toast 之外的系统弹窗 */
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
/* flex 会覆盖 HTML hidden 的默认 display:none，这里必须显式兜底 */
.lang-sheet-mask[hidden] { display: none; }

.lang-sheet {
  width: 100%;
  max-width: 560px;                 /* 平板/宽屏不拉成一条长条 */
  margin: 0 auto;
  max-height: 70vh;
  overflow-y: auto;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  background: #14161d;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .5);
  animation: langSheetUp .22s ease-out;
}
@keyframes langSheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.lang-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 4px;
}
.lang-sheet-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #f7f8fb;
}
.lang-sheet-close {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: rgba(247, 248, 251, .7);
  font-size: 16px;
  border-radius: 12px;
  cursor: pointer;
}
.lang-sheet-close:active { background: rgba(255, 255, 255, .1); }

.lang-sheet-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 46px;                 /* 触控目标 ≥ 44px */
  margin-top: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, .045);
  color: #fff;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.lang-sheet-opt:active { background: rgba(255, 255, 255, .1); }
.lang-sheet-opt.on { border-color: var(--brand); color: var(--brand2); }
.lang-sheet-opt.on::after { content: '✓'; font-size: 14px; color: var(--brand2); }

/* 我的页语言行（仅 App 模式渲染，故无需限定 html.in-firefly-app） */
.me-lang-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 46px;                 /* 触控目标 ≥ 44px */
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, .045);
  color: #f7f8fb;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.me-lang-row:active { background: rgba(255, 255, 255, .1); }
.me-lang-row .me-lang-ico {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--grad);
  color: #fff;
  box-shadow: 0 6px 16px rgba(255, 44, 85, .26);
}
.me-lang-row .me-lang-name { flex: 1; }
.me-lang-row .me-lang-arrow { color: var(--text); opacity: .55; font-size: 18px; }

/* —— 语言弹层：切换中状态（点击后立即反馈，抵消整页加载的等待感） —— */
.lang-sheet-mask.switching .lang-sheet-opt{opacity:.45;pointer-events:none}
.lang-sheet-mask.switching .lang-sheet-opt.on{opacity:1}
.lang-sheet-loading{margin:10px 0 2px;text-align:center;font-size:12px;color:rgba(255,255,255,.55)}
