/* 古诗库 · 唐音阁 —— 原生 App 质感的移动阅读体验（iOS 风格 + 纸墨主题） */
:root {
  --paper: #f7f3ec;
  --paper-dim: #f0ebe1;
  --card: #fffdf8;
  --ink: #2b2620;
  --ink-2: #6f675c;
  --ink-3: #a39a8c;
  --line: rgba(60, 50, 35, .12);          /* hairline */
  --accent: #a8432f;                       /* 朱砂 */
  --accent-soft: #f3e4df;
  --indigo: #34506b;                       /* 黛青 */
  --indigo-soft: #e4ebf1;
  --r-card: 16px;
  --ease-ios: cubic-bezier(.32, .72, 0, 1);
  --dur: .34s;
  --serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  touch-action: manipulation;
}
button { font: inherit; background: none; border: none; cursor: pointer; color: inherit; touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
input { font-family: var(--sans); }
input[type="search"]::-webkit-search-cancel-button { display: none; }

/* ================= 列表视图 ================= */
#view-list { transition: transform var(--dur) var(--ease-ios), opacity var(--dur) var(--ease-ios); }
#view-list.pushed { transform: translateX(-72px); opacity: .55; pointer-events: none; }

/* ---------- 顶栏（iOS 大标题折叠） ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(247, 243, 236, .92);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  padding: calc(var(--sat) + 6px) 16px 8px;
}
.topbar::after {                        /* 滚动后出现的 hairline */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0;
  height: .5px; background: var(--ink); opacity: 0; transition: opacity .25s;
  pointer-events: none;
}
.topbar.scrolled::after { opacity: .18; }

.top-row {
  display: flex; align-items: center; justify-content: space-between;
  height: 0; opacity: 0; overflow: hidden;
  transition: height .28s var(--ease-ios), opacity .2s;
}
.topbar.compact .top-row { height: 34px; opacity: 1; }
.compact-title { font-size: 17px; font-weight: 600; letter-spacing: 1px; }
.compact-sub { font-size: 12px; color: var(--ink-3); }

.large-row {
  display: flex; align-items: baseline; gap: 10px;
  max-height: 60px; overflow: hidden;
  transition: max-height .28s var(--ease-ios), opacity .2s, margin .28s var(--ease-ios);
}
.topbar.compact .large-row { max-height: 0; opacity: 0; margin: -4px 0; }
.large-title { font-family: var(--serif); font-size: 32px; font-weight: 700; letter-spacing: 8px; }
.large-sub { font-size: 12px; color: var(--ink-3); }

/* ---------- 搜索（iOS 风格） ---------- */
.search-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.search-wrap {
  position: relative; flex: 1; display: flex; align-items: center;
  background: rgba(60, 50, 35, .07);
  border-radius: 11px; padding: 0 10px; height: 38px;
  transition: background .2s, box-shadow .2s;
}
.search-wrap:focus-within { box-shadow: 0 0 0 1.5px rgba(168, 67, 47, .35); background: rgba(60, 50, 35, .05); }
.s-ico { flex: 0 0 auto; color: var(--ink-3); margin-right: 7px; }
#search {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  font-size: 16px;                    /* ≥16px，避免 iOS 聚焦自动放大 */
  color: var(--ink); height: 100%;
}
#search::placeholder { color: var(--ink-3); }
#search::-webkit-search-cancel-button, #search::-webkit-search-decoration { display: none; -webkit-appearance: none; }
.s-clear { flex: 0 0 auto; display: flex; padding: 2px; }
.s-cancel {
  flex: 0 0 auto; color: var(--accent); font-size: 16px; padding: 4px 0 4px 2px;
  max-width: 60px; overflow: hidden; white-space: nowrap;
  animation: fade-in .25s ease;
}
@keyframes fade-in { from { opacity: 0; } }

/* ---------- chips 与筛选按钮 ---------- */
.bar-row { display: flex; align-items: center; gap: 8px; }
.chipbar { display: flex; gap: 8px; overflow-x: auto; flex: 1; scrollbar-width: none; padding: 2px 0 1px; -webkit-overflow-scrolling: touch; }
.chipbar::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; font-size: 13.5px; padding: 6px 14px;
  border-radius: 999px; background: rgba(60, 50, 35, .06); color: var(--ink-2);
  white-space: nowrap; transition: transform .18s var(--ease-ios), background .18s, color .18s;
}
.chip:active { transform: scale(.94); }
.chip.on { background: var(--accent); color: #fff; }
.filter-btn {
  flex: 0 0 auto; font-size: 13.5px; padding: 6px 14px; border-radius: 999px;
  background: var(--indigo-soft); color: var(--indigo); font-weight: 500;
  transition: transform .18s var(--ease-ios);
}
.filter-btn:active { transform: scale(.94); }
.filter-btn span { font-weight: 700; }

/* ---------- 已选筛选 ---------- */
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 0; }
.active-filters:empty { display: none; }
.af {
  font-size: 12.5px; padding: 4px 11px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  animation: pop-in .22s var(--ease-ios);
}
.af b::after { content: " ✕"; opacity: .55; }
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } }

