/* 亲密手记 · 拆一封来信 — base system. Mobile first, no external assets. */
:root {
  color-scheme: light;
  --paper: #f6efe4;
  --paper-deep: #eee3d3;
  --sheet: #fffaf2;
  --ink: #3a2630;
  --body: #4b3a41;
  --muted: #73626a;
  --faint: #a6958d;
  --line: #e5d8c8;
  --line-strong: #cdb9a3;
  --seal: #9c3f3a;
  --seal-deep: #7f302c;
  --seal-soft: #f5e4dc;
  --post-red: #b8574b;
  --post-blue: #4f6787;
  --blue-soft: #e5eaf1;
  --sage: #57735c;
  --sage-soft: #e6eee3;
  --amber: #a5682a;
  --amber-soft: #f6e9d6;
  --shadow-sm: 0 1px 2px rgb(74 47 42 / 6%), 0 6px 18px rgb(74 47 42 / 6%);
  --shadow-md: 0 2px 4px rgb(74 47 42 / 6%), 0 18px 40px rgb(74 47 42 / 10%);
  --radius: 14px;
  --gutter: 18px;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", serif;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --airmail: repeating-linear-gradient(-45deg, var(--post-red) 0 9px, transparent 9px 15px, var(--post-blue) 15px 24px, transparent 24px 30px);
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; scrollbar-gutter: stable; scroll-padding-top: 72px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--paper);
  color: var(--body);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
