/* HanPath — 自包含样式。零外部依赖（字体走系统栈，纹理走内联 SVG data URI）。
   视觉语言：宣纸 / 朱砂 / 墨 —— 面向「学汉字」人群的东亚古典基调。
   明暗双主题（跟随系统 + 手动切换），RTL 一律用逻辑属性。
   ★ 只用纯 CSS 生成质感，不引外部图片：既零成本，也不会因第三方资源挂掉而变形。 */

:root {
  /* — 纸与墨 — */
  --paper: #f7f2e7;          /* 宣纸 */
  --paper-2: #fdfaf3;        /* 页面卡面 */
  --ink: #211f1c;            /* 墨 */
  --ink-2: #4a453d;          /* 淡墨 */
  --muted: #7a7368;
  --line: #ded3bd;
  --line-2: #c9bda3;
  /* — 朱 — */
  --brand: #b23a2e;          /* 朱砂 */
  --brand-2: #8f2c22;
  --brand-ink: #fff8f0;
  --accent: #a9803c;         /* 赭石/金 */
  --celadon: #3f6157;        /* 黛青 */
  --ok: #3f7a52;
  --bad: #b3422e;
  --tone1: #b23a2e; --tone2: #c07a1e; --tone3: #3f7a52; --tone4: #2f5f96; --tone5: #6a4c8a;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(60,45,25,.06), 0 6px 18px rgba(60,45,25,.07);
  --shadow-hover: 0 2px 4px rgba(60,45,25,.09), 0 10px 26px rgba(60,45,25,.12);
  /* 宣纸纤维：内联 SVG turbulence，不产生网络请求 */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "Source Han Serif CN",
           "STSong", "SimSun", "Noto Serif SC", "Yu Mincho", "Hiragino Mincho ProN", Georgia, serif;
}

html[data-theme="dark"] {
  --paper: #14130f; --paper-2: #1e1c17; --ink: #ece5d8; --ink-2: #c8bfae;
  --muted: #9b9284; --line: #322e26; --line-2: #453f35;
  --brand: #e0705f; --brand-2: #f0917f; --brand-ink: #1a1208;
  --accent: #d8ab5c; --celadon: #7fb0a1;
  --ok: #74c593; --bad: #e88a76;
  --tone1: #e0705f; --tone2: #dda24a; --tone3: #74c593; --tone4: #71a5d8; --tone5: #b392cf;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 6px 18px rgba(0,0,0,.35);
  --shadow-hover: 0 2px 6px rgba(0,0,0,.55), 0 12px 30px rgba(0,0,0,.45);
}
html[data-theme="dark"] a.card:hover { box-shadow: var(--shadow-hover); }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --paper: #14130f; --paper-2: #1e1c17; --ink: #ece5d8; --ink-2: #c8bfae;
    --muted: #9b9284; --line: #322e26; --line-2: #453f35;
    --brand: #e0705f; --brand-2: #f0917f; --brand-ink: #1a1208;
    --accent: #d8ab5c; --celadon: #7fb0a1;
    --ok: #74c593; --bad: #e88a76;
    --tone1: #e0705f; --tone2: #dda24a; --tone3: #74c593; --tone4: #71a5d8; --tone5: #b392cf;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 6px 18px rgba(0,0,0,.35);
    --shadow-hover: 0 2px 6px rgba(0,0,0,.55), 0 12px 30px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; color: var(--ink); background-color: var(--paper);
  background-image: var(--grain),
    radial-gradient(1200px 600px at 15% -10%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(178,58,46,.05), transparent 55%);
  background-size: 180px 180px, auto, auto;
  background-blend-mode: multiply, normal, normal;
  font: 16px/1.7 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
        "Noto Sans", "Noto Sans Arabic", "Noto Sans Devanagari", "Noto Sans JP", sans-serif;
}
html[data-theme="dark"] body, html:not([data-theme="light"]) body { background-blend-mode: overlay, normal, normal; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) body { background-blend-mode: overlay, normal, normal; }
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