/* ---------- 列表卡片（原生 cell 质感） ---------- */
.list { padding: 12px 16px calc(var(--sab) + 24px); }
.card {
  display: block;
  background: var(--card);
  border-radius: var(--r-card);
  box-shadow: 0 .5px 1.5px rgba(50, 40, 25, .08), 0 0 0 .5px rgba(60, 50, 35, .05);
  padding: 14px 16px; margin-bottom: 11px;
  transition: transform .18s var(--ease-ios), box-shadow .18s, background .18s;
  will-change: transform;
}
.card:active { transform: scale(.977); background: #f8f3e9; box-shadow: 0 .5px 1px rgba(50, 40, 25, .06); }
.card .t { font-size: 17px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; }
.card .t .badges { display: flex; gap: 5px; margin-left: auto; flex: 0 0 auto; }
.card .a { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.card .l { font-size: 14.5px; color: var(--ink); margin-top: 8px; letter-spacing: .5px; font-family: var(--serif); }
.card .l i { color: var(--ink-3); font-style: normal; }
.card .tags { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
  background: rgba(60, 50, 35, .06); color: var(--ink-2);
}
.tag.na { background: var(--accent-soft); color: var(--accent); }
.tag.ng { background: var(--indigo-soft); color: var(--indigo); }

.empty { text-align: center; color: var(--ink-2); padding: 46px 16px; font-size: 15px; }
.empty span { font-size: 13px; color: var(--ink-3); }
.sentinel { text-align: center; color: var(--ink-3); padding: 26px 16px; font-size: 13px; }
.foot { text-align: center; font-size: 12px; color: var(--ink-3); padding: 8px 16px calc(var(--sab) + 28px); }

/* ================= 详情视图（iOS push 覆盖层） ================= */
#view-poem {
  position: fixed; inset: 0; z-index: 30;
  background: var(--paper);
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform var(--dur) var(--ease-ios), visibility 0s linear var(--dur);
  will-change: transform;
}
#view-poem.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform var(--dur) var(--ease-ios);
}
#view-poem.dragging { transition: none !important; }

.poem-bar { display: block; padding-bottom: 6px; }
.poem-bar .top-row { height: 40px; opacity: 1; }
.back-btn {
  font-size: 16.5px; color: var(--accent); display: flex; align-items: center;
  padding: 4px 8px 4px 0; transition: opacity .15s;
}
.back-btn:active { opacity: .45; }
.back-btn .chev { font-size: 24px; line-height: 1; margin-right: 1px; font-weight: 500; }
.poem-compact {
  position: absolute; left: 50%; transform: translateX(-50%);
  max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  opacity: 0; transition: opacity .2s;
}
.poem-bar.scrolled .poem-compact { opacity: 1; }

.poem { padding: 18px 20px calc(var(--sab) + 44px); max-width: 640px; margin: 0 auto; }
.poem h2 {
  font-family: var(--serif); font-size: 27px; letter-spacing: 3px;
  text-align: center; animation: rise .4s var(--ease-ios);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.poem .meta { text-align: center; color: var(--ink-2); font-size: 14px; margin-top: 6px; animation: rise .45s var(--ease-ios); }
.poem .meta .sep { color: var(--ink-3); margin: 0 6px; }
.poem .badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 12px; animation: rise .5s var(--ease-ios); }
.poem .content {
  margin: 24px auto 6px; font-family: var(--serif);
  font-size: 20px; letter-spacing: 2px; line-height: 2.35; text-align: center;
}
.poem .content p { margin: 0; animation: rise .5s var(--ease-ios); }
.poem .notes-line { text-align: center; font-size: 13px; color: var(--ink-3); margin: 10px 0 20px; }

.poem .tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 22px; }

