:root {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  color: #171b1a;
  background: #f6f7f7;
  font-synthesis: none;
  --ink: #171b1a;
  --muted: #68716e;
  --surface: #ffffff;
  --structural: #f6f7f7;
  --border: #dfe3e1;
  --accent: #c8332a;
  --accent-soft: #fff3f1;
  --celadon: #e8f1ec;
  --green: #2f7a56;
  --shadow: 0 10px 30px rgba(27, 38, 34, .06);
  --reader-scale: 1;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf1ef;
  --muted: #aeb7b3;
  --surface: #171b1a;
  --structural: #111513;
  --border: #343b38;
  --accent: #ef6a60;
  --accent-soft: #35201e;
  --celadon: #24352d;
  --green: #6cbd92;
  --shadow: 0 10px 30px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html, body, #root { margin: 0; min-height: 100%; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px 310px minmax(0, 1fr);
  grid-template-rows: 86px minmax(0, 1fr);
  background: var(--structural);
  color: var(--ink);
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 236px minmax(280px, 440px) 1fr auto;
  align-items: center;
  gap: 24px;
  height: 86px;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; border: 0; background: none; cursor: pointer; padding: 0; }
.brand strong { font-family: "STSong", "Songti SC", serif; font-size: 23px; letter-spacing: .04em; white-space: nowrap; }
.seal-mark { display: grid; place-content: center; width: 72px; height: 72px; border: 3px solid var(--accent); border-radius: 8px; color: var(--accent); font-family: "STSong", "Songti SC", serif; font-weight: 800; font-size: 19px; line-height: 1.05; text-align: center; }
.seal-mark.small { width: 42px; height: 42px; border-width: 2px; font-size: 12px; border-radius: 5px; flex: 0 0 auto; }

.global-search { height: 48px; display: flex; align-items: center; gap: 10px; border: 1px solid var(--green); border-radius: 8px; padding: 0 14px; background: var(--surface); }
.global-search:focus-within { box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 16%, transparent); }
.global-search input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 15px; }
.global-search input:disabled { color: var(--muted); }
.offline-state { justify-self: end; display: flex; align-items: center; gap: 9px; white-space: nowrap; color: var(--muted); font-size: 14px; }
.offline-state i { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 12%, transparent); }
.toolbar { display: flex; align-items: center; border-left: 1px solid var(--border); padding-left: 18px; }
.toolbar button { min-width: 42px; height: 44px; border: 0; background: none; cursor: pointer; color: var(--ink); font-family: "STSong", "Songti SC", serif; }

