/* 宣纸底色、墨色文字、与社徽一致的朱砂色；移动端优先 */
:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --paper-deep: #efe8da;
  --surface: #fffdf8;
  --ink: #231916;
  --ink-soft: #4b3f38;
  --muted: #7f7268;
  --line: #e4dccd;
  --seal: #b8361a;
  --seal-bright: #e9470a;
  --seal-press: #9a2d15;
  --seal-wash: #f8e6dc;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(60 35 20 / .05), 0 8px 24px rgb(60 35 20 / .07);
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", STSong, SimSun, serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --dock-height: calc(76px + var(--safe-bottom));
  font: 16px/1.6 "PingFang SC", Inter, "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(120% 50% at 100% 0%, rgb(233 71 10 / .07), transparent 60%),
    var(--paper);
  -webkit-font-smoothing: antialiased;
}
body[data-step="crop"] { padding-bottom: var(--dock-height); }
a { color: var(--seal); text-underline-offset: .2em; }
button, input { font: inherit; color: inherit; }
/* 按钮连续点按不触发 iOS 双击缩放网页 */
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: wait; opacity: .55; }
:focus-visible { outline: 2.5px solid var(--seal-bright); outline-offset: 3px; }
h1, h2, h3, h4, p, figure, dl, dd, fieldset { margin: 0; }
img { max-width: 100%; display: block; }

/* ---------- 顶栏与标识 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center;
  min-height: 56px; padding: env(safe-area-inset-top, 0px) 20px 0;
  background: rgb(247 243 234 / .86);
  backdrop-filter: saturate(1.3) blur(14px);
  -webkit-backdrop-filter: saturate(1.3) blur(14px);
  border-bottom: 1px solid rgb(228 220 205 / .7);
}
.wordmark { display: inline-flex; align-items: center; gap: .7rem; min-height: 44px; text-decoration: none; color: var(--ink); }
.brand-logo { width: auto; height: 22px; object-fit: contain; flex-shrink: 0; }

.app { width: min(100%, 560px); margin-inline: auto; padding: 0 20px calc(32px + var(--safe-bottom)); }
.step { animation: rise .35s cubic-bezier(.2, .8, .2, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }


/* ---------- 第一步：选图 ---------- */
/* 首页第一屏只放标题与两个入口，铺满视口；精选名印在下一屏 */
.home-first {
  display: flex; flex-direction: column; padding: 28px 0 32px;
  min-height: calc(100vh - 56px - env(safe-area-inset-top, 0px));
  min-height: calc(100svh - 56px - env(safe-area-inset-top, 0px));
}
.home-actions { margin-block: auto; padding-top: 24px; }

/* 首页：统一左对齐，依靠字号与颜色建立层级 */
.hero h1 {
  font-family: var(--serif); font-size: 2.5rem; font-weight: 800;
  line-height: 1.12; letter-spacing: .1em;
}
.lede { margin-top: 8px; font-size: .95rem; letter-spacing: .06em; color: var(--muted); }

/* 拍照识印：取景卡片，四角与取景页、裁切框一致 */
.capture {
  position: relative; width: 100%; aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 24px; border: 0; border-radius: 22px;
  color: #fff;
  background:
    radial-gradient(90% 140% at 100% 0%, rgb(255 255 255 / .16), transparent 55%),
    linear-gradient(135deg, var(--seal-bright), var(--seal));
  box-shadow: 0 10px 28px rgb(184 54 26 / .28);
  transition: transform .12s;
}
.capture:active:not(:disabled) { transform: scale(.985); }
.capture .corner { width: 24px; height: 24px; border-color: rgb(255 255 255 / .85); border-width: 2.5px; }
.capture .corner.tl { top: 16px; left: 16px; }
.capture .corner.tr { top: 16px; right: 16px; }
.capture .corner.bl { bottom: 16px; left: 16px; }
.capture .corner.br { bottom: 16px; right: 16px; }
.capture-ring {
  width: 56px; height: 56px; margin-bottom: 4px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgb(255 255 255 / .16); box-shadow: inset 0 0 0 1.5px rgb(255 255 255 / .55);
}
.capture-title { font-family: var(--serif); font-size: 1.35rem; letter-spacing: .2em; margin-right: -.2em; }

.ghost-wide {
  width: 100%; min-height: 52px; margin-top: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
  color: var(--ink); font-weight: 600; font-size: .95rem;
  transition: background .15s;
}
.ghost-wide:active:not(:disabled) { background: var(--paper-deep); }
.ghost-wide svg { color: var(--seal); }

