/* ─────────────────────────────────────────────────────────────
   base.css · reset、排版、应用外壳布局、页面级工具类
   只引用 tokens.css 的变量；这里新增的变量全是“由令牌派生”的角色变量。
   ───────────────────────────────────────────────────────────── */

/* ── 派生角色变量 ──
   --on / --fill / --fill-hover 描述“我现在站在什么底上”：页面、卡片、内嵌块各设一遍，
   组件（chip、输入框、分段轨道、进度条的缝…）只认这三个，放到哪层都自动取对颜色。 */
:root {
  --on: var(--bg);
  --fill: var(--surface);
  --fill-hover: var(--surface-2);
  --raised: var(--surface); /* 分段控件拇指这类“浮起来的小块” */

  --stagger-step: calc(var(--dur-1) / 3); /* 40ms 级联 */
  --z-nav: 40;
  --z-fab: 45;
  --z-sheet: 100;
  --z-toast: 200;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --raised: var(--surface-3);
  }
}
:root[data-theme="dark"] {
  --raised: var(--surface-3);
}
@media (min-width: 720px) {
  :root {
    --gutter: var(--s-6);
  }
}
@media (min-width: 1024px) {
  :root {
    --gutter: var(--s-7);
  }
}

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
}
* {
  margin: 0;
}
[hidden] {
  display: none !important;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scrollbar-gutter: stable;
  background: var(--bg);
}
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  /* 中文字面占满字框、Inter 的数字偏高：1.5 行高下两者的视觉中线才对得齐 */
  line-height: var(--lh-body);
  letter-spacing: var(--track-body);
  font-feature-settings: var(--font-features);
  font-optical-sizing: auto;
  font-kerning: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* 中英/中数之间自动留缝（支持的浏览器生效），不用手敲空格 */
  text-autospace: normal;
  line-break: strict;
  overflow-wrap: anywhere;
}
h1,
h2,
h3,
h4 {
  font-size: inherit;
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
  letter-spacing: var(--track-title);
  text-wrap: balance;
}
p {
  text-wrap: pretty;
}
a {
  color: inherit;
  text-decoration: none;
}
button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
}
img,
svg {
  display: block;
  max-width: 100%;
}
svg.icon {
  flex: none;
}
ul,
ol {
  padding: 0;
  list-style: none;
}
table {
  border-collapse: collapse;
}

::selection {
  background: var(--accent-soft-2);
  color: var(--ink);
}

/* 焦点环：只在键盘导航时出现；透明 outline 留给 Windows 高对比度模式 */
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

/* 滚动条：细、退后 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  background-clip: content-box;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ── 应用外壳 ── */
.skip-link {
  position: fixed;
  top: var(--s-2);
  left: var(--s-2);
  z-index: var(--z-toast);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: var(--fw-semibold);
  transform: translateY(-200%);
}
.skip-link:focus-visible {
  transform: none;
}

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: var(--hero-glow), var(--bg);
}
.boot__mark {
  width: 64px;
  height: 64px;
  animation: boot-breathe calc(var(--dur-4) * 2) var(--ease-in-out) infinite alternate;
}
@keyframes boot-breathe {
  from {
    opacity: 0.55;
    transform: scale(0.96);
  }
}

.app {
  position: relative;
  isolation: isolate;
  min-height: 100dvh;
}
/* 页面顶部那团光晕：只有带 .hero 的页面点亮，其余页面保持纯底色。
   铺在整个 .app 上（含侧栏背后），桌面端侧栏和内容区之间才不会切出一条竖缝。 */
.app::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  z-index: -1;
  height: 460px;
  background: var(--hero-glow);
  opacity: 0;
  transition: opacity var(--dur-4) var(--ease-out);
  pointer-events: none;
}
.app:has(.hero)::before {
  opacity: 1;
}
.sidebar {
  display: none;
}
.app__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  /* 与 .page 的内容左右缘对齐：窄屏取 gutter，宽屏取居中后的偏移 */
  padding-inline: max(var(--gutter), env(safe-area-inset-left), calc((100% - var(--page-max)) / 2 + var(--gutter)))
    max(var(--gutter), env(safe-area-inset-right), calc((100% - var(--page-max)) / 2 + var(--gutter)));
  transition: background-color var(--dur-2) var(--ease-out);
}
/* 毛玻璃只在内容滚到顶栏下面时才出现；停在页顶时保持透明，光晕才不会被切出一条缝 */
.app[data-scrolled] .topbar {
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(20px);
  backdrop-filter: saturate(1.6) blur(20px);
}
.topbar__title {
  font-size: var(--fs-title-2);
  font-weight: var(--fw-bold);
  white-space: nowrap;
}
.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

