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

body {
  font-family: 'Noto Serif SC', 'SimSun', serif;
  background: #faf8f3;
  color: #2c2c2c;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: #3d2b1f;
  color: #f5e6c8;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

#site-logo {
  height: 48px;
  width: 48px;
  object-fit: contain;
  border-radius: 4px;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.1em;
}

#nav-toggle {
  font-size: 1.1rem;
  background: none;
  border: 1px solid #c9a97a55;
  border-radius: 4px;
  color: #f5e6c8;
  padding: 3px 10px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s;
}

#nav-toggle:hover { background: rgba(255,255,255,0.1); }

.legend {
  margin-left: auto;
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 13px;
  height: 13px;
  border-radius: 3px;
}

.dot-shici { background: #f5c842; }
.dot-xuci  { background: #7ecfb3; }
.dot-key   { background: #ff8c00; }

/* ── Three-column layout ── */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 49px);
  transition: grid-template-columns 0.2s ease;
}

.layout.nav-hidden {
  grid-template-columns: 0px 1fr;
}

/* ── Left nav panel ── */
.panel-text {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid #ddd;
  transition: width 0.2s ease;
}

.layout.nav-hidden .panel-text {
  border-right: none;
}

#nav-search-box {
  background: #f0e8dc;
  padding: 8px 10px;
  flex-shrink: 0;
}

#nav-search {
  width: 100%;
  box-sizing: border-box;
  background: #faf5ee;
  border: 1px solid #d4b896;
  border-radius: 6px;
  color: #4a3020;
  font-size: 0.88rem;
  padding: 6px 10px;
  outline: none;
}
#nav-search::placeholder { color: #b09070; }
#nav-search:focus { border-color: #a07850; }

#article-nav {
  background: #f5ede0;
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

.nav-period-header {
  font-size: 1rem;
  font-weight: 700;
  color: #5a3010;
  letter-spacing: 0.15em;
  padding: 12px 16px 6px;
  border-bottom: 1px solid #d4b896;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.nav-period-header:hover { color: #3a1e08; }

.nav-period-arrow {
  font-size: 0.75rem;
  color: #a07850;
  transition: transform 0.2s;
}
.nav-period.collapsed .nav-period-arrow {
  transform: rotate(-90deg);
}

.nav-period-body {
  overflow: hidden;
  max-height: 2000px;
  transition: max-height 0.3s ease;
}
.nav-period.collapsed .nav-period-body {
  max-height: 0;
}

.nav-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px 7px 28px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #3a2010;
  cursor: pointer;
  background: rgba(160,120,80,0.07);
  border-top: 1px solid rgba(160,120,80,0.15);
  user-select: none;
  transition: background 0.15s;
}

.nav-category-header:hover { background: rgba(160,120,80,0.15); }

.nav-cat-arrow {
  font-size: 0.75rem;
  transition: transform 0.2s;
  color: #a07850;
}

.nav-category.collapsed .nav-cat-arrow {
  transform: rotate(-90deg);
}

.nav-category-body {
  overflow: hidden;
  max-height: 500px;
  transition: max-height 0.25s ease;
}

.nav-category.collapsed .nav-category-body {
  max-height: 0;
}
.nav-category.search-expanded .nav-category-body {
  max-height: none;
}

.nav-group-header {
  font-size: 0.82rem;
  color: #9a7050;
  padding: 6px 16px 3px 22px;
  font-style: italic;
  letter-spacing: 0.05em;
}

.nav-article-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 28px;
  font-size: 0.88rem;
  color: #4a3020;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}

.nav-article-item:hover {
  background: rgba(160,120,80,0.1);
}

.nav-article-item.active {
  background: rgba(160,120,80,0.18);
  border-left-color: #a07850;
  color: #2a1808;
  font-weight: 600;
}

.nav-num {
  font-size: 0.72rem;
  background: #ddc8a8;
  color: #6a4820;
  padding: 1px 6px;
  border-radius: 8px;
  flex-shrink: 0;
  min-width: 22px;
  text-align: center;
}

.nav-article-item.active .nav-num {
  background: #c9a97a;
  color: #2c2c2c;
}

/* ── Middle text panel ── */
#article-body {
  overflow-y: auto;
  padding: 24px 52px;
  border-right: 1px solid #ddd;
}

