/* BooksReader · 纯前端版 —— 提夫尼蓝阅读主题 */

:root {
  --bg:        #A8E6DF;
  --bg-deep:   #7FD2C8;
  --bg-soft:   #CBF2ED;
  --paper:     #F8FFFE;
  --paper-2:   #EEFBF9;
  --ink:       #0D3B3B;
  --ink-2:     #2F6B67;
  --ink-3:     #5C8E8A;
  --accent:    #0B6E66;
  --accent-2:  #0A8B7E;
  --line:      rgba(13, 59, 59, .13);
  --shadow:    0 10px 30px rgba(9, 74, 70, .13);
  --reader-font: 19px;
  --reader-lh: 1.95;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1200px 600px at 10% -10%, #D9F7F3 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 110%, #86DCD2 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-soft) 0%, var(--bg) 55%, var(--bg-deep) 100%);
}

#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.view { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; }
.view.active { display: flex; }
.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

.ghost-btn {
  padding: 7px 13px; border-radius: 999px;
  background: rgba(255,255,255,.58);
  border: 1px solid var(--line);
  color: var(--accent);
  font-size: 13px; font-weight: 600;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}
.ghost-btn:hover { background: rgba(255,255,255,.9); }
.ghost-btn:active { transform: scale(.96); }
.ghost-btn.on { background: var(--accent); color: #fff; border-color: transparent; }
.ghost-btn:disabled { opacity: .45; cursor: default; transform: none; }
.danger-btn { color: #A33A34; border-color: rgba(163,58,52,.25); }
.danger-btn.on, .danger-btn:not(:disabled):hover { background: #A33A34; color: #fff; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 18px; line-height: 1;
  color: var(--accent);
  background: rgba(255,255,255,.6);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.icon-btn:hover { background: #fff; }

/* ══ 书库 ══ */
.lib-head {
  flex: 0 0 auto;
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  padding: 26px 30px 14px;
}
.lib-head h1 { margin: 0; font-size: 26px; letter-spacing: .3px; color: var(--ink); }
.lib-meta { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); }
.lib-actions {
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; justify-content: flex-end;
}
.lib-actions .ghost-btn b { color: var(--accent-2); font-weight: 800; }

.book-grid {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 8px 30px 40px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px; align-content: start;
  -webkit-overflow-scrolling: touch;
}

.book-card {
  position: relative;
  display: flex; flex-direction: column; gap: 12px;
  padding: 20px 20px 16px;
  border-radius: 18px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(255,255,255,.9);
  box-shadow: 0 8px 24px rgba(9,74,70,.10);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  overflow: hidden;
}
.book-card::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: linear-gradient(180deg, #0FA497, #0B6E66); opacity: .85;
}
.book-card:hover { transform: translateY(-3px); box-shadow: 0 14px 32px rgba(9,74,70,.16); }
.book-card:active { transform: translateY(-1px) scale(.995); }
.book-card.selectable { padding-left: 52px; }
.book-card.selected {
  background: rgba(230,255,251,.96);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(11,110,102,.2), 0 12px 28px rgba(9,74,70,.15);
}
.bc-select {
  position: absolute; left: 16px; top: 18px;
  width: 23px; height: 23px; border-radius: 7px;
  display: grid; place-items: center;
  border: 1.5px solid rgba(11,110,102,.38);
  background: rgba(255,255,255,.7);
  color: transparent; font-size: 14px; font-weight: 800;
}
.book-card.selected .bc-select {
  color: #fff; border-color: var(--accent); background: var(--accent);
}

.bc-title { font-size: 16.5px; font-weight: 700; line-height: 1.45; color: var(--ink); padding-left: 8px; }
.bc-sub { font-size: 12px; color: var(--ink-3); padding-left: 8px; }
.bc-progress { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-left: 8px; }
.bc-bar { height: 5px; border-radius: 3px; background: rgba(11,110,102,.13); overflow: hidden; }
.bc-bar > i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg,#0FA497,#0B6E66); }
.bc-row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-3); }
.bc-cta {
  align-self: flex-start; margin-left: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 12.5px; font-weight: 600;
}
.bc-tag {
  position: absolute; right: 14px; top: 14px;
  font-size: 10.5px; color: var(--accent);
  background: rgba(11,110,102,.12);
  padding: 2px 8px; border-radius: 999px;
}

.empty { padding: 60px 30px; text-align: center; color: var(--ink-2); }
.empty .dim { color: var(--ink-3); font-size: 13px; }
.empty code { background: rgba(255,255,255,.7); padding: 2px 6px; border-radius: 5px; }

/* ══ 阅读器 ══ */
.reader-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: rgba(255,255,255,.55);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.rh-mid { flex: 1 1 auto; min-width: 0; }
.rh-title { font-size: 14.5px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rh-chapter { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.rh-tools { display: flex; gap: 6px; flex: 0 0 auto; }

.page-area {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 22px 18px 10px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  position: relative;
}
.page-content {
  max-width: 46em; margin: 0 auto;
  padding: 34px 40px 44px;
  background: var(--paper);
  border-radius: 16px;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: var(--reader-font);
  line-height: var(--reader-lh);
  letter-spacing: .1px;
  min-height: 60vh;
  user-select: text; -webkit-user-select: text;
  touch-action: manipulation;
}
.page-content p {
  margin: 0 0 1.05em;
  text-align: justify;
  hyphens: auto;
  border-radius: 6px;
  transition: background .2s;
}
.page-content p:last-child { margin-bottom: 0; }
.page-content p.speaking {
  background: rgba(15, 164, 151, .12);
  box-shadow: -6px 0 0 rgba(15,164,151,.55);
}
.page-content .page-empty { color: var(--ink-3); text-align: center; padding: 60px 0; font-size: 14px; }

.page-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(200,242,237,.75);
  color: var(--accent); font-size: 14px; font-weight: 600;
  backdrop-filter: blur(2px);
}

.reader-foot {
  flex: 0 0 auto;
  padding: 6px 18px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.55);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.progress-track { height: 4px; border-radius: 2px; background: rgba(11,110,102,.15); overflow: hidden; margin-bottom: 8px; }
.progress-track > div { height: 100%; width: 0%; background: linear-gradient(90deg,#11A99B,#0B6E66); border-radius: 2px; transition: width .2s ease; }
.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.page-btn {
  padding: 8px 16px; border-radius: 999px;
  background: rgba(255,255,255,.7);
  border: 1px solid var(--line);
  color: var(--accent); font-size: 13px; font-weight: 600;
}
.page-btn:disabled { opacity: .38; cursor: default; }
.page-label { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ══ 抽屉 ══ */
.mask { position: fixed; inset: 0; z-index: 90; background: rgba(8,48,46,.28); backdrop-filter: blur(1.5px); }
.drawer {
  position: fixed; z-index: 100; top: 0; right: 0; bottom: 0;
  width: min(360px, 86vw);
  background: #F6FFFD;
  box-shadow: -10px 0 30px rgba(9,74,70,.18);
  transform: translateX(102%);
  transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 6px; }
.tab { padding: 7px 16px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-3); }
.tab.active { background: var(--accent); color: #fff; }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 10px 10px 30px; }
.drawer-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; cursor: pointer; color: var(--ink); font-size: 13.5px; line-height: 1.5; }
.drawer-item:hover { background: rgba(11,110,102,.08); }
.drawer-item.current { background: rgba(11,110,102,.14); font-weight: 700; }
.drawer-item .pg { flex: 0 0 auto; font-size: 11px; color: var(--ink-3); min-width: 44px; font-variant-numeric: tabular-nums; }
.drawer-item .del { flex: 0 0 auto; margin-left: auto; width: 26px; height: 26px; border-radius: 50%; color: #A33; font-size: 15px; background: rgba(200,60,60,.08); }
.drawer-empty { padding: 40px 16px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ══ 单词卡 ══ */
.word-card {
  position: fixed; z-index: 110; left: 50%; bottom: 0;
  transform: translate(-50%, 105%);
  width: min(560px, 92vw); max-height: 72vh; overflow-y: auto;
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(9,74,70,.22);
  transition: transform .24s cubic-bezier(.2,.9,.3,1);
  padding: 18px 20px calc(22px + env(safe-area-inset-bottom));
}
.word-card.open { transform: translate(-50%, 0); }
.wc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.wc-word { font-size: 24px; font-weight: 800; color: var(--ink); letter-spacing: .2px; }
.wc-phon { display: flex; gap: 14px; margin-top: 4px; font-size: 12.5px; color: var(--ink-3); }
.wc-actions { display: flex; gap: 10px; margin: 14px 0 6px; flex-wrap: wrap; }
.play-btn { padding: 8px 16px; border-radius: 999px; background: rgba(11,110,102,.10); color: var(--accent); font-size: 13px; font-weight: 600; border: 1px solid rgba(11,110,102,.18); }
.play-btn:hover { background: rgba(11,110,102,.18); }
.wc-body { margin-top: 6px; }
.wc-def { padding: 10px 0; border-top: 1px solid var(--line); }
.wc-def:first-child { border-top: none; }
.wc-pos { display: inline-block; margin-right: 8px; font-size: 11px; font-weight: 700; color: #fff; background: var(--accent-2); padding: 2px 8px; border-radius: 999px; vertical-align: 2px; }
.wc-zh { font-size: 15px; font-weight: 700; color: var(--ink); }
.wc-en { font-size: 13px; color: var(--ink-2); margin-top: 5px; line-height: 1.65; }
.wc-ex { margin-top: 12px; padding: 12px 14px; background: var(--paper-2); border-left: 3px solid var(--accent-2); border-radius: 0 10px 10px 0; font-size: 13px; line-height: 1.7; color: var(--ink-2); }
.wc-approx { font-size: 11.5px; color: #A15C00; margin-bottom: 6px; }
.wc-error { padding: 16px 0; color: var(--ink-3); font-size: 13.5px; }

.toast {
  position: fixed; left: 50%; bottom: 78px;
  transform: translate(-50%, 20px);
  background: rgba(11,60,58,.9); color: #fff;
  padding: 9px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ══ 生词本 ══ */
.vocab-list { margin-top: 8px; max-height: 50vh; overflow-y: auto; }
.vocab-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.vocab-item:hover { background: rgba(11,110,102,.06); }
.vi-w { font-size: 15px; font-weight: 700; color: var(--ink); min-width: 92px; }
.vi-zh {
  font-size: 13px; color: var(--ink-2);
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.vi-del {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  color: #A33; font-size: 15px; background: rgba(200,60,60,.08);
}
.vocab-empty { padding: 40px 12px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ══ 同步 ══ */
.sync-input {
  width: 100%; margin: 10px 0 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  letter-spacing: .5px;
}
.sync-input:focus { outline: none; border-color: var(--accent-2); }
.sync-info {
  margin-top: 10px; font-size: 12.5px; color: var(--ink-3);
  line-height: 1.7; word-break: break-all;
}
.hint { font-size: 12.5px; color: var(--ink-3); line-height: 1.7; margin: 8px 0 0; }
.rate-range {
  width: 100%;
  margin: 6px 0 4px;
  accent-color: var(--accent);
}
select.sync-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent) 50%),
    linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* ══ 手机 / 平板 ══ */
@media (max-width: 820px) {
  .lib-head { padding: 18px 16px 10px; }
  .lib-head h1 { font-size: 21px; }
  .lib-actions .ghost-btn { padding: 6px 10px; font-size: 12px; }
  .book-grid { padding: 6px 14px 30px; gap: 12px; grid-template-columns: 1fr; }

  .reader-head { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .rh-mid { order: 2; flex: 1 1 100%; }
  .rh-title { font-size: 13px; }
  .rh-chapter { font-size: 10.5px; }
  .rh-tools { order: 3; width: 100%; justify-content: space-between; gap: 4px; }
  .ghost-btn { padding: 6px 9px; font-size: 12px; }
  .icon-btn { width: 32px; height: 32px; font-size: 16px; }

  .page-area { padding: 10px 8px 6px; }
  .page-content { padding: 22px 18px 30px; border-radius: 12px; max-width: none; min-height: 50vh; }

  .reader-foot { padding: 5px 12px calc(8px + env(safe-area-inset-bottom)); }
  .page-btn { padding: 7px 13px; font-size: 12.5px; }
  .word-card { width: 100vw; border-radius: 18px 18px 0 0; max-height: 76vh; }
}

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