.page {
  flex: 1;
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding: var(--s-2) max(var(--gutter), env(safe-area-inset-right)) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s-8))
    max(var(--gutter), env(safe-area-inset-left));
}
.page:focus-visible {
  box-shadow: none;
}
.view {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-width: 0;
}

.tabbar {
  position: fixed;
  inset: auto 0 0;
  z-index: var(--z-nav);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 max(var(--s-2), env(safe-area-inset-right)) env(safe-area-inset-bottom) max(var(--s-2), env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(20px);
  backdrop-filter: saturate(1.6) blur(20px);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  border-radius: var(--r-md);
  color: var(--ink-2);
  font-size: var(--fs-micro);
  font-weight: var(--fw-semibold);
  line-height: 1;
  transition: color var(--dur-2) var(--ease-out);
  user-select: none;
}
.tab__icon {
  transition: transform var(--dur-2) var(--ease-spring);
}
.tab:active .tab__icon {
  transform: scale(0.88);
}
.tab[aria-current="page"] {
  color: var(--accent-text);
}
.tab:focus-visible {
  box-shadow: inset var(--focus-ring);
}

/* ── 桌面：左侧栏 + 居中内容 ── */
@media (min-width: 1024px) {
  .app {
    display: grid;
    grid-template-columns: var(--nav-w) minmax(0, 1fr);
  }
  .tabbar,
  .topbar__settings {
    display: none;
  }
  .sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    padding: var(--s-6) var(--s-4) var(--s-5);
    overflow-y: auto;
  }
  .brand {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: var(--s-3);
    padding: var(--s-1) var(--s-3);
    border-radius: var(--r-md);
  }
  .brand__mark {
    width: 32px;
    height: 32px;
  }
  .brand__name {
    font-size: var(--fs-title-2);
    font-weight: var(--fw-heavy);
    letter-spacing: var(--track-title);
  }
  .sidebar__cta {
    margin: var(--s-6) 0 var(--s-5);
  }
  .sidebar__nav,
  .sidebar__foot {
    display: flex;
    flex-direction: column;
    gap: var(--s-1);
  }
  .sidebar__foot {
    margin-top: auto;
    padding-top: var(--s-5);
    gap: var(--s-3);
  }
  .nav-item {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    min-height: var(--hit);
    padding: 0 var(--s-4) 0 var(--s-3);
    border-radius: var(--r-pill);
    color: var(--ink-2);
    font-weight: var(--fw-semibold);
    transition:
      background-color var(--dur-2) var(--ease-out),
      color var(--dur-2) var(--ease-out);
  }
  .nav-item:hover {
    background: var(--fill);
    color: var(--ink);
  }
  .nav-item:active {
    transform: scale(0.98);
  }
  .nav-item[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--accent-text);
  }

  .topbar {
    height: calc(var(--topbar-h) + var(--s-5));
  }
  .topbar__title {
    font-size: var(--fs-title-1);
  }
  .page {
    padding-top: var(--s-3);
    padding-bottom: var(--s-10);
  }
  .view {
    gap: var(--s-6);
  }
}

