/* ==========================================================================
   小马上岸 · 移动 App 端 基础样式
   重置 / 排版 / 手机画框 / 状态栏 / 导航栏 / 内容区 / 标签栏 / 工具类

   本文件是跨端「预览页五条硬性约束」的参考实现：
     1. 滚动 flex 列容器的子项必须 flex-shrink: 0（见下方 .screen > *）
     2. 说明文字必须画框之外，不得浮在原型之上（见「聚合预览模式」与「独立预览页」段落）
     3. 独立预览页必须一屏无滚动条且画框不被裁切（见「独立预览页」段落）
     4. 底部固定操作区不要用 position: sticky，应移出滚动容器常驻画框
        （见 components.css 的 .action-dock 段落）
     5. 底部标签栏只属于顶级 Tab 页；二级及以下页面不显示标签栏，
        底部操作区改为通栏固定条（见 components.css 的 .action-dock--bar 段落）
   完整约束与自检方法见 ../../README.md，其余端请对齐后再动手。
   ========================================================================== */

*,
*::before,
*::after { box-sizing: border-box; }

html, body, h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-normal);
  color: var(--color-on-surface);
  background: var(--color-bg-tint);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  transition: background var(--dur-base) var(--ease-standard);
}

/* 画框外的氛围光晕 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(620px 420px at 14% 8%, var(--color-primary-soft), transparent 68%),
    radial-gradient(520px 380px at 88% 90%, var(--color-accent-soft), transparent 70%);
}

/* ==========================================================================
   聚合预览（iframe 内嵌）模式
   页面被 index.html 用 iframe 内嵌时，外壳画框由聚合页统一提供，
   这里把页面自身的画框「拍平」，避免出现双层边框套娃。
   ========================================================================== */
.aux-link,
.page-footnote { display: none !important; }

html.in-frame,
html.in-frame body {
  height: 100%;
  min-height: 0;
  overflow: hidden;               /* 滚动交给内部 .screen，避免双层滚动条 */
}
html.in-frame body {
  display: block;
  padding: 0;
  background: var(--color-bg);
}
html.in-frame body::before { display: none; }
html.in-frame .phone {
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
html.in-frame .phone-notch { display: none; }
html.in-frame .phone-screen { border-radius: 0; }

/* ==========================================================================
   独立预览页（单独打开某一页）的窗口级布局
   仅当「文档里存在手机画框、且不在聚合预览 iframe 内」时生效，
   design-system.html 等没有画框的文档完全不受影响。
   目标：
     1. 一屏内完整展示画框，不产生垂直 / 水平滚动条；
     2. 顶部预留一条说明栏，承载「返回聚合预览」与本页说明文字，
        说明文字不再浮在画框之上遮挡原型。
   ========================================================================== */
html:not(.in-frame):has(body > .phone) {
  --pv-bar: 0px;                  /* 顶部说明栏高度（已移除说明栏） */
  --pv-gap: var(--space-4);       /* 画框与窗口边缘的呼吸间距 */
  height: 100%;
  overflow: hidden;
}
html:not(.in-frame):has(body > .phone) body {
  height: 100%;
  min-height: 0;
  display: grid;
  /* 只能用 start 定位：布局盒始终是未缩放的 375×812，
     若用 center，超出内容盒的部分会被 overflow:hidden 裁掉，
     视觉画框会整体下坠并顶出窗口底部。 */
  place-items: start center;
  /* 用 clip 而非 hidden：不生成滚动容器，画框未缩放时的布局溢出
     既不会出现滚动条，也无法被焦点滚动 / scrollIntoView 带动。 */
  overflow: clip;
  /* 顶部让出说明栏，底部只留呼吸间距 */
  padding: calc(var(--pv-bar) + var(--pv-gap)) var(--space-4) var(--pv-gap);
}
/* 画框按窗口等比缩放：min(1, 可用宽/画框宽, 可用高/画框高)。
   transform 不参与布局，配合 transform-origin: top center，
   视觉左上角与布局盒左上角重合，因此画框精确落在
   [说明栏 + 间距] 到 [窗口底部 - 间距] 之间，既不裁切也不溢出。
   （两个长度相除得到数值属 CSS Values 4，2023 起主流浏览器均支持） */
html:not(.in-frame):has(body > .phone) .phone {
  transform: scale(min(1,
    (100vw - var(--space-4) * 2) / var(--frame-w),
    (100vh - var(--pv-bar) - var(--pv-gap) * 2) / var(--frame-h)));
  transform-origin: top center;
}
/* 说明栏左段：返回聚合预览入口 */
html:not(.in-frame):has(body > .phone) .aux-link {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 101;
  height: var(--pv-bar);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}
/* 说明栏主体：本页说明文字，单行居中，过长省略号 */
html:not(.in-frame):has(body > .phone) .page-footnote {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--pv-bar);
  display: block;
  /* 左侧让出返回入口的宽度，说明文字永远不会压住它 */
  padding: 0 var(--space-4) 0 172px;
  line-height: var(--pv-bar);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--fs-12);
  border: 0;
  border-bottom: 1px solid var(--color-outline);
  border-radius: 0;
  box-shadow: none;
  background: var(--color-surface);
}

