/* ==========================================================================
   SGTool · 基础层：重置与排版
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;

  /* 永远为滚动条保留槽位。否则有滚动条的页面可用宽度会少一个滚动条，
     容器居中后与没有滚动条的页面相差约 8px，切页时内容会左右跳动。 */
  scrollbar-gutter: stable;
}

body {
  display: flex;
  flex-direction: column;

  /* 让 .site-main 的 flex:1 有可分配的剩余空间，页脚才能贴住底部。
     100dvh 是移动端的动态视口高度，避免地址栏造成跳动。 */
  min-height: 100vh;
  min-height: 100dvh;

  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  line-height: var(--leading-tight);
}

p {
  margin: 0;
}

ul, ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* 主题切换期间关闭全部过渡。
   各组件的颜色过渡时长不同（例如一言的背景 400ms、文字 220ms），
   不同步会让中途出现文字色与底色对不上的瞬间，看起来像闪一下。
   切换本身是一步到位的整体变化，瞬间完成更干净。
   类由 theme.js 在切换时加上，两帧后移除。 */
html.is-theme-switching,
html.is-theme-switching *,
html.is-theme-switching *::before,
html.is-theme-switching *::after {
  transition: none !important;
}

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

/* hidden 属性必须始终生效：组件里给元素设了 display 会覆盖它的默认行为 */
[hidden] {
  display: none !important;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

code, pre, kbd {
  font-family: var(--font-mono);
}

code {
  padding: 1px 5px;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-muted);
  font-size: .92em;
}

hr {
  height: var(--border-width);
  margin: var(--space-5) 0;
  border: 0;
  background: var(--color-border);
}

/* 键盘可达性 */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* 跳转链接：仅键盘聚焦时出现 */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-text-invert);
  font-size: var(--text-sm);
}

.skip-link:focus {
  top: 0;
  text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
