/* =================================================================
 * 量子签 · styles.css
 * 双主题:UI 用 [data-theme] 切换。
 *   classical: 纸黄-墨黑-朱砂红,衬线毛笔风
 *   cyber:     紫黑-霓虹紫-青绿,等宽现代
 * 整站竖屏全屏,五大屏(app/on/handle/reveal/ledger)叠在一起,用 .screen 类切换。
 * ================================================================= */

/* ---------- 全局变量 ---------- */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --r-md: 12px;
  --r-lg: 20px;
  --tr: 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---------- 古风主题 ---------- */
[data-theme="classical"] {
  --bg: #f4e9d2;
  --bg-2: #ead9b6;
  --paper: #f8f0dc;
  --paper-shadow: rgba(80, 40, 10, 0.18);
  --ink: #2a1a0a;
  --ink-2: #5a3a1a;
  --cinnabar: #c0341e;
  --gold: #b8860b;
  --muted: #8a6b3f;
  --font-display: "STKaiti", "KaiTi", "楷体", "FangSong", "宋体", serif;
  --font-body: "STKaiti", "KaiTi", "楷体", "FangSong", "宋体", serif;
  --seal-color: #c0341e;
}

/* ---------- 赛博主题(反转后) ---------- */
[data-theme="cyber"] {
  --bg: #0a0612;
  --bg-2: #1a0b2e;
  --paper: #1a0b2e;
  --paper-shadow: rgba(124, 77, 255, 0.4);
  --ink: #f3e8ff;
  --ink-2: #b388ff;
  --cinnabar: #18ffff;
  --gold: #ffd54f;
  --muted: #7c4dff;
  --font-display: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  --font-body: "JetBrains Mono", "Fira Code", "PingFang SC", sans-serif;
  --seal-color: #18ffff;
}

/* ---------- 基础 ---------- */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* iOS Safari:禁止长按弹出菜单/选中(签文内容除外,保留可读性) */
body, .btn, .icon-btn, .ledger-item, .divination-item {
  -webkit-touch-callout: none;
}

/* 允许签文、诗、签簿摘要被用户选中复制(更友好) */
.lot-paper, .poem, .lot-title, .reveal-body, .ledger-item .excerpt {
  -webkit-user-select: text;
  user-select: text;
}

html,
body {
  margin: 0;
  padding: 0;
  /* dvh 自适应移动浏览器地址栏伸缩,fallback 给旧浏览器。
     固定 100dvh + overflow:hidden = 永远是单屏 App 外壳,
     从结构上杜绝整窗(浏览器级)滚动条出现。 */
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* 禁止下拉橡皮筋/nesting 滚动联动 */
  overscroll-behavior: none;
  transition: background var(--tr), color var(--tr);
}

body {
  display: flex;
  flex-direction: column;
  font-size: 16px;
  line-height: 1.6;
}

/* ---------- 主舞台 ---------- */
#stage {
  flex: 1 1 auto;
  min-height: 0;          /* flex 收缩:防止子内容把 stage 撑破造成整屏滚动 */
  position: relative;
  overflow: hidden;
  /* 四向独立应用 safe-area,修正之前 safe-left 同时给了左右的 bug */
  padding: calc(var(--safe-top) + 8px)
    var(--safe-right) 0 var(--safe-left);
}

.screen {
  position: absolute;
  inset: 0;
  padding: calc(var(--safe-top) + 24px)
    calc(var(--safe-right) + 20px)
    calc(var(--safe-bottom) + 24px)
    calc(var(--safe-left) + 20px);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: opacity var(--tr), transform var(--tr);
  /* 严格不可滚动:每个屏幕都在当前视口内完成主要展示。*/
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* =================================================================
 * 屏幕 1 · 请签(app)
 * ================================================================= */

#screen-app {
  align-items: center;
  justify-content: space-between;
  text-align: center;
  min-height: 0;          /* flex column:允许子内容纵向收缩,防整屏溢出 */
}

.brand {
  flex-shrink: 0;     /* 顶部品牌区固定高度,不被挤也不溢出屏 */
  margin-top: 0;
}