/* ==========================================================================
   手机画框
   ========================================================================== */
.phone {
  position: relative;
  z-index: 1;
  width: var(--frame-w);
  height: var(--frame-h);
  border-radius: 44px;
  padding: 10px;
  background: #0F172A;
  box-shadow:
    0 0 0 1.5px #1F2937,
    0 32px 70px -18px rgba(15, 23, 42, 0.5),
    0 8px 20px -8px rgba(15, 23, 42, 0.35);
  flex: none;
}

[data-theme="dark"] .phone {
  background: #05080F;
  box-shadow:
    0 0 0 1.5px #1E293B,
    0 32px 70px -18px rgba(0, 0, 0, 0.75);
}

.phone-screen {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--screen-radius);
  overflow: hidden;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  transition: background var(--dur-base) var(--ease-standard);
}

/* 灵动岛 / 刘海 */
.phone-notch {
  position: absolute;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 22px;
  border-radius: var(--radius-full);
  background: #0F172A;
  z-index: 55;
}
[data-theme="dark"] .phone-notch { background: #05080F; }

/* ==========================================================================
   Safe Area 差异化：iOS（默认）灵动岛 vs Android 打孔屏
   画框加 data-device="android" 即切换为打孔屏状态栏；
   默认不写即为 iOS 灵动岛（顶部居中胶囊）。
   ========================================================================== */
.phone[data-device="android"] .phone-notch {
  width: 13px;
  height: 13px;
  top: 17px;
  left: 30px;
  transform: none;
  border-radius: 50%;
}
.phone[data-device="android"] .statusbar {
  padding: 0 var(--space-6) 0 54px; /* 让开左侧挖孔摄像头 */
}

/* ==========================================================================
   状态栏
   ========================================================================== */
.statusbar {
  flex: none;
  height: var(--statusbar-h);
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-num);
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  color: var(--color-on-surface);
  letter-spacing: 0.01em;
  user-select: none;
}
.statusbar .sb-right {
  display: flex;
  align-items: center;
  gap: 5px;
}
.statusbar svg { width: 15px; height: 15px; }

/* ==========================================================================
   导航栏
   ========================================================================== */
