:root {
  --paper: #F5F3EE;
  --card: #FFFDF8;
  --ink: #1B1915;
  --ink-2: #5E5850;
  --ink-3: #8F887D;
  --rule: rgba(27, 25, 21, .16);

  --yellow: #F6D54A;
  --sky: #9CCBEA;
  --jade: #164F40;
  --gold: #D8B46A;
  --red: #E5372A;
  --marker: #2346D6;
  --tile: #E8ECE6;
  --grout: #C3CBC1;

  /* 当前主题，由 body[data-theme] 覆盖 */
  --bg: var(--paper);
  --fg: var(--ink);
  --fg-2: var(--ink-2);
  --line: var(--rule);
  --accent: var(--sky);
  --on-accent: var(--ink);

  --serif: "Songti SC", "STSongti-SC-Black", "STSong", "Noto Serif SC", "Source Han Serif SC", "Noto Serif CJK SC", serif;
  --brush: var(--sans);
  --num: "Didot", "Bodoni 72", "Bodoni MT", "Noto Serif Display", "Songti SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;

  --edge: 2px solid var(--ink);
  --lift: 5px 5px 0 var(--ink);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
body[data-theme="xiao"] { --bg: var(--yellow); --fg: var(--ink); --fg-2: #4A3F12; --line: rgba(27, 25, 21, .22); --accent: var(--ink); --on-accent: var(--yellow); }
body[data-theme="ya"] { --bg: var(--jade); --fg: #F1E8D2; --fg-2: rgba(241, 232, 210, .66); --line: rgba(216, 180, 106, .35); --accent: var(--gold); --on-accent: var(--jade); }
body[data-theme="sun"] { --bg: #F1F2EE; --fg: var(--ink); --fg-2: var(--ink-2); --line: var(--rule); --accent: var(--marker); --on-accent: #fff; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .3s, color .3s;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 8px; }
body[data-theme="xin"] :focus-visible { outline-color: #2F6FA3; }
[hidden] { display: none !important; }

#view {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 22px) 20px calc(var(--safe-b) + 116px);
  outline: none;
}

/* ---------- 通用 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border: var(--edge); border-radius: 999px;
  background: var(--card); color: var(--ink); box-shadow: 3px 3px 0 var(--ink); font-weight: 700; font-size: 16px;
  transition: transform .1s ease, box-shadow .1s ease;
}
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn svg { width: 19px; height: 19px; }
.btn-ink { background: var(--ink); color: var(--paper); }
.wide { width: 100%; }


.heat { display: inline-flex; gap: 3px; flex: none; }
.heat i { width: 6px; height: 12px; border-radius: 2px; background: var(--line); transform: skewX(-12deg); }
.heat i.on { background: var(--red); }
body[data-theme="ya"] .heat i.on { background: var(--gold); }

.sec-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; font: 900 22px/1.3 var(--serif); margin: 34px 0 14px; }
.sec-title small { font: 400 13px/1.4 var(--sans); color: var(--fg-2); }

/* ---------- 首页 · 心法卡片 ---------- */
.brand { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 2px 2px 18px; }
.brand h1 { margin: 0; font: 900 24px/1.2 var(--serif); letter-spacing: .04em; }
.brand p { margin: 0; color: var(--ink-3); font-size: 14px; }
.brand p b { font: 400 22px/1 var(--num); color: var(--ink); }

.xdeck { position: relative; height: min(60dvh, 520px); min-height: 400px; margin-bottom: 50px; touch-action: pan-y; user-select: none; -webkit-user-select: none; outline: none; }
.xc { position: absolute; inset: 0; perspective: 1400px; transform-origin: 50% 100%; will-change: transform; transition: transform .42s cubic-bezier(.22, 1, .36, 1), opacity .3s; }
.xc.dragging { transition: none; }
.xc.leaving { pointer-events: none; transition: transform .4s cubic-bezier(.25, .8, .35, 1), opacity .4s; }
.xc.top { cursor: grab; }
.xc.top:active { cursor: grabbing; }
.xc:not(.top) .xc-hint { visibility: hidden; }
.xc-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3, 1.3, .4, 1); }
.xc.flipped .xc-inner { transform: rotateY(180deg); }
.xc-face {
  position: absolute; inset: 0; display: flex; flex-direction: column; padding: 22px 22px 18px;
  border: var(--edge); border-radius: 22px; box-shadow: var(--lift);
  backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden;
}
.xc-front { background: var(--sky); }
.xc-back { background: var(--card); transform: rotateY(180deg); overflow: auto; }
.xc-attack { margin: 0; font-size: 14px; color: var(--ink-2); }
.xc-quote { flex: 1; display: flex; align-items: center; margin: 0; font: 900 clamp(27px, 8vw, 34px)/1.4 var(--serif); text-wrap: pretty; }
.xc-quote.long { font-size: clamp(22px, 6.2vw, 26px); }
.xc-hint { margin: 0; font-size: 13px; color: var(--ink-2); }
.xc-small { margin: 0 0 16px; font: 900 19px/1.45 var(--serif); padding-bottom: 14px; border-bottom: 1.5px dashed var(--rule); }
.xc-back .kv { margin: 0; }
.leaf-actions { display: grid; grid-template-columns: 52px 1.4fr 1fr; gap: 10px; }
.leaf-actions .btn { white-space: nowrap; }
.btn-prev { padding: 0; font: 400 30px/1 var(--serif); }

/* ---------- 笑 雅 损 ---------- */
.sec-head h1 { margin: 0; font: 900 64px/1 var(--serif); letter-spacing: .04em; }
.sec-head p { margin: 10px 0 22px; color: var(--fg-2); font-size: 15px; }

.slab {
  position: relative; margin: 0; min-height: 280px; display: flex; flex-direction: column; justify-content: space-between;
  padding: 24px 22px 18px; cursor: pointer; user-select: none; -webkit-user-select: none;
}
.slab-text { margin: 0; font: 900 clamp(30px, 9.4vw, 40px)/1.32 var(--serif); text-wrap: balance; }
.slab-text.long { font-size: clamp(25px, 7.4vw, 31px); }
.slab-text.swap { animation: swap .32s cubic-bezier(.2, 1.3, .4, 1) both; }
@keyframes swap { from { opacity: 0; transform: translateY(12px) scale(.97); } }
.slab-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 22px; font-size: 13px; color: var(--fg-2); }

/* 幽默：贴纸卡片，歪一点 */
[data-theme="xiao"] .slab { background: var(--card); border: var(--edge); border-radius: 20px; box-shadow: 6px 6px 0 var(--ink); transform: rotate(-1.2deg); }
[data-theme="xiao"] .slab-foot { color: var(--ink-3); }
/* 高雅：无框，金线上下封住，像题字 */
[data-theme="ya"] .slab { border-top: 1px solid var(--gold); border-bottom: 1px solid var(--gold); padding: 30px 4px 18px; text-align: center; }
[data-theme="ya"] .slab::before, [data-theme="ya"] .slab::after { content: ""; position: absolute; left: 0; right: 0; height: 1px; background: var(--gold); opacity: .5; }
[data-theme="ya"] .slab::before { top: 4px; }
[data-theme="ya"] .slab::after { bottom: 4px; }
[data-theme="ya"] .slab-text { font-weight: 700; letter-spacing: .04em; color: #F7EFDB; }
[data-theme="ya"] .slab-foot { justify-content: center; gap: 14px; }
/* 无敌损：公厕瓷砖墙，马克笔写上去 */
[data-theme="sun"] .slab { padding-left: 28px;
  background-color: var(--tile);
  background-image: linear-gradient(var(--grout) 2px, transparent 2px), linear-gradient(90deg, var(--grout) 2px, transparent 2px);
  background-size: 46px 46px; background-position: -1px -1px;
  border: var(--edge); border-radius: 6px; box-shadow: inset 0 0 40px rgba(120, 130, 115, .25);
}
[data-theme="sun"] .slab-text {
  font-family: var(--brush); font-weight: 900; color: #0E0E0E; transform: rotate(-3deg) skewX(-6deg); letter-spacing: -.01em;
  font-size: clamp(33px, 10.2vw, 44px); line-height: 1.3; text-shadow: 0 0 1px rgba(0, 0, 0, .6);
}
[data-theme="sun"] .slab-text.long { font-size: clamp(27px, 8vw, 34px); }
[data-theme="sun"] .slab-text.swap { animation: scrawl .3s cubic-bezier(.3, 1.4, .5, 1) both; }
@keyframes scrawl { from { opacity: 0; transform: rotate(-6deg) scale(1.12); } }
[data-theme="sun"] .slab-foot { color: var(--ink-2); }
[data-theme="sun"] .slab-foot > span:last-child { background: var(--tile); padding: 0 4px; }
[data-theme="sun"] .heat i.on { background: var(--marker); }
[data-theme="sun"] .sec-head h1 { font-family: var(--brush); }
[data-theme="sun"] .line > span:first-child { font-family: var(--brush); font-weight: 800; font-size: 17px; }

.slab-actions { display: grid; grid-template-columns: 1.5fr 1fr; gap: 12px; margin-top: 22px; }
.btn-main { background: var(--ink); color: var(--paper); }
[data-theme="ya"] .btn { border-color: var(--gold); box-shadow: 3px 3px 0 #0C2E25; background: transparent; color: var(--fg); }
[data-theme="ya"] .btn-main { background: var(--gold); color: var(--jade); }

.lines { list-style: none; margin: 0; padding: 0; counter-reset: n; }
.line {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: none; border: 0;
  border-top: 1px solid var(--line); padding: 14px 4px; border-radius: 0;
}
.lines li:last-child .line { border-bottom: 1px solid var(--line); }
.line > span:first-child { flex: 1; font: 700 18px/1.5 var(--serif); }
.line.hit { animation: hit .7s ease-out; }
@keyframes hit { from { background: var(--accent); color: var(--on-accent); } }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 12px); transform: translateX(-50%); z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr); width: min(420px, calc(100% - 24px));
  background: var(--ink); border-radius: 22px; padding: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
}
body[data-theme="ya"] .tabbar { background: #0C2E25; }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 56px;
  border-radius: 16px; color: rgba(245, 243, 238, .6); font-size: 11px; transition: background .2s, color .2s;
}
.tab-glyph { font: 900 21px/1.1 var(--serif); }
.tabbar a[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
body[data-theme="xiao"] .tabbar a[aria-current="page"] { background: var(--yellow); color: var(--ink); }

/* ---------- 心法详情 ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(27, 25, 21, .45); z-index: 30; animation: fade .2s both; }
.sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 31; width: min(480px, 100%); max-height: 88dvh; overflow: auto;
  transform: translateX(-50%); background: var(--paper); color: var(--ink); border: var(--edge); border-bottom: 0;
  border-radius: 26px 26px 0 0; padding: 10px 20px calc(var(--safe-b) + 22px); animation: rise .34s cubic-bezier(.2, .9, .3, 1) both;
}
.sheet.closing { animation: sink .2s ease-in both; }
.sheet-backdrop.closing { animation: fade .2s reverse both; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translate(-50%, 100%); } }
@keyframes sink { to { transform: translate(-50%, 100%); } }
.grab { width: 44px; height: 5px; border-radius: 9px; background: var(--rule); margin: 0 auto 18px; }

.chat { display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }
.msg { display: flex; gap: 10px; align-items: flex-end; max-width: 92%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 12px; border: var(--edge); display: grid; place-items: center;
  font: 900 18px/1 var(--serif); background: var(--card);
}
.msg.them .avatar { background: var(--ink); color: var(--paper); }
.msg.me .avatar { background: var(--sky); }
.bubble { border: var(--edge); border-radius: 18px; padding: 11px 15px; background: var(--card); font: 600 17px/1.5 var(--serif); }
.msg.them .bubble { border-bottom-left-radius: 4px; }
.msg.me .bubble { border-bottom-right-radius: 4px; background: var(--sky); font-weight: 900; }
.kv { display: grid; gap: 14px; margin: 0 0 22px; }
.kv div { display: grid; grid-template-columns: 84px 1fr; gap: 8px; font-size: 15px; }
.kv dt { color: var(--ink-3); font-size: 13.5px; padding-top: 2px; }
.kv dd { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 92px); transform: translate(-50%, 20px); z-index: 40;
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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