.skip {
  position: absolute; inset-inline-start: -9999px; top: 0; background: var(--brand);
  color: var(--brand-ink); padding: .5rem .9rem; border-radius: 0 0 var(--radius) 0; z-index: 60;
}
.skip:focus { inset-inline-start: 0; }

/* ---------------- header：印章 + 纸头条 ---------------- */
.top {
  background: linear-gradient(180deg, var(--paper-2), color-mix(in srgb, var(--paper-2) 92%, var(--line)));
  border-bottom: 1px solid var(--line-2);
  padding: .8rem 1rem .55rem; position: sticky; top: 0; z-index: 40;
}
.topbar { max-width: 62rem; margin: 0 auto; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.2rem; color: var(--ink); letter-spacing: .01em; }
.brand:hover { text-decoration: none; }
/* 印章 Logo：朱底白字 + 双线框 */
.logo {
  width: 2.15rem; height: 2.15rem; display: inline-grid; place-items: center; flex: 0 0 auto;
  background: var(--brand); color: #fff;
  border-radius: 5px; box-shadow: inset 0 0 0 2px var(--brand), inset 0 0 0 3px color-mix(in srgb, #fff 70%, transparent);
  font-family: var(--serif); font-size: 1.35rem; line-height: 1; font-weight: 600;
  transform: rotate(-1.5deg);
}
.tag { margin: .25rem 0 .5rem; color: var(--muted); font-size: .9rem; max-width: 46rem; }
.spacer { flex: 1 1 auto; }

.tools { display: inline-flex; align-items: center; gap: .45rem; }
.iconbtn {
  border: 1px solid var(--line-2); background: var(--paper-2); color: var(--ink-2);
  border-radius: 9px; padding: .32rem .6rem; font: inherit; font-size: .88rem; cursor: pointer; line-height: 1.2;
}
.iconbtn:hover { border-color: var(--brand); color: var(--brand); }
.iconbtn[aria-expanded="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.langpick { display: inline-flex; align-items: center; gap: .3rem; font-size: .88rem; color: var(--muted); margin: 0; }
.langpick select {
  background: var(--paper-2); color: var(--ink); border: 1px solid var(--line-2);
  border-radius: 9px; padding: .3rem .45rem; font: inherit; font-size: .9rem; max-width: 9.5rem;
}

/* ---------------- nav：JS 存在时是抽屉，没有 JS 时是完整列表 ---------------- */
.nav { max-width: 62rem; margin: .45rem auto 0; }
.navgrid { display: flex; flex-wrap: wrap; gap: .35rem; list-style: none; padding: 0; margin: 0; }
.navgrid a {
  display: inline-block; padding: .38rem .72rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink-2);
  font-size: .9rem; white-space: nowrap; transition: transform .12s, border-color .12s, background .12s;
}
.navgrid a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; transform: translateY(-1px); }
.navgrid a.on {
  background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600;
}
@media (max-width: 47.99rem) {
  .js .navgrid {
    display: none; position: absolute; inset-inline: .5rem; top: 100%; z-index: 45;
    padding: .6rem; background: var(--paper-2); border: 1px solid var(--line-2);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-hover); align-items: flex-start;
  }
  .js .navgrid.open { display: flex; }
  .top { position: relative; }
}