.brand h1 {
  font-family: var(--font-display);
  font-size: clamp(48px, 14vw, 96px);
  margin: 0;
  color: var(--ink);
  letter-spacing: 0.08em;
  font-weight: 400;
}

.brand .subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  letter-spacing: 0.3em;
}

/* 签筒 */
.tube-wrap {
  flex: 1 1 auto;
  min-height: 0;          /* 允许向内收缩:熵表/按钮加高时签筒自适应,不被挤出屏 */
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
}

/* 首屏签到筒区域可点(等同按按钮)。只在 APP 默认态显手势光标 */
#screen-app.active .tube-wrap {
  cursor: pointer;
}
#screen-app.active .tube-wrap:active .tube {
  transform: scale(0.97);
  transition: transform 0.12s ease;
}

.tube {
  /* 尺寸随视口缩放,矮屏不会溢出;父级 tube-wrap 已允许收缩,这里再保险 */
  width: clamp(120px, 42vw, 168px);
  height: clamp(180px, 60vw, 248px);
  position: relative;
  filter: drop-shadow(0 20px 40px var(--paper-shadow));
}

.tube .body {
  position: absolute;
  inset: 12% 0 8% 0;
  background: linear-gradient(
    180deg,
    var(--cinnabar) 0%,
    color-mix(in srgb, var(--cinnabar) 70%, #000) 100%
  );
  border-radius: 50% / 12%;
  border: 3px solid var(--gold);
}

.tube .mouth {
  position: absolute;
  top: 10%;
  left: 0;
  right: 0;
  height: 16%;
  background: color-mix(in srgb, var(--cinnabar) 50%, #000);
  border-radius: 50%;
  border: 3px solid var(--gold);
}

.tube .label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: clamp(22px, 8vw, 36px);
  color: var(--paper);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  writing-mode: vertical-rl;
  letter-spacing: 0.2em;
}

.tube .stick {
  position: absolute;
  width: 10px;
  background: var(--paper);
  border: 1px solid var(--gold);
  border-radius: 4px;
  opacity: 0;
}

.tube .stick.out {
  animation: stickFly 0.6s var(--tr) forwards;
}

@keyframes stickFly {
  0% {
    top: 5%;
    opacity: 0;
    transform: translateX(-50%) rotate(0deg);
  }
  40% {
    opacity: 1;
  }
  100% {
    top: -40%;
    opacity: 1;
    transform: translateX(-50%) rotate(15deg);
  }
}

/* 摇晃时签筒抖动 */
.tube-wrap.shaking .tube {
  animation: tubeShake 0.15s linear infinite;
}

@keyframes tubeShake {
  0% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(-4px, -2px) rotate(-2deg); }
  50% { transform: translate(0, 2px) rotate(0deg); }
  75% { transform: translate(4px, -2px) rotate(2deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* 量子状态条(启动阶段简约反馈,取代旧 entropy-meter) */
.quantum-status {
  width: 100%;
  max-width: 360px;
  margin: 0 auto 16px;
  padding: 10px 14px;
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  border-radius: var(--r-md);
  font-size: 13px;
  transition: var(--tr);
}

.quantum-status .qs-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--ink-2);
  opacity: 0.35;
  transition: var(--tr);
}
.quantum-status .qs-dot.idle    { opacity: 0.35; }
.quantum-status .qs-dot.live    {
  background: var(--cinnabar);
  opacity: 1;
  animation: qs-pulse 1.2s infinite ease-in-out;
}
.quantum-status .qs-dot.ready   {
  background: #2fae6b;
  opacity: 1;
  box-shadow: 0 0 8px color-mix(in srgb, #2fae6b 60%, transparent);
}

@keyframes qs-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.5); opacity: 0.5; }
}

.quantum-status .qs-text {
  color: var(--ink-2);
  flex: 1 1 auto;
  min-width: 0;
}
.quantum-status .qs-detail {
  flex-basis: 100%;
  margin-top: 2px;
  font-size: 11px;
  font-family: monospace;
  color: var(--muted);
  letter-spacing: 0.02em;
  word-break: break-all;
}

