:root {
  --paper: #f3e3bd;
  --paper-edge: #fff0ca;
  --ink: #3f3326;
  --ink-soft: #6d5c48;
  --cloth: #2c4a40;
  --accent: #e0773a;
  --star: #f2c14e;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", serif;
  --sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --glass: rgba(255, 246, 225, .9);
  --shadow: 0 10px 30px rgba(20, 30, 25, .25);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--cloth); color: var(--ink); font-family: var(--sans); }
button { font: inherit; color: inherit; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#table { position: fixed; inset: 0; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; cursor: grab; }
#world.page-hover { cursor: ew-resize; }
#world.pointing { cursor: pointer; }
#world.dragging { cursor: grabbing; }
.shade { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(10, 20, 16, .35)); }

/* 书名与底部阅读工具 */
.head { position: absolute; top: max(18px, env(safe-area-inset-top)); left: clamp(16px, 3.2vw, 55px); pointer-events: none; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff1d4; }
.brand b { display: block; font: 650 22px/1.35 var(--serif); letter-spacing: .06em; }
.brand small { color: #e1d7b6; font-size: 10px; letter-spacing: .18em; }
.imprint { width: 41px; height: 41px; display: grid; place-items: center; font-size: 19px; background: #ead5a6; color: #365848; border: 3px double #6c735c; border-radius: 12px; transform: rotate(-5deg); }

.reader-tools {
  position: absolute; left: 50%; bottom: max(clamp(10px, 3vh, 28px), env(safe-area-inset-bottom));
  transform: translateX(-50%); display: flex; align-items: center; padding: 4px;
  max-width: calc(100% - 16px); background: #f4e8cc; color: #493d2c;
  border: 1px solid #c6b38d; border-radius: 16px; box-shadow: var(--shadow), inset 0 0 0 2px #fbf1db;
}
.reader-tools button {
  display: grid; justify-items: center; align-content: center; gap: 3px;
  min-width: 44px; min-height: 46px; padding: 3px clamp(5px, 1.5vw, 20px);
  border: 0; background: transparent; color: inherit; border-radius: 10px;
  font-size: 12px; white-space: nowrap;
}
.reader-tools i { display: inline-flex; font-size: 18px; color: #655339; }
.reader-tools button:hover:enabled { background: #e9d9b7; }
.reader-tools button[aria-pressed="true"] { background: #dbe4cc; color: #304d35; }
.reader-tools button:disabled { opacity: .32; cursor: default; }
.reader-tools .turn { padding-inline: 6px; }
.smallcap { font-size: 11px; letter-spacing: .25em; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }

/* 提示气泡 */
.toast { position: absolute; left: 50%; top: 22%; transform: translate(-50%, 10px); background: #1f1c1e; color: var(--paper-edge); padding: 10px 18px; border-radius: 999px; font-family: var(--serif); font-size: 16px; opacity: 0; transition: .35s; pointer-events: none; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 加载 */
#loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--cloth); color: var(--paper-edge); font-family: var(--serif); letter-spacing: .2em; transition: opacity .6s; }
#loading.gone { opacity: 0; pointer-events: none; }
.loaf { width: 76px; height: 46px; border-radius: 40px 40px 14px 14px; background: linear-gradient(#1f1c1e 55%, #f4efe6 55%); position: relative; animation: breathe 1.8s ease-in-out infinite; }
.loaf::before, .loaf::after { content: ""; position: absolute; top: 14px; width: 9px; height: 9px; border-radius: 50%; background: #e39a3b; }
.loaf::before { left: 22px; } .loaf::after { left: 44px; }
@keyframes breathe { 50% { transform: scale(1.05, .95); } }

/* 对话框 */
dialog { border: 0; padding: 0; border-radius: 18px; background: var(--paper); color: var(--ink); width: min(620px, 92vw); max-height: 86vh; box-shadow: 0 30px 80px rgba(0, 0, 0, .4); }
dialog::backdrop { background: rgba(18, 28, 24, .55); backdrop-filter: blur(3px); }
dialog .inside { padding: 30px 34px 32px; position: relative; overflow: auto; max-height: 86vh; background: repeating-linear-gradient(0deg, transparent 0 31px, rgba(160, 130, 90, .08) 31px 32px); }
dialog h2 { font-family: var(--serif); font-size: 30px; margin: 8px 0 16px; letter-spacing: .06em; }
dialog p { font-family: var(--serif); font-size: 17px; line-height: 1.9; margin: 0 0 12px; text-indent: 2em; }
.close { position: absolute; top: 14px; right: 14px; border: 0; background: rgba(0, 0, 0, .06); width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* 读者的桌面 */
[hidden] { display: none !important; }
button:focus-visible, input:focus-visible { outline: 3px solid #dd8e49; outline-offset: 4px; }
#choices { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 15px; }
#choices button { background: #fff3d9; border: 1px solid #cbb891; border-radius: 5px; padding: 10px 14px; }
#fallback { position: absolute; inset: 0; padding: 0; color: var(--paper-edge); background: var(--cloth); display: grid; place-content: center; justify-items: center; gap: 12px; }
#fallback .smallcap { color: #e9dbc0; }
.printed-spread { position: relative; display: flex; width: min(78vw,66vh); filter: drop-shadow(0 10px 6px #142c26); }
.printed-spread img { width: 50%; }
.printed-spread #printFold { position: absolute; inset: 0; width: 100%; height: 100%; }
@media (max-width: 760px) {
  .head { top: max(12px, env(safe-area-inset-top)); }
  .brand { gap: 8px; }
  .brand b { font-size: 18px; }
  .imprint { width: 35px; height: 35px; }
  dialog .inside { padding: 23px 18px; }
  dialog h2 { font-size: 23px; padding-right: 20px; }
}
@media (max-height: 540px) and (orientation: landscape) {
  .head { top: 8px; }
  .brand small { display: none; }
  .reader-tools { bottom: max(4px, env(safe-area-inset-bottom)); }
  .reader-tools button { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; }
}
.print-tab { position: absolute; right: 4%; bottom: 7%; display: inline-flex; align-items: center; gap: 4px; background: #f8d68c; color: #574127; border: 1px solid #85643d; border-radius: 4px; padding: 5px 9px; }
.print-tab i { display: inline-flex; }
#taskHint { text-indent: 0; font-size: 14px; }

body[data-chapter="cover"] .head,
body[data-chapter="cover"] .reader-tools button:not(#openBook),
body:not([data-chapter="cover"]) #openBook { display: none; }
#openBook { padding-inline: 28px; font: 600 17px var(--serif); letter-spacing: .12em; }
#printCover { position: absolute; inset: 0; margin: auto; width: min(70vw,52vh); height: fit-content;
  padding: 0; border: 0; background: #335750; box-shadow: 5px 5px #dfd0ac, 8px 8px #34534b, 12px 16px 24px #172d25; }
#printCover canvas { width: 100%; display: block; }
