/* ============================================================
   汉字字体技术科普 · 古风知识门户
   暖纸墨色 · 柔和圆角 · 无统计卡片
   ============================================================ */
:root {
  --bg: #fbf6ed;
  --surface: #fffdf7;
  --surface2: #fef9f0;
  --text: #3d3226;
  --text2: #6b5e52;
  --text3: #7a6e5e;
  --border: #e5dbcc;
  --border-light: #f0e8da;
  --accent: #b56341;
  --accent-light: #fdf0e8;
  --accent2: #7a8b6f;
  --accent2-light: #f2f5ef;

  --sidebar-w: 220px;
  --topbar-h: 52px;
  --radius: 16px;
  --radius-sm: 10px;

  --sans: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --serif: "Noto Serif SC", "Songti SC", "SimSun", "KaiTi", serif;
  --mono: "IBM Plex Mono", "SF Mono", "Fira Code", "Consolas", monospace;
  --sans-zh: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --ink: #3d3226;
  --ink-rgb: 61,50,38;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* 语义标题继承卡片排版，不使用浏览器默认字号/间距 */
h1, h2, h3, h4 { font-size: inherit; font-weight: inherit; margin: 0; }
html { scroll-behavior: smooth; background: transparent; }
body {
  font-family: var(--sans); font-size: 15px; line-height: 1.8;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   WEBGL BACKGROUND CANVASES
   ============================================================ */
.bg-canvas {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: -1;
}
.bg-canvas--dark  { opacity: 0.06; mix-blend-mode: multiply; }
.bg-canvas--light { opacity: 0.12; mix-blend-mode: screen; }

/* ============================================================
   TOPBAR · 温润顶栏
   ============================================================ */
.app-topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: rgba(251,246,237,0.9); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border); z-index: 200;
  display: flex; align-items: center; padding: 0 24px; gap: 18px;
}
/* 阅读进度条 */
.progress-bar {
  position: absolute; bottom: 0; left: 0; right: 0; height: 2px;
  background: transparent;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #c4845a);
  transition: width 0.15s linear;
}
.topbar-brand {
  font-family: var(--serif); font-weight: 700; font-size: 0.95rem;
  color: var(--text); white-space: nowrap; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
}
.topbar-brand .brand-seal {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--accent); color: #fff;
  font-family: var(--serif); font-weight: 700; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
}
/* 汉堡菜单按钮（仅移动端可见） */
.nav-toggle {
  display: none; flex-shrink: 0;
  width: 38px; height: 38px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); cursor: pointer;
  flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: background 0.2s, border-color 0.2s; -webkit-tap-highlight-color: transparent;
}
.nav-toggle span {
  display: block; width: 17px; height: 2px; border-radius: 2px;
  background: var(--text2); transition: transform 0.3s, opacity 0.2s;
}
.nav-toggle:hover { background: var(--accent-light); border-color: var(--accent); }
.nav-toggle:hover span { background: var(--accent); }
body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ============================================================
   SIDEBAR · 古韵侧栏
   ============================================================ */
.app-sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w); background: var(--surface);
  border-right: 1px solid var(--border); z-index: 100;
  overflow-y: auto; padding: 18px 10px;
}
.sidebar-section { margin-bottom: 18px; }
.sidebar-label {
  font-family: var(--serif); font-size: 0.68rem; font-weight: 600;
  color: var(--text3); padding: 6px 14px 4px; letter-spacing: 0.06em;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 14px; border-radius: 10px; font-size: 0.82rem;
  color: var(--text2); cursor: pointer; transition: all 0.2s;
  text-decoration: none; margin-bottom: 2px;
  font-family: var(--sans); text-align: left; border: none; background: transparent;
}
.sidebar-item:hover { background: var(--accent-light); color: var(--accent); }
.sidebar-item.active { background: var(--accent-light); color: var(--accent); font-weight: 500; }
.sidebar-item[aria-pressed="true"] { background: var(--accent2-light); color: var(--accent2); }
.sidebar-item .si-icon { font-size: 0.95rem; width: 20px; text-align: center; flex-shrink: 0; opacity: 0.7; }
.sidebar-item .si-count { margin-left: auto; font-size: 0.66rem; color: var(--text3); }

