/* 吳記書社 —— 全局样式 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #2a1a10;
  --paper: #f5ead9;
  --gold: #d4a86a;
  --gold-dark: #b08d4f;
  --red: #8c1f28;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Kaiti SC", "KaiTi", "STKaiti", "Noto Serif SC", serif;
  background: var(--ink);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
}

button { touch-action: manipulation; }

/* ===== 着陆页 ===== */
#landing {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: #241811;
  background-image: radial-gradient(ellipse at 50% 40%, #33221610, transparent),
    repeating-linear-gradient(0deg, transparent 0 34px, #ffffff06 34px 35px);
}
#landing.visible { display: flex; }

.landing-inner {
  text-align: center;
  color: var(--gold);
  max-width: 640px;
  padding: 24px;
}

.landing-title {
  /* 固定 2×2：上「吳記」下「書社」，任何宽度都不重新断行 */
  font-size: clamp(40px, 12vw, 48px);
  font-weight: 400;
  margin-bottom: 26px;
  color: #e8c98f;
  display: flex;
  flex-direction: column;
  align-items: center;
  row-gap: 0.1em;
  line-height: 1.2;
}
.landing-title .lt-row {
  letter-spacing: 0.42em;
  padding-left: 0.42em; /* 补偿末字后的字距，保证两字视觉居中 */
}

.landing-sub {
  font-size: 18px;
  letter-spacing: 0.25em;
  margin-bottom: 30px;
  opacity: 0.9;
}

.landing-desc {
  font-size: 15px;
  line-height: 2;
  opacity: 0.75;
  margin-bottom: 14px;
}
.landing-desc.small { font-size: 13px; opacity: 0.55; letter-spacing: 0.12em; }

#enter-btn {
  margin-top: 34px;
  padding: 13px 58px;
  font-size: 17px;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  color: #e8c98f;
  background: transparent;
  border: 1px solid #a67c3f;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.25s;
}
#enter-btn:hover { background: #a67c3f22; border-color: #e8c98f; }

.landing-status {
  margin-top: 22px;
  font-size: 12px;
  letter-spacing: 0.4em;
  opacity: 0.4;
}

/* ===== 顶部按钮 ===== */
#top-bar {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  gap: 8px;
}

#recommend-btn {
  padding: 8px 18px;
  font-size: 14px;
  letter-spacing: 0.15em;
  color: var(--paper);
  background: rgba(42, 26, 16, 0.85);
  border: 1px solid var(--gold-dark);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
#recommend-btn:hover { background: rgba(90, 60, 35, 0.9); }

/* ===== 底部提示 ===== */
#main-hint {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 9px 26px;
  font-size: 14px;
  letter-spacing: 0.1em;
  color: #efe3cc;
  background: rgba(42, 26, 16, 0.82);
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.4s;
  font-family: "Microsoft YaHei", sans-serif;
}

/* ===== 手持操作栏 ===== */
#holding-bar {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: none;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: rgba(42, 26, 16, 0.9);
  border: 1px solid var(--gold-dark);
  border-radius: 10px;
}
#holding-bar.visible { display: flex; }

#holding-title {
  color: #f0dfc0;
  font-size: 16px;
  letter-spacing: 0.08em;
  max-width: 200px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#btn-read, #btn-putback {
  padding: 7px 16px;
  font-size: 14px;
  letter-spacing: 0.1em;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--gold-dark);
  transition: all 0.2s;
}
#btn-read { background: var(--red); color: #f5ead9; border-color: #b0555c; }
#btn-read:hover { background: #a8323c; }
#btn-putback { background: transparent; color: #e8c98f; }
#btn-putback:hover { background: #a67c3f22; }

