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

:root {
  --bg: #f5f0eb;
  --surface: #fff;
  --text: #2c2c2c;
  --text-secondary: #666;
  --accent: #8b4513;
  --accent-light: #a0522d;
  --border: #ddd;
  --highlight: #fff3cd;
  --match-bg: #e8f4fd;
  --match-current: #ffd700;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 8px;
  --font: "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", serif;
  --font-sans: "PingFang SC", "Microsoft YaHei", sans-serif;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  min-height: 100vh;
}

/* Header */
header {
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.logo:hover { color: var(--accent-light); }

/* Search area */
.search-area {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.search-area input {
  flex: 1;
  min-width: 120px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  outline: none;
}

.search-area input:focus { border-color: var(--accent); }

.search-area button {
  padding: 6px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8125rem;
  white-space: nowrap;
  font-family: var(--font-sans);
}

.search-area button:hover { background: var(--accent-light); }

.search-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-left: 4px;
  flex-wrap: wrap;
}

.search-nav span { white-space: nowrap; }

.search-nav button {
  padding: 4px 8px;
  font-size: 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.search-nav button:hover { background: var(--border); }

/* Main content */
#main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* Loading */
.loading {
  text-align: center;
  padding: 60px 0;
  color: var(--text-secondary);
  font-family: var(--font-sans);
}

.error {
  text-align: center;
  padding: 60px 0;
  color: #c00;
  font-family: var(--font-sans);
}

/* Books grid */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.book-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, box-shadow 0.15s;
}

.book-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.book-name {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.book-count {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
}

/* Articles list */
.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--accent);
}

.articles-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.article-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 20px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.1s;
}

.article-item:hover { background: #faf5ef; }

.article-item .title { font-size: 0.9375rem; }

.article-item .count {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  white-space: nowrap;
  margin-left: 12px;
}

/* Back link */
.back-link {
  display: inline-block;
  margin-bottom: 16px;
  font-size: 0.875rem;
  color: var(--accent);
  text-decoration: none;
  font-family: var(--font-sans);
}

.back-link:hover { text-decoration: underline; }

/* Reader */
.reader-header {
  margin-bottom: 24px;
}

.reader-book {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
}

.reader-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.paragraph-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  padding: 20px 24px;
  scroll-margin-top: 80px;
}

.paragraph-wrap.has-match {
  border-left: 3px solid #6c757d;
}

.paragraph-wrap.current-match {
  border-left: 3px solid var(--match-current);
  background: #fefef0;
}

.para-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.para-num {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: var(--font-sans);
}

.toggle-btn {
  padding: 3px 10px;
  font-size: 0.75rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.1s;
}

.toggle-btn:hover, .toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.para-text {
  font-size: 1rem;
  line-height: 1.9;
  text-align: justify;
}

.vanilla-text { color: var(--text); }

.trans-text {
  color: var(--text-secondary);
  font-family: var(--font-sans);
  line-height: 1.8;
}

.anno-word {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.anno-word:hover {
  color: var(--accent-light);
  background: #fef0e0;
  border-radius: 2px;
}

.explain-section {
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
}

.explain-group {
  margin-top: 8px;
}

.explain-label {
  display: block;
  font-weight: 600;
  color: #6b4e3a;
  margin-bottom: 4px;
  font-size: 0.8125rem;
}

.explain-item {
  display: inline-block;
  background: #f8f4ef;
  border: 1px solid #e8ddd0;
  border-radius: 4px;
  padding: 2px 8px;
  margin: 3px 4px 3px 0;
  color: #5a4636;
  line-height: 1.6;
}

.explain-word {
  font-weight: 600;
  color: #8b4513;
}

.place-notes {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
}

.notes-label {
  font-weight: 600;
  color: var(--text-secondary);
}

.place-item {
  display: block;
  color: #555;
  margin-top: 4px;
}

/* Match highlight in text */
.match-highlight {
  background: var(--match-current);
  padding: 0 2px;
  border-radius: 2px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
}

.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  max-width: 480px;
  width: calc(100% - 40px);
  max-height: 70vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 1rem;
}

.modal-close {
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 16px 20px 20px;
  font-size: 0.9375rem;
  line-height: 1.8;
}

/* Responsive */
@media (max-width: 640px) {
  .header-inner { padding: 10px 14px; }
  #main { padding: 16px 14px; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .book-card { padding: 14px; }
  .book-name { font-size: 1rem; }
  .paragraph-wrap { padding: 14px 16px; }
  .para-text { font-size: 0.9375rem; }
  .search-nav { width: 100%; }
}
