/* ==========================================================================
   kbapp · Base — reset / 4px 网格 / 排版 / 布局变量 / 焦点 / 降噪
   仅用 var(--token)，零硬编码颜色。
   ========================================================================== */

/* ---- Reset ---- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-family: var(--font-body);
  /* 默认字号跟随 UI 基准；正文用 --text-base */
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* 暗色主题跟随系统：当未显式设定 data-theme 时，由 no-flash 脚本写入。
   此处仅兜底——若 html 无 data-theme 且系统为暗色，:root 仍是亮色，
   所以主题判定完全交给 theme.js 内联脚本（见 layout / token_entry / error 的 head）。 */

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-read);
  color: var(--fg);
  background: var(--bg);
  min-height: 100dvh;
  line-height: 1.5;
}

/* ---- 排版基元 ---- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--weight-display);
  color: var(--fg);
  line-height: 1.25;
  letter-spacing: -0.01em;
}
h1 { font-size: var(--text-2xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); font-weight: var(--weight-emphasis); }

p {
  font-size: var(--text-base);
  color: var(--fg-2);
  line-height: 1.7;
}

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

small { font-size: var(--text-xs); }

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

/* 阅读体（笔记 / 名言正文，详情页用）*/
.reading {
  font-family: var(--font-reading);
  font-size: var(--text-md);
  line-height: 1.8;
  color: var(--fg);
  letter-spacing: 0;
}

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

/* 元信息 / 时间戳：三级灰 + 等宽 */
.meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--meta);
  letter-spacing: 0.01em;
}

/* 小字（≤13px）轻微字距，提升可读性 */
.text-xs, .text-sm {
  letter-spacing: 0.01em;
}

/* 眉标 / ALL CAPS：宽字距 */
.eyebrow {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: var(--weight-emphasis);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---- 布局变量 ---- */
:root {
  --layout-sidebar: 240px;
  --layout-rail: 248px;
  --layout-content-max: 760px;   /* 阅读栏内容最大宽 */
  --layout-gap: var(--space-6);
}

/* 应用骨架栅格：侧栏 | 主区 | 右 Rail */
.app-shell {
  display: grid;
  grid-template-columns: var(--layout-sidebar) minmax(0, 1fr) var(--layout-rail);
  min-height: 100dvh;
}

/* 主区内容居中限宽 */
.main {
  min-width: 0;
  padding: var(--space-8) var(--space-10);
  background: var(--bg);
}
.main__inner {
  max-width: 1040px;
  margin: 0 auto;
}

/* 右 Rail */
.rail {
  border-left: 1px solid var(--border);
  background: var(--bg);
  padding: var(--space-6) var(--space-5);
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  overflow-y: auto;
}

/* ---- 焦点可达性：2px 松墨绿环，offset 2px ---- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* 输入框聚焦环：不破坏圆角 */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* 去除非键盘焦点描边（鼠标点击不显示环）*/
:focus:not(:focus-visible) {
  outline: none;
}

/* ---- 选区：松墨绿下划线高亮 ---- */
::selection {
  background: var(--accent-soft);
  color: var(--fg);
}

/* ---- 滚动条：克制，跟随中性 ---- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-pill);
  border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---- 图片：统一圆角 + 中性边框，禁用宽高溢出 ---- */
img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-md);
}

button { font-family: inherit; }

/* ---- 表面深度：边框 OR 阴影二选一，不叠加（组件层约定）---- */

/* ---- 尊重 prefers-reduced-motion：降级为即时 / 无 transform ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .app-shell,
  .entry-row,
  .topic-node,
  .toast {
    transform: none !important;
  }
}

/* ---- 响应式：断点 768 / 1280 ---- */
@media (max-width: 1280px) {
  .app-shell {
    grid-template-columns: var(--layout-sidebar) minmax(0, 1fr);
  }
  .rail { display: none; }
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .main { padding: var(--space-4) var(--space-3); }
  .main__inner { max-width: 100%; }
}