/* ── Hero ──
   手机：直接坐在页面底色上、居中，光晕来自页面顶部；
   桌面：一张 --r-xl 大卡、内容左对齐（Revolut 网页版的账户头部就是这个排法）。 */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-5) 0 var(--s-4);
  text-align: center;
}
.hero__label {
  color: var(--ink-2);
  font-size: var(--fs-sub);
  font-weight: var(--fw-semibold);
}
.hero__meta {
  color: var(--ink-2);
  font-size: var(--fs-sub);
  font-variant-numeric: tabular-nums;
}
.hero__block {
  width: 100%;
  margin-top: var(--s-4);
}
@media (min-width: 1024px) {
  .hero {
    --on: var(--surface);
    --fill: var(--surface-2);
    --fill-hover: var(--surface-3);
    align-items: flex-start;
    padding: var(--s-7);
    border-radius: var(--r-xl);
    background: var(--hero-glow), var(--surface);
    box-shadow: var(--shadow-card);
    text-align: left;
  }
}

/* ── 布局工具 ── */
.layout-2col {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-4);
  align-items: start;
}
.col-main,
.col-side {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-width: 0;
}
/* 1024–1180 之间侧栏已经占了 244px，主列会被挤到不足 400px，所以双列从 1180 起 */
@media (min-width: 1180px) {
  .layout-2col {
    grid-template-columns: minmax(0, 1fr) var(--col-side);
    gap: var(--s-6);
  }
  .col-main,
  .col-side {
    gap: var(--s-6);
  }
}
.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-4);
}
@media (min-width: 720px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap, var(--s-4));
  min-width: 0;
}
.stack--tight {
  --stack-gap: var(--s-2);
}
.stack--loose {
  --stack-gap: var(--s-6);
}
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}
.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-width: 0;
}

/* ── 文字工具 ── */
.t-title-1 {
  font-size: var(--fs-title-1);
  font-weight: var(--fw-bold);
  line-height: var(--lh-snug);
  letter-spacing: var(--track-title);
}
.t-title-2 {
  font-size: var(--fs-title-2);
  font-weight: var(--fw-bold);
  line-height: var(--lh-snug);
  letter-spacing: var(--track-title);
}
.t-title-3 {
  font-size: var(--fs-title-3);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
}
.t-body {
  font-size: var(--fs-body);
}
.t-sub {
  font-size: var(--fs-sub);
}
.t-cap {
  font-size: var(--fs-cap);
}
.t-micro {
  font-size: var(--fs-micro);
}
.t-strong {
  font-weight: var(--fw-semibold);
}
.muted {
  color: var(--ink-2);
}
.faint {
  color: var(--ink-3);
}
.num {
  font-variant-numeric: tabular-nums;
}
.nowrap {
  white-space: nowrap;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.noscript {
  padding: var(--s-8) var(--gutter);
  text-align: center;
}

/* ── 进场：12px 上浮淡入，40ms 级联 ──
   路由只在视图刚挂载的那一小段时间给容器加 .stagger，之后数据变化引起的重绘不会再闪一遍。
   fill-mode 用 backwards：播完就彻底放手，不给 position:fixed 的子元素（FAB）留下 transform 包含块。 */
.stagger > * {
  animation: rise var(--dur-4) var(--ease-out) backwards;
  animation-delay: calc(var(--stagger-i, 8) * var(--stagger-step));
}
.stagger > :nth-child(1) {
  --stagger-i: 0;
}
.stagger > :nth-child(2) {
  --stagger-i: 1;
}
.stagger > :nth-child(3) {
  --stagger-i: 2;
}
.stagger > :nth-child(4) {
  --stagger-i: 3;
}
.stagger > :nth-child(5) {
  --stagger-i: 4;
}
.stagger > :nth-child(6) {
  --stagger-i: 5;
}
.stagger > :nth-child(7) {
  --stagger-i: 6;
}
.stagger > :nth-child(8) {
  --stagger-i: 7;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes fade-out {
  to {
    opacity: 0;
  }
}
@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}
@keyframes breathe {
  from {
    opacity: 0.35;
  }
}

/* sheet 打开时锁住背景滚动 */
html.has-sheet,
html.has-sheet body {
  overflow: hidden;
}

/* ── 减少动效 ──
   令牌已把时长压到 1ms；这里再兜住 delay 与无限循环动画。
   唯一的例外是加载指示：改成缓慢的明暗呼吸（时长只能写死，因为令牌此时都是 1ms）。 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-delay: 0ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .spinner,
  .boot__mark {
    animation: breathe 1.4s ease-in-out infinite alternate !important;
  }
}