/* ===== 悬停提示 ===== */
#hover-tip {
  position: fixed;
  z-index: 15;
  display: none;
  padding: 8px 14px;
  background: rgba(30, 20, 12, 0.92);
  color: #f0dfc0;
  font-size: 13px;
  border: 1px solid var(--gold-dark);
  border-radius: 6px;
  pointer-events: none;
  max-width: 260px;
}
#hover-tip b { color: #e8c98f; font-size: 14px; }
#hover-tip span { display: block; margin-top: 3px; font-size: 11px; opacity: 0.6; }

/* ===== 店主荐书 ===== */
#rec-dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20, 12, 6, 0.45);
}
#rec-dialog.visible { display: flex; }

.rec-box {
  position: relative;
  width: min(430px, 88vw);
  padding: 30px 32px;
  background: #f7efdd;
  border: 2px solid var(--gold-dark);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.4);
}

.rec-title {
  font-size: 14px;
  letter-spacing: 0.4em;
  color: var(--red);
  margin-bottom: 16px;
  border-bottom: 1px dashed #c9b088;
  padding-bottom: 10px;
}

#rec-text {
  font-size: 17px;
  line-height: 1.9;
  color: #3a2a18;
}

#rec-result {
  display: none;
  margin-top: 16px;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.8;
  background: #efe2c4;
  border-radius: 6px;
  color: #4a3520;
}
#rec-result b { color: var(--red); }
#rec-result span { font-size: 13px; opacity: 0.7; }

.rec-actions {
  margin-top: 22px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}
.rec-actions button {
  padding: 9px 22px;
  font-size: 14px;
  letter-spacing: 0.1em;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--gold-dark);
}
#rec-accept { background: var(--red); color: #f5ead9; border-color: #b0555c; }
#rec-accept:hover { background: #a8323c; }
#rec-decline { background: transparent; color: #6a5030; }
#rec-decline:hover { background: #e5d5b5; }

.rec-x {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 16px;
  color: #9a7a4a;
  cursor: pointer;
}

/* ===== 阅读器 ===== */
#reader {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  flex-direction: column;
  background: rgba(24, 15, 8, 0.94);
}
#reader.visible { display: flex; }

.reader-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 30px 12px;
}
.reader-meta { display: flex; align-items: baseline; gap: 14px; }
#reader-title { font-size: 22px; color: #e8c98f; letter-spacing: 0.1em; }
#reader-author { font-size: 13px; color: #a8906a; }

#reader-close {
  padding: 8px 18px;
  font-size: 14px;
  letter-spacing: 0.1em;
  color: #e8c98f;
  background: transparent;
  border: 1px solid var(--gold-dark);
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
}
#reader-close:hover { background: #a67c3f22; }