/* ---------------- layout ---------------- */
main { max-width: 62rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
h1, h2, h3, .display { font-family: var(--serif); letter-spacing: .01em; }
h1 { font-size: 1.85rem; line-height: 1.35; margin: .2rem 0 .5rem; font-weight: 700; }
h2 { font-size: 1.3rem; margin: 2rem 0 .7rem; font-weight: 700; }
h2:first-of-type { margin-top: 1.4rem; }
h3 { font-size: 1.06rem; margin: 1.3rem 0 .4rem; }
p { margin: .55rem 0; }
.lead { color: var(--muted); font-size: 1.05rem; }
section { margin-bottom: 1.6rem; }

/* ---------------- hero：米字格 + 云纹 ---------------- */
.hero {
  position: relative; overflow: hidden; margin: .3rem 0 1.6rem; padding: 1.6rem 1.3rem;
  border: 1px solid var(--line-2); border-radius: var(--radius-lg);
  background:
    linear-gradient(0deg, color-mix(in srgb, var(--paper-2) 88%, transparent), color-mix(in srgb, var(--paper-2) 88%, transparent)),
    repeating-linear-gradient(45deg, rgba(178,58,46,.045) 0 10px, transparent 10px 20px);
  box-shadow: var(--shadow);
}
.hero::after {  /* 右上朱印 */
  content: "漢"; position: absolute; inset-inline-end: .9rem; top: .6rem;
  font-family: var(--serif); font-size: 4.6rem; color: color-mix(in srgb, var(--brand) 14%, transparent);
  line-height: 1; pointer-events: none; user-select: none;
}
.hero h1 { font-size: 2.1rem; margin: 0 0 .35rem; }
.hero .tagline { font-family: var(--serif); font-size: 1.15rem; color: var(--brand-2); margin: 0 0 .6rem; }
.hero .lead { max-width: 40rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.hero .hzrow { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.hzcell {
  width: 2.9rem; height: 2.9rem; display: grid; place-items: center; font-family: var(--serif);
  font-size: 1.7rem; color: var(--ink); border: 1px solid var(--line-2); border-radius: 6px;
  background: var(--paper-2); box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--paper-2) 80%, transparent);
}

/* 统计条：真实数量，不做虚标 */
.stats { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.1rem; padding: 0; list-style: none; }
.stats li {
  border: 1px solid var(--line); border-radius: 999px; padding: .25rem .7rem; font-size: .86rem; color: var(--muted);
  background: var(--paper-2);
}
.stats b { color: var(--ink); font-variant-numeric: tabular-nums; }

.grid { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.grid.sm { grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); }
.card {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: .9rem 1rem; box-shadow: var(--shadow);
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s;
}
.card h3 { margin-top: 0; }
.card a { font-weight: 600; }
a.card { display: block; color: inherit; }
a.card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: var(--line-2); }
a.card:hover h3 { color: var(--brand); }
.kicker { display: block; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: .15rem; }

/* ---------------- hanzi ---------------- */
.hz { font-family: var(--serif); }
.big { font-size: 3.4rem; line-height: 1.15; }
.py { color: var(--brand-2); font-variant-numeric: tabular-nums; }
.gloss { color: var(--muted); }

.tblwrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--paper-2); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { background: color-mix(in srgb, var(--paper) 70%, var(--paper-2)); font-weight: 700; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--brand) 5%, transparent); }

/* ---------------- tools ---------------- */
.tool {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 1.05rem; box-shadow: var(--shadow); margin: 1.1rem 0;
}
.tool h2, .tool h3 { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.wrap > * { flex: 0 0 auto; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  border-radius: 999px; padding: .28rem .72rem; font: inherit; font-size: .9rem; cursor: pointer;
  transition: border-color .12s, background .12s;
}
.chip:hover { border-color: var(--brand); }
.chip[aria-pressed="true"], .chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn {
  background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 10px;
  padding: .6rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer; box-shadow: var(--shadow);
}
.btn:hover { text-decoration: none; background: var(--brand-2); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line-2); box-shadow: none; }
.btn.ghost:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.btn:disabled { opacity: .5; cursor: default; }

.stage {
  min-height: 6.5rem; display: grid; place-items: center; padding: 1rem; gap: .3rem;
  background: var(--paper-2); border: 1px dashed var(--line-2); border-radius: var(--radius-lg); text-align: center;
  position: relative;
}
.out { font-size: 1.1rem; min-height: 1.7rem; }
.readout { font-size: 2.1rem; font-weight: 600; }

