/* =========================================================
   《那个英雄的名字》— 阅读站样式
   ========================================================= */

/* ---------- 1. 变量与基础 ---------- */
:root {
  --bg: #f3eee2;
  --bg-soft: #ece5d6;
  --card: #fbf8f0;
  --ink: #211c17;
  --ink-2: #4b443a;
  --ink-3: #8a8071;
  --line: #dfd4bf;
  --line-soft: #e9e0cf;
  --accent: #8b4a2b;
  --accent-2: #b3763f;
  --accent-tint: rgba(139, 74, 43, .09);

  --serif: "Songti SC", "Source Han Serif SC", "Noto Serif SC", "STSong",
           "SimSun", Georgia, "Times New Roman", serif;
  --sans: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Segoe UI",
          system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --fs: 18.5px;
  --lh: 2.05;
  --sbw: 300px;

  --gate-bg: #131009;
  --gate-ink: #efe6d6;
  --gate-muted: #a2957f;
  --gate-line: rgba(239, 230, 214, .14);
  --gate-accent: #d9a06a;
  --gate-card: rgba(255, 249, 236, .045);
}

[data-theme="night"] {
  --bg: #14150f;
  --bg-soft: #1a1b14;
  --card: #1e1f17;
  --ink: #d9d3c5;
  --ink-2: #aaa395;
  --ink-3: #7b7466;
  --line: #2d2e24;
  --line-soft: #26271e;
  --accent: #c99061;
  --accent-2: #d9a97b;
  --accent-tint: rgba(201, 144, 97, .12);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .28s ease, color .28s ease;
}

body.is-locked { overflow: hidden; }
button { font: inherit; color: inherit; }

::selection { background: rgba(179, 118, 63, .24); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; }

/* ---------- 2. 顶部进度 ---------- */
.scroll-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 80;
  opacity: 0;
  transition: opacity .3s ease;
  pointer-events: none;
}
.scroll-progress.is-on { opacity: 1; }
.scroll-progress i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ---------- 3. 进入页（填空题） ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(20px, 5vh, 56px) 20px clamp(24px, 5vh, 56px);
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(217, 160, 106, .16), transparent 62%),
    radial-gradient(80% 60% at 90% 100%, rgba(139, 74, 43, .18), transparent 60%),
    var(--gate-bg);
  color: var(--gate-ink);
  transition: opacity .5s ease, visibility .5s ease;
}
.gate::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(0deg, rgba(255, 255, 255, .014) 0 1px, transparent 1px 3px);
  opacity: .6;
}
.gate.is-gone { opacity: 0; visibility: hidden; pointer-events: none; }

.gate-glow {
  position: fixed;
  left: 50%;
  top: -22vh;
  width: min(1100px, 130vw);
  height: 62vh;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(217, 160, 106, .22), transparent 72%);
  filter: blur(8px);
  pointer-events: none;
}

.gate-inner { position: relative; z-index: 1; width: 100%; max-width: 820px; }

.gate-panel {
  position: relative;
  border: 1px solid var(--gate-line);
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(255, 248, 234, .055), rgba(255, 248, 234, .015));
  backdrop-filter: blur(2px);
  padding: clamp(26px, 4.2vw, 50px) clamp(22px, 4.4vw, 54px) clamp(24px, 3.6vw, 42px);
  box-shadow: 0 40px 100px rgba(0, 0, 0, .45);
}

.gate-seal {
  position: absolute;
  top: clamp(16px, 3vw, 28px);
  right: clamp(16px, 3vw, 28px);
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(217, 160, 106, .55);
  color: var(--gate-accent);
  font-size: 20px;
  line-height: 1;
  transform: rotate(-3deg);
  opacity: .85;
}

.gate-kicker {
  margin: 0 0 clamp(12px, 1.6vw, 18px);
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: .3em;
  color: var(--gate-muted);
}

.gate-title {
  margin: 0;
  font-size: clamp(30px, 5.2vw, 50px);
  font-weight: 600;
  letter-spacing: .12em;
  line-height: 1.3;
}
.gate-title::after {
  content: "";
  display: block;
  width: 56px;
  height: 1px;
  margin-top: clamp(16px, 2vw, 22px);
  background: linear-gradient(90deg, var(--gate-accent), transparent);
}

