/* ============================================================
   book.gemert.cn — 书房阅读器样式
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f8f6f0;
  --surface:   #ffffff;
  --border:    #e0dbd0;
  --text:      #2c2416;
  --text-mute: #7a6e5f;
  --accent:    #8b5e3c;
  --accent-lt: #f5ede4;
  --zh-color:  #5a6b5a;
  --zh-bg:     #f0f4f0;
  --radius:    8px;
  --max-w:     720px;
  font-size: 16px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Georgia', 'Times New Roman', serif;
  line-height: 1.8;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Topbar ---- */
#topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
}
.logo {
  font-size: 1.2rem; font-weight: bold;
  color: var(--accent); letter-spacing: 0.05em;
  flex-shrink: 0;
}
.top-nav { display: flex; gap: 16px; flex: 1; }
.top-nav a { font-size: 0.9rem; color: var(--text-mute); font-family: sans-serif; }
.top-nav a:hover { color: var(--accent); text-decoration: none; }
.top-auth { display: flex; align-items: center; gap: 8px; }
.auth-user { font-size: 0.85rem; color: var(--text-mute); font-family: sans-serif; }

/* ---- Buttons ---- */
.btn-ghost {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px 12px;
  font-size: 0.85rem; cursor: pointer; color: var(--text);
  font-family: sans-serif;
}
.btn-ghost:hover { background: var(--accent-lt); border-color: var(--accent); color: var(--accent); }
.btn-primary {
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
  padding: 10px 24px; font-size: 1rem;
  cursor: pointer; width: 100%; margin-top: 8px;
}
.btn-primary:hover { opacity: 0.9; }
.btn-sm {
  background: var(--accent-lt); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 4px;
  padding: 3px 10px; font-size: 0.8rem;
  cursor: pointer; font-family: sans-serif;
}
.btn-sm:hover { background: var(--accent); color: #fff; }

/* ---- Main layout ---- */
#app {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 32px 16px 80px;
}

/* ---- Book list page ---- */
.page-title {
  font-size: 1.5rem; font-weight: bold;
  margin-bottom: 24px; color: var(--text);
  font-family: sans-serif;
}
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}
.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.book-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
.book-cover {
  width: 100%; aspect-ratio: 2/3;
  background: var(--accent-lt);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover-placeholder {
  font-size: 3rem; color: var(--accent); opacity: 0.4;
}
.book-info { padding: 12px; }
.book-title { font-size: 0.95rem; font-weight: bold; line-height: 1.4; margin-bottom: 4px; }
.book-author { font-size: 0.8rem; color: var(--text-mute); font-family: sans-serif; }
.book-meta {
  font-size: 0.75rem; color: var(--text-mute);
  margin-top: 4px; font-family: sans-serif;
}

/* ---- Book detail page ---- */
.book-header {
  margin-bottom: 32px;
}
.book-header-cover {
  float: left; margin-right: 24px; margin-bottom: 16px;
  width: 140px;
}
.book-header-cover img { width: 100%; border-radius: 4px; }
.book-header-cover .placeholder-cover {
  width: 140px; aspect-ratio: 2/3;
  background: var(--accent-lt);
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; font-size: 4rem; color: var(--accent); opacity: 0.4;
}
.book-header h1 { font-size: 1.6rem; line-height: 1.3; }
.book-header h2 { font-size: 1rem; color: var(--text-mute); margin: 4px 0 8px; font-weight: normal; }
.book-header .author { color: var(--text-mute); font-style: italic; font-size: 1rem; }
.book-desc {
  clear: both; margin-top: 16px;
  color: var(--text-mute); font-size: 0.95rem;
  line-height: 1.7;
}
.chapter-list { margin-top: 24px; }
.chapter-list h3 { font-size: 1rem; font-family: sans-serif; margin-bottom: 12px; color: var(--text-mute); }
.chapter-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; margin-bottom: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer; transition: background 0.15s;
}
.chapter-item:hover { background: var(--accent-lt); border-color: var(--accent); }
.chapter-item.unread { opacity: 0.7; }
.ch-num {
  font-size: 0.75rem; font-family: sans-serif;
  color: var(--text-mute); min-width: 32px; flex-shrink: 0;
}
.ch-title { flex: 1; font-size: 0.95rem; }
.ch-words { font-size: 0.75rem; color: var(--text-mute); font-family: sans-serif; }
.ch-continue {
  font-size: 0.7rem; background: var(--accent); color: #fff;
  border-radius: 10px; padding: 1px 8px; font-family: sans-serif;
}

