/* ============================================================
   安愈 · 基础与组件样式
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body { min-height: 100vh; }

h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: 6px;
}

/* 无障碍：仅屏幕阅读器 */
.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;
}

/* ---------- 应用外壳 ---------- */
#app {
  max-width: var(--app-max);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 60px rgba(35, 51, 48, .06);
}

#view {
  flex: 1 1 auto;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  min-width: 0;
}
#view.with-mini { padding-bottom: calc(var(--tabbar-h) + var(--mini-h) + var(--safe-b) + 12px); }
#view.no-tabbar { padding-bottom: calc(var(--safe-b) + 8px); }
#view.no-tabbar.with-mini { padding-bottom: calc(var(--mini-h) + var(--safe-b) + 12px); }

.page { animation: pageIn var(--dur-2) var(--ease-out) both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 图标 ---------- */
.ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.35em; height: 1.35em; flex: 0 0 auto; vertical-align: -.28em;
}
.ico svg { width: 100%; height: 100%; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 22px;
  border-radius: var(--r-pill);
  font-size: var(--fs-h3); font-weight: 600;
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background var(--dur-1);
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  color: #fff; box-shadow: var(--sh-brand);
}
:root[data-theme="dark"] .btn-primary, :root:not([data-theme="light"]) .btn-primary { color: #0E1614; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .btn-primary { color: #fff; } }
.btn-ghost { background: var(--surface); color: var(--brand-600); border: 1px solid var(--brand-200); }
.btn-soft { background: var(--brand-50); color: var(--brand-700); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 34px; padding: 0 14px; font-size: var(--fs-sm); }
.btn[disabled] { opacity: .48; pointer-events: none; }

.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); flex: 0 0 auto;
  transition: background var(--dur-1);
}
.icon-btn:active { background: var(--line-soft); }
.icon-btn .ico { width: 22px; height: 22px; }

