/* ============================================================================
   base.css —「WEB 前端开发基础 · 期末复习」
   职责：reset 补充 + 排版基线 + 链接 / 焦点 / 跳过链接 + 动效基线 + 小工具类。
   不含任何组件外观（组件在 components.css），不含布局（在 layout.css）。
   所有颜色 / 间距 / 字号一律引用 tokens.css 的语义 token，禁止写死。
   ============================================================================ */

/* ---------------------------------------------------------------------------
   1. 根元素与文档
   --------------------------------------------------------------------------- */

:root {
  /* 由 ui.js 在锁定滚动时写入实际滚动条宽度，避免页面横向跳动（UI-SPEC §6.6）*/
  --scrollbar-comp: 0px;
}

html {
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

body {
  overflow-wrap: break-word;
  text-rendering: optimizeLegibility;
}

/* 滚动锁：Modal / Drawer 打开时由 ui.js 挂到 body 上 */
body.is-locked {
  overflow: hidden;
  padding-right: var(--scrollbar-comp);
}

/* 隐藏属性永远优先于任何 display 声明 */
[hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------------------
   2. 排版基线
   --------------------------------------------------------------------------- */

h1 {
  font-size: var(--text-3xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  font-weight: var(--weight-semibold);
}

h2 {
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  font-weight: var(--weight-semibold);
}

h3 {
  font-size: var(--text-xl);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  font-weight: var(--weight-semibold);
}

h4 {
  font-size: var(--text-lg);
  line-height: var(--leading-normal);
  font-weight: var(--weight-medium);
}

h5,
h6 {
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  font-weight: var(--weight-medium);
}

p {
  line-height: var(--leading-relaxed);
}

small {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

strong,
b {
  font-weight: var(--weight-medium);
  color: var(--color-text-primary);
}

/* 行内代码：Markdown 渲染器与正文都用这一个外观 */
code {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  background-color: var(--color-bg-inset);
  color: var(--color-text-primary);
  overflow-wrap: anywhere;
}

pre code {
  padding: 0;
  background: none;
  font-size: inherit;
  overflow-wrap: normal;
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.35em;
  border: var(--border-width) solid var(--color-border-control);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background-color: var(--color-surface);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
  text-align: center;
  color: var(--color-text-secondary);
}

hr {
  height: 0;
  margin: var(--space-6) 0;
  border: 0;
  border-top: var(--border-width) solid var(--color-border);
}

blockquote {
  margin: 0;
  padding-left: var(--space-4);
  border-left: var(--border-width-strong) solid var(--color-border-strong);
  color: var(--color-text-secondary);
}

/* 长文（精讲、解析）：40em ≈ 40 汉字/行（UI-SPEC §3.5）*/
.prose {
  max-width: 40em;
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  color: var(--color-text-primary);
}

.prose > * + * {
  margin-top: var(--space-4);
}

.prose ul,
.prose ol {
  padding-left: var(--space-6);
  list-style: disc;
}

.prose ol {
  list-style: decimal;
}

.prose li + li {
  margin-top: var(--space-2);
}

/* ---------------------------------------------------------------------------
   3. 链接
   --------------------------------------------------------------------------- */

a {
  color: var(--color-accent-text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  border-radius: var(--radius-xs);
}

a:hover {
  color: var(--color-accent-hover);
}

/* 整卡链接 / 非下划线链接 */
a.is-plain {
  color: inherit;
  text-decoration: none;
}

/* ---------------------------------------------------------------------------
   4. 焦点（UI-SPEC §7.0：唯一的焦点环写法在 tokens.css，这里只补例外）
   --------------------------------------------------------------------------- */

/* 程序化聚焦的容器（页面标题、main）不画环：它们不是可操作元素 */
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible {
  outline: none;
}

/* 会被 overflow: hidden 裁掉的容器（选项行、Tabs 内元素）改用内阴影环 */
.focus-inset:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 var(--border-width-strong) var(--color-focus-ring);
}

/* 焦点不被粘性头部遮住（QR: focus-not-obscured）*/
:focus-visible {
  scroll-margin-block: calc(var(--layout-header-h) + var(--space-4));
}

/* ---------------------------------------------------------------------------
   5. 跳过链接（skip link）
   --------------------------------------------------------------------------- */

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-tooltip);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background-color: var(--color-accent);
  color: var(--color-accent-fg);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform var(--dur-2) var(--ease-out);
}

.skip-link:focus-visible {
  transform: translateY(0);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
   6. 动效基线
   --------------------------------------------------------------------------- */

/* 只在 transform / opacity 上做过渡；颜色过渡由各组件自己声明，避免互相覆盖 */
@media (prefers-reduced-motion: no-preference) {
  .page > * {
    animation: page-enter var(--dur-3) var(--ease-out) both;
  }
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* 只显示一次的辅助动画：颜色与位移一律瞬时完成（tokens.css 已有全局降级，
   这里额外保证动画元素本身仍然可见）*/
@media (prefers-reduced-motion: reduce) {
  .page > * {
    animation: none !important;
  }
}

/* ---------------------------------------------------------------------------
   7. 小工具类（供页面与后续工人复用，不新增视觉语言）
   --------------------------------------------------------------------------- */

.muted {
  color: var(--color-text-secondary);
}

.tertiary {
  color: var(--color-text-tertiary);
  font-size: var(--text-sm);
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clamp-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack--tight {
  gap: var(--space-2);
}

.stack--loose {
  gap: var(--space-8);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.row--between {
  justify-content: space-between;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

.empty-line {
  min-height: 1px;
}