.navbar {
  flex: none;
  height: var(--navbar-h);
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-bg);
  position: relative;
  z-index: var(--z-navbar);
}
.navbar-title {
  font-size: var(--fs-16);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.navbar-title.center { text-align: center; }
.navbar-sub {
  display: block;
  font-size: var(--fs-11);
  font-weight: var(--fw-regular);
  color: var(--color-on-surface-variant);
  margin-top: 1px;
}
.navbar-action {
  width: var(--touch-min);
  height: var(--touch-min);
  margin-right: calc(-1 * (var(--touch-min) - 24px) / 2);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--color-on-surface-variant);
  transition: background var(--dur-fast) var(--ease-standard);
}
.navbar-action:active { background: var(--color-surface-2); }
.navbar-action i[data-ico] { width: 24px !important; height: 24px !important; }
.navbar-action svg { width: 24px; height: 24px; }
.navbar-spacer { width: var(--touch-min); flex: none; }

/* ==========================================================================
   品牌标识（Logo）
   图形标路径、配色与容器几何的唯一来源见 ui/README.md §4
   --bm 是唯一尺寸变量：宽高、圆角、图形字号全部由它派生
   ========================================================================== */
.brand-mark {
  --bm: var(--brand-mark-md);
  width: var(--bm); height: var(--bm); flex: none;
  border-radius: calc(var(--bm) * .30);
  background: var(--brand-gradient); color: #fff;
  display: grid; place-items: center;
  font-size: calc(var(--bm) * .58);
  box-shadow: var(--brand-shadow);
}
.brand-mark--sm { --bm: var(--brand-mark-sm); }
.brand-mark--lg { --bm: var(--brand-mark-lg); }
.brand-mark--xl { --bm: var(--brand-mark-xl); }

/* 锁定组合：[图形标] + 名称（+ 可选副标），间距 11px 与其余五端一致 */
.brand-lockup { display: flex; align-items: center; gap: 11px; min-width: 0; }
/* 锁定组合文字：字重 800 / 字距 -.02em，与其余五端逐字一致（ui/README.md §4.5） */
.brand-name {
  font-size: var(--fs-16); font-weight: 800; letter-spacing: -0.02em;
  line-height: 1.15; white-space: nowrap; color: var(--color-on-surface);
}

/* ==========================================================================
   内容区
   ========================================================================== */
.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--gutter) var(--space-6);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.screen.flush { padding: 0; }
/* .has-tabbar 是「本页挂载底部标签栏」的语义标记，只有顶级 Tab 页
   （home / practice / diagnosis / profile）才带这个类；二级及以下页面
   必须去掉它，并把底部操作区换成通栏固定条 .action-dock--bar
   （见 components.css），不能靠把标签栏藏起来蒙混过关。
   本规则的留白数值与基础 .screen 一致，作用仅是标记 + 兜底。
   注意 .screen 只负责滚动；底部的固定操作区请用 .action-dock 系列实现，
   不要再用 position: sticky —— 粘滞范围会被滚动容器的 content box 截断，
   永远贴不到内容区底部，表现为按钮悬在半空。 */
.screen.has-tabbar { padding-bottom: var(--space-6); }

/* 关键修复：.screen 同时是「滚动容器」和「flex 列容器」。
   子项默认 flex-shrink:1，一旦内容高于屏幕，flex 会把子项压缩到最小高度，
   而不是让 .screen 滚动。带 overflow:hidden 的卡片（.hero-card / .cam-stage）
   由于 min-height:auto 解析为 0，会被单独压扁（实测 228px → 40px、250px → 0），
   于是「头部卡片」的文本被裁切、错位。
   置 flex-shrink:0 后子项保持自然高度，溢出交给 .screen 的 overflow-y:auto。 */
.screen > * { flex-shrink: 0; }

.screen::-webkit-scrollbar { width: 4px; }
.screen::-webkit-scrollbar-thumb {
  background: var(--color-outline-strong);
  border-radius: var(--radius-full);
}
.screen::-webkit-scrollbar-track { background: transparent; }

/* ==========================================================================
   底部标签栏
   ========================================================================== */
