/* 至本学习账本 —— 批改过的纸质账本：米黄账簿纸 / 墨色硬边 / 朱砂批改红 */
:root {
  --paper: #F3EEE2;
  --paper-hi: #FBF8F1;
  --ink: #1E1C18;
  --ink-2: #6A6355;
  --ink-3: #938B7B;
  --line: #D6CDB9;
  --line-soft: #E4DDCD;
  --red: #BF3E28;
  --red-soft: #E8735B;
  --gold: #A8762A;
  --green: #2C6152;

  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;

  --r: 3px;
  --pad: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  /* 账簿横线 */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 31px,
    rgba(30, 28, 24, 0.035) 31px,
    rgba(30, 28, 24, 0.035) 32px
  );
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* 纸张颗粒 */
.paper {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='140' height='140' filter='url(%23n)' opacity='0.14'/></svg>");
}

.app, .brand, .tabbar, .toast { position: relative; z-index: 1; }

/* ---------- 报头 ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px var(--pad) 12px;
  border-bottom: 1px solid var(--ink);
  background: linear-gradient(to bottom, var(--paper-hi), var(--paper));
}
.brand::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -3px;
  height: 1px;
  background: var(--line);
}
.seal {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid;
  place-items: center;
  background: var(--red);
  color: var(--paper-hi);
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 700;
  border-radius: var(--r);
  box-shadow: 2px 2px 0 rgba(30, 28, 24, 0.16);
  text-decoration: none;
}
.brand-text { flex: 1 1 auto; min-width: 0; }
.brand-name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.2;
}
.brand-sub {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  margin-top: 2px;
}
.brand-id {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: var(--r);
  padding: 2px 6px;
  white-space: nowrap;
}
.brand-id:empty { display: none; }

/* ---------- 版面 ---------- */
.app { padding: 18px var(--pad) 28px; max-width: 560px; margin: 0 auto; }
/* 入场动画只在「设备允许动效」时启用：不写这条媒体查询的话，动画被禁用的 WebView 会永远停在 opacity:0，整页空白 */
@media (prefers-reduced-motion: no-preference) {
  .view > * { animation: rise 0.42s cubic-bezier(0.22, 0.7, 0.3, 1) both; }
  .view > *:nth-child(1) { animation-delay: 0.00s; }
  .view > *:nth-child(2) { animation-delay: 0.05s; }
  .view > *:nth-child(3) { animation-delay: 0.10s; }
  .view > *:nth-child(4) { animation-delay: 0.15s; }
  .view > *:nth-child(5) { animation-delay: 0.20s; }
  .view > *:nth-child(6) { animation-delay: 0.24s; }
  .view > *:nth-child(7) { animation-delay: 0.28s; }
  .view > *:nth-child(n + 8) { animation-delay: 0.32s; }
}
@keyframes rise { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }

.sec-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--ink-2);
  margin: 24px 0 10px;
}
.sec-title::before {
  content: "";
  width: 14px; height: 2px;
  background: var(--red);
  transform: translateY(-3px);
}
.sec-title .hint { font-family: var(--sans); font-size: 11px; letter-spacing: 0; color: var(--ink-3); margin-left: auto; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--paper-hi);
  border: 1px solid var(--ink);
  border-radius: var(--r);
  box-shadow: 3px 3px 0 rgba(30, 28, 24, 0.09);
  padding: 15px 16px;
  margin-bottom: 12px;
}
.card.soft { border-color: var(--line); box-shadow: 2px 2px 0 rgba(30, 28, 24, 0.05); }
.card.flat { box-shadow: none; }

.hero { padding: 18px 16px 16px; }
.hero-label {
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ink-3);
  font-family: var(--serif);
}
.hero-num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 54px;
  line-height: 1;
  letter-spacing: -0.03em;
  margin: 6px 0 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.hero-unit { font-family: var(--sans); font-size: 13px; color: var(--ink-2); letter-spacing: 0.05em; }