/* 熵率仪表 */
.entropy-meter {
  width: 100%;
  max-width: 360px;
  margin: 0 auto 16px;
  padding: 14px 16px;
  flex-shrink: 0;          /* 仪表盘保持设定高度,不参与纵向收缩 */
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  border-radius: var(--r-md);
  font-size: 12px;
}
.entropy-meter .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
}

.entropy-meter .src {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entropy-meter .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-2);
  opacity: 0.3;
}

.entropy-meter .dot.live {
  background: var(--cinnabar);
  opacity: 1;
  box-shadow: 0 0 8px var(--cinnabar);
}

.entropy-meter .s-val {
  color: var(--cinnabar);
  flex-shrink: 0;
  font-weight: bold;
  font-family: monospace;
}

.entropy-meter .stat {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed color-mix(in srgb, var(--ink) 20%, transparent);
  font-size: 11px;
  color: var(--muted);
}

/* 主按钮 —— 移动端触摸目标≥44px,主 CTA 全宽 */
.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-block;
  min-height: 50px;            /* 触摸友好下限 */
  padding: 14px 28px;
  border: 2px solid var(--ink);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.3em;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  border-radius: var(--r-md);
  background: var(--paper);
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
  margin: 0;
  touch-action: manipulation; /* 消除点击 300ms 延迟 */
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
  background: var(--ink);
  color: var(--paper);
}

.btn.primary {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 56px;
  font-size: 19px;
  letter-spacing: 0.25em;
  background: var(--cinnabar);
  color: var(--paper);
  border-color: var(--cinnabar);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--cinnabar) 35%, transparent);
}