.reader-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.reader-page {
  width: min(560px, 88vw);
  height: min(680px, 74vh);
  background: linear-gradient(150deg, #fbf5e6, #f3ead3);
  border-radius: 3px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.55), inset 0 0 60px #e5d8b855;
  padding: 52px 48px;
  overflow-y: auto;
  color: #3a2a18;
  font-size: 17px;
  line-height: 2.1;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.reader-page.flip-next { transform: translateX(-46px) rotateY(-9deg); opacity: 0; }
.reader-page.flip-prev { transform: translateX(46px) rotateY(9deg); opacity: 0; }

.reader-page::-webkit-scrollbar { width: 6px; }
.reader-page::-webkit-scrollbar-thumb { background: #cbb98f; border-radius: 3px; }

/* 书页内部 */
.rp-heading {
  font-size: 15px;
  letter-spacing: 0.45em;
  color: var(--red);
  margin-bottom: 22px;
  text-align: center;
}
.reader-page p { margin-bottom: 20px; text-align: justify; }
.rp-quote {
  font-size: 19px;
  line-height: 2.3;
  color: #4a3518;
  text-align: center !important;
  padding: 26px 8px;
}
.rp-sign { text-align: right !important; color: #8a6a40; font-size: 15px; }

.rp-title {
  font-size: 34px;
  letter-spacing: 0.18em;
  text-align: center;
  margin-top: 130px;
  color: #2a1a10;
}
.rp-author {
  text-align: center;
  margin-top: 26px;
  font-size: 16px;
  letter-spacing: 0.2em;
  color: #6a5030;
}
.rp-cat {
  text-align: center;
  margin-top: 60px;
  font-size: 13px;
  letter-spacing: 0.15em;
  color: #a8906a;
}

.rp-back { text-align: center; padding-top: 60px; }
.rp-back-title { font-size: 26px; letter-spacing: 0.2em; color: #2a1a10; }
.rp-back-author { margin-top: 12px; font-size: 14px; color: #6a5030; letter-spacing: 0.15em; }
.rp-back-blurb {
  margin-top: 34px;
  text-align: justify !important;
  font-size: 15px;
  color: #4a3a24;
}
.rp-back-mark {
  margin-top: 44px;
  font-size: 12px;
  letter-spacing: 0.3em;
  color: #a8906a;
}

.rp-cover-img {
  width: 82%;
  aspect-ratio: 320 / 448;
  margin: 12px auto 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 2px;
  box-shadow: 0 8px 26px rgba(60, 40, 15, 0.3);
}
.page-cover-page { display: flex; }

.reader-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 16px 0 26px;
}
.reader-foot button {
  padding: 9px 24px;
  font-size: 14px;
  letter-spacing: 0.1em;
  color: #e8c98f;
  background: transparent;
  border: 1px solid var(--gold-dark);
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
}
.reader-foot button:hover { background: #a67c3f22; }
#reader-indicator {
  color: #a8906a;
  font-size: 14px;
  letter-spacing: 0.2em;
  min-width: 70px;
  text-align: center;
}

/* ===== 读者留言 ===== */
#guestbook-btn {
  padding: 8px 18px;
  font-size: 14px;
  letter-spacing: 0.15em;
  color: var(--paper);
  background: rgba(42, 26, 16, 0.85);
  border: 1px solid var(--gold-dark);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
#guestbook-btn:hover { background: rgba(90, 60, 35, 0.9); }

#guestbook-dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20, 12, 6, 0.55);
}
#guestbook-dialog.visible { display: flex; }

.gb-box {
  position: relative;
  width: min(480px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 30px;
  background: #f7efdd;
  border: 2px solid var(--gold-dark);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.4);
}

.gb-title {
  font-size: 15px;
  letter-spacing: 0.4em;
  color: var(--red);
  margin-bottom: 8px;
  border-bottom: 1px dashed #c9b088;
  padding-bottom: 10px;
}
.gb-sub {
  font-size: 13px;
  color: #7a6540;
  margin-bottom: 18px;
  line-height: 1.6;
}

.gb-row { margin-bottom: 14px; }
.gb-row label {
  display: block;
  font-size: 13px;
  color: #5a4528;
  margin-bottom: 5px;
  letter-spacing: 0.05em;
}
.gb-row input, .gb-row textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: #3a2a18;
  background: #fdf9f0;
  border: 1px solid #c9b088;
  border-radius: 5px;
  transition: border-color 0.2s;
}
.gb-row input:focus, .gb-row textarea:focus {
  outline: none;
  border-color: var(--gold-dark);
}
.gb-row textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.7;
}
.gb-count {
  text-align: right;
  font-size: 12px;
  color: #a8906a;
  margin-top: 4px;
}

.gb-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
}
#gb-submit {
  padding: 12px 48px;
  font-size: 15px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: #f5ead9;
  background: var(--red);
  border: 1px solid #b0555c;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
#gb-submit:hover:not(:disabled) { background: #a8323c; }
#gb-submit:disabled { opacity: 0.6; cursor: not-allowed; }