.hero-today { font-size: 13px; color: var(--ink-2); }
.hero-today b { font-family: var(--mono); color: var(--red); font-size: 15px; }
.hero-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.hero-sync { display: flex; align-items: baseline; gap: 10px; }
.hero-when { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
button.linkish {
  background: none;
  border: 0;
  padding: 0;
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: 0.1em;
}

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.metric { padding: 12px 6px; text-align: center; border-right: 1px dashed var(--line); }
.metric:last-child { border-right: 0; }
.metric b {
  display: block;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  line-height: 1.2;
}
.metric span { font-size: 11px; color: var(--ink-3); letter-spacing: 0.08em; }
.metric.gold b { color: var(--gold); }
.metric.red b { color: var(--red); }

/* ---------- 柱状图（田字格） ---------- */
.chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 7px;
  height: 128px;
  align-items: end;
  padding-top: 6px;
}
.col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.col-track {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  max-width: 34px;
  border: 1px solid var(--line);
  border-radius: 1px;
  background:
    repeating-linear-gradient(to bottom, transparent 0 25%, rgba(30, 28, 24, 0.07) 25% calc(25% + 1px)),
    repeating-linear-gradient(to right, transparent 0 50%, rgba(30, 28, 24, 0.05) 50% calc(50% + 1px));
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.col-bar {
  width: 100%;
  background: linear-gradient(to bottom, var(--ink) 0%, #37332b 100%);
  transition: height 0.5s cubic-bezier(0.22, 0.7, 0.3, 1);
}
.col.today .col-bar { background: linear-gradient(to bottom, var(--red) 0%, #9c3220 100%); }
.col-val {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.col-day {
  font-family: var(--serif);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}
.col.today .col-day { color: var(--red); font-weight: 700; }
.chart-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 11px;
  color: var(--ink-3);
}
.chart-foot i { font-style: normal; font-family: var(--mono); color: var(--red); }

/* ---------- 引导 / 提示 ---------- */
.guide { border-color: var(--red); background: #FFFDF7; }
.guide-kicker {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--paper-hi);
  background: var(--red);
  padding: 2px 7px;
  border-radius: 1px;
  font-family: var(--serif);
}
.guide h3 { font-family: var(--serif); font-size: 17px; margin: 9px 0 4px; letter-spacing: 0.04em; }
.guide p { font-size: 13px; color: var(--ink-2); margin: 0 0 12px; }
.warn { border-color: var(--gold); background: #FCF8EC; }
.warn h3 { font-family: var(--serif); font-size: 15px; margin: 0 0 5px; color: #7c5517; }
.warn p { font-size: 12.5px; color: var(--ink-2); margin: 0; }

.note {
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.7;
  padding: 2px 2px 0;
}
.note b { color: var(--ink-2); font-weight: 600; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.12em;
  color: var(--paper-hi);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: var(--r);
  box-shadow: 3px 3px 0 rgba(30, 28, 24, 0.18);
  padding: 11px 18px;
  cursor: pointer;
  width: 100%;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(30, 28, 24, 0.18); }
.btn.red { background: var(--red); border-color: var(--red); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: 2px 2px 0 rgba(30, 28, 24, 0.08);
}
.btn.sm { width: auto; padding: 7px 13px; font-size: 13px; letter-spacing: 0.08em; }
.btn:disabled { opacity: 0.42; pointer-events: none; box-shadow: none; }
.btn-row { display: flex; gap: 9px; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 13px; }
.field label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink-3);
  font-family: var(--serif);
  margin-bottom: 5px;
}
.inp-row { display: flex; gap: 8px; }
input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--paper-hi);
  border: 1px solid var(--ink);
  border-radius: var(--r);
  padding: 11px 12px;
  outline: none;
}
input::placeholder { color: var(--ink-3); letter-spacing: 0; font-family: var(--sans); }
input:focus { border-color: var(--red); box-shadow: 0 0 0 2px rgba(191, 62, 40, 0.12); }
input:disabled { background: var(--line-soft); }
.field .btn { width: auto; flex: 0 0 auto; white-space: nowrap; }
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--ink);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 18px;
}
.seg a {
  text-align: center;
  padding: 9px;
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: 0.14em;
  color: var(--ink-2);
  text-decoration: none;
  background: var(--paper-hi);
}
.seg a.on { background: var(--ink); color: var(--paper-hi); }