.btn.primary:active {
  background: color-mix(in srgb, var(--cinnabar) 70%, #000);
}

/* 首屏引导按钮:呼吸引导用户点击。
   .tap-to-start = 未触发过摇签的默认态;
   进入 SHAKING/TRANSITIONING 时 app.js 会 add "ready" 并改文案,
   此时去掉呼吸动画(避免跟“摇动中”文案冲突)。 */
.btn.primary.tap-to-start:not(.ready) {
  animation: tap-pulse 2.4s infinite ease-in-out;
}
@keyframes tap-pulse {
  0%, 100% {
    box-shadow:
      0 6px 18px color-mix(in srgb, var(--cinnabar) 35%, transparent),
      0 0 0 0 color-mix(in srgb, var(--cinnabar) 45%, transparent);
  }
  50% {
    transform: translateY(-1px);
    box-shadow:
      0 10px 26px color-mix(in srgb, var(--cinnabar) 50%, transparent),
      0 0 0 12px color-mix(in srgb, var(--cinnabar) 0%, transparent);
  }
}
.btn.primary.ready {
  background: color-mix(in srgb, #2fae6b 90%, #000);
  border-color: color-mix(in srgb, #2fae6b 90%, #000);
  animation: none;
}

.btn.small {
  align-self: center;          /* 保持轻量 chip 样 */
  min-height: 44px;
  padding: 10px 20px;
  font-size: 14px;
  letter-spacing: 0.2em;
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn[hidden] {
  display: none !important;
}

.center-actions {
  width: 100%;
  max-width: 420px;
  margin: 14px auto calc(var(--safe-bottom) + 20px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 10px;
  flex-shrink: 0;
}

.center-actions .btn.small {
  width: 100%;
  align-self: stretch;
}

#screen-app .center-actions .btn.small,
#screen-divination .center-actions .btn.small,
#screen-reveal .center-actions .btn.small,
#screen-ledger .center-actions .btn.small {
  grid-column: 1 / -1;
}

/* =================================================================
 * 屏幕 2 · 解签(handle)
 * ================================================================= */

#screen-handle {
  align-items: center;
  min-height: 0;
}

/* 解签屏:一屏摘要展示,不产生内部滚动。 */
#screen-handle .lot-paper {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
}

.lot-paper {
  width: 100%;
  max-width: 460px;
  background: var(--paper);
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
  border-radius: var(--r-md);
  padding: clamp(16px, 4vw, 24px) clamp(14px, 4vw, 22px);
  position: relative;
  box-shadow: 0 12px 40px var(--paper-shadow);
  margin: auto 0;
}

.lot-paper::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid color-mix(in srgb, var(--gold) 60%, transparent);
  border-radius: 8px;
  pointer-events: none;
}

.lot-no-row {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.lot-no {
  font-family: var(--font-display);
  color: var(--cinnabar);
  font-size: 14px;
  letter-spacing: 0.2em;
}

.lot-grade {
  font-family: var(--font-display);
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 10px;
  letter-spacing: 0.15em;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink-2);
  white-space: nowrap;
}

.lot-grade[data-tone="吉"] {
  background: color-mix(in srgb, var(--cinnabar) 16%, transparent);
  color: var(--cinnabar);
}

.lot-grade[data-tone="平"] {
  background: color-mix(in srgb, var(--gold) 18%, transparent);
  color: var(--gold);
}

.lot-grade[data-tone="凶"] {
  background: color-mix(in srgb, #333 22%, transparent);
  color: #777;
}

.lot-title {
  font-family: var(--font-display);
  font-size: clamp(20px, 5.8vw, 28px);
  text-align: center;
  color: var(--ink);
  margin: 0 0 4px;
  font-weight: bold;
  line-height: 1.3;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lot-story {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin: 0 0 10px;
  font-style: italic;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.poem {
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(15px, 4.1vw, 19px);
  line-height: 1.45;
  color: var(--ink);
  margin: 7px 0;
  padding: 8px 4px;
  border-top: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  flex-shrink: 0;
}

.cat-tag {
  display: inline-block;
  background: var(--cinnabar);
  color: var(--paper);
  padding: 2px 12px;
  border-radius: 20px;
  font-size: 12px;
  letter-spacing: 0.1em;
  margin-right: 8px;
}

.interp {
  margin-top: 20px;
  font-size: 15px;
  color: var(--ink-2);
}

.interp .omen {
  margin-top: 12px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--gold) 12%, transparent);
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  font-size: 13px;
}

/* ---------- 六项占断 ---------- */
.section-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: clamp(12px, 3.6vw, 14px);
  color: var(--cinnabar);
  margin: 8px 0 7px;
  letter-spacing: 0.22em;
  flex-shrink: 0;
}

.section-title::before,
.section-title::after {
  content: "";
  width: clamp(20px, 12vw, 40px);
  height: 1px;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--gold) 50%, transparent);
}

.divinations {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  flex: 0 0 auto;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
  margin-bottom: 0;
}

.divination-item {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 7px 8px 8px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--paper) 96%, white), color-mix(in srgb, var(--gold) 9%, var(--paper))),
    var(--paper);
  border: 1px solid color-mix(in srgb, var(--gold) 38%, transparent);
  border-radius: 8px;
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, white 42%, transparent),
    0 3px 0 color-mix(in srgb, var(--gold) 24%, transparent);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2px;
  overflow: hidden;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-body);
  min-height: 50px;
  touch-action: manipulation;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.divination-item:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, white 30%, transparent),
    0 1px 0 color-mix(in srgb, var(--gold) 22%, transparent);
}

.divination-item::after {
  content: "›";
  position: absolute;
  right: 7px;
  top: 50%;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1;
  transform: translateY(-50%);
  opacity: 0.72;
}

.divination-item.is-viewed {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--cinnabar) 9%, var(--paper)), color-mix(in srgb, var(--gold) 10%, var(--paper))),
    var(--paper);
  border-color: color-mix(in srgb, var(--cinnabar) 42%, var(--gold));
}

.divination-item.is-viewed::after {
  content: "✓";
  color: var(--cinnabar);
  opacity: 1;
}

.dv-index {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.06em;
}

.dv-name {
  font-family: var(--font-display);
  font-weight: bold;
  color: var(--cinnabar);
  padding-right: 12px;
  font-size: 13px;
  letter-spacing: 0.15em;
  white-space: nowrap;
}