.gate-question {
  margin: clamp(18px, 2.4vw, 26px) 0 0;
  font-size: clamp(15px, 1.7vw, 17px);
  color: #cfc3ae;
  letter-spacing: .04em;
  text-wrap: pretty;
}

/* 填空题 */
.quiz {
  margin-top: clamp(22px, 3vw, 30px);
  padding-top: clamp(18px, 2.4vw, 26px);
  border-top: 1px solid var(--gate-line);
}

.quiz-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.quiz-label {
  flex: 0 0 auto;
  padding-bottom: 10px;
  font-family: var(--sans);
  font-size: 15px;
  letter-spacing: .18em;
  color: #cfc3ae;
  white-space: nowrap;
}

.quiz-blank {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  border-bottom: 1px dashed rgba(217, 160, 106, .45);
  transition: border-color .2s ease;
}
.quiz-blank::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: var(--gate-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .28s ease;
}
.quiz-blank:focus-within { border-bottom-color: transparent; }
.quiz-blank:focus-within::after { transform: scaleX(1); }

.quiz-input {
  width: 100%;
  height: 44px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--gate-ink);
  font-family: var(--mono);
  font-size: clamp(17px, 2.2vw, 20px);
  letter-spacing: .18em;
  outline: none;
}
.quiz-input::placeholder {
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: .04em;
  color: #6f665a;
}

.quiz-mark {
  flex: 0 0 auto;
  width: 24px;
  height: 44px;
  display: grid;
  place-items: center;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1;
}
.quiz-mark.is-ok { color: #9fbc8c; }
.quiz-mark.is-bad { color: #e08e6a; }

.quiz-row.is-shake { animation: shake .42s cubic-bezier(.36, .07, .19, .97) both; }

.quiz-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.quiz-note {
  margin: 0;
  min-height: 1.6em;
  font-family: var(--sans);
  font-size: 12.5px;
  letter-spacing: .04em;
  color: #8d8271;
}
.quiz-note.is-error { color: #e08e6a; }
.quiz-note.is-ok { color: #a9c199; }

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 20px;
  border: 1px solid rgba(239, 230, 214, .3);
  border-radius: 2px;
  background: transparent;
  color: var(--gate-ink);
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: .08em;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .1s ease;
}
.btn:hover { border-color: rgba(239, 230, 214, .62); background: rgba(255, 249, 236, .07); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary {
  border-color: var(--gate-accent);
  background: var(--gate-accent);
  color: #1b1509;
  font-weight: 600;
}
.btn-primary:hover { background: #e6b27f; border-color: #e6b27f; color: #1b1509; }

/* 获取密码 */
.getkey {
  margin-top: clamp(22px, 3vw, 30px);
  padding-top: clamp(16px, 2.2vw, 22px);
  border-top: 1px solid var(--gate-line);
}
.getkey-title {
  margin: 0 0 12px;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: .28em;
  color: var(--gate-muted);
}
.getkey-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.getkey-link .gl-label { display: inline-block; }

.getkey-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--gate-line);
  border-radius: 2px;
  background: transparent;
  color: #d8ccb6;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: .03em;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .2s ease, color .2s ease, background-color .2s ease;
}
.getkey-link b { color: var(--gate-accent); font-size: 1.1em; }
.getkey-link .arrow { color: var(--gate-accent); font-size: 12px; }
.getkey-link:hover {
  border-color: rgba(217, 160, 106, .6);
  background: rgba(217, 160, 106, .08);
  color: #f2e7d3;
}

.contact-box {
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px dashed rgba(217, 160, 106, .34);
  border-radius: 2px;
  background: rgba(217, 160, 106, .07);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 2;
  color: #d7cbb7;
  animation: fadeIn .28s ease both;
}
.contact-box .cb-title {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: .24em;
  color: var(--gate-accent);
}
.contact-box dl { margin: 0; }
.contact-box .cb-row { display: flex; gap: 10px; align-items: baseline; }
.contact-box dt { min-width: 3.6em; color: #8d8271; font-size: 12.5px; }
.contact-box dd {
  margin: 0;
  user-select: all;
  word-break: break-all;
  color: #efe6d6;
  letter-spacing: .04em;
}

.gate-foot {
  margin: 18px 0 0;
  text-align: center;
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: .2em;
  color: #6d6457;
}

/* ---------- 4. 阅读区布局 ---------- */
.reader { min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sbw);
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  transition: transform .3s ease;
}

.sb-top { padding: 26px 22px 18px; border-bottom: 1px solid var(--line); }
.sb-kicker {
  margin: 0 0 8px;
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: .3em;
  color: var(--ink-3);
}
.sb-book {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .1em;
  line-height: 1.5;
}
.sb-meta {
  margin: 8px 0 0;
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: .08em;
  color: var(--ink-3);
}

.toc {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 10px 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  overscroll-behavior: contain;
}
.toc::-webkit-scrollbar { width: 8px; }
.toc::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

.toc-item {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 9px 12px 9px 14px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: .02em;
  transition: background-color .18s ease, color .18s ease;
}
.toc-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 2px;
  height: 0;
  background: var(--accent);
  transform: translateY(-50%);
  transition: height .2s ease;
}
.toc-item:hover { background: var(--accent-tint); color: var(--ink); }
.toc-item .toc-no {
  flex: 0 0 auto;
  min-width: 3.2em;
  font-size: 11px;
  letter-spacing: .06em;
  color: var(--ink-3);
}
.toc-item .toc-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-item.is-active { background: var(--accent-tint); color: var(--ink); font-weight: 600; }
.toc-item.is-active::before { height: 60%; }
.toc-item.is-active .toc-no { color: var(--accent); }

.sb-bottom {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
}
.sb-progress { height: 2px; background: var(--line-soft); overflow: hidden; }
.sb-progress i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .12s linear;
}
.sb-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--ink-3);
}
.link-btn {
  border: 0;
  background: none;
  padding: 2px 0;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--ink-3);
  cursor: pointer;
  border-bottom: 1px solid transparent;
}
.link-btn:hover { color: var(--accent); border-bottom-color: currentColor; }