/* ---------- 列表 ---------- */
.rows { padding: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  border-bottom: 1px dashed var(--line);
}
.row:last-child { border-bottom: 0; }
.row-main { flex: 1 1 auto; min-width: 0; }
.row-title { font-size: 14.5px; }
.row-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.row-end { text-align: right; flex: 0 0 auto; }
.amt {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  font-weight: 600;
}
.amt.plus { color: var(--gold); }
.amt.minus { color: var(--red); }
.badge {
  font-size: 11px;
  font-family: var(--serif);
  letter-spacing: 0.1em;
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.badge.red { color: var(--red); border-color: var(--red); }
.badge.solid { background: var(--ink); color: var(--paper-hi); border-color: var(--ink); }
.chev { color: var(--ink-3); font-family: var(--mono); }

/* ---------- 商店 ---------- */
.item { margin-bottom: 12px; }
.item-top { display: flex; align-items: flex-start; gap: 10px; }
.face {
  font-family: var(--mono);
  font-size: 26px;
  line-height: 1;
  color: var(--red);
  letter-spacing: -0.02em;
  flex: 0 0 auto;
  min-width: 62px;
}
.face small { font-size: 12px; letter-spacing: 0.05em; }
.item-name { font-family: var(--serif); font-size: 15px; letter-spacing: 0.04em; }
.item-desc { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; line-height: 1.5; }
.bar {
  height: 6px;
  border: 1px solid var(--ink);
  border-radius: 1px;
  margin: 12px 0 9px;
  background: repeating-linear-gradient(45deg, transparent 0 3px, rgba(30, 28, 24, 0.05) 3px 6px);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--gold);
  transition: width 0.55s cubic-bezier(0.22, 0.7, 0.3, 1);
}
.item-foot { display: flex; align-items: center; gap: 10px; }
.need { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); flex: 1 1 auto; }
.need em { font-style: normal; color: var(--red); }

/* ---------- 券 ---------- */
.ticket {
  position: relative;
  display: flex;
  align-items: stretch;
  background: var(--paper-hi);
  border: 1px solid var(--ink);
  border-radius: var(--r);
  margin-bottom: 11px;
  overflow: hidden;
}
/* 撕票孔压在虚线上：left = 面值栏 92px + 1px 虚线 - 半个孔 7.5px */
.ticket::before, .ticket::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--ink);
  left: 85.5px;
}
.ticket::before { top: -9px; }
.ticket::after { bottom: -9px; }
.ticket-val {
  flex: 0 0 92px;
  display: grid;
  place-content: center;
  gap: 3px;
  text-align: center;
  padding: 14px 4px;
  border-right: 1px dashed var(--line);
}
.ticket-val b {
  display: block;
  font-family: var(--mono);
  font-size: 30px;
  line-height: 1;
  color: var(--red);
}
.ticket-val span { font-size: 10px; letter-spacing: 0.14em; color: var(--ink-3); }
.ticket-body { flex: 1 1 auto; min-width: 0; padding: 14px 15px 14px 13px; }
.ticket-code {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: rgba(30, 28, 24, 0.05);
  border: 1px dashed var(--ink-3);
  border-radius: 2px;
  padding: 3px 7px;
  display: inline-block;
  margin-top: 4px;
}
.ticket.used { opacity: 0.5; }
.ticket.used .ticket-val b { color: var(--ink-3); }
.stamp {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%) rotate(-11deg);
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.16em;
  color: var(--red);
  border: 1.5px solid var(--red);
  border-radius: 2px;
  padding: 3px 7px;
  background: rgba(251, 248, 241, 0.75);
}