/* ---- Reader page ---- */
.reader-nav {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.reader-nav .back-link { font-size: 0.85rem; font-family: sans-serif; }
.reader-nav .chapter-picker {
  font-size: 0.85rem; padding: 4px 8px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text);
  cursor: pointer;
}
.reader-nav .spacer { flex: 1; }
.view-seg {
  display: flex; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.view-seg button {
  padding: 4px 12px; font-size: 0.8rem;
  background: none; border: none; cursor: pointer;
  font-family: sans-serif; color: var(--text-mute);
}
.view-seg button.active {
  background: var(--accent); color: #fff;
}

.chapter-title {
  font-size: 1.4rem; font-weight: bold;
  margin-bottom: 8px; line-height: 1.3;
}
.chapter-title-zh {
  font-size: 1.1rem; color: var(--text-mute);
  margin-bottom: 24px; font-weight: normal;
}
.chapter-meta {
  font-size: 0.8rem; color: var(--text-mute); font-family: sans-serif;
  margin-bottom: 24px;
}

/* ---- Reader content ---- */
.reader-body { font-size: 1.05rem; line-height: 1.85; }

.para-en {
  margin-bottom: 16px;
  color: var(--text);
}
.para-zh {
  margin-bottom: 20px;
  color: var(--zh-color);
  font-size: 0.95em;
  background: var(--zh-bg);
  border-left: 3px solid #b8ccb8;
  padding: 8px 12px;
  border-radius: 0 4px 4px 0;
  display: none;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  line-height: 1.75;
}

/* View mode classes */
body.view-zh   .para-en  { display: none; }
body.view-zh   .para-zh  { display: block; color: var(--text); background: none; border: none; padding: 0; }
body.view-bi   .para-zh  { display: block; }
body.view-en   .para-zh  { display: none; }

/* Word hover highlight */
.word {
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s;
}
.word:hover { background: #fde68a; }
.word.selected { background: #fde68a; }

/* ---- Reader footer nav ---- */
.reader-footer {
  display: flex; justify-content: space-between;
  margin-top: 40px; padding-top: 20px;
  border-top: 1px solid var(--border);
}
.reader-footer a {
  font-size: 0.9rem; font-family: sans-serif;
  color: var(--accent);
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.reader-footer a:hover { background: var(--accent-lt); text-decoration: none; }

/* ---- Wordbook / Sentencebook ---- */
.notebook-list { display: flex; flex-direction: column; gap: 10px; }
.nb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex; align-items: flex-start; gap: 12px;
}
.nb-card.mastered { opacity: 0.5; }
.nb-main { flex: 1; }
.nb-word { font-size: 1.1rem; font-weight: bold; }
.nb-phonetic { font-size: 0.8rem; color: var(--text-mute); font-style: italic; }
.nb-def { font-size: 0.85rem; color: var(--text-mute); margin-top: 4px; font-family: sans-serif; }
.nb-sent-en { font-size: 0.9rem; }
.nb-sent-zh { font-size: 0.85rem; color: var(--zh-color); font-family: sans-serif; }
.nb-actions { display: flex; flex-direction: column; gap: 4px; }
.nb-actions button {
  background: none; border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 8px; font-size: 0.75rem;
  cursor: pointer; font-family: sans-serif; color: var(--text-mute);
}
.nb-actions button:hover { border-color: var(--accent); color: var(--accent); }
.nb-actions button.mastered-btn.on { background: #e8f5e9; border-color: #81c784; color: #388e3c; }

/* ---- Dict popup ---- */
.dict-popup {
  position: fixed; z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  min-width: 240px; max-width: 360px;
  font-family: sans-serif;
}
.dict-word    { font-size: 1.2rem; font-weight: bold; }
.dict-phonetic { font-size: 0.85rem; color: var(--text-mute); margin-bottom: 8px; }
.dict-body    { font-size: 0.85rem; line-height: 1.6; color: var(--text); white-space: pre-wrap; }
.dict-actions { margin-top: 10px; text-align: right; }

/* ---- Sent bar ---- */
.sent-bar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 8px 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  display: flex; align-items: center; gap: 10px;
  z-index: 150; font-family: sans-serif;
  max-width: calc(100vw - 32px);
}
.sent-bar-text {
  font-size: 0.85rem; color: var(--text-mute);
  max-width: 200px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* ---- Auth modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: 100%; max-width: 360px;
  position: relative;
  font-family: sans-serif;
}
.modal-close {
  position: absolute; top: 12px; right: 16px;
  background: none; border: none; font-size: 1.1rem;
  cursor: pointer; color: var(--text-mute);
}
.modal-tabs { display: flex; gap: 0; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 8px 20px; background: none; border: none;
  cursor: pointer; font-size: 0.95rem; color: var(--text-mute);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; font-size: 0.95rem; width: 100%;
}
.auth-form input:focus { outline: 2px solid var(--accent); }
.form-err { color: #c0392b; font-size: 0.85rem; }
.form-err.hidden { display: none; }

/* ---- Loading / empty states ---- */
.loading { color: var(--text-mute); font-family: sans-serif; padding: 40px 0; text-align: center; }
.empty { color: var(--text-mute); font-family: sans-serif; padding: 40px 0; text-align: center; }

.hidden { display: none !important; }

/* ---- TTS button ---- */
.tts-btn {
  position: fixed; bottom: 16px; right: 16px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 50%;
  width: 44px; height: 44px; font-size: 1.2rem;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 140;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  #app { padding: 20px 12px 80px; }
  #topbar { padding: 0 12px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .book-header-cover { float: none; width: 100px; margin: 0 auto 16px; display: block; }
  .book-header { text-align: center; }
  .reader-body { font-size: 0.98rem; }
  .dict-popup { max-width: calc(100vw - 32px); }
  .sent-bar { bottom: 12px; }
}
