/**
 * 基础样式重置 —— 主题「晨曦 Aurora」
 *
 * @description 全站基础层：重置、排版、容器、按钮、表单、卡片、工具类
 *              所有颜色 / 圆角 / 阴影一律取自 design-token.css
 */

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  /* 锚点跳转时给固定导航栏让位。少了这一句，点目录/页内锚点跳过去，
     目标标题正好被顶栏压在底下 —— 表现为「跳过去了但看不见」。 */
  scroll-padding-top: calc(var(--nav-h) + 16px);
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 15px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 顶部一道极淡的品牌光晕，让浅色页面不至于太"平" */
body::before {
  content: '';
  position: fixed;
  inset: 0 0 auto 0;
  height: 320px;
  background: radial-gradient(120% 100% at 50% 0%, var(--primary-soft) 0%, transparent 68%);
  pointer-events: none;
  /* -1：压在所有内容之下。原来是 0，靠下面 body > * 的 z-index:1 才不盖住正文；
     现在下面那条不再给 z-index，这里必须改成 -1，否则会盖在内容之上。 */
  z-index: var(--z-behind);
}

/* ⚠️ 这里**不能**给 z-index。
   一旦 body 的直接子元素（<main> / <footer> / .tabbar …）带上 z-index，
   它自己就成了独立的层叠上下文：里面 z-index:1200 的弹窗会被「困」在这一层，
   对外只按父级的 1 参与比较 —— 结果底部 TabBar（98）反而盖在弹窗之上，
   工具页的分享海报弹窗就是这么被挡住的。
   去掉 z-index（保持 auto，不创建层叠上下文）后，弹窗的层级才在根上下文生效。 */
body > * { position: relative; }

::selection {
  background: var(--primary);
  color: var(--text-onbrand);
}

a {
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
a:hover { text-decoration: none; }

ul { list-style: none; }

/* height:auto 不能省：只写 max-width:100% 时，若 <img> 自带 width/height 属性
   或别处给它定了高，等比缩放会被破坏，图片会被压扁 / 拉长。
   （带具体类名的规则如 .good-thumb{height:54px} 优先级更高，不受这条影响。） */
img { display: block; max-width: 100%; height: auto; }

button, input, select, textarea { font-family: inherit; }

/* 焦点环 —— 鼠标要安静，键盘要清晰
   原写法把 :focus 和 :focus-visible 一起设成 none，理由只是「点击后残留一圈线不好看」。
   但这两个选择器的语义完全不同：
     · :focus        鼠标点击、脚本 focus() 都会命中  → 不显示 outline（满足观感）
     · :focus-visible 只在键盘导航（Tab）时命中       → **必须**显示
   一起干掉之后，键盘用户 Tab 到按钮、链接、自定义控件上完全看不出焦点在哪
   （输入框还有 border + box-shadow 兜着，按钮和链接则一点反馈都没有）。
   现在拆开：鼠标点击依旧安静，键盘导航有清晰的品牌色焦点环。 */
:focus { outline: none; }

:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-xs);
}

/* 滚动条：细而克制 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ==================== 通用工具类 ==================== */
.hidden { display: none !important; }
/* 注意：这里**不要**再定义 .show { display: block !important }。
   全站有 33 个页面靠 classList.add('show') 做淡入（.toast.show / .report-modal.show /
   .modal-overlay.show …），一旦存在 !important 的全局 .show，这些容器会被强制
   display:block，淡入动画和 flex 居中布局全部失效。旧入口遗留的这条规则已删除。 */

/* ==================== Toast 提示 ====================
 * utils.js 的 showToast() 往 <body> 里塞一个 .toast 元素，
 * 但这条规则此前只定义在 admin.css（后台），前台 33 个工具页调 showToast
 * 其实什么都没显示。前台样式放到这里，补齐这个缺口。 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  z-index: var(--z-toast);
  max-width: min(88vw, 420px);
  padding: .75rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: .9rem;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) translateY(100px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==================== 容器 ==================== */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
}

main {
  /* 内页顶部/底部预留呼吸空间：导航与内容、内容与页脚不再贴死。
     首页/关于（page-has-hero）的 hero 必须顶到导航栏，padding 归零。 */
  padding: 28px 0 56px;
}
body.page-has-hero main { padding: 0; }

/* ==================== 排版 ==================== */
h1, h2, h3, h4 {
  line-height: 1.3;
  letter-spacing: -.2px;
  font-weight: 700;
}