.dv-status {
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.08em;
}

.divination-item.is-viewed .dv-status {
  color: var(--cinnabar);
}

.divination-progress {
  flex-shrink: 0;
  min-height: 24px;
  margin: 8px 0 0;
  padding: 4px 10px;
  border: 1px dashed color-mix(in srgb, var(--gold) 42%, transparent);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}

.divination-progress[data-complete="true"] {
  border-color: color-mix(in srgb, var(--cinnabar) 45%, transparent);
  color: var(--cinnabar);
}

/* 印章 */
.seal {
  position: absolute;
  top: 10px;
  right: 12px;
  pointer-events: none;
  width: 38px;
  height: 38px;
  border: 2px solid var(--seal-color);
  color: var(--seal-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.1em;
  border-radius: 4px;
  transform: rotate(-8deg);
  opacity: 0.85;
  text-align: center;
  line-height: 1.1;
}

/* =================================================================
 * 屏幕 3 · 占断详情(divination)
 * ================================================================= */

#screen-divination {
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.divination-page {
  width: 100%;
  max-width: 460px;
  flex: 0 1 auto;
  min-height: 0;
  max-height: 100%;
  margin: 0;
  padding: clamp(22px, 6vw, 30px) clamp(18px, 5vw, 24px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid color-mix(in srgb, var(--ink) 28%, transparent);
  border-radius: var(--r-md);
  box-shadow: 0 12px 40px var(--paper-shadow);
}

.divination-page-top {
  text-align: center;
  flex-shrink: 0;
}

.divination-page-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.divination-page-kicker,
.answer-label,
.divination-detail-progress {
  color: var(--cinnabar);
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.22em;
}

.divination-detail-progress {
  padding: 2px 8px;
  border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  border-radius: 999px;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.divination-detail-progress[data-complete="true"] {
  border-color: color-mix(in srgb, var(--cinnabar) 44%, transparent);
  color: var(--cinnabar);
}

.divination-page h2 {
  margin: 8px 0 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(40px, 15vw, 72px);
  line-height: 1;
  letter-spacing: 0.08em;
}

.divination-answer,
.divination-omen-box {
  padding: 16px 16px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--gold) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold) 28%, transparent);
  overflow: hidden;
}

.divination-answer p,
.divination-omen-box p {
  margin: 8px 0 0;
  color: var(--ink-2);
  font-size: clamp(18px, 5.2vw, 24px);
  line-height: 1.6;
}

.divination-omen-box p {
  color: var(--muted);
  font-size: clamp(14px, 4.2vw, 17px);
}

/* =================================================================
 * 屏幕 3 · 反转(reveal)
 * ================================================================= */

#screen-reveal {
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 0;
  background: radial-gradient(
    circle at 50% 30%,
    var(--bg-2) 0%,
    var(--bg) 70%
  );
}

/* 反转屏:卡片一屏展示,正文按移动端摘要限制行数。 */
#screen-reveal .reveal-card {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.reveal-card .emoji {
  flex-shrink: 0;
  font-size: clamp(48px, 16vw, 72px);
  animation: emojiBlink 0.6s ease-in-out 3;
}

@keyframes emojiBlink {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.reveal-title {
  font-family: var(--font-display);
  font-size: clamp(20px, 6vw, 24px);
  color: var(--cinnabar);
  text-shadow: 0 0 8px color-mix(in srgb, var(--cinnabar) 50%, transparent);
  margin: 16px 0 12px;
  line-height: 1.35;
  flex-shrink: 0;
}

.reveal-card {
  width: 100%;
  max-width: 380px;
  padding: clamp(22px, 6vw, 40px) clamp(18px, 5vw, 24px);
  margin: auto 0;
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  border: 1px solid color-mix(in srgb, var(--cinnabar) 22%, transparent);
  border-radius: var(--r-lg);
  box-shadow: 0 14px 42px var(--paper-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.reveal-body {
  font-size: clamp(13px, 4vw, 15px);
  color: var(--ink-2);
  display: -webkit-box;
  overflow: hidden;
  line-height: 1.7;
  margin: 0 0 18px;
  text-align: left;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
}

.reveal-epilogue {
  width: 100%;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  display: -webkit-box;
  overflow: hidden;
  padding: 12px;
  border-top: 1px dashed var(--muted);
  text-align: left;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* =================================================================
 * 屏幕 4 · 签簿(ledger)
 * ================================================================= */

#screen-ledger {
  padding-top: calc(var(--safe-top) + 16px);
  min-height: 0;
}

/* 签簿列表是次级历史功能,允许内部滚动浏览完整记录。 */
#screen-ledger #ledgerList {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 2px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.ledger-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding: 0 4px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  margin-bottom: 12px;
}

.ledger-header h2 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0;
}

.ledger-empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
  font-size: 14px;
}