.module-nav { grid-column: 1; grid-row: 2; min-height: 0; display: flex; flex-direction: column; gap: 6px; padding: 24px 14px calc(24px + env(safe-area-inset-bottom)); background: var(--surface); border-right: 1px solid var(--border); overflow: auto; }
.module-nav > button { min-height: 56px; display: flex; align-items: center; gap: 14px; padding: 0 16px; border: 0; border-left: 4px solid transparent; border-radius: 6px; background: transparent; cursor: pointer; color: var(--ink); font-size: 16px; text-align: left; }
.module-nav > button svg { color: var(--muted); flex: 0 0 auto; }
.module-nav > button:hover { background: var(--structural); }
.module-nav > button.active { background: var(--celadon); border-left-color: var(--green); color: var(--green); font-weight: 650; }
.module-nav > button.active svg { color: var(--green); }
.local-progress { margin-top: auto; padding: 18px 12px 0; border-top: 1px solid var(--border); display: grid; gap: 8px; color: var(--muted); font-size: 12px; }
.local-progress i { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.local-progress b { display: block; height: 100%; background: var(--green); border-radius: inherit; }
.local-progress strong { color: var(--green); font-size: 16px; }

.item-panel { grid-column: 2; grid-row: 2; min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; background: var(--surface); border-right: 1px solid var(--border); transition: width .2s ease; }
.item-panel-head { height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--border); }
.high-freq-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.high-freq-tabs button { min-height: 58px; display: grid; align-content: center; gap: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; }
.high-freq-tabs button strong { color: var(--ink); font-family: "STSong", "Songti SC", serif; font-size: 17px; }
.high-freq-tabs button span { font-size: 12px; }
.high-freq-tabs button.active { color: var(--accent); border-color: var(--green); background: var(--celadon); box-shadow: inset 3px 0 0 var(--green); }
.high-freq-tabs button.active strong { color: var(--green); }
.module-category-tabs { display: flex; gap: 8px; padding: 12px 14px; overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.module-category-tabs button { flex: 0 0 auto; min-width: 104px; min-height: 54px; display: grid; align-content: center; gap: 3px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; text-align: left; }
.module-category-tabs button strong { color: var(--ink); font-family: "STSong", "Songti SC", serif; font-size: 15px; }
.module-category-tabs button span { font-size: 11px; }
.module-category-tabs button.active { color: var(--accent); border-color: var(--green); background: var(--celadon); box-shadow: inset 3px 0 0 var(--green); }
.module-category-tabs button.active strong { color: var(--green); }
.item-panel-head > div { display: grid; gap: 3px; }
.item-panel-head strong { font-family: "STSong", "Songti SC", serif; font-size: 18px; }
.item-panel-head span { font-size: 12px; color: var(--muted); }
.item-panel-head button { width: 42px; height: 42px; border: 0; background: transparent; cursor: pointer; border-radius: 6px; }
.item-list { overflow: auto; min-height: 0; padding: 6px 8px; }
.item-list > button { width: 100%; min-height: 58px; display: grid; gap: 4px; padding: 10px 14px; border: 0; border-left: 4px solid transparent; border-radius: 5px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.item-list > button:hover { background: var(--structural); }
.item-list > button.active { background: var(--celadon); border-left-color: var(--green); color: var(--green); }
.item-list > button strong { font-weight: 580; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-list > button span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-list { color: var(--muted); text-align: center; padding: 36px 12px; }
.list-pagination { height: 54px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: center; gap: 20px; color: var(--muted); font-size: 13px; }
.list-pagination button { width: 42px; height: 42px; border: 0; background: none; cursor: pointer; }
.list-pagination button:disabled { opacity: .3; cursor: default; }

.reading-pane { grid-column: 3; grid-row: 2; min-width: 0; min-height: 0; overflow: auto; background: var(--surface); position: relative; }
.detail-article { width: min(900px, calc(100% - 80px)); min-height: calc(100vh - 156px); margin: 0 auto; padding: 58px 20px 130px 34px; position: relative; font-size: calc(17px * var(--reader-scale)); line-height: 1.85; }
.bookmark-line { position: absolute; left: 4px; top: 0; bottom: 0; width: 1px; background: color-mix(in srgb, var(--accent) 65%, transparent); }
.bookmark-line::before { content: ""; position: sticky; top: 0; display: block; width: 18px; height: 36px; margin-left: -8px; background: var(--accent); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%); }
.detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 30px; padding-bottom: 28px; border-bottom: 1px solid var(--border); }
.detail-title-row h1 { margin: 5px 0 0; font-family: "STSong", "Songti SC", "Noto Serif CJK SC", serif; font-size: calc(45px * var(--reader-scale)); font-weight: 700; line-height: 1.2; letter-spacing: .03em; }
.detail-meta { color: var(--green); font-size: 13px; font-weight: 650; }
.pinyin { margin: 8px 0 0; color: var(--muted); font-size: .88em; letter-spacing: .06em; }
.favorite-button { min-width: 110px; height: 48px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); cursor: pointer; color: var(--muted); }
.favorite-button.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.detail-section { padding: 26px 0 6px; border-bottom: 1px solid color-mix(in srgb, var(--border) 72%, transparent); }
.detail-section h2 { margin: 0 0 13px; padding-left: 12px; border-left: 3px solid var(--accent); font-family: "STSong", "Songti SC", serif; font-size: calc(21px * var(--reader-scale)); line-height: 1.3; }
.detail-section h3 { margin: 0 0 7px; font-size: calc(16px * var(--reader-scale)); }
.detail-section p { margin: 0 0 14px; white-space: pre-wrap; }
.detail-section ul { padding-left: 1.4em; }
.detail-section blockquote { margin: 0 0 14px; padding: 15px 18px; border-left: 0; background: var(--structural); color: var(--ink); }
.detail-section cite { display: block; margin-top: 8px; color: var(--muted); font-style: normal; font-size: .86em; }
.tag-lines { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 10px; }
.tag-lines span { color: var(--muted); font-size: .84em; }
.summary-answer { font-family: "STSong", "Songti SC", serif; font-size: 1.12em; }
.editorial-entry { padding: 0 0 16px 18px; border-left: 1px solid var(--border); }
.essay-sample p:empty { min-height: .8em; }
.traditional-title { margin: 10px 0 0; color: var(--muted); font-family: "STSong", "Songti SC", serif; font-size: .92em; }
.poetry-detail { width: min(1040px, calc(100% - 54px)); }
.poetry-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin-top: 32px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.poetry-version { min-width: 0; padding: 28px 30px 34px; background: var(--surface); }
.poetry-version + .poetry-version { border-left: 1px solid var(--border); }
.poetry-version > header { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-bottom: 22px; padding-bottom: 13px; border-bottom: 2px solid var(--accent); }
.poetry-version > header strong { color: var(--accent); font-family: "STSong", "Songti SC", serif; font-size: 23px; }
.poetry-version > header span { color: var(--muted); font-size: 11px; }
.simplified-version { background: color-mix(in srgb, var(--celadon) 35%, var(--surface)); }
.poetry-author { margin: 0 0 18px; color: var(--green); font-weight: 650; }
.poetry-lines p { margin: 0 0 12px; white-space: pre-wrap; font-family: "STSong", "Songti SC", serif; font-size: calc(19px * var(--reader-scale)); line-height: 1.85; }
.poetry-notes { margin-top: 24px; padding-top: 18px; border-top: 1px dashed var(--border); color: var(--muted); font-size: .86em; }
.poetry-notes > strong { display: block; margin-bottom: 10px; color: var(--ink); }
.poetry-notes p { margin: 0 0 9px; }
.poetry-source { display: grid; gap: 5px; margin-top: 24px; color: var(--muted); font-size: 12px; }
.poetry-source strong { color: var(--ink); }
.poetry-source span { overflow-wrap: anywhere; }
.error-text { color: var(--accent); }
.reader-pagination { position: sticky; bottom: 0; z-index: 5; min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 10px max(28px, calc((100% - 820px) / 2)); background: color-mix(in srgb, var(--surface) 95%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--border); }
.reader-pagination button { min-width: 130px; height: 48px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); cursor: pointer; }
.reader-pagination button:disabled { opacity: .35; cursor: default; }
.reader-pagination span { color: var(--muted); font-size: 13px; }
.empty-reading { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); }