.main { margin-left: var(--sbw); padding: 0 clamp(18px, 4vw, 64px); outline: none; }

.content { max-width: 40em; margin: 0 auto; padding: clamp(48px, 9vh, 96px) 0 40px; }

/* ---------- 5. 正文排版 ---------- */
.cover { text-align: center; padding: 0 0 clamp(40px, 8vh, 84px); }
.cover-kicker {
  margin: 0 0 clamp(18px, 3vw, 28px);
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: .46em;
  color: var(--ink-3);
}
.cover-title {
  margin: 0;
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 600;
  letter-spacing: .16em;
  line-height: 1.4;
  text-indent: .16em;
}
.cover-rule {
  width: 46px;
  height: 1px;
  margin: clamp(22px, 3.4vw, 34px) auto;
  background: var(--accent);
  opacity: .55;
}
.cover-sub {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: .3em;
  color: var(--ink-3);
}
.cover-hint {
  margin: clamp(28px, 4vw, 44px) 0 0;
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: .28em;
  color: var(--ink-3);
  opacity: .8;
}
.cover-hint::after {
  content: "";
  display: block;
  width: 1px;
  height: 34px;
  margin: 14px auto 0;
  background: linear-gradient(var(--line), transparent);
}

.chapter { padding: clamp(36px, 6vh, 64px) 0 0; scroll-margin-top: 0; }

.chapter-head { margin: 0 0 clamp(20px, 3vw, 30px); }
.ch-no {
  display: block;
  margin-bottom: 10px;
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: .38em;
  color: var(--accent);
}
.ch-title {
  margin: 0;
  font-size: clamp(21px, 2.6vw, 25px);
  font-weight: 600;
  letter-spacing: .06em;
  line-height: 1.6;
}
.chapter-head::after {
  content: "";
  display: block;
  width: 100%;
  height: 1px;
  margin-top: clamp(16px, 2.4vw, 22px);
  background: linear-gradient(90deg, var(--line), transparent);
}

.chapter-body p {
  margin: 0 0 .95em;
  text-indent: 2em;
  text-align: justify;
  text-justify: inter-ideograph;
  word-break: break-word;
}
.chapter-body p:last-child { margin-bottom: 0; }

/* 文末署名：日期与名字靠右 */
.chapter-body p.is-sign {
  text-indent: 0;
  text-align: right;
  letter-spacing: .08em;
  color: var(--ink-2);
  margin: 0 0 .5em;
}
.chapter-body p:not(.is-sign) + p.is-sign { margin-top: 1.6em; }