/* 移动端遮罩层 */
.sidebar-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(61,50,38,0.32); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
body.nav-open .sidebar-scrim { opacity: 1; pointer-events: auto; }

/* ============================================================
   MAIN
   ============================================================ */
.app-main { margin-left: var(--sidebar-w); padding-top: var(--topbar-h); min-height: 100vh; background: var(--bg); position: relative; z-index: 1; }
.main-inner { padding: 32px 28px 80px; max-width: 1200px; }

/* ============================================================
   BENTO GRID · 12 列
   ============================================================ */
.bento { display: grid; grid-template-columns: repeat(12, 1fr); gap: 18px; counter-reset: section; }
.bs-12 { grid-column: span 12; }
.bs-8  { grid-column: span 8; }
.bs-7  { grid-column: span 7; }
.bs-6  { grid-column: span 6; }
.bs-5  { grid-column: span 5; }
.bs-4  { grid-column: span 4; }
.bs-3  { grid-column: span 3; }

/* ============================================================
   WIDGET CARD · 温润卡片
   ============================================================ */
.widget {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 24px;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.widget:hover { box-shadow: 0 6px 28px rgba(61,50,38,0.07); border-color: #d8cebf; transform: translateY(-2px); }
.widget.lab-card:hover { border-color: var(--accent); }

/* 滚动渐入（仅位移+透明度，尊重省电模式） */
.reveal { opacity: 0; transform: translateY(16px); transition: opacity 0.6s cubic-bezier(0.22,1,0.36,1), transform 0.6s cubic-bezier(0.22,1,0.36,1); }
.reveal.revealed { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
  .widget:hover { transform: none; }
}
.widget-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.widget-title {
  font-family: var(--serif); font-weight: 600; font-size: 0.95rem; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.widget-title .wt-icon { font-size: 1rem; opacity: 0.6; }
.widget-badge {
  font-family: var(--serif); font-size: 0.64rem; padding: 3px 10px;
  border-radius: 12px; white-space: nowrap;
}
.widget-badge.warm  { background: var(--accent-light); color: var(--accent); }
.widget-badge.leaf  { background: var(--accent2-light); color: var(--accent2); }
.widget-badge.ink   { background: #f2ede5; color: #6b5e52; }
.widget-body { font-size: 0.86rem; color: var(--text2); line-height: 1.78; }
.widget-body p { margin-bottom: 0.7em; }
.widget-body p:last-child { margin-bottom: 0; }
/* 通栏卡片限制正文行宽，避免中文一行过长伤阅读（引用/hero 除外） */
.widget.bs-12:not(.quote-card):not(.hero-card) > .widget-body > p { max-width: 78ch; }

/* Quote widget */
.widget.quote-card {
  background: linear-gradient(135deg, #fef9f2, #fdf3e8);
  border-left: 3px solid var(--accent);
  padding: 24px 28px;
}
.widget.quote-card .widget-body p {
  font-family: var(--serif); font-size: 1.05rem; font-weight: 600;
  color: var(--accent); margin: 0; line-height: 1.6;
}
.widget.quote-card .widget-body .src {
  display: block; margin-top: 8px; font-family: var(--sans);
  font-size: 0.7rem; font-weight: 400; color: var(--text3);
}

/* Interactive widget */
.widget.lab-card {
  background: var(--surface2); border-style: dashed; border-color: #e5dbcc;
}

/* Feature widget */
.widget.feature-card {
  background: linear-gradient(160deg, #fefcf7 0%, #fdf6ed 100%);
}

/* Hero · 首屏入口卡片 */
.widget.hero-card {
  padding: 34px 34px 32px;
  background: linear-gradient(150deg, #fffdf8 0%, #fdf2e6 60%, #fbecdb 100%);
  border-color: #ecd9c4;
  position: relative; overflow: hidden;
}
.widget.hero-card::after {
  content: '字'; position: absolute; right: -18px; bottom: -46px;
  font-family: var(--serif); font-weight: 900; font-size: 12rem; line-height: 1;
  color: var(--accent); opacity: 0.05; pointer-events: none; user-select: none;
}
.widget.hero-card .widget-title { font-size: 1.15rem; }
.widget.hero-card .widget-body { position: relative; z-index: 1; }
@media (max-width: 680px) {
  .widget.hero-card { padding: 24px 18px; }
  .widget.hero-card::after { font-size: 8rem; bottom: -30px; }
}

/* ============================================================
   SECTION HEADER · 章节标题
   ============================================================ */
.section-head {
  grid-column: span 12;
  display: flex; align-items: center; gap: 14px;
  margin: 22px 0 2px; padding-top: 4px;
  counter-increment: section;
}
.section-head:first-of-type { margin-top: 6px; }
.sh-dot {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-weight: 700; font-size: 0.9rem;
  box-shadow: 0 3px 10px rgba(181,99,65,0.28);
}
.sh-dot::before { content: counter(section, decimal-leading-zero); }
.sh-title {
  font-family: var(--serif); font-weight: 700; font-size: 1.25rem; color: var(--text);
  letter-spacing: 0.03em; white-space: nowrap;
}
.section-head::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, var(--border), transparent);
}

/* ============================================================
   BLOCKQUOTE / IMG
   ============================================================ */
.widget blockquote {
  margin: 0.8em 0; padding: 12px 16px;
  border-left: 2px solid var(--accent);
  background: var(--accent-light);
  font-family: var(--serif); font-weight: 500; font-size: 0.84rem;
  line-height: 1.7; color: var(--text); border-radius: 0 8px 8px 0;
}
.widget blockquote .src {
  display: block; margin-top: 6px; font-size: 0.66rem;
  color: var(--text3); font-weight: 400;
}

.img-wrap { margin: 0.8em 0; }
.img-wrap img { max-width: 100%; height: auto; max-height: 260px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); }
.img-wrap figcaption { margin-top: 6px; font-size: 0.7rem; color: var(--text3); }
.widget.feature-card .img-wrap img { max-height: 240px; }

/* ============================================================
   INTERACTIVE
   ============================================================ */
.pixel-grid {
  display: grid; grid-template-columns: repeat(16, 1fr);
  width: 304px; border: 1px solid var(--border); margin: 0 auto;
  background: #fffefb; border-radius: 8px; overflow: hidden;
}
.pixel { width: 19px; height: 19px; background: #fdf9f2; border: 1px solid rgba(181,99,65,0.06); cursor: pointer; transition: background 0.1s; }
.pixel.active { background: var(--accent) !important; }
.pixel:hover { outline: 2px solid var(--accent); outline-offset: -1px; z-index: 1; position: relative; }
.pixel:focus-visible { outline: 2px solid var(--accent2); outline-offset: -1px; z-index: 2; position: relative; }
.pixel-ctrls { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.pixel-info { min-height: 2em; font-family: var(--mono); font-size: 0.55rem; color: var(--text3); text-align: center; word-break: break-all; max-width: 304px; margin-top: 6px; line-height: 1.5; }

.btn {
  font-family: var(--serif); font-size: 0.76rem; padding: 6px 14px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; border-radius: 20px; transition: all 0.25s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-sm { font-size: 0.68rem; padding: 4px 10px; }

input[type="range"] { width: 100%; -webkit-appearance: none; appearance: none; height: 4px; border-radius: 2px; background: var(--border); outline: none; cursor: pointer; accent-color: var(--accent); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 1px 4px rgba(181,99,65,0.35); transition: transform 0.15s; }
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: none; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 1px 4px rgba(181,99,65,0.35); }

.input-text { padding: 8px 12px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); font-family: var(--serif); font-size: 1.2rem; text-align: center; outline: none; width: 72px; transition: border-color 0.2s; }
.input-text:focus { border-color: var(--accent); }

canvas { display: block; margin: 0 auto; border-radius: 8px; }
#bezierCanvas { width: 100%; max-width: 460px; height: auto; aspect-ratio: 460 / 260; }

.font-lab-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0.8em 0; }
.font-lab-item { text-align: center; padding: 14px 8px; background: var(--surface2); border: 1px solid var(--border-light); border-radius: 10px; }
.font-lab-item .font-name { font-family: var(--serif); font-size: 0.64rem; color: var(--text3); margin-bottom: 4px; }
.font-lab-item .font-char { font-size: clamp(2.8rem, 6vw, 4.5rem); line-height: 1.2; margin-bottom: 2px; color: var(--ink); }
.font-lab-item .font-desc { font-size: 0.7rem; color: var(--text2); }

/* ============================================================
   REFS TABLE
   ============================================================ */
.ref-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.ref-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
.ref-table td:first-child { font-family: var(--mono); font-size: 0.68rem; color: var(--text3); width: 36px; white-space: nowrap; }
.ref-table td:nth-child(2) { color: var(--text2); line-height: 1.65; }
.ref-table td:last-child { text-align: right; white-space: nowrap; }

/* ============================================================
   SCROLL-TO-TOP BUTTON
   ============================================================ */
.scroll-top {
  position: fixed; bottom: 32px; right: 32px; z-index: 300;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text2); font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s, background 0.2s, border-color 0.2s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.scroll-top.visible {
  opacity: 1; transform: translateY(0); pointer-events: auto;
}
.scroll-top:hover {
  background: var(--accent-light); border-color: var(--accent); color: var(--accent);
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  margin-left: var(--sidebar-w); border-top: 1px solid var(--border);
  background: var(--surface); padding: 24px 28px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 14px; font-size: 0.76rem; color: var(--text3);
}
.app-footer a { color: var(--text2); text-decoration: none; }
.app-footer a:hover { color: var(--accent); }

code { background: #f5ede0; padding: 2px 6px; border-radius: 4px; font-family: var(--mono); font-size: 0.88em; color: var(--accent); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 600; color: var(--text); }

/* 键盘可访问性：统一焦点环 */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.btn:focus-visible, .sidebar-item:focus-visible, .nav-toggle:focus-visible { outline-offset: 3px; }
input:focus-visible { outline: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .nav-toggle { display: flex; }
  /* 侧栏改为可开合抽屉 */
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 2px 0 24px rgba(0,0,0,0.08);
    will-change: transform;
  }
  body.nav-open .app-sidebar { transform: translateX(0); }
  .app-main, .app-footer { margin-left: 0; }
  /* 6 列网格：大卡通栏，中小卡两两成对，避免整片塌成单列 */
  .bento { grid-template-columns: repeat(6, 1fr); }
  .bs-12, .bs-8, .bs-7 { grid-column: span 6; }
  .bs-6, .bs-5, .bs-4, .bs-3 { grid-column: span 3; }
}
@media (max-width: 680px) {
  .app-topbar { padding: 0 14px; gap: 12px; }
  .bento { grid-template-columns: 1fr; gap: 14px; }
  .bs-8, .bs-7, .bs-6, .bs-5, .bs-4, .bs-3, .bs-12 { grid-column: span 1; }
  .main-inner { padding: 20px 14px 60px; }
  .widget { padding: 18px 16px; }
  .pixel-grid { width: 256px; } .pixel { width: 16px; height: 16px; }
  .font-lab-grid { grid-template-columns: repeat(2, 1fr); }
  /* 触摸友好：更大的滑块拇指与按钮 */
  input[type="range"] { height: 6px; }
  input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; }
  input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border: none; }
  .btn { padding: 8px 16px; } .btn-sm { padding: 6px 12px; }
  /* 图文卡片在小屏上堆叠为单列 */
  .widget.feature-card .widget-body[style*="grid"] {
    grid-template-columns: 1fr !important;
  }
}
@media print {
  .app-topbar, .app-sidebar, .app-footer, .bg-canvas, .scroll-top, .progress-bar { display: none !important; }
  .app-main { margin-left: 0; padding-top: 0; }
  .widget { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
}