.tonebar { display: flex; gap: .5rem; flex-wrap: wrap; }
.tonebtn {
  flex: 1 1 8rem; border: 2px solid var(--line); background: var(--paper-2); color: var(--ink);
  border-radius: 10px; padding: .6rem; cursor: pointer; text-align: center; font: inherit;
}
.tonebtn:hover { border-color: var(--brand); }
.tonebtn .n { display: block; font-size: 1.7rem; font-family: var(--serif); }
.tonebtn[data-t="1"] .n { color: var(--tone1); }
.tonebtn[data-t="2"] .n { color: var(--tone2); }
.tonebtn[data-t="3"] .n { color: var(--tone3); }
.tonebtn[data-t="4"] .n { color: var(--tone4); }
.tonebtn[data-t="5"] .n { color: var(--tone5); }
.tonebtn.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.tonebtn.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }

/* 米字格：写字练习 */
.padwrap { display: flex; gap: .8rem; flex-wrap: wrap; align-items: flex-start; }
canvas.pad {
  width: 100%; max-width: 20rem; aspect-ratio: 1; touch-action: none; display: block;
  background: var(--paper-2); border: 1px solid var(--line-2); border-radius: var(--radius);
}
.progress { height: 8px; background: color-mix(in srgb, var(--paper) 60%, var(--paper-2)); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .3s; }

/* 笔顺动画容器（hanzi-writer） */
.strokebox { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.strokesvg { width: 12rem; height: 12rem; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--paper-2); }
@media (max-width: 30rem) { .strokesvg { width: 9rem; height: 9rem; } }

.note { font-size: .93rem; color: var(--muted); border-inline-start: 3px solid var(--brand); padding-inline-start: .75rem; }
.ok { color: var(--ok); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.badge {
  display: inline-block; font-size: .78rem; padding: .1rem .5rem; border-radius: 999px;
  background: var(--paper-2); border: 1px solid var(--line-2); color: var(--muted);
}
.lv1 { color: var(--tone3); } .lv2 { color: var(--tone4); } .lv3 { color: var(--accent); }

/* 每日一读 / 学习路径 */
.poem {
  font-family: var(--serif); padding: 1.2rem 1.1rem; border: 1px solid var(--line-2);
  border-radius: var(--radius-lg); background: var(--paper-2); box-shadow: var(--shadow);
}
.poem .line { font-size: 1.5rem; line-height: 2; letter-spacing: .06em; }
.poem .meta { color: var(--muted); font-size: .95rem; margin-top: .5rem; }
.steps { counter-reset: d; list-style: none; padding: 0; margin: 0; }
.steps li {
  counter-increment: d; position: relative; padding: .6rem 0 .6rem 2.6rem;
  border-bottom: 1px solid var(--line);
}
.steps li::before {
  content: counter(d); position: absolute; inset-inline-start: 0; top: .6rem;
  width: 1.85rem; height: 1.85rem; display: grid; place-items: center; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink); font-size: .85rem; font-weight: 700;
}

/* ---------------- footer ---------------- */
.foot { border-top: 1px solid var(--line-2); background: color-mix(in srgb, var(--paper) 65%, var(--paper-2)); padding: 1.1rem 1rem 1.6rem; margin-top: 2.4rem; }
.foot .inner { max-width: 62rem; margin: 0 auto; }
.altlangs { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem .9rem; padding: 0; margin: .35rem 0 .8rem; font-size: .92rem; }
.src { color: var(--muted); font-size: .88rem; margin: 0; }

@media (max-width: 34rem) {
  h1 { font-size: 1.5rem; } .hero h1 { font-size: 1.7rem; } .big { font-size: 2.6rem; }
  .hero { padding: 1.2rem 1rem; } .hero::after { font-size: 3.4rem; }
  .tag { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
@media print { .top, .foot, .tool .row, .nav { display: none; } .card, .tool, .hero { box-shadow: none; } }