.hint { margin-top: 18px; text-align: center; font-size: .8rem; color: var(--muted); }
.crop-hint { margin-top: 12px; }

/* ---------- 第二步：裁切 ---------- */
.step-head { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 6px; padding: 12px 0 14px; }
.step-head h2 { font-family: var(--serif); font-size: 1.2rem; letter-spacing: .08em; }
.icon-button {
  width: 44px; height: 44px; display: grid; place-items: center;
  margin-left: -10px; border: 0; border-radius: 50%; background: transparent;
}
.icon-button:active { background: var(--paper-deep); }

.frame {
  position: relative; width: min(100%, 62dvh); margin-inline: auto;
  border-radius: 6px; overflow: hidden; background: #fff; box-shadow: var(--shadow);
}
canvas { display: block; width: 100%; height: auto; touch-action: none; cursor: grab; }
canvas:active { cursor: grabbing; }
canvas:focus-visible { outline: none; }
.frame:focus-within { box-shadow: 0 0 0 3px var(--seal-bright), var(--shadow); }
.corner { position: absolute; width: 26px; height: 26px; border: 3px solid var(--seal-bright); pointer-events: none; }
.corner.tl { top: 10px; left: 10px; border-right: 0; border-bottom: 0; border-top-left-radius: 6px; }
.corner.tr { top: 10px; right: 10px; border-left: 0; border-bottom: 0; border-top-right-radius: 6px; }
.corner.bl { bottom: 10px; left: 10px; border-right: 0; border-top: 0; border-bottom-left-radius: 6px; }
.corner.br { bottom: 10px; right: 10px; border-left: 0; border-top: 0; border-bottom-right-radius: 6px; }

.scan { position: absolute; inset: 0; background: rgb(35 25 22 / .18); pointer-events: none; }
.scan span {
  position: absolute; left: 0; right: 0; height: 30%;
  background: linear-gradient(transparent, rgb(233 71 10 / .35));
  border-bottom: 2px solid var(--seal-bright);
  animation: scan 1.4s ease-in-out infinite alternate;
}
@keyframes scan { from { top: -30%; } to { top: 100%; } }
.scan-label {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  padding: 6px 14px; border-radius: 999px; white-space: nowrap;
  background: rgb(35 25 22 / .78); color: #fff; font-size: .86rem; letter-spacing: .04em;
}
.scan-label:empty { display: none; }

