/* ============================================================================
   base.css — 重置、应用外壳、无障碍基线
   ========================================================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  font-size: var(--fs-body-l);
  line-height: var(--lh-body-l);
  font-weight: var(--fw-regular);
  color: var(--c-on-surface);
  background: var(--c-surface-dim);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Android 触感：去掉点击高亮与 300ms 延迟，改由自定义涟漪反馈 */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--c-primary); }

svg { display: block; flex: none; }

/* ---------- 焦点环：只在键盘导航时出现 ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: var(--shape-xs);
}

/* ---------- 应用外壳 ----------
   Compact（默认）：铺满屏幕，底部导航栏 —— 手机形态。
   Medium：居中"设备画布" —— 平板竖屏或窄桌面窗口，铺满会显得空旷。
   Expanded：铺满窗口 + 左侧 Navigation Rail —— 真正的桌面形态。 */
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-inline: auto;
  height: 100vh;
  height: 100dvh;
  background: var(--c-surface);
  position: relative;
  overflow: hidden;
}

@supports (height: 100dvh) { .app { height: 100dvh; } }

/* Medium —— 居中画布 */
@media (min-width: 600px) and (max-width: 839px) {
  body { background: var(--c-surface-dim); }
  .app {
    max-width: var(--app-medium);
    height: min(100dvh, 980px);
    margin-block: max(0px, calc((100dvh - 980px) / 2));
    border-radius: var(--shape-l);
    box-shadow: var(--elev-2);
  }
}

/* Expanded —— 桌面：横向布局，导航栏跑到左侧变成 Rail */
@media (min-width: 840px) {
  body { background: var(--c-surface); }
  .app {
    flex-direction: row;
    max-width: none;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
  .navbar { order: -1; }
}

/* 顶部安全区（刘海屏与状态栏）—— 桌面无刘海，env() 取 0 */
.app { padding-top: env(safe-area-inset-top, 0); }
@media (min-width: 840px) { .app { padding-top: 0; } }

/* ---------- 视图容器 ---------- */
.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.view__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  .view__body { scroll-behavior: auto; }
}

/* ---------- 屏幕阅读器专用 ---------- */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- 文本工具类 ---------- */
.t-display   { font-size: var(--fs-display);  line-height: var(--lh-display);  font-weight: var(--fw-regular); letter-spacing: -0.02em; }
.t-headline  { font-size: var(--fs-headline); line-height: var(--lh-headline); font-weight: var(--fw-regular); }
.t-title-l   { font-size: var(--fs-title-l);  line-height: var(--lh-title-l);  font-weight: var(--fw-regular); }
.t-title-m   { font-size: var(--fs-title-m);  line-height: var(--lh-title-m);  font-weight: var(--fw-medium); }
.t-title-s   { font-size: var(--fs-title-s);  line-height: var(--lh-title-s);  font-weight: var(--fw-medium); }
.t-body-l    { font-size: var(--fs-body-l);   line-height: var(--lh-body-l); }
.t-body-m    { font-size: var(--fs-body-m);   line-height: var(--lh-body-m); }
.t-body-s    { font-size: var(--fs-body-s);   line-height: var(--lh-body-s); }
.t-label-l   { font-size: var(--fs-label-l);  line-height: var(--lh-label-l);  font-weight: var(--fw-medium); }
.t-label-m   { font-size: var(--fs-label-m);  line-height: var(--lh-label-m);  font-weight: var(--fw-medium); }
.t-label-s   { font-size: var(--fs-label-s);  line-height: var(--lh-label-s);  font-weight: var(--fw-medium); letter-spacing: var(--tracking-label); }

.t-muted   { color: var(--c-on-surface-variant); }
.t-primary { color: var(--c-primary); }
.t-correct { color: var(--c-correct); }
.t-wrong   { color: var(--c-wrong); }
.t-num     { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.t-balance { text-wrap: balance; }
.t-pretty  { text-wrap: pretty; }

/* ---------- 减少动态效果 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