/* ---------- 配图位 ---------- */
.image-slot {
  margin: 6px 0 22px; border-radius: var(--r-card); overflow: hidden;
  background: rgba(60, 50, 35, .05);
  padding: 34px 16px; text-align: center; color: var(--ink-3);
}
.image-slot.ready { padding: 0; background: none; }
.image-slot img { max-width: 100%; display: block; margin: 0 auto; }
.image-slot figcaption { font-size: 12.5px; margin-top: 8px; }
.image-slot.ready figcaption { padding: 0 16px 10px; }

/* ---------- 注解与词条 ---------- */
.section { margin-top: 28px; animation: rise .4s var(--ease-ios); }
.section > h3 {
  font-size: 13px; color: var(--ink-2); letter-spacing: 4px; font-weight: 600;
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.section > h3::after { content: ""; flex: 1; height: .5px; background: var(--line); }
.ann {
  background: var(--card); border-radius: var(--r-card);
  box-shadow: 0 .5px 1.5px rgba(50, 40, 25, .07);
  padding: 13px 15px; margin-bottom: 10px;
}
.ann .head { font-size: 12px; color: var(--ink-2); display: flex; gap: 8px; margin-bottom: 5px; }
.ann .head .k { color: var(--accent); font-weight: 600; }
.ann p { font-size: 15px; line-height: 1.75; }
.gloss { display: flex; gap: 14px; padding: 10px 2px; }
.gloss + .gloss { border-top: .5px solid var(--line); }
.gloss .term { flex: 0 0 auto; font-family: var(--serif); font-weight: 700; font-size: 16.5px; min-width: 60px; }
.gloss .term small { display: block; font-family: var(--sans); font-size: 11px; color: var(--indigo); font-weight: 400; }
.gloss .exp { font-size: 14px; color: var(--ink-2); line-height: 1.65; }
.gloss .exp .kind { font-size: 11px; color: var(--ink-3); margin-right: 6px; }
.src-line { margin-top: 28px; font-size: 12px; color: var(--ink-3); text-align: center; }

/* ---------- 骨架屏 ---------- */
.skel { padding-top: 8px; }
.sk { border-radius: 8px; background: linear-gradient(100deg, rgba(60,50,35,.07) 40%, rgba(60,50,35,.13) 50%, rgba(60,50,35,.07) 60%); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; margin: 0 auto 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-title { width: 45%; height: 26px; }
.sk-meta { width: 32%; height: 14px; }
.sk-line { width: 70%; height: 17px; margin-top: 22px; }
.sk-line.w80 { width: 80%; } .sk-line.w60 { width: 60%; }

/* ================= 筛选弹层（iOS 底部 Sheet） ================= */
.sheet-mask {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20, 15, 10, .38);
  opacity: 0; transition: opacity .28s;
}
.sheet-mask.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 80vh; display: flex; flex-direction: column;
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(30, 22, 12, .18);
  transform: translateY(105%);
  transition: transform var(--dur) var(--ease-ios);
  padding-bottom: var(--sab);
}
.sheet.open { transform: translateY(0); }
.sheet.dragging { transition: none !important; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: rgba(60, 50, 35, .22); margin: 7px auto 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 20px 10px; font-size: 17px; font-weight: 600; }
.sheet-head .link-btn { color: var(--ink-3); font-size: 15.5px; padding: 4px 6px; font-weight: 400; transition: opacity .15s; }
.sheet-head .link-btn:active { opacity: .5; }
.sheet-head .link-btn.done { color: var(--accent); font-weight: 600; }
.sheet-head .link-btn + .link-btn { margin-left: 10px; }
.sheet-body { overflow-y: auto; padding: 2px 20px 24px; -webkit-overflow-scrolling: touch; }
.facet { margin-bottom: 18px; }
.facet > h4 { font-size: 12.5px; color: var(--ink-3); margin-bottom: 9px; letter-spacing: 1.5px; font-weight: 600; }
.facet .opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  font-size: 13.5px; padding: 6px 13px; border-radius: 999px;
  background: rgba(60, 50, 35, .06); color: var(--ink-2);
  transition: transform .18s var(--ease-ios), background .18s, color .18s;
}
.opt:active { transform: scale(.94); }
.opt.on { background: var(--indigo); color: #fff; }
.opt .n { font-size: 11px; opacity: .6; margin-left: 3px; }

/* ---------- 桌面适配 ---------- */
@media (min-width: 720px) {
  #view-list { max-width: 680px; margin: 0 auto; }
  .list { padding-left: 0; padding-right: 0; }
  .active-filters { padding-left: 0; padding-right: 0; }
  #view-poem { box-shadow: -20px 0 60px rgba(40, 30, 15, .12); }
  .poem { padding-top: 30px; }
  .poem .content { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