/* ---------- 页内正方形取景 ---------- */
.camera { position: fixed; inset: 0; z-index: 35; overflow: hidden; background: #000; color: #fff; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.camera-frame {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%);
  width: min(calc(100vw - 40px), 60dvh, 560px); aspect-ratio: 1;
  border-radius: 6px; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .55); pointer-events: none;
}
.camera-hint {
  position: absolute; top: calc(100% + 16px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: .9rem; letter-spacing: .06em; text-shadow: 0 1px 3px rgb(0 0 0 / .6);
}
.camera-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center;
  padding: 16px 20px calc(24px + var(--safe-bottom));
}
.camera-side { min-width: 64px; min-height: 44px; border: 0; border-radius: 999px; background: rgb(255 255 255 / .14); color: #fff; font-size: .95rem; }
.shutter {
  width: 76px; height: 76px; padding: 6px; border: 4px solid #fff; border-radius: 50%; background: transparent;
}
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active:not(:disabled) span { transform: scale(.9); }
.shutter:disabled { opacity: .4; cursor: default; }

.zoom-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 14px 4px 6px; color: var(--muted); }
.zoom-row input { width: 100%; min-width: 0; height: 44px; accent-color: var(--seal); }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: 1fr 2.2fr; gap: 10px;
  max-width: 560px; margin-inline: auto;
  padding: 12px 20px calc(12px + var(--safe-bottom));
  background: linear-gradient(transparent, var(--paper) 30%);
}
.primary, .secondary {
  min-height: 52px; border-radius: 16px; font-weight: 650; font-size: 1rem; letter-spacing: .06em;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  transition: background .15s, transform .1s;
}
.primary { border: 0; background: var(--seal); color: #fff; box-shadow: 0 6px 18px rgb(184 54 26 / .25); }
.primary:active:not(:disabled) { background: var(--seal-press); transform: scale(.985); }
.secondary { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.secondary:active:not(:disabled) { background: var(--paper-deep); }

.status {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 40;
  transform: translateX(-50%); width: max-content; max-width: calc(100% - 40px);
  padding: 10px 16px; border-radius: 14px;
  background: var(--ink); color: #fff; font-size: .88rem; box-shadow: var(--shadow);
  animation: rise .25s ease-out;
}
body[data-step="crop"] .status { bottom: calc(var(--dock-height) + 6px); }
.status[data-error="true"] { background: var(--seal); }

/* ---------- 第三步：结果 ---------- */
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 20px 2px 14px; }
.result-head h2 { font-family: var(--serif); font-size: 1.35rem; letter-spacing: .08em; }
.result-head h2:focus { outline: none; }
.badge { flex: none; font-size: .76rem; padding: 4px 10px; border-radius: 999px; background: var(--seal-wash); color: var(--seal); font-weight: 600; }

#selected .record { padding: 14px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }

.record-media { display: grid; gap: 10px; }
.record-media.is-compare { grid-template-columns: 1fr 1fr; }
.compare, .impression-preview {
  position: relative; display: block; border-radius: 14px; overflow: hidden; background: #fff;
  border: 1px solid var(--line);
}
.compare img, .impression-preview img { width: 100%; aspect-ratio: 1; object-fit: contain; padding: 8px; }
.compare span, .compare-label {
  position: absolute; left: 8px; top: 8px; padding: 1px 8px; border-radius: 999px;
  font-size: .7rem; background: rgb(35 25 22 / .7); color: #fff;
}
.compare-label { background: var(--seal); }
.record-media:not(.is-compare) .impression-preview { width: min(100%, 260px); margin-inline: auto; }

.zoom-hint {
  position: absolute; right: 8px; bottom: 8px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: rgb(35 25 22 / .7); color: #fff;
}

.record-content { min-width: 0; overflow-wrap: anywhere; margin-top: 14px; }
.record-heading { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.record h3 { font-family: var(--serif); font-size: 1.3rem; line-height: 1.35; }
.demo-label { font-size: .7rem; padding: 1px 7px; border: 1px solid var(--seal); color: var(--seal); border-radius: 4px; white-space: nowrap; }

/* 五段式识读报告 */
.report-section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.report-section h4 {
  margin-bottom: 8px; font-family: var(--serif); font-size: .98rem; letter-spacing: .12em; color: var(--seal);
}
.report-section p { color: var(--ink-soft); font-size: .92rem; line-height: 1.8; }
.report-section p + p { margin-top: 8px; }
.report-section p:empty, .report-section small:empty { display: none; }
.report-section small { display: block; margin-top: 4px; color: var(--muted); font-size: .78rem; line-height: 1.6; }
.section-reading .inscription {
  padding: 12px 16px; border-radius: 14px;
  background: linear-gradient(135deg, var(--seal-wash), #fbefe7);
  font-family: var(--serif); font-size: 1.6rem; line-height: 1.4; letter-spacing: .18em; color: var(--seal);
}
.section-reading .inscription + p { margin-top: 10px; }
.facts > div { display: grid; grid-template-columns: 2.8rem minmax(0, 1fr); gap: 10px; padding: 8px 0; }
.facts dt { font-size: .82rem; color: var(--muted); padding-top: 1px; }
.facts dd { font-size: .93rem; }
.facts + p { margin-top: 8px; }

.sources { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.sources li { padding: 10px 14px; border-radius: 12px; background: var(--paper); border-left: 3px solid var(--seal-bright); }
.source-type { display: inline-block; margin-right: 6px; font-size: .72rem; color: var(--seal); letter-spacing: .1em; }
.sources li > strong, .sources li > a { font-weight: 600; font-size: .9rem; line-height: 1.5; }
.sources li > p { font-size: .8rem; margin-top: 6px; line-height: 1.65; }

.alternatives { margin-top: 26px; }
.alt-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 0 2px; }
.alt-heading h2, .alt-heading h3 { font-family: var(--serif); font-size: 1.1rem; letter-spacing: .06em; }

/* 首页精选名印 */
.featured { padding-top: 8px; }
.featured .alt-heading { padding: 0; }
.featured .tile { flex-basis: 40%; }
.tile[aria-busy="true"] { opacity: .6; }
.seal-strip {
  display: flex; gap: 10px; margin: 10px -20px 0; padding: 4px 20px 8px;
  overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 20px;
  scrollbar-width: none; overscroll-behavior-x: contain;
}
.seal-strip::-webkit-scrollbar { display: none; }
.tile {
  flex: 0 0 42%; max-width: 190px; min-width: 0; scroll-snap-align: start;
  display: grid; align-content: start; gap: 8px; padding: 8px 8px 12px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
  text-align: left; transition: transform .1s, border-color .15s;
}
.tile:active { transform: scale(.98); border-color: var(--seal); }
.tile-image { display: block; border-radius: 10px; background: #fff; overflow: hidden; }
.tile img { width: 100%; aspect-ratio: 1; object-fit: contain; padding: 6px; }
.tile-title { font-size: .86rem; font-weight: 600; padding: 0 4px; line-height: 1.4; overflow-wrap: anywhere; }
.tile small { font-size: .72rem; line-height: 1.5; color: var(--seal); padding: 0 4px; }
.again { margin-top: 28px; }

/* ---------- 档案面板（手机为底部抽屉） ---------- */
dialog {
  width: 100%; max-width: 560px; max-height: 88dvh; margin: auto auto 0;
  padding: 0 18px calc(18px + var(--safe-bottom));
  border: 0; border-radius: 24px 24px 0 0; background: var(--surface); color: var(--ink);
  overflow-y: auto; overscroll-behavior: contain;
}
dialog[open] { animation: sheet .3s cubic-bezier(.2, .8, .2, 1); }
dialog::backdrop { background: rgb(35 25 22 / .45); }
@keyframes sheet { from { transform: translateY(100%); } }
.sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 10px auto 0; }
.dialog-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; justify-content: flex-end; align-items: center;
  padding: 8px 0 10px; background: var(--surface);
}
.dialog-head h2 { font-size: .95rem; color: var(--muted); font-weight: 500; letter-spacing: .1em; }
.close { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--paper-deep); }
#dialog-body .record-content { margin-top: 12px; }

/* ---------- 印蜕全屏查看 ---------- */
.viewer {
  width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0;
  border-radius: 0; background: #17110f; color: #fff; overflow: hidden;
  /* 浮层内只使用自定义缩放，禁止网页级缩放与滚动 */
  touch-action: none;
  display: none; grid-template-rows: auto minmax(0, 1fr) auto;
}
.viewer[open] { display: grid; animation: rise .2s ease-out; }
.viewer::backdrop { background: #17110f; }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
}
.viewer-title { font-family: var(--serif); font-size: 1rem; font-weight: 600; letter-spacing: .08em; }
.viewer .close { background: rgb(255 255 255 / .12); color: #fff; }
.viewer-stage { position: relative; overflow: hidden; display: grid; place-items: center; touch-action: none; cursor: zoom-in; }
.viewer-stage[data-zoomed="true"] { cursor: grab; }
.viewer-stage:focus-visible { outline: 2px solid var(--seal-bright); outline-offset: -4px; }
.viewer-image {
  max-width: calc(100% - 32px); max-height: calc(100% - 16px); object-fit: contain;
  background: #fff; border-radius: 4px; user-select: none; -webkit-user-drag: none;
  transform-origin: center; will-change: transform;
}
.viewer-foot {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px calc(12px + var(--safe-bottom));
}
.viewer-zoom { display: flex; gap: 8px; }
.viewer-zoom button {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgb(255 255 255 / .12); color: #fff; font-size: 1.3rem; line-height: 1;
}
.viewer-zoom button:disabled { cursor: default; opacity: .35; }
.viewer-caption { flex: 1; min-width: 0; font-size: .78rem; color: rgb(255 255 255 / .7); }
.viewer-original { color: #ffb08a; font-size: .84rem; font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; }

/* ---------- 宽屏 ---------- */
@media (min-width: 720px) {
  .brand-logo { height: 26px; }
  .hero h1 { font-size: 3rem; }
  .capture { aspect-ratio: 2 / 1; }
  .featured .seal-strip { display: grid; grid-template-columns: repeat(4, 1fr); overflow: visible; margin-inline: 0; padding-inline: 0; }
  dialog:not(.viewer) { margin: auto; border-radius: 24px; padding-top: 4px; }
  .sheet-grip { display: none; }
  .tile { flex-basis: 30%; }
}

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

/* ---------- 未能可靠识别 ---------- */
.unmatched-photo {
  width: min(100%, 320px); margin: 4px auto 0; padding: 10px;
  border-radius: 22px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.unmatched-photo img { width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: 14px; background: #fff; }
.unmatched-message { margin: 20px 4px 24px; text-align: center; line-height: 1.7; color: var(--muted); }
.unmatched-retake { width: 100%; }
#unmatched-title:focus { outline: none; }