.ledger-item {
  flex: 0 0 auto;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  border-radius: var(--r-md);
  border-left: 3px solid var(--cinnabar);
  font-size: 12px;
  touch-action: manipulation;
  transition: transform 0.15s ease;
}

.ledger-item:active {
  transform: scale(0.99);
}

.ledger-item .head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 4px;
}

.ledger-item .head .title {
  font-family: var(--font-display);
  font-weight: bold;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-item .head .date {
  color: var(--muted);
  flex-shrink: 0;
  font-size: 10px;
}

.ledger-item .excerpt {
  color: var(--ink-2);
  display: -webkit-box;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* =================================================================
 * 通用顶栏
 * ================================================================= */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 20;
  padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 4px) 6px calc(var(--safe-left) + 4px);
  flex-shrink: 0;
  /* 毛玻璃半透明:内容滚动时不会被签文透出来干扰 */
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  backdrop-filter: blur(14px) saturate(180%);
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
}

.topbar .title {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--ink);
  letter-spacing: 0.2em;
}

.topbar .icon-btn {
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--ink);
  padding: 10px;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.18s ease;
}

.topbar .icon-btn:active {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
}

/* =================================================================
 * Toast 提示
 * ================================================================= */

#toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 9999;
  max-width: 80%;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =================================================================
 * AR 背景(摄像头叠层)
 * ================================================================= */

.ar-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}

.ar-bg video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.25;
  filter: blur(2px) saturate(0.7);
}

.ar-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--bg) 40%, transparent),
    var(--bg)
  );
}

/* =================================================================
 * Modal(分享卡片)
 * ================================================================= */

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  padding: 20px;
}

.modal-bg.show {
  display: flex;
}

.modal-card {
  background: var(--paper);
  border-radius: var(--r-lg);
  padding: 18px;
  max-width: 380px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow: hidden;
}

.modal-card img {
  width: 100%;
  max-height: calc(90dvh - 72px);
  object-fit: contain;
  border-radius: 12px;
  display: block;
}

.modal-card .close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0,0,0,0.4);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

/* =================================================================
 * Loading
 * ================================================================= */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--ink) 30%, transparent);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =================================================================
 * 翻牌过渡
 * ================================================================= */

.flip-3d {
  perspective: 1200px;
}

