/* ==========================================================================
   基础样式：重置、排版、纸感底纹、无障碍基线
   ========================================================================== */

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

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

body,
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd,
ul,
ol {
  margin: 0;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  color: var(--text-body);
  background-color: var(--bg-base);
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--dur-base) var(--ease-out),
    color var(--dur-base) var(--ease-out);
}

h1,
h2,
h3,
h4 {
  color: var(--text-strong);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
}

h1 {
  font-size: var(--fs-h1);
}

h2 {
  font-size: var(--fs-h2);
}

h3 {
  font-size: var(--fs-h3);
}

p {
  line-height: var(--lh-normal);
}

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

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

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

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

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

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

button:disabled {
  cursor: not-allowed;
}

/* v1.7.26：占位文案统一走 --text-muted —— 浏览器默认的 ::placeholder 是半透明灰，
   在深色主题下几乎不可读（且各浏览器不一致）。占位文案承担「输入什么」的引导，
   必须可读，故不使用最弱的 --text-faint。 */
::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

/* ---------- 图标基线（内联 SVG 统一由 icons.js 生成） ----------
   尺寸由 SVG 自身的 width/height 属性决定，便于按上下文单独调整；
   此处只负责不可压缩与描边基线。 */
.icon {
  flex: 0 0 auto;
  stroke-width: 1.6;
}

/* ---------- 焦点可见 ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ---------- 选区 ---------- */
::selection {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* ---------- 滚动条 ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--hairline-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--hairline-strong);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: content-box;
}

/* ---------- 工具类 ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 跳转到主内容（键盘可见） */
.skip-link {
  position: absolute;
  top: var(--sp-2);
  left: var(--sp-2);
  z-index: 200;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--accent-contrast);
  background: var(--accent);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  transform: translateY(-200%);
  transition: transform var(--dur-fast) var(--ease-out);
}

.skip-link:focus-visible {
  transform: translateY(0);
  color: var(--accent-contrast);
}

/* 元信息标签：小号、大写、微拉字距 */
.meta-label {
  /* v1.7.32：去 mono。这个类实际装的是「工具集」「方言」「预设」这类中文标签，
     mono 对中文只能回退，字距被 --tracking-label 的 .12em 拉到可疑；英文 slug 仍靠
     text-transform 大写维持元信息感。 */
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* 细分割线 */
.rule {
  height: 1px;
  border: 0;
  background: var(--hairline);
}

/* noscript 提示 */
.no-script {
  margin: var(--sp-6);
  padding: var(--sp-5);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--warn);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  color: var(--text-body);
  box-shadow: var(--shadow-1);
}

/* ---------- 减弱动效 ---------- */
@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;
  }

  body {
    background-attachment: scroll;
  }
}

/* ---------- 系统高对比度模式（forced-colors，v1.7.27） ---------- */
/* 该模式下浏览器会**强制替换**背景与文字色，凡是「只靠底色深浅」表达的信息
   （当前项、选中态、待确认态、面板边界）都会一起消失。这里统一补形状线索：
   状态 → 高亮描边，容器 → CanvasText 边框，控件 → ButtonBorder。
   注意：本模式会丢弃 box-shadow，所以边界一律用 border / outline，不用阴影。 */
@media (forced-colors: active) {
  .panel,
  .tool-card,
  .notice,
  .empty,
  .tabpanel,
  .td-topbar {
    border: 1px solid CanvasText;
  }

  .btn,
  .icon-btn,
  .input,
  .select,
  .textarea,
  .td-nav-btn,
  .td-toggle-btn,
  .tab__close,
  .tab__menu {
    border-color: ButtonBorder;
  }

  /* 当前项 / 选中 / 待确认：补高亮描边，不再依赖底色差 */
  .tab.is-active,
  .tab.is-armed,
  [aria-pressed="true"],
  [aria-selected="true"],
  [aria-expanded="true"] {
    outline: 1px solid Highlight;
    outline-offset: -2px;
  }

  /* 焦点环放在状态描边之后，保证聚焦时一定比状态环更明显 */
  :focus-visible {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }

  .btn:disabled,
  .icon-btn:disabled {
    color: GrayText;
    border-color: GrayText;
  }
}