/* ==================== 内页页头（统一「大气」版式） ==================== */
/* 首页有 Hero，内页若只放一个 1.4rem 的小标题会显得局促。
   这里把内页页头也做成有呼吸感的「小 Hero」：更大的字号 + 品牌竖条 + 底部渐变细线。 */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
  padding-bottom: 1.4rem;
  position: relative;
}
.page-header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--primary) 0%, transparent 62%);
  opacity: .45;
}
.page-header h1 {
  font-size: clamp(1.6rem, 2.6vw, 2.05rem);
  font-weight: 780;
  letter-spacing: -.9px;
  display: flex;
  align-items: center;
  gap: .6rem;
  line-height: 1.2;
}
.page-header h1 .fas,
.page-header h1 .far,
.page-header h1 .fab {
  color: var(--primary);
  font-size: .82em;
}
.page-header p {
  font-size: .95rem;
  color: var(--text-3);
  margin-top: .5rem;
}
/* 页头右侧的说明/操作 */
.page-header .page-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ==================== 按钮 ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0.7rem 1.6rem;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--grad-brand);
  color: var(--text-inv);
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover {
  color: var(--text-inv);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px var(--primary-shadow);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--card);
  color: var(--text-2);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: var(--text-onbrand); }

.btn-sm { padding: 0.4rem 1rem; font-size: 0.82rem; }
.btn-block { width: 100%; }

/* 让 .btn-* 单独使用（不带 .btn）时也有完整外观 */
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0.7rem 1.5rem;
  border-radius: var(--radius-pill);
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
}
.btn-full { width: 100%; }

/* ==================== 表单 ==================== */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
.form-label .req { color: var(--danger); }

.form-input,
.form-select,
.form-textarea,
.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  transition: border-color var(--dur), box-shadow var(--dur);
  font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus,
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* ==================== 卡片 ==================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* 相邻卡片留白。
   .card 本身没有外边距，两张卡上下相邻时会直接贴死
   （个人中心「每日签到」卡紧贴「账户充值」卡就是这么来的）。
   相邻 margin 会折叠，已经在别处设过 margin-bottom 的地方不会变成双倍。 */
.card + .card { margin-top: 1.25rem; }

.card-title {
  font-size: .98rem;
  font-weight: 650;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .45rem;
}
.card-title .fas { color: var(--primary); }

/* ==================== 空状态 ==================== */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: var(--text-3);
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state i {
  font-size: 2.6rem;
  opacity: .35;
  display: block;
  margin-bottom: .8rem;
}
.empty-state p { font-size: .9rem; }

/* ==================== 徽章 ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .65rem;
  border-radius: var(--radius-pill);
  font-size: .74rem;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}

/* ==================== 网格 ==================== */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ==================== 辅助类 ==================== */
.text-center { text-align: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.p-1 { padding: 8px; }
.p-2 { padding: 16px; }

/* 数字（价格 / 统计）用等宽字形，避免跳动 */
.num, .tabular { font-variant-numeric: tabular-nums; }

/* ==================== 响应式 ==================== */
@media (max-width: 992px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .container { padding: 0 16px; }
  main.container { padding: 16px 16px 32px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-header h1 { font-size: 1.2rem; }
  .btn-primary,
  .btn-secondary,
  .btn-ghost,
  .btn-danger { min-height: 44px; }
}

/* ==================== 无障碍：尊重系统的「减少动态效果」 ====================
 * 前庭功能障碍 / 晕动症用户会在系统里开「减少动态效果」。不响应这个设置，
 * 页面上的位移、缩放、轮播就会让他们不适。
 * 这里做全局兜底，把动画与过渡压到近乎为 0，而不是逐个组件去改一遍。
 * （homepage.css 里另有针对 hero 的细化处理，两者不冲突。） */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==================== 触摸设备：点击目标最小 44px ====================
 * 只在「视口 ≤768px」的断点里给 min-height 并不够 —— 平板和触屏笔记本
 * 同样靠手指操作，而它们的宽度往往大于 768px。
 * 用 (hover: none) 判断「没有精确指针」比猜宽度准得多。
 * 刻意不含 .btn-sm：那是表格行内、分页器里的紧凑按钮，撑到 44px 会把布局顶散。 */
@media (hover: none) {
  .btn,
  .btn-primary,
  .btn-secondary,
  .btn-ghost,
  .btn-danger {
    min-height: 44px;
  }
}
