:root {
  --paper: #f3eee6;
  --paper-deep: #e7dfd2;
  --sheet: rgba(255, 252, 247, 0.92);
  --ink: #241c16;
  --soft: #6f6256;
  --faint: #9a8d7e;
  --line: rgba(74, 52, 32, 0.12);
  --seal: #9c3b32;
  --moss: #31483d;
  --gold: #8d6a3f;
  --shadow: 0 18px 50px rgba(62, 42, 22, 0.08);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "PMingLiU", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 100% -10%, rgba(156, 59, 50, 0.08), transparent 55%),
    radial-gradient(700px 380px at -10% 20%, rgba(141, 106, 63, 0.12), transparent 50%),
    linear-gradient(180deg, #f7f3ec 0%, var(--paper) 32%, #efe8dc 100%);
  letter-spacing: 0.01em;
}

body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
  opacity: 0.05;
  mix-blend-mode: multiply;
}

a { color: inherit; }

button, input, textarea, select { font: inherit; color: inherit; }

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  padding: 22px 18px 118px;
  position: relative;
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.seal, .mini-seal {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1.5px solid var(--seal);
  color: var(--seal);
  font-family: var(--serif);
  border-radius: 4px;
  letter-spacing: 0.12em;
  transform: rotate(-8deg);
  background: rgba(255, 250, 245, 0.7);
  box-shadow: inset 0 0 0 3px rgba(156, 59, 50, 0.08);
}

.mini-seal {
  width: 34px;
  height: 34px;
  font-size: 13px;
  flex: none;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.28em;
}

h1, h2, h3, p { margin: 0; }

h1 {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 0.14em;
}

.leave {
  color: var(--soft);
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.16em;
  padding-bottom: 6px;
}

.greeting {
  margin: 8px 0 18px;
}

.greeting strong {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 500;
}

.greeting p {
  margin-top: 6px;
  color: var(--soft);
  line-height: 1.7;
}

.stats {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.stats span, .chip, .word, .pill {
  border: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.72);
  border-radius: 999px;
}

.stats span {
  padding: 6px 10px;
  color: var(--soft);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 12px;
  margin: 0 -2px 8px;
  scrollbar-width: none;
}

.scroller::-webkit-scrollbar { display: none; }

.chip, .word {
  flex: none;
  text-decoration: none;
  color: var(--soft);
  padding: 7px 12px;
  font-size: 13px;
}

.chip.on, .word.on {
  color: #fffaf6;
  background: var(--ink);
  border-color: var(--ink);
}

.words { margin-bottom: 8px; }

.card, .sheet, .panel {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.card {
  display: block;
  text-decoration: none;
  padding: 16px 16px 15px 18px;
  margin-bottom: 12px;
  position: relative;
}

.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18px;
  bottom: 18px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent, var(--seal));
}