/* ---------- 绑定码 ---------- */
.codebox { text-align: center; padding: 22px 16px 18px; }
.code {
  font-family: var(--mono);
  font-size: 40px;
  letter-spacing: 0.2em;
  color: var(--ink);
  background:
    repeating-linear-gradient(to right, transparent 0 calc(33.33% - 1px), var(--line) calc(33.33% - 1px) 33.33%);
  border-bottom: 2px solid var(--red);
  padding: 6px 0 8px;
  margin: 4px 0 8px;
  text-indent: 0.2em;
}
.countdown { font-size: 12px; color: var(--ink-2); font-family: var(--mono); }
.countdown.danger { color: var(--red); }
.steps { counter-reset: s; margin: 4px 0 0; padding: 0; list-style: none; }
.steps li {
  position: relative;
  padding: 0 0 11px 27px;
  font-size: 13.5px;
  color: var(--ink-2);
}
.steps li::before {
  counter-increment: s;
  content: counter(s);
  position: absolute;
  left: 0; top: 1px;
  width: 19px; height: 19px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--paper-hi);
  background: var(--ink);
  border-radius: 50%;
}
.steps li:last-child { padding-bottom: 0; }

/* ---------- 其他 ---------- */
.balance-chip {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--ink);
  border-radius: var(--r);
  background: var(--paper-hi);
  margin-bottom: 14px;
  box-shadow: 3px 3px 0 rgba(30, 28, 24, 0.09);
}
.balance-chip .lbl { font-family: var(--serif); font-size: 12px; letter-spacing: 0.18em; color: var(--ink-2); }
.balance-chip .val {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 32px;
  line-height: 1;
  color: var(--gold);
}

.empty { text-align: center; padding: 34px 20px; color: var(--ink-3); }
.empty .mark { font-family: var(--serif); font-size: 15px; letter-spacing: 0.2em; color: var(--line); }
.empty p { font-size: 13px; margin: 8px 0 0; }

.sk { border-color: var(--line-soft); box-shadow: none; }
.sk-line {
  height: 12px;
  border-radius: 1px;
  background: linear-gradient(to right, var(--line-soft) 25%, #EFE9DA 37%, var(--line-soft) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.15s ease infinite;
  margin-bottom: 9px;
}
.sk-line.tall { height: 42px; }
.sk-line:last-child { margin-bottom: 0; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.tabbar {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--paper-hi);
  border-top: 1px solid var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}
.tabbar a {
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 8px 0 7px;
  text-decoration: none;
  color: var(--ink-3);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  font-family: var(--serif);
  border-right: 1px dashed var(--line-soft);
}
.tabbar a:last-child { border-right: 0; }
.tabbar a.on { color: var(--red); }
/* display:grid 会盖掉 [hidden] 的默认 display:none，登录/注册页必须显式收掉底栏 */
.tabbar[hidden] { display: none; }
.ti { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on .ti { stroke-width: 2; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: 84vw;
  background: var(--ink);
  color: var(--paper-hi);
  font-size: 13px;
  padding: 9px 15px;
  border-radius: 2px;
  box-shadow: 3px 3px 0 rgba(30, 28, 24, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); }

.auth-top { margin-bottom: 20px; }
.auth-top h2 { font-family: var(--serif); font-size: 24px; letter-spacing: 0.1em; margin: 0 0 4px; }
.auth-top p { font-size: 12.5px; color: var(--ink-2); margin: 0; }
.legal { font-size: 11px; color: var(--ink-3); line-height: 1.7; margin-top: 16px; }
.linkish { color: var(--red); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.split { display: flex; gap: 10px; align-items: center; margin: 16px 0; color: var(--ink-3); font-size: 11px; }
.split::before, .split::after { content: ""; flex: 1; height: 1px; background: var(--line); }