.tabbar {
  flex: none;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: stretch;
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--color-outline);
  border-radius: 0 0 var(--screen-radius) var(--screen-radius);
  position: relative;
  z-index: var(--z-tabbar);
}
.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--color-text-tertiary);
  font-size: var(--fs-11);
  font-weight: var(--fw-medium);
  transition: color var(--dur-fast) var(--ease-standard);
}
.tabbar-item svg { width: 22px; height: 22px; }
.tabbar-item.is-active { color: var(--color-primary); font-weight: var(--fw-semibold); }
.tabbar-item:active { opacity: 0.6; }

/* 中间凸起的 AI 主按钮 */
.tabbar-ai {
  flex: none;
  width: 68px;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.tabbar-ai-btn {
  position: absolute;
  top: -16px;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-2xl);
  background: var(--gradient-ai);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-primary), 0 0 0 4px color-mix(in srgb, var(--color-surface) 92%, transparent);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.tabbar-ai-btn svg { width: 30px; height: 30px; }
.tabbar-ai-btn:active { transform: scale(0.92); }
.tabbar-ai-label {
  margin-top: 42px;
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  color: var(--color-primary);
}
.tabbar-ai.is-active .tabbar-ai-label { color: var(--color-primary); }

/* Home Indicator */
.home-indicator {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 134px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--color-on-surface);
  opacity: 0.22;
  pointer-events: none;
  z-index: 56;
}

/* ==========================================================================
   排版工具类
   ========================================================================== */
.t-hero { font-size: var(--fs-24); font-weight: var(--fw-bold); line-height: var(--lh-tight); letter-spacing: -0.02em; }
.t-title { font-size: var(--fs-20); font-weight: var(--fw-bold); line-height: var(--lh-tight); letter-spacing: -0.015em; }
.t-heading { font-size: var(--fs-16); font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
.t-body { font-size: var(--fs-14); line-height: var(--lh-normal); }
.t-label { font-size: var(--fs-13); font-weight: var(--fw-medium); }
.t-caption { font-size: var(--fs-12); line-height: var(--lh-normal); }
.t-micro { font-size: var(--fs-11); line-height: var(--lh-normal); }

.muted { color: var(--color-on-surface-variant); }
.tertiary { color: var(--color-text-tertiary); }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.strong { font-weight: var(--fw-semibold); }
.bold { font-weight: var(--fw-bold); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.text-primary { color: var(--color-primary); }
.text-secondary { color: var(--color-secondary); }
.text-accent { color: var(--color-accent); }
.text-ai { color: var(--color-ai); }
.text-error { color: var(--color-error); }
.text-warning { color: var(--color-warning); }

/* ==========================================================================
   布局工具类
   ========================================================================== */
.row { display: flex; align-items: center; gap: var(--space-2); }
.row-4 { display: flex; align-items: center; gap: var(--space-4); }
.col { display: flex; flex-direction: column; }
.col-1 { display: flex; flex-direction: column; gap: var(--space-1); }
.col-2 { display: flex; flex-direction: column; gap: var(--space-2); }
.col-3 { display: flex; flex-direction: column; gap: var(--space-3); }
.col-4 { display: flex; flex-direction: column; gap: var(--space-4); }
.col-5 { display: flex; flex-direction: column; gap: var(--space-5); }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.center { justify-content: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.flex-1 { flex: 1; min-width: 0; }
.grow { flex-grow: 1; }
.full { width: 100%; }
.relative { position: relative; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* 段落标题 */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.section-title {
  font-size: var(--fs-16);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.section-title::before {
  content: "";
  width: 3px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--gradient-primary);
}
.section-more {
  font-size: var(--fs-12);
  color: var(--color-text-tertiary);
  display: flex;
  align-items: center;
  gap: 2px;
}
.section-more svg { width: 13px; height: 13px; }

/* 图标基类 */
[data-ico] {
  display: inline-flex;
  width: 1em;
  height: 1em;
  flex: none;
  align-items: center;
  justify-content: center;
}
[data-ico] > svg {
  width: 100%;
  height: 100%;
  display: block;
}
