/* ============================================================
   基础层：重置 / 舞台 / 手机外壳 / 通用动效
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background: var(--cream);
  color: var(--ink);
  line-height: 1.7;
  letter-spacing: .01em;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

input {
  font: inherit;
  color: inherit;
}

img,
svg {
  display: block;
  max-width: 100%;
}

::selection {
  background: var(--cinnabar-soft);
  color: var(--cinnabar-deep);
}

/* --- 键盘可达：焦点圈必须可见 --- */
:focus-visible {
  outline: 2px solid var(--cinnabar);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================
   舞台：宽屏显示手机外壳并居中，窄屏自动全屏
   ============================================================ */

.stage {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 与 .phone 的 calc 对齐：上下左右各 16px */
  padding: 16px;
  position: relative;
  isolation: isolate;
}

/* 背景氛围：两团暖色光晕 + 极淡噪点，避免纯色平铺 */
.stage::before {
  content: "";
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -2;
  background:
    radial-gradient(52rem 38rem at 8% -8%, rgba(206, 90, 72, .13), transparent 62%),
    radial-gradient(46rem 34rem at 102% 4%, rgba(217, 155, 52, .16), transparent 58%),
    radial-gradient(40rem 30rem at 50% 110%, rgba(71, 143, 118, .10), transparent 60%),
    var(--cream);
}

.stage::after {
  content: "";
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

/* 移动端：消除 300ms 点击延迟，也避免浏览器把连点误判成双击缩放 */
button,
.tab,
.pill,
.amount-item,
.history-item,
.switch {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* hidden 属性必须永远有效。
   元素自己声明了 display:flex/block 之后，会把 [hidden] 的默认 display:none 覆盖掉，
   结果就是「JS 设了 hidden，元素照样显示」—— 姓名卦象那块的标题就这么漏出来的。 */
[hidden] {
  display: none !important;
}

/* --- 应用外壳 ---
   不再锁死 390×812。宽高都跟屏幕走：
     · 宽：最多 430，两侧各留 16px 呼吸位
     · 高：最多 896（完整机型比例），但永远不超过视口
   这样从 320 的小手机到 4K 大屏都是同一套代码，不需要 JS 算缩放。 */
.phone {
  width: min(430px, calc(100vw - 32px));
  height: min(896px, calc(100vh - 32px));
  height: min(896px, calc(100dvh - 32px));
  background: var(--cream);
  border-radius: clamp(22px, 3.4vw, 42px);
  box-shadow:
    0 0 0 1px var(--line-mid),
    0 2px 0 0 rgba(255, 255, 255, .8) inset,
    var(--sh3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* 侧边说明已移除：它是开发者备注，在窄窗口会压到手机框上。
   预览就要干干净净，别让人分不清哪块是设计、哪块是注释。 */

/* ============================================================
   状态栏 / 导航栏
   ============================================================ */

.statusbar {
  flex: 0 0 auto;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.statusbar-icons {
  display: flex;
  align-items: center;
  color: var(--ink);
}

.navbar {
  flex: 0 0 auto;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0 16px;
}

.navbar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .1em;
}

.navbar-back {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--ink-2);
  border-radius: var(--r-full);
  transition: background var(--dur-fast) ease-out;
}

.navbar-back:hover {
  background: var(--cinnabar-ghost);
}

.navbar-back[hidden] {
  display: none;
}

/* ============================================================
   屏幕容器
   ============================================================ */

.screens {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 20px 32px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition:
    opacity var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out),
    visibility 0s linear var(--dur-base);
  scrollbar-width: none;
}

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

.screen.is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out),
    visibility 0s;
}

/* ============================================================
   底部 Tab Bar
   ============================================================ */

.tabbar {
  flex: 0 0 auto;
  height: 64px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  background: rgba(255, 252, 245, .92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
  padding-bottom: 4px;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  letter-spacing: .1em;
  color: var(--ink-3);
  min-height: 44px;
  transition: color var(--dur-fast) ease-out;
}

.tab svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.is-active {
  color: var(--cinnabar);
}

.tab.is-active svg {
  stroke-width: 2.1;
}

/* ============================================================
   入场编排：一个序列，不是一堆零散微交互
   ============================================================ */

.reveal {
  opacity: 0;
  transform: translateY(20px);
}

.is-active .reveal {
  animation: reveal-up var(--dur-slow) var(--ease-out) forwards;
}

.is-active .reveal:nth-child(1) { animation-delay: 40ms; }
.is-active .reveal:nth-child(2) { animation-delay: 110ms; }
.is-active .reveal:nth-child(3) { animation-delay: 180ms; }
.is-active .reveal:nth-child(4) { animation-delay: 250ms; }
.is-active .reveal:nth-child(5) { animation-delay: 320ms; }
.is-active .reveal:nth-child(6) { animation-delay: 390ms; }
.is-active .reveal:nth-child(7) { animation-delay: 460ms; }
.is-active .reveal:nth-child(8) { animation-delay: 530ms; }

@keyframes reveal-up {
  to {
    opacity: 1;
    transform: none;
  }
}

/* --- 降级：所有动效在用户要求减少动效时关闭 --- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }
}

/* ============================================================
   窄屏：去掉手机壳，直接全屏（真机行为）
   ============================================================ */

/* ============================================================
   真机模式：≤520px 直接铺满，不画外壳
   ============================================================ */

@media (max-width: 520px) {
  .stage {
    padding: 0;
    align-items: stretch;
  }

  .phone {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }

  .statusbar {
    height: env(safe-area-inset-top, 28px);
    padding-top: 6px;
  }
}