#gb-status {
  margin-top: 14px;
  text-align: center;
  font-size: 13px;
  min-height: 20px;
  line-height: 1.6;
}
.gb-ok { color: #2d6a4f; }
.gb-err { color: var(--red); }

.gb-x {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 18px;
  color: #9a7a4a;
  cursor: pointer;
}

/* ===== 留言板便签层 ===== */
#bulletin-notes {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  display: none; /* 3D 场景中由 JS 控制显示 */
}
.bn-note {
  position: absolute;
  width: 140px;
  padding: 8px 10px;
  background: #f4d35e;
  box-shadow: 2px 3px 8px rgba(0,0,0,0.25);
  font-size: 11px;
  line-height: 1.5;
  color: #3a2a18;
  transform: rotate(var(--r, 0deg));
  overflow: hidden;
}
.bn-head { margin-bottom: 4px; }
.bn-name { font-weight: bold; font-size: 12px; }
.bn-from { font-size: 10px; opacity: 0.7; margin-left: 4px; }
.bn-body { font-size: 11px; opacity: 0.9; }
.bn-book { font-size: 10px; margin-top: 4px; opacity: 0.75; }

/* ===== 移动端（触屏）===== */
.touch-only { display: none; }
#touch-ui { display: none; }

body.is-touch .touch-only { display: block; }
body.is-touch #touch-ui { display: block; }

/* 底部提示移到顶部居中，避免与摇杆抢位置 */
body.is-touch #main-hint {
  top: 60px;
  bottom: auto;
  font-size: 12px;
  padding: 7px 16px;
  opacity: 0.82;
  white-space: nowrap;
}

/* 虚拟摇杆 */
#joy-base {
  position: fixed;
  left: calc(24px + env(safe-area-inset-left));
  bottom: calc(28px + env(safe-area-inset-bottom));
  width: 118px;
  height: 118px;
  border-radius: 50%;
  z-index: 18;
  touch-action: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(212, 168, 106, 0.14), rgba(42, 26, 16, 0.38) 72%);
  border: 2px solid rgba(212, 168, 106, 0.55);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.35);
}
#joy-base.active { border-color: rgba(232, 201, 143, 0.9); }
#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, rgba(240, 220, 180, 0.95), rgba(176, 141, 79, 0.82));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.05s linear;
  pointer-events: none;
}

/* 手持栏抬到摇杆上方 */
body.is-touch #holding-bar {
  bottom: calc(162px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px);
  gap: 10px;
  padding: 9px 14px;
}
body.is-touch #holding-title { max-width: 34vw; font-size: 14px; }
body.is-touch #btn-read,
body.is-touch #btn-putback { padding: 10px 14px; }

/* 阅读器内允许滚动/选择 */
.reader-page {
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
}

@media (pointer: coarse) {
  #recommend-btn { min-height: 40px; padding: 10px 16px; }

  .landing-sub { font-size: 16px; margin-bottom: 22px; }
  .landing-desc { font-size: 14px; line-height: 1.9; }
  #enter-btn { min-height: 50px; padding: 13px 42px; }

  /* 荐书对话框按钮加大触控区 */
  .rec-actions button { min-height: 46px; padding: 10px 20px; }
  .rec-x { min-width: 44px; min-height: 44px; }

  /* 阅读器手机布局 */
  .reader-head { padding: 12px 16px 8px; gap: 10px; }
  .reader-meta { gap: 8px; flex-wrap: wrap; }
  #reader-title { font-size: 17px; letter-spacing: 0.05em; }
  #reader-author { font-size: 12px; }
  #reader-close { min-height: 42px; padding: 8px 14px; }

  .reader-page {
    width: 94vw;
    height: calc(100dvh - 150px);
    padding: 26px 20px;
    font-size: 16px;
    line-height: 2;
  }
  .rp-title { font-size: 26px; margin-top: 44px; }
  .rp-quote { font-size: 17px; padding: 18px 6px; }
  .rp-cover-img { width: 70%; }

  .reader-foot { gap: 12px; padding: 8px 0 16px; }
  .reader-foot button { min-height: 46px; padding: 10px 18px; }
  #reader-indicator { font-size: 12px; min-width: 52px; }
}