.flip-inner {
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.flip-inner.flipped {
  transform: rotateY(180deg);
}

.flip-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flip-back {
  transform: rotateY(180deg);
}

/* =================================================================
 * 移动端响应式:超小屏 / 小屏 / 横屏 / 大屏 / 桌面
 * 全尺寸兼容,iPhone SE → iPad Pro → 桌面浏览器
 * ================================================================= */

/* ---------- 超小屏(≤340px,iPhone SE 1代/mini 安卓机) ---------- */
@media (max-width: 340px) {
  body { font-size: 14px; line-height: 1.55; }

  .brand h1 { font-size: 40px; letter-spacing: 0.06em; }
  .brand .subtitle { font-size: 10px; letter-spacing: 0.25em; }

  .tube { width: clamp(110px, 50vw, 148px); height: clamp(168px, 62vw, 210px); }

  .entropy-meter { font-size: 10px; padding: 10px 10px; }
  .entropy-meter .row { margin: 3px 0; }
  .entropy-meter .src { gap: 5px; }
  .entropy-meter .stat { font-size: 9px; gap: 6px; flex-wrap: wrap; }

  .lot-paper { padding: 13px 12px; }
  .lot-no { font-size: 12px; }
  .lot-title { font-size: 21px; }
  .lot-story { margin-bottom: 4px; font-size: 11px; }
  .poem { font-size: 13px; line-height: 1.24; margin: 4px 0; padding: 5px 4px; }
  .section-title { font-size: 11px; margin: 6px 0 5px; }
  .divinations { gap: 5px; }
  .divination-item { min-height: 46px; padding: 6px 6px; font-size: 11px; }
  .dv-index { font-size: 8px; }
  .dv-name { font-size: 11px; padding-right: 10px; }
  .dv-status { font-size: 9px; }
  .divination-progress { min-height: 22px; margin-top: 6px; font-size: 10px; }
  .divination-page { gap: 10px; padding: 18px 14px; }
  .divination-page-meta { gap: 6px; }
  .divination-page-kicker,
  .answer-label,
  .divination-detail-progress { font-size: 10px; }
  .divination-page h2 { font-size: 42px; }
  .divination-answer,
  .divination-omen-box { padding: 12px; }
  .divination-answer p { font-size: 16px; line-height: 1.5; }
  .divination-omen-box p { font-size: 13px; line-height: 1.45; }

  .seal { width: 34px; height: 34px; font-size: 9px; }

  .btn { font-size: 15px; letter-spacing: 0.2em; padding: 12px 20px; }
  .btn.primary { min-height: 50px; font-size: 17px; letter-spacing: 0.2em; }
  .btn.small { min-height: 42px; font-size: 13px; padding: 8px 16px; }

  .center-actions { gap: 8px; margin-bottom: calc(var(--safe-bottom) + 12px); }

  .ledger-item { padding: 12px 14px; font-size: 12px; }

  .modal-card { max-width: 94vw; padding: 14px; }
}

/* ---------- 小屏(341~375px,iPhone 12/13 mini 等) ---------- */
@media (min-width: 341px) and (max-width: 375px) {
  .entropy-meter { font-size: 11px; }
  .entropy-meter .stat { font-size: 10px; }
  .btn.primary { letter-spacing: 0.22em; }
}

/* ---------- 矮屏幕(max-height ≤ 640px,横屏小手机/折叠屏) ---------- */
@media (max-height: 640px) and (orientation: portrait) {
  .brand { margin-top: 0; }
  .brand h1 { font-size: clamp(38px, 11vw, 64px); }
  .entropy-meter { padding: 10px 14px; margin-bottom: 10px; }
  .center-actions { margin-bottom: calc(var(--safe-bottom) + 8px); gap: 8px; }
  .center-actions .btn.small { min-height: 40px; }
}

/* ---------- 横屏(orientation: landscape,矮长屏) ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  #screen-app {
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    gap: 16px;
    padding-top: calc(var(--safe-top) + 12px);
    padding-bottom: calc(var(--safe-bottom) + 12px);
  }
  #screen-app .brand { margin-top: 0; flex-shrink: 0; }
  #screen-app .brand h1 { font-size: clamp(28px, 5vw, 44px); }
  #screen-app .brand .subtitle { font-size: 11px; }

  .tube-wrap { flex: 1; min-height: 0; }
  .tube { width: clamp(110px, 22vh, 150px); height: clamp(160px, 42vh, 220px); }

  .entropy-meter { max-width: 240px; margin: 0; font-size: 11px; }
  .entropy-meter .row { margin: 2px 0; }

  .center-actions { width: auto; max-width: 220px; margin: 0; gap: 8px; }
  .center-actions { grid-template-columns: 1fr; }
  .center-actions .btn.primary { width: 100%; min-height: 48px; }
  .center-actions .btn.small { grid-column: 1 / -1; min-height: 40px; }

  /* 解签/反转屏横屏时也改成左右双列 */
  #screen-handle {
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
    gap: 16px;
    padding-top: calc(var(--safe-top) + 12px);
    padding-bottom: calc(var(--safe-bottom) + 12px);
  }
  #screen-handle .lot-paper {
    height: 100%;
    max-height: 100%;
    max-width: 60vw;
    margin: 0;
    padding: 12px 14px;
  }
  #screen-handle .lot-no-row,
  #screen-handle .lot-story {
    display: none;
  }
  #screen-handle .lot-title {
    font-size: clamp(28px, 4vw, 42px);
    margin-bottom: 6px;
  }
  #screen-handle .poem { display: none; }
  #screen-handle .section-title { margin: 6px 0 5px; }
  #screen-handle .divinations { gap: 5px; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: 1fr; }
  #screen-handle .divination-item { min-height: 44px; padding: 5px 6px; }
  #screen-handle .dv-index { display: none; }
  #screen-handle .dv-name { font-size: 11px; padding-right: 8px; }
  #screen-handle .dv-status { font-size: 9px; }
  #screen-handle .divination-progress { display: none; }
  #screen-handle .center-actions {
    align-self: center;
    max-width: 200px;
    margin: 0;
  }

  #screen-divination {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding-top: calc(var(--safe-top) + 12px);
    padding-bottom: calc(var(--safe-bottom) + 12px);
  }
  #screen-divination .divination-page {
    height: 100%;
    max-width: 60vw;
    padding: 16px 18px;
    gap: 10px;
  }
  #screen-divination .divination-page h2 { font-size: clamp(34px, 5vw, 52px); }
  #screen-divination .divination-answer,
  #screen-divination .divination-omen-box { padding: 10px 12px; }
  #screen-divination .divination-answer p { font-size: 18px; line-height: 1.45; }
  #screen-divination .divination-omen-box p { font-size: 13px; line-height: 1.35; }
  #screen-divination .center-actions {
    align-self: center;
    max-width: 200px;
    margin: 0;
  }

  #screen-reveal .reveal-card { max-width: 60vw; padding: 18px 20px; }
  #screen-reveal .center-actions { max-width: 200px; margin: 0; }
}

