/* 全局重置与骨架布局。 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: var(--fs-base);
  line-height: 1.5;
  /* 禁止双击缩放与长按选中，接近原生 App 手感 */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* 输入框内仍然要能选中文本 */
input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

/* ---------------------------------------------------------------------------
   骨架：#app 是三行网格 —— 顶栏 / 滚动区 / 底部导航。
   固定头尾、只让中间滚动，比整页滚动更接近原生，也避免键盘弹出时顶栏被顶飞。

   高度优先用 dvh（动态视口高度，键盘弹出时自动收缩，Chrome 108+），
   老 WebView 退回 vh。
   --------------------------------------------------------------------------- */
#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

@supports (height: 100dvh) {
  #app {
    height: 100dvh;
  }
}

/* 顶栏 */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  min-height: var(--topbar-h);
  padding: 0 var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* 标题 + 服务器指示灯。包一层是为了让 router 改写标题文字时
   不会连带把指示灯一起清掉（它设的是 h1 的 textContent） */
.title-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-xs);
  min-width: 0;
}

.title-wrap h1 {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* 连不上服务器时的指示灯。默认那档（灰）由 .dot 自带 */
.topbar h1 {
  font-size: var(--fs-lg);
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* 顶栏左右两侧各留一个等宽槽位，标题才能真正居中 */
.topbar .slot {
  min-width: var(--tap);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* 中间滚动区 */
.scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--gap);
  /* 底部再留一点，防止最后一项贴着导航栏 */
  padding-bottom: calc(var(--gap) * 2);
}

/* 主内容在大屏居中 */
.scroll > .page {
  max-width: var(--max-w);
  margin: 0 auto;
}

/* 底部导航 */
.tabbar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tabbar button {
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  gap: 2px;
}

.tabbar button .ico {
  font-size: var(--fs-lg);
  line-height: 1;
}

.tabbar button.active {
  color: var(--primary);
}

/* ---------------------------------------------------------------------------
   通用工具类
   --------------------------------------------------------------------------- */

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-dim);
}

.center {
  text-align: center;
}

.stack {
  display: grid;
  gap: var(--gap-sm);
}

/* 分区标题 */
.section-title {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin: var(--gap) 0 var(--gap-sm);
}

.section-title:first-child {
  margin-top: 0;
}

/* 滚动条在桌面浏览器下弱化，避免打断卡片视觉 */
.scroll::-webkit-scrollbar {
  width: 6px;
}

.scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* 极老 WebView 的能力兜底提示，由 main.js 在能力不足时显示 */
.compat-warning {
  margin: var(--gap-lg);
  padding: var(--gap);
  border: 1px solid var(--st-error);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-base);
}