/* ---------- 页头 ---------- */
.page-head {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-t) + 6px) 10px 6px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  min-height: 52px;
}
.page-head.scrolled {
  border-bottom-color: var(--line);
  background: var(--glass-strong);
  backdrop-filter: blur(14px);
  box-shadow: 0 2px 12px rgba(35, 51, 48, .06);
}
.page-head.transparent { background: transparent; border-bottom: 0; }
.page-head .head-title { flex: 1 1 auto; min-width: 0; text-align: center; }
.page-head .head-title h1 {
  font-size: var(--fs-h2); font-weight: 600; letter-spacing: .02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.page-head .head-title p { font-size: var(--fs-xs); color: var(--ink-3); }
.head-right { display: flex; align-items: center; gap: 2px; min-width: 40px; justify-content: flex-end; }
.head-spacer { width: 40px; flex: 0 0 auto; }

/* ---------- 底部 Tab ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 60;
  width: 100%; max-width: var(--app-max);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--glass-strong);
  backdrop-filter: blur(18px) saturate(1.3);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-4); font-size: var(--fs-xs); font-weight: 500;
  transition: color var(--dur-1);
}
.tabbar a .ico { width: 23px; height: 23px; }
.tabbar a.active { color: var(--brand-600); }
.tabbar a.active .ico { transform: translateY(-1px); }

/* ---------- 迷你播放条 ---------- */
.mini {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 6px);
  z-index: 55;
  width: calc(100% - 24px); max-width: calc(var(--app-max) - 24px);
  height: 54px; padding: 0 8px 0 8px;
  display: flex; align-items: center; gap: 10px;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--glass-line);
  border-radius: var(--r-pill);
  box-shadow: var(--sh-2);
  animation: miniIn var(--dur-2) var(--ease-out) both;
}
.mini.no-tabbar { bottom: calc(var(--safe-b) + 10px); }
@keyframes miniIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }
.mini-art {
  width: 40px; height: 40px; border-radius: var(--r-pill); overflow: hidden; flex: 0 0 auto;
  position: relative;
}
.mini-art svg { width: 100%; height: 100%; }
.mini.playing .mini-art { animation: spin 16s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.mini-main { flex: 1 1 auto; min-width: 0; }
.mini-main h4 {
  font-size: var(--fs-sm); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mini-main p { font-size: var(--fs-xs); color: var(--ink-3); }
.mini .icon-btn { width: 38px; height: 38px; color: var(--brand-600); }

/* ---------- 卡片通用 ---------- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}

/* 插画容器 */
.art { width: 100%; height: 100%; display: block; }

/* ---------- 章节标题 ---------- */
.sec-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 22px 16px 10px;
}
.sec-head h2 {
  font-family: var(--font-serif);
  font-size: var(--fs-h1); font-weight: 600; letter-spacing: .04em;
}
.sec-more {
  font-size: var(--fs-sm); color: var(--ink-3);
  display: inline-flex; align-items: center; gap: 1px; flex: 0 0 auto;
}
.sec-more .ico { width: 15px; height: 15px; }

/* ---------- 内容卡（横滑） ---------- */
.hscroll {
  display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x proximity;
  padding: 2px 16px 6px; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.hscroll::-webkit-scrollbar { display: none; }

.track-card {
  position: relative; flex: 0 0 auto;
  width: 148px; aspect-ratio: 3 / 4;
  border-radius: var(--r-lg); overflow: hidden;
  box-shadow: var(--sh-1);
  scroll-snap-align: start;
  transition: transform var(--dur-1) var(--ease);
  isolation: isolate;
}
.track-card.lg { width: 172px; }
.track-card:active { transform: scale(.975); }
.tc-art { position: absolute; inset: 0; }
.tc-scrim { position: absolute; inset: 0; background: var(--on-art-scrim); }
.tc-top { position: absolute; top: 8px; left: 8px; z-index: 2; }
.tc-bottom { position: absolute; left: 10px; right: 10px; bottom: 9px; z-index: 2; }
.tc-title {
  font-size: var(--fs-h3); font-weight: 600; color: var(--on-art);
  text-shadow: 0 1px 6px rgba(0,0,0,.5);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tc-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 2px; }
.tc-learn {
  font-size: var(--fs-xs); color: var(--on-art-2);
  display: inline-flex; align-items: center; gap: 2px;
  text-shadow: 0 1px 4px rgba(0,0,0,.45);
}
.tc-learn .ico { width: 13px; height: 13px; }
.tc-play {
  width: 26px; height: 26px; border-radius: var(--r-pill);
  background: rgba(255,255,255,.9); color: var(--brand-700);
  display: inline-flex; align-items: center; justify-content: center;
}
.tc-play .ico { width: 16px; height: 16px; }

/* ---------- 权益角标 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .02em;
  backdrop-filter: blur(6px);
}
.badge .ico { width: 13px; height: 13px; }
.badge-free { background: rgba(20,32,30,.44); color: #fff; }
.badge-vip { background: linear-gradient(135deg, #E7C68F, #C9A87C); color: #4A3A22; }
.badge-paid { background: rgba(255,255,255,.92); color: var(--brand-700); }

/* ---------- 网格卡 ---------- */
.grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  padding: 8px 16px 20px;
}
.grid-card {
  background: var(--surface); border-radius: var(--r-lg); overflow: hidden;
  box-shadow: var(--sh-1);
  display: flex; flex-direction: column;
  transition: transform var(--dur-1) var(--ease);
}
.grid-card:active { transform: scale(.98); }
.gc-art { position: relative; aspect-ratio: 4 / 3; }
.gc-badge { position: absolute; top: 8px; left: 8px; }
.gc-info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1 1 auto; }
.gc-info h3 { font-size: var(--fs-h3); font-weight: 600; }
.gc-info p {
  font-size: var(--fs-sm); color: var(--ink-3); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.gc-foot {
  margin-top: auto; padding-top: 8px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: var(--fs-xs); color: var(--ink-4);
}
.gc-foot .ico { width: 13px; height: 13px; }

/* ---------- 列表行 ---------- */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  transition: background var(--dur-1);
}
.list-row:active { background: var(--line-soft); }
.lr-art { width: 58px; height: 58px; border-radius: var(--r-md); overflow: hidden; flex: 0 0 auto; }
.lr-main { flex: 1 1 auto; min-width: 0; }
.lr-main h3 { font-size: var(--fs-h3); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr-main p { font-size: var(--fs-sm); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; color: var(--ink-4); font-size: var(--fs-xs); }
.lr-lock .ico { width: 16px; height: 16px; }

/* ---------- 空态 ---------- */
.empty { padding: 40px 24px; text-align: center; color: var(--ink-3); }
.empty-art { width: 152px; height: 152px; margin: 0 auto 16px; border-radius: 26px; overflow: hidden; opacity: .9; box-shadow: var(--sh-1); }
.empty p { font-size: var(--fs-body); margin-bottom: 14px; }

/* ---------- 头像 ---------- */
.avatar { display: inline-block; border-radius: 50%; overflow: hidden; flex: 0 0 auto; box-shadow: var(--sh-1); }
.avatar svg { width: 100%; height: 100%; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translate(-50%, 12px);
  z-index: 400; max-width: min(340px, 84vw);
  display: flex; align-items: center; gap: 7px;
  padding: 11px 18px; border-radius: var(--r-pill);
  background: rgba(24, 38, 35, .92); color: #fff;
  font-size: var(--fs-sm); box-shadow: var(--sh-3);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease-out);
  backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .ico { width: 17px; height: 17px; }

/* ---------- 底部弹层 ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 150; }
.sheet-mask {
  position: absolute; inset: 0; background: var(--overlay);
  opacity: 0; transition: opacity var(--dur-2) var(--ease);
}
.sheet-wrap.open .sheet-mask { opacity: 1; }
.sheet {
  position: absolute; left: 50%; bottom: 0; transform: translate(-50%, 100%);
  width: 100%; max-width: var(--app-max);
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 8px 18px calc(18px + var(--safe-b));
  box-shadow: var(--sh-3);
  transition: transform var(--dur-3) var(--ease-out);
  max-height: 86vh; overflow-y: auto;
}
.sheet-wrap.open .sheet { transform: translate(-50%, 0); }
.sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet-title { font-size: var(--fs-h2); font-weight: 600; text-align: center; margin-bottom: 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1 1 0; }

/* ---------- 对话框 ---------- */
.dlg-wrap { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 24px; }
.dlg-mask { position: absolute; inset: 0; background: var(--overlay); opacity: 0; transition: opacity var(--dur-2); }
.dlg-wrap.open .dlg-mask { opacity: 1; }
.dlg {
  position: relative; width: 100%; max-width: 320px;
  background: var(--surface); border-radius: var(--r-xl);
  padding: 24px 22px 18px; box-shadow: var(--sh-3);
  transform: scale(.94); opacity: 0;
  transition: transform var(--dur-2) var(--ease-out), opacity var(--dur-2);
}
.dlg-wrap.open .dlg { transform: none; opacity: 1; }
.dlg-title { font-size: var(--fs-h2); font-weight: 600; text-align: center; margin-bottom: 10px; }
.dlg-body { font-size: var(--fs-sm); color: var(--ink-2); text-align: center; line-height: 1.68; }
.dlg-body p + p { margin-top: 8px; }
.dlg-actions { display: flex; gap: 10px; margin-top: 20px; }
.dlg-actions .btn { flex: 1 1 0; min-height: 42px; }

/* ---------- 表单 ---------- */
.field { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.field .ico { width: 20px; height: 20px; color: var(--ink-4); flex: 0 0 auto; }
.field input {
  flex: 1 1 auto; min-width: 0; border: 0; background: none; outline: none;
  font-size: var(--fs-body); padding: 2px 0;
}
.field input::placeholder { color: var(--ink-4); }
.field .field-act { flex: 0 0 auto; font-size: var(--fs-sm); color: var(--brand-600); font-weight: 600; }

textarea.ta {
  width: 100%; min-height: 110px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface-2); outline: none; resize: vertical;
  font-size: var(--fs-body); line-height: 1.7;
}
textarea.ta:focus { border-color: var(--brand-300); }

.checkline { display: flex; align-items: flex-start; gap: 9px; font-size: var(--fs-sm); color: var(--ink-3); }
.checkbox {
  width: 20px; height: 20px; border-radius: 50%; flex: 0 0 auto; margin-top: 1px;
  border: 1.6px solid var(--ink-4);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--dur-1), border-color var(--dur-1);
  color: transparent;
}
.checkbox .ico { width: 13px; height: 13px; }
.checkbox.on { background: var(--brand-500); border-color: var(--brand-500); color: #fff; }
.checkline a { color: var(--brand-600); }

/* ---------- 分段控件 ---------- */
.segment {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-2); border-radius: var(--r-pill);
}
.segment button {
  padding: 7px 16px; border-radius: var(--r-pill);
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-3);
  transition: background var(--dur-1), color var(--dur-1);
}
.segment button.on { background: var(--surface); color: var(--brand-700); box-shadow: var(--sh-1); }