/* ---------- 大屏手机(431~767px,iPhone Pro Max/Plus) ---------- */
@media (min-width: 431px) and (max-width: 767px) {
  .center-actions { max-width: 400px; }
  .lot-paper { max-width: 480px; }
  .reveal-card { max-width: 420px; }
  .entropy-meter { max-width: 400px; }
}

/* ---------- 平板/iPad(≥768px):中央约束 + 双列卡 ---------- */
@media (min-width: 768px) {
  #screen-app { justify-content: center; gap: 24px; }
  .brand { margin-top: 0; }
  .brand h1 { font-size: clamp(64px, 9vw, 112px); }
  .center-actions { max-width: 420px; }

  .entropy-meter { max-width: 440px; }

  .lot-paper { max-width: 520px; }
  .reveal-card { max-width: 460px; }

  /* 六项占断:平板横排两列更宽松 */
  .divinations {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .divination-item { break-inside: avoid; }

  .modal-card { max-width: 420px; }
}

/* ---------- 桌面(≥1024px):居中"手机框"预览形态 ---------- */
@media (min-width: 1024px) {
  body {
    /* 桌面端用一个柔和背景,把内容包成手机竖屏 */
    background:
      radial-gradient(circle at 30% 20%, color-mix(in srgb, var(--bg-2) 80%, transparent), transparent 60%),
      var(--bg);
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  /* 给整个 app 一个"设备外壳"视觉 */
  .topbar,
  #stage {
    max-width: 460px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
  }

  #stage {
    border-left: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
    border-right: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
    box-shadow: 0 0 80px color-mix(in srgb, var(--paper-shadow) 60%, transparent);
  }
}

/* ---------- 用户开启系统「减少动态效果」时降级 ---------- */
@media (prefers-reduced-motion: reduce) {
  .tube-wrap.shaking .tube { animation: none; }
  .tube .stick.out { animation-duration: 0.1s; }
  .emoji { animation: none !important; }
  .spinner { animation-duration: 2s; }
  .ledger-item { transition: none; }
}