.article-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  border-bottom: 2px solid #c9a97a;
  padding-bottom: 8px;
}

#prev-article, #next-article {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #8b6340;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s, color 0.15s;
}
#prev-article:hover, #next-article:hover {
  opacity: 1;
  color: #3d2b1f;
}

#article-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: #3d2b1f;
  flex: 1;
}

#bg-toggle {
  flex-shrink: 0;
  font-size: 0.85rem;
  padding: 2px 8px;
  border: 1px solid #a07850;
  border-radius: 10px;
  background: transparent;
  color: #7a5530;
  cursor: pointer;
  line-height: 1.6;
}
#bg-toggle:hover { background: #f5ece0; }

/* ── Background side drawer ── */
.bg-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  background: #fdf6ec;
  border-left: 3px solid #c9a97a;
  box-shadow: -4px 0 20px rgba(0,0,0,0.12);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 200;
  overflow-y: auto;
  padding: 48px 24px 32px;
  box-sizing: border-box;
}
.bg-drawer.open { transform: translateX(0); }

#map-drawer {
  width: 520px;
}

#map-drawer-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #7a5530;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
#map-drawer-close:hover { background: #f0e8d8; }

#map-drawer-content img {
  width: 100%;
  border-radius: 6px;
  margin-top: 8px;
}

#map-toggle {
  flex-shrink: 0;
  font-size: 0.85rem;
  padding: 2px 8px;
  border: 1px solid #5a8a50;
  border-radius: 10px;
  background: transparent;
  color: #3a6030;
  cursor: pointer;
  line-height: 1.6;
}
#map-toggle:hover { background: #eaf5e0; }

#bg-drawer-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #7a5530;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
#bg-drawer-close:hover { background: #f0e8d8; }

#bg-drawer-content {
  font-size: 1.05rem;
  color: #4a3520;
  line-height: 1.9;
}
#bg-drawer-content h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #3d2b1f;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid #c9a97a;
}
#bg-drawer-content p {
  margin: 0 0 12px;
  text-indent: 2em;
}

#text-display {
  font-size: 1.8rem;
  line-height: 2.4;
  text-align: justify;
}

#text-display .text-para {
  margin-bottom: 1.5em;
  text-indent: 2em;
}
}

mark {
  border-radius: 2px;
  padding: 1px 0;
  cursor: pointer;
}