.cat-guan { --accent: #9c3b32; }
.cat-gong { --accent: #31483d; }
.cat-ti { --accent: #8d6a3f; }
.cat-wang { --accent: #3d4c66; }
.cat-jie { --accent: #8a5a3a; }
.cat-en { --accent: #a5684b; }
.cat-wen { --accent: #6a5a78; }
.cat-jing { --accent: #2f4f4a; }
.cat-za { --accent: #8a8175; }

.card-top, .row, .spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.when, .meta, .hint, .fine {
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.tag {
  color: var(--accent, var(--seal));
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: 0.18em;
}

.card h2, .sheet h2, .panel h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0.08em;
  margin: 10px 0 8px;
  line-height: 1.45;
}

.essence, .mirror, .step p, .original, .reason {
  color: var(--soft);
  line-height: 1.85;
  font-size: 15px;
}

.pills, .kws {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.pill, .kws span {
  font-size: 12px;
  color: var(--soft);
  background: rgba(255, 252, 247, 0.9);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
}

.empty {
  text-align: center;
  padding: 42px 18px;
}

.empty .seal { margin: 0 auto 16px; }

.empty p { color: var(--soft); line-height: 1.8; margin-bottom: 16px; }

.btn, button.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  border-radius: 999px;
  background: var(--ink);
  color: #f8f3ea;
  letter-spacing: 0.22em;
  font-size: 15px;
}

.btn.ghost, button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}

.btn.danger {
  background: transparent;
  color: var(--seal);
  border: 1px solid rgba(156, 59, 50, 0.28);
  letter-spacing: 0.12em;
  min-height: 44px;
  margin-top: 8px;
}

.actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.sheet, .panel { padding: 18px 16px 16px; margin-bottom: 14px; }

.paper {
  margin-top: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35), transparent 28%),
    #fffdf8;
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 8px 12px 12px;
}

textarea, input[type="text"], input[type="password"] {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 16px;
  line-height: 1.8;
}

textarea { min-height: 240px; resize: vertical; }

label.field {
  display: block;
  margin-bottom: 12px;
}

label.field span, .fold summary {
  display: block;
  margin-bottom: 6px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.18em;
}

label.field input, label.field select, label.field textarea {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 8px 0;
  outline: none;
  font-size: 16px;
}

label.field textarea { min-height: 88px; }

.fold {
  margin-top: 8px;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}

.fold summary {
  cursor: pointer;
  margin: 8px 0 12px;
}

.quote {
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.7;
  letter-spacing: 0.04em;
}

.mirror { margin-top: 8px; }

.step {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.step b {
  display: block;
  font-weight: 500;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--gold);
  margin-bottom: 6px;
}

.thread {
  display: block;
  text-decoration: none;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.thread:first-of-type { border-top: 0; }

.thread strong {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: 0.06em;
}

.warn {
  background: rgba(156, 59, 50, 0.08);
  color: var(--seal);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 12px;
  line-height: 1.6;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--soft);
  margin-top: 8px;
  font-size: 13px;
  letter-spacing: 0.12em;
}

.pager a { color: var(--ink); text-decoration: none; }

.dock {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(430px, calc(100% - 28px));
  display: flex;
  background: rgba(255, 252, 247, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 12px 40px rgba(50, 32, 12, 0.1);
  z-index: 5;
  backdrop-filter: blur(12px);
}

.dock a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  padding: 10px 0 11px;
  color: var(--faint);
}

.dock a.on { color: var(--ink); }

.dock span {
  display: block;
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: 0.18em;
}

.dock small {
  font-size: 11px;
  letter-spacing: 0.14em;
}

.page-gate {
  min-height: 100vh;
}

.page-gate .app { padding-top: 8vh; padding-bottom: 40px; }

.gate {
  min-height: 68vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.gate-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
}

.inscription {
  writing-mode: vertical-rl;
  font-family: var(--serif);
  letter-spacing: 0.45em;
  color: var(--gold);
  font-size: 15px;
  padding-top: 6px;
}

.gate h1 { font-size: 40px; }

.gate .lead {
  margin-top: 10px;
  color: var(--soft);
  line-height: 1.8;
  max-width: 18em;
}

.switch {
  display: flex;
  gap: 18px;
  margin: 22px 0 14px;
  letter-spacing: 0.16em;
  font-size: 14px;
}

.switch a { color: var(--faint); text-decoration: none; }
.switch a.on { color: var(--ink); border-bottom: 1px solid var(--ink); padding-bottom: 4px; }

.veil {
  position: fixed;
  inset: 0;
  background: rgba(36, 28, 22, 0.28);
  display: grid;
  place-items: center;
  z-index: 9;
  padding: 24px;
}

.veil[hidden] { display: none !important; }

.veil-card {
  width: min(320px, 100%);
  background: #fbf7f1;
  border-radius: 24px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}

.veil-card .seal { margin: 0 auto 14px; }

.veil-card p { color: var(--soft); line-height: 1.7; }

.filter-note {
  color: var(--soft);
  font-size: 13px;
  margin: 0 0 12px;
}

.filter-note a { color: var(--seal); }

.icon-btn, .seal-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
}

.icon-btn svg, .dock svg { width: 22px; height: 22px; display: block; }

.icon-btn.solid {
  background: var(--ink);
  color: #f6f1e8;
}

.icon-btn.danger { color: var(--seal); }

.seal-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(156, 59, 50, 0.45);
  color: var(--seal);
  font-family: var(--serif);
  border-radius: 5px;
  transform: rotate(-6deg);
  background: rgba(255, 250, 245, 0.75);
}

.seal-btn.on, .seal-btn.has {
  background: var(--seal);
  color: #fff8f4;
  border-color: var(--seal);
}

.read-top { align-items: center; margin-bottom: 8px; }

.heard, .heard-edit {
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1.65;
  letter-spacing: 0.04em;
  margin: 12px 0 18px;
  white-space: pre-wrap;
}

.heard-edit {
  min-height: 7em;
  font-size: 24px;
  background: transparent;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  color: var(--faint);
  font-size: 13px;
  letter-spacing: 0.12em;
  margin: 0 0 14px;
}

.meta-line span + span::before {
  content: "·";
  margin-right: 8px;
  color: var(--faint);
}

.mirror { margin: 0 0 12px; }

.next-line {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  color: var(--ink);
  line-height: 1.7;
  margin: 0 0 18px;
}

.next-line i {
  width: 7px;
  height: 7px;
  margin-top: 0.55em;
  border-radius: 50%;
  background: var(--gold);
  flex: none;
}

.tool-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 8px 0 22px;
}

.link-list { margin-top: 4px; }

.thread {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.rel {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(156, 59, 50, 0.35);
  color: var(--seal);
  font-family: var(--serif);
  font-size: 13px;
  border-radius: 4px;
  transform: rotate(-6deg);
}

.thread-copy { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.thread-copy strong { font-size: 16px; }
.reason { color: var(--soft); line-height: 1.6; font-size: 14px; }

.dock a { display: grid; place-items: center; min-height: 52px; }

body.sheet-open { overflow: hidden; }

.mask {
  position: fixed;
  inset: 0;
  background: rgba(36, 28, 22, 0.28);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.icon-btn[hidden],
.seal-btn[hidden],
form[hidden],
.mask[hidden],
.veil[hidden] {
  display: none !important;
}

.drawer {
  width: min(480px, 100%);
  height: min(86vh, 760px);
  background: #f7f3ec;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 40px rgba(50, 32, 12, 0.12);
  display: flex;
  flex-direction: column;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
}

.drawer-bar, .drawer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.drawer-bar .close-drawer { margin-left: auto; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 4px;
  scrollbar-width: none;
}

.chips:empty { display: none; }

.ai-body {
  flex: 1;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 16px;
  line-height: 1.85;
  color: var(--ink);
  padding: 8px 2px 12px;
}

.ai-body.waiting::before {
  content: "";
  display: block;
  width: 36px;
  height: 36px;
  margin: 28px auto;
  border: 1px solid var(--seal);
  border-radius: 4px;
  transform: rotate(-8deg);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

.drawer-actions { padding-top: 8px; }