.overview-page { grid-column: 2 / -1; grid-row: 2; min-width: 0; overflow: auto; padding: 58px clamp(30px, 5vw, 84px) 60px; background: var(--surface); }
.overview-intro { max-width: 720px; margin-bottom: 42px; }
.overview-intro h1 { margin: 0 0 10px; font-family: "STSong", "Songti SC", serif; font-size: 46px; }
.overview-intro p { margin: 0; color: var(--muted); font-size: 17px; }
.overview-rail { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.overview-rail button { min-height: 190px; padding: 26px; border: 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: transparent; text-align: left; cursor: pointer; }
.overview-rail button:nth-child(3n) { border-right: 0; }
.overview-rail button:nth-last-child(-n+3) { border-bottom: 0; }
.overview-rail button:hover { background: var(--celadon); }
.overview-rail span { color: var(--green); font-size: 14px; font-weight: 650; }
.overview-rail strong { display: block; margin: 18px 0 8px; font-family: "STSong", "Songti SC", serif; font-size: 36px; }
.overview-rail p { margin: 0; color: var(--muted); line-height: 1.6; }
.overview-notes { display: grid; grid-template-columns: minmax(220px, .7fr) minmax(0, 1.3fr); gap: 44px; margin-top: 46px; }
.overview-notes > div { padding-top: 18px; border-top: 3px solid var(--accent); }
.overview-notes h2 { margin: 0 0 14px; font-family: "STSong", "Songti SC", serif; }
.overview-notes strong { font-size: 42px; }
.overview-notes p { color: var(--muted); line-height: 1.75; }
.source-note { margin-top: 50px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }

.loading-screen { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 16px; padding: 30px; text-align: center; color: var(--muted); background: var(--surface); }
.loading-screen strong { color: var(--ink); font-family: "STSong", "Songti SC", serif; font-size: 24px; }

@media (max-width: 1099px) {
  .app-shell { grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: 78px 62px minmax(0, 1fr); }
  .topbar { height: 78px; grid-template-columns: auto minmax(220px, 1fr) auto; padding: 0 22px; gap: 18px; }
  .offline-state { display: none; }
  .module-nav { grid-column: 1 / -1; grid-row: 2; min-height: 62px; flex-direction: row; padding: 0 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .module-nav > button { min-width: max-content; min-height: 62px; padding: 0 12px; border-left: 0; border-bottom: 3px solid transparent; border-radius: 0; }
  .module-nav > button.active { border-bottom-color: var(--accent); color: var(--accent); background: transparent; }
  .module-nav > button svg, .local-progress { display: none; }
  .item-panel { grid-column: 1; grid-row: 3; }
  .reading-pane { grid-column: 2; grid-row: 3; }
  .overview-page { grid-column: 1 / -1; grid-row: 3; }
  .detail-article { width: calc(100% - 40px); padding-left: 30px; }
  .poetry-detail { width: calc(100% - 24px); }
  .poetry-version { padding: 24px 22px 30px; }
  .overview-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-rail button:nth-child(3n) { border-right: 1px solid var(--border); }
  .overview-rail button:nth-child(2n) { border-right: 0; }
  .overview-rail button:nth-last-child(-n+3) { border-bottom: 1px solid var(--border); }
  .overview-rail button:nth-last-child(-n+2) { border-bottom: 0; }
}

@media (max-width: 759px), (max-width: 900px) and (orientation: portrait) {
  .app-shell { display: block; min-height: 100vh; }
  .topbar { position: sticky; height: auto; min-height: 74px; grid-template-columns: 1fr auto; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
  .brand strong { font-size: 19px; }
  .seal-mark.small { width: 36px; height: 36px; font-size: 10px; }
  .global-search { grid-column: 1 / -1; grid-row: 2; height: 46px; }
  .toolbar button:nth-child(1), .toolbar button:nth-child(2) { display: none; }
  .toolbar { border: 0; padding: 0; }
  .offline-state { display: flex; position: absolute; top: calc(28px + env(safe-area-inset-top)); left: 190px; font-size: 12px; }
  .module-nav { position: sticky; top: calc(120px + env(safe-area-inset-top)); z-index: 15; height: 56px; padding: 0 6px; }
  .module-nav > button { min-height: 56px; padding: 0 11px; font-size: 14px; }
  .item-panel { display: block; border-right: 0; border-bottom: 1px solid var(--border); }
  .high-freq-tabs { padding: 10px 14px; }
  .high-freq-tabs button { min-height: 54px; }
  .module-category-tabs { padding: 10px 14px; }
  .item-panel.collapsed .item-list, .item-panel.collapsed .list-pagination { display: none; }
  .item-panel-head { height: 58px; }
  .item-list { max-height: 330px; padding-bottom: 10px; }
  .item-list > button { min-height: 56px; }
  .reading-pane { min-height: calc(100vh - 250px); overflow: visible; }
  .detail-article { width: 100%; min-height: 0; padding: 36px 20px 108px 34px; }
  .detail-title-row { gap: 16px; }
  .detail-title-row h1 { font-size: calc(36px * var(--reader-scale)); }
  .poetry-detail { width: 100%; }
  .poetry-compare { grid-template-columns: 1fr; }
  .poetry-version + .poetry-version { border-left: 0; border-top: 1px solid var(--border); }
  .poetry-version { padding: 22px 18px 26px; }
  .favorite-button { min-width: 52px; width: 52px; }
  .favorite-button span { display: none; }
  .reader-pagination { position: fixed; left: 0; right: 0; bottom: 0; min-height: 70px; padding: 9px 16px calc(9px + env(safe-area-inset-bottom)); }
  .reader-pagination button { min-width: 105px; height: 46px; }
  .overview-page { padding: 36px 20px 100px; }
  .overview-intro h1 { font-size: 38px; }
  .overview-rail { grid-template-columns: 1fr; }
  .overview-rail button, .overview-rail button:nth-child(3n), .overview-rail button:nth-child(2n), .overview-rail button:nth-last-child(-n+3), .overview-rail button:nth-last-child(-n+2) { min-height: 142px; border-right: 0; border-bottom: 1px solid var(--border); }
  .overview-rail button:last-child { border-bottom: 0; }
  .overview-notes { grid-template-columns: 1fr; gap: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

@media (max-width: 520px) {
  .offline-state { display: none; }
}