/* 章末：标出章节名称 */
.chapter-end { margin: clamp(30px, 5vw, 52px) 0 0; text-align: center; }
.ce-rule {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: .34em;
}
.ce-rule span {
  width: clamp(28px, 8vw, 64px);
  height: 1px;
  background: var(--line);
}
.ce-name {
  margin: 12px 0 0;
  font-size: 14.5px;
  letter-spacing: .16em;
  color: var(--ink-2);
}
.ce-next {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  padding: 7px 16px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: .14em;
  color: var(--ink-3);
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, background-color .2s ease;
}
.ce-next:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-tint); }

.site-foot {
  max-width: 40em;
  margin: 0 auto;
  padding: clamp(40px, 8vh, 80px) 0 clamp(56px, 10vh, 96px);
  border-top: 1px solid var(--line);
  text-align: center;
}
.sf-title { margin: 0; font-size: 16px; letter-spacing: .2em; color: var(--ink-2); }
.sf-note {
  margin: 10px 0 0;
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: .16em;
  color: var(--ink-3);
}

/* ---------- 6. 工具条与移动端 ---------- */
.tools {
  position: fixed;
  right: clamp(12px, 2vw, 26px);
  bottom: clamp(12px, 2vw, 26px);
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  background: var(--card);
  box-shadow: 0 10px 26px rgba(40, 30, 16, .12);
  opacity: .95;
}
.tool {
  min-width: 52px;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: .06em;
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease;
}
.tool + .tool { border-top: 1px solid var(--line-soft); }
.tool:hover { background: var(--accent-tint); color: var(--accent); }
.tool.is-on { color: var(--accent); }

.drawer-btn { display: none; }
body.is-drawer .drawer-btn { opacity: 0; pointer-events: none; }

/* 侧栏里的阅读设置（手机上用它替代浮动工具条） */
.sb-tools { display: none; gap: 6px; margin-bottom: 14px; }
.sb-tool {
  flex: 1 1 0;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: .06em;
  cursor: pointer;
  transition: color .18s ease, border-color .18s ease, background-color .18s ease;
}
.sb-tool:hover, .sb-tool.is-on { color: var(--accent); border-color: var(--accent); background: var(--accent-tint); }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(20, 16, 10, .45);
  border: 0;
  backdrop-filter: blur(2px);
  animation: fadeIn .2s ease both;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

@media (max-width: 960px) {
  :root { --sbw: 284px; }

  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0, 0, 0, .28); }
  body.is-drawer .sidebar { transform: translateX(0); }
  .main { margin-left: 0; padding: 0 clamp(18px, 5vw, 34px); }

  .drawer-btn {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 46;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px 7px 11px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--card);
    color: var(--ink-2);
    font-family: var(--sans);
    font-size: 12px;
    letter-spacing: .1em;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(40, 30, 16, .1);
    transition: opacity .2s ease;
  }
  .content { padding-top: clamp(58px, 9vh, 78px); }

  /* 手机上没有右侧留白，浮动工具条会压到正文，改到目录抽屉里 */
  .tools { display: none; }
  .sb-tools { display: flex; }

  .site-foot { padding-bottom: 120px; }
}

@media (max-width: 720px) {
  :root { --fs: 17px; --lh: 1.95; }

  .gate { padding: 16px; align-items: flex-start; }
  .gate-panel { padding: 26px 20px 24px; }
  .gate-seal { width: 34px; height: 34px; font-size: 16px; }
  .cover-title { font-size: 30px; }
  .chapter-body p { text-align: left; text-justify: auto; }

  .quiz-label { font-size: 14px; padding-bottom: 12px; }
  .quiz-input { font-size: 17px; letter-spacing: .1em; }
  .quiz-foot { flex-direction: column-reverse; align-items: stretch; }
  .quiz-foot .btn { width: 100%; }
  .gate-kicker { letter-spacing: .2em; max-width: calc(100% - 52px); }
  .getkey-actions { flex-direction: column; }
  .getkey-link { width: 100%; justify-content: space-between; }
}

@media (min-width: 1500px) {
  :root { --sbw: 320px; }
  .content { max-width: 42em; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto !important; }
}

@media print {
  .sidebar, .tools, .drawer-btn, .scroll-progress, .gate { display: none !important; }
  .main { margin: 0; }
  body { background: #fff; color: #000; }
}