mark.mark-shici { background: #faeea0; color: #2c2c2c; }
mark.mark-shici:hover { background: #f5e070; }
mark.mark-xuci { background: #c8ede3; color: #1a3a2c; }
mark.mark-xuci:hover { background: #a8ddd0; }
mark.mark-key { background: #ff8c00; color: #fff; font-weight: 700; }
mark.mark-key:hover { background: #e07800; }
mark.mark-annotation {
  background: #f2eafa;
  color: #5a3a7a;
  cursor: default;
  position: relative;
  display: inline;
  padding: 0 1px;
}
mark.mark-annotation:hover { background: #e6d5f7; }

.ann-phonetic {
  font-size: 0.6em;
  color: #7a4a9c;
  vertical-align: 0.1em;
}

ruby.phonetic-only {
  display: inline-ruby;
  ruby-position: over;
}
ruby.phonetic-only rt {
  font-size: 0.5em;
  color: #7a4a9c;
  line-height: 1.2;
  text-align: center;
}

mark.mark-annotation::after {
  content: attr(data-annotation);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #3a1a5c;
  color: #fff;
  font-size: 0.78em;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: normal;
  width: max-content;
  max-width: 260px;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}
mark.mark-annotation:hover::after { opacity: 1; }

.key-sentence {
  text-decoration: underline;
  text-decoration-style: dashed;
  text-decoration-color: #e07800;
  text-underline-offset: 4px;
}

/* ── Right results panel ── */
.panel-results {
  overflow-y: auto;
  padding: 24px 24px;
  background: #fefcf8;
}

/* Word detail view */
.word-detail { padding: 4px 0; }
.word-detail.hidden { display: none; }
#results.hidden { display: none; }

#detail-back {
  font-family: inherit;
  font-size: 0.85rem;
  background: none;
  border: 1px solid #c9a97a;
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
  color: #3d2b1f;
  margin-bottom: 20px;
  display: inline-block;
}
#detail-back:hover { background: #f5e6c8; }

.detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.detail-word {
  font-size: 1.8rem !important;
  padding: 4px 14px !important;
}

.detail-type-badge {
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
}

.detail-section { margin-bottom: 20px; }

.detail-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #999;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  border-bottom: 1px solid #e8e0d0;
  padding-bottom: 4px;
}

/* Usage blocks */
.usage-block {
  margin-bottom: 10px;
  border: 1px solid #e8e0d0;
  border-radius: 6px;
  overflow: hidden;
}

.usage-block.usage-key {
  border-color: #e8a020;
}

.usage-key .usage-main {
  background: #fff8e6;
}

.key-badge {
  margin-left: 10px;
  font-size: 0.68rem;
  background: #e8a020;
  color: #fff;
  padding: 1px 7px;
  border-radius: 8px;
  font-weight: 700;
  vertical-align: middle;
  letter-spacing: 0.05em;
}

.usage-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  background: #f8f5ee;
  font-size: 1.02rem;
  color: #333;
  font-weight: 600;
}

.usage-num {
  font-size: 0.7rem;
  background: #c9a97a;
  color: #fff;
  padding: 1px 7px;
  border-radius: 10px;
  flex-shrink: 0;
}

.usage-sub {
  padding: 6px 12px 6px 24px;
  border-top: 1px solid #ede6d8;
}

.sub-desc {
  font-size: 0.95rem;
  color: #555;
  margin-bottom: 4px;
}

.ex-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 0 4px 12px;
}

.ex-list li {
  font-size: 0.9rem;
  color: #666;
  line-height: 1.6;
  border-left: 2px solid #e0d4c0;
  padding-left: 8px;
}

.ex-source {
  font-size: 0.72rem;
  color: #bbb;
  margin-left: 6px;
}

.compounds-section { margin-top: 16px; }

.compound-block {
  margin-bottom: 8px;
  padding: 8px 12px;
  background: #f0f8ff;
  border-radius: 6px;
  border: 1px solid #c8e0f0;
}

.compound-term { font-weight: 700; color: #1a5a8a; margin-right: 8px; }
.compound-desc { font-size: 0.88rem; color: #333; }

/* Result list */
.result-group { margin-bottom: 28px; }

.group-title {
  font-size: 0.95rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 4px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.shici-title { background: #f5e891; color: #4a3800; }
.xuci-title  { background: #b8f0df; color: #0f3a2a; }

.count {
  font-size: 0.78rem;
  font-weight: 400;
  opacity: 0.7;
}

.word-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.word-item {
  border: 1px solid #e8e0d0;
  border-radius: 6px;
  padding: 9px 12px;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.word-item:hover {
  border-color: #c9a97a;
  box-shadow: 0 2px 6px rgba(0,0,0,0.07);
}

.word-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 1;
  flex-wrap: wrap;
}

.word-tag {
  font-size: 1.05rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.shici-tag { background: #f5c842; color: #2c2c2c; }
.xuci-tag  { background: #7ecfb3; color: #1a3a2c; }

.meanings {
  font-size: 0.82rem;
  color: #777;
  line-height: 1.5;
  flex: 1;
}

.occurrence-count {
  font-size: 0.75rem;
  color: #bbb;
  flex-shrink: 0;
}

.occurrences {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sentence {
  font-size: 0.9rem;
  color: #444;
  background: #f8f5ee;
  padding: 6px 12px;
  border-radius: 4px;
  border-left: 3px solid #c9a97a;
  line-height: 1.8;
}

.sentence em {
  font-style: normal;
  font-weight: 700;
  color: #8b4513;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  #article-nav { max-height: 200px; }
  #article-body { border-right: none; border-bottom: 1px solid #ddd; }
}

.key-tag { background: #ff8c00 !important; color: #fff !important; }

/* ── Bottom drawer ── */
.word-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 45vh;
  background: #fff;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 100;
  overflow-y: auto;
  padding: 20px 32px 24px;
  border-radius: 14px 14px 0 0;
}

.word-drawer.open {
  transform: translateY(0);
}

#word-drawer-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #999;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}

#word-drawer-close:hover { background: #f0f0f0; color: #333; }