/* A faint paper grain made from gradients only. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 100% 0%, rgb(222 196 180 / 28%), transparent 55%),
    radial-gradient(ellipse at 0% 100%, rgb(214 204 186 / 30%), transparent 50%);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-appearance: none; appearance: none; }
button:not(:disabled), summary, label { cursor: pointer; }
button, a, input, summary, label { touch-action: manipulation; }
a { color: inherit; text-underline-offset: 4px; }
:focus-visible { outline: 2px solid var(--post-blue); outline-offset: 3px; border-radius: 6px; }
h1[tabindex="-1"]:focus { outline: none; }
h1, h2, h3, p, ol, ul { margin-top: 0; }
h1, h2, h3 { color: var(--ink); font-weight: 600; }
p { margin-bottom: 1em; }
img, svg, canvas { max-width: 100%; }
::selection { background: #ead2c8; color: var(--ink); }
[hidden], .hidden { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.tiny-note { font-size: 13px; line-height: 1.7; color: var(--muted); }

/* Header */
.site-header {
  width: min(1080px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px var(--gutter);
  min-height: 64px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: 0 0 30px; display: inline-flex; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-name { font-family: var(--font-serif); font-size: 19px; font-weight: 600; letter-spacing: .12em; line-height: 1.1; }
.brand-name small { display: block; margin-top: 4px; font-family: var(--font-body); font-size: 10px; font-weight: 400; letter-spacing: .18em; color: var(--muted); }
.header-link { min-height: 44px; padding: 8px 4px 8px 12px; border: 0; background: none; color: var(--muted); font-size: 14px; }
.app-shell { width: min(1080px, 100%); margin: 0 auto; padding: 0 var(--gutter) 48px; }

/* Shared text pieces */
.eyebrow, .section-kicker {
  display: block;
  margin: 0 0 10px;
  color: var(--seal);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .14em;
  line-height: 1.6;
}
.view { animation: none; }
.app-shell, .site-header { transition: opacity 150ms ease; }
.app-shell.is-view-changing, .view-repositioning .site-header { opacity: 0; transition-duration: 90ms; }
.app-shell.is-view-changing { pointer-events: none; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 22px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  transition: background 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--ease), box-shadow 160ms var(--ease);
}
.btn svg { width: 18px; height: 18px; flex: 0 0 18px; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fffaf2; box-shadow: 0 6px 16px rgb(58 38 48 / 16%); }
.btn-secondary { background: var(--sheet); border-color: var(--line-strong); color: var(--ink); }
.btn-quiet { background: transparent; color: var(--muted); padding-left: 14px; padding-right: 14px; font-weight: 500; font-size: 15px; }
.btn-wide { width: 100%; }
.btn:active:not(:disabled) { transform: scale(.985); }
.btn:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
.inline-link { padding: 6px 2px; min-height: 40px; border: 0; background: none; color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 4px; }
.text-button { min-height: 44px; padding: 8px 4px 8px 12px; border: 0; background: none; color: var(--muted); font-size: 14px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 8px 8px 8px 0; border: 0; background: none; color: var(--muted); font-size: 14px; text-decoration: none; }

/* Flow pages: setup, intro, review, notices */
.flow { max-width: 600px; margin: 0 auto; padding: 4px 0 24px; }
.flow-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.step-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.step-dots { display: flex; gap: 6px; margin: 4px 0 24px; }
.step-dots i { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.step-dots i.done { background: var(--line-strong); }
.step-dots i.active { background: var(--seal); }
.flow-title { font-family: var(--font-serif); font-size: 28px; line-height: 1.4; letter-spacing: .01em; margin-bottom: 12px; text-wrap: balance; }
.flow-desc { font-size: 16px; line-height: 1.8; color: var(--muted); margin-bottom: 22px; }
.flow-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-top: 26px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.flow-footer .btn-primary { min-width: 168px; }
.flow-note { width: 100%; margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.validation-message { min-height: 1.6em; margin: 6px 0 0; color: var(--seal-deep); font-size: 14px; }
.validation-message:empty { min-height: 0; }
.setup-flow { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
.setup-flow .validation-message:empty { min-height: 1.6em; }
.setup-flow .flow-footer {
  position: fixed;
  z-index: 5;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(600px, calc(100% - 2 * var(--gutter)));
  flex-wrap: nowrap;
  margin: 0;
  padding: 14px 0 max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.setup-flow .flow-footer .btn-primary { flex: 1; min-width: 0; }
.setup-flow .flow-footer .btn-quiet { flex: none; padding-inline: 10px; font-size: 14px; }

.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice {
  position: relative;
  width: 100%;
  padding: 16px 52px 16px 18px;
  text-align: left;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--body);
  transition: border-color 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}
.choice-title { display: block; color: var(--ink); font-size: 17px; font-weight: 600; line-height: 1.5; }
.choice-desc { display: block; margin-top: 4px; font-size: 14px; line-height: 1.65; color: var(--muted); }
.choice-mark { position: absolute; right: 18px; top: 50%; width: 20px; height: 20px; margin-top: -10px; border: 1.5px solid var(--line-strong); border-radius: 50%; background: var(--sheet); }
.choice.selected { border-color: var(--seal); background: var(--seal-soft); box-shadow: 0 0 0 1px var(--seal) inset; }
.choice.selected .choice-mark { border-color: var(--seal); background: var(--seal); box-shadow: inset 0 0 0 4px var(--seal-soft); }

.check-group { display: flex; flex-direction: column; gap: 10px; }
.check-row { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius); font-size: 16px; line-height: 1.6; color: var(--ink); }
.check-row input { flex: 0 0 22px; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--seal); }
.check-row small { display: block; margin-top: 4px; font-size: 13.5px; line-height: 1.65; color: var(--muted); }

/* Modal and toast */
.modal-open { overflow: hidden; }
.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); background: rgb(46 28 34 / 38%); animation: fade-in 160ms var(--ease); }
.modal { position: relative; width: min(100%, 460px); max-height: calc(100svh - 32px); overflow-y: auto; overscroll-behavior: contain; padding: 26px 22px 22px; border-radius: 20px; background: var(--sheet); box-shadow: var(--shadow-md); color: var(--body); animation: view-in 200ms var(--ease); }
.modal::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px; border-radius: 20px 20px 0 0; background: var(--airmail); opacity: .9; }
.modal-close { position: absolute; right: 10px; top: 12px; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; }
.modal-title { font-family: var(--font-serif); font-size: 23px; line-height: 1.45; margin: 4px 40px 12px 0; }
.modal p { font-size: 15.5px; line-height: 1.8; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions .btn { min-height: 48px; font-size: 15px; padding: 10px 18px; }
.card-preview { margin: 6px 0 4px; text-align: center; }
.card-preview img { display: block; width: auto; max-width: 100%; max-height: 46vh; height: auto; margin: 0 auto; border-radius: 10px; box-shadow: var(--shadow-sm); }
.toast { position: fixed; z-index: 120; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); max-width: min(460px, calc(100% - 32px)); padding: 12px 20px; border-radius: 16px; background: var(--ink); color: #fffaf2; font-size: 14.5px; line-height: 1.6; text-align: center; box-shadow: var(--shadow-md); opacity: 0; transform: translate(-50%, 8px); pointer-events: none; transition: opacity 180ms var(--ease), transform 180ms var(--ease); }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast:empty { display: none; }

/* Loading */
.loading-view { min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; }
.loading-mark { display: block; }
.loading-seal { transform-box: fill-box; transform-origin: center; animation: pulse 1.2s ease-in-out infinite; }
.loading-label { font-family: var(--font-serif); font-size: 20px; color: var(--ink); margin: 0; }

@keyframes view-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.75); opacity: .6; } }

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: #4d3340; border-color: #4d3340; }
  .btn-secondary:hover { border-color: var(--ink); }
  .btn-quiet:hover, .back-link:hover, .text-button:hover, .header-link:hover { color: var(--ink); }
  .choice:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
}
@media (min-width: 720px) {
  :root { --gutter: 28px; }
  .site-header { min-height: 76px; }
  .flow { padding-top: 20px; }
  .flow-title { font-size: 32px; }
}
@media (max-width: 360px) {
  :root { --gutter: 16px; }
  .flow-title { font-size: 25px; }
  .btn { padding-left: 18px; padding-right: 18px; }
}
@media (prefers-contrast: more) {
  :root { --muted: #5a4950; --line: #b8a593; --line-strong: #8f7b68; }
}