/* ---------- 页签 ---------- */
.tabs { display: flex; gap: 20px; padding: 4px 16px 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; padding: 8px 0 12px; flex: 0 0 auto;
  font-size: var(--fs-h3); font-weight: 500; color: var(--ink-3);
  transition: color var(--dur-1);
}
.tabs button.on { color: var(--ink); font-weight: 600; }
.tabs button.on::after {
  content: ''; position: absolute; left: 50%; bottom: 5px; transform: translateX(-50%);
  width: 20px; height: 3px; border-radius: 2px; background: var(--brand-500);
}

/* ---------- 进度环 ---------- */
.ring { display: block; }

/* ---------- 滑杆 ---------- */
.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: none; }
.slider::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px;
  background: linear-gradient(to right, var(--brand-500) var(--pct, 50%), var(--line) var(--pct, 50%));
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand-500); margin-top: -6.5px;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.slider::-moz-range-track { height: 5px; border-radius: 3px; background: var(--line); }
.slider::-moz-range-progress { height: 5px; border-radius: 3px; background: var(--brand-500); }
.slider::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 2px solid var(--brand-500); }

/* ---------- 通用工具 ---------- */
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.serif { font-family: var(--font-serif); }
.pad { padding: 16px; }
.pad-x { padding-left: 16px; padding-right: 16px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; } .mt-6 { margin-top: 24px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* 长文可读排版 */
.prose { padding: 4px 18px 30px; font-size: var(--fs-body); line-height: 1.85; color: var(--ink-2); }
.prose h2 { font-family: var(--font-serif); font-size: var(--fs-h2); color: var(--ink); margin: 22px 0 8px; }
.prose h3 { font-size: var(--fs-h3); color: var(--ink); margin: 16px 0 6px; }
.prose p { margin: 8px 0; }
.prose ol { counter-reset: n; }
.prose ol li { counter-increment: n; position: relative; padding-left: 24px; margin: 7px 0; }
.prose ol li::before {
  content: counter(n); position: absolute; left: 0; top: .28em;
  width: 17px; height: 17px; border-radius: 50%; background: var(--brand-100); color: var(--brand-700);
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- 动效降级 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
:root[data-reduce-motion] *, :root[data-reduce-motion] *::before, :root[data-reduce-motion] *::after {
  animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important;
}

/* ---------- 宽屏 ---------- */
@media (min-width: 700px) {
  body { background: var(--bg-2); }
  #app { border-radius: 0; }
}
