/* Reading area — volume/entry rendering */

/* Home page */
.home { max-width: 60rem; margin: 0 auto; }
.home-title { font-family: var(--font-serif); font-size: 2.6rem; letter-spacing: 0.15em; text-align: center; margin: 1rem 0 .3rem; }
.home-sub { text-align: center; color: var(--muted); font-size: 1rem; margin-bottom: 2.5rem; }
.home-intro { max-width: var(--measure); margin: 0 auto 2.5rem; font-family: var(--font-serif); font-size: 1rem; line-height: 1.85; color: var(--ink-soft); }
.home-intro p { margin: 0 0 1rem; text-indent: 2em; }

.home-progress { max-width: var(--measure); margin: 0 auto 2.5rem; padding: 1rem 1.2rem; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); }
.progress-label { display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--muted); margin-bottom: .5rem; }
.progress-num { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.progress-bar { height: 6px; background: var(--bg-soft); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(to right, var(--accent), var(--accent-soft)); transition: width .4s ease; }

.toc-title { font-family: var(--font-serif); font-size: 1.2rem; letter-spacing: 0.1em; text-align: center; margin: 2rem 0 1rem; color: var(--accent); }
.toc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .6rem; }
.toc-card { display: block; padding: .7rem .9rem; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; }
.toc-card:hover { border-color: var(--accent); box-shadow: var(--shadow-1); text-decoration: none; }
.toc-card-title { font-family: var(--font-serif); font-size: 0.98rem; color: var(--ink); margin-bottom: .2rem; }
.toc-card-meta { color: var(--muted); font-size: 0.8rem; display: flex; align-items: center; gap: .4rem; }

/* Volume page */
.volume { max-width: var(--measure); margin: 0 auto; }
.volume-head { margin-bottom: 2rem; }
.volume-title { font-family: var(--font-serif); font-size: 2rem; letter-spacing: 0.12em; color: var(--ink); margin: .5rem 0 .3rem; }
.volume-meta { color: var(--muted); font-size: 0.9rem; }
.reader-modes { display: flex; gap: 4px; margin-top: 1rem; }
.mode-btn {
  padding: 4px 12px;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--muted);
}
.mode-btn:hover { border-color: var(--accent); color: var(--accent); }
.mode-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

/* Entry card */
.entry {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px dashed var(--border);
  scroll-margin-top: 80px;
}
.entry:last-child { border-bottom: 0; }
.entry-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.entry-num {
  font-family: var(--font-serif);
  color: var(--accent);
  font-size: 0.95rem;
  letter-spacing: 0.15em;
  font-weight: 600;
}
.entry-anchor {
  color: var(--muted); font-size: 0.9rem;
  opacity: 0; transition: opacity .2s;
  padding: 4px 6px; /* larger tap target */
}
.entry:hover .entry-anchor { opacity: 1; }
.entry-anchor:hover { color: var(--accent); text-decoration: none; }
/* Touch devices: no hover → keep anchor visible so it's reachable */
@media (hover: none) {
  .entry-anchor { opacity: 0.55; }
  .entry-anchor:active { opacity: 1; color: var(--accent); }
}

.entry p.original {
  font-family: var(--font-serif);
  font-size: var(--size-orig);
  line-height: var(--lh-orig);
  color: var(--ink);
  margin: 0 0 1rem;
  text-indent: 2em;
  letter-spacing: 0.02em;
}
.entry p.translation {
  font-family: var(--font-sans);
  font-size: var(--size-trans);
  line-height: var(--lh-trans);
  color: var(--translation-tint);
  margin: 0 0 1.2rem;
  padding: .6rem 0 .6rem 1rem;
  border-left: 3px solid var(--accent-soft);
  text-indent: 0;
  background: linear-gradient(to right, var(--bg-soft) 0%, transparent 50%);
}
.entry p.translation.placeholder {
  color: var(--muted);
  font-style: italic;
  border-left-color: var(--border);
  background: transparent;
}

/* Reader mode toggles */
.volume.mode-orig .translation { display: none; }
.volume.mode-trans .original { display: none; }

/* Footnote markers */
sup.fn {
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0 2px;
  margin: 0 1px;
  vertical-align: super;
  font-size: 0.7em;
  user-select: none;
}
sup.fn:hover { color: var(--accent-soft); }
sup.fn.active { color: var(--accent-soft); background: var(--bg-soft); border-radius: 3px; }

/* Inline term references — same behavior as sup.fn but embedded in body text */
a.ann-ref {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed var(--accent-soft);
  cursor: pointer;
  padding-bottom: 1px;
}
a.ann-ref:hover { color: var(--accent); border-bottom-color: var(--accent); text-decoration: none; }
a.ann-ref.active { background: var(--bg-soft); color: var(--accent); border-bottom-color: var(--accent); border-radius: 3px; padding: 0 2px; }

/* Annotation popover */
.fn-pop {
  position: absolute;
  z-index: 200;
  max-width: min(380px, calc(100vw - 24px));
  padding: .7rem .9rem;
  background: var(--bg-elev);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--ink);
}
.fn-pop b { color: var(--accent); }

/* Annotations foldout */
.annotations {
  margin-top: 1.2rem;
  padding: .6rem .9rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
}
.annotations summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  outline: none;
}
.annotations summary:hover { color: var(--accent); }
.ann-list { margin: .6rem 0 0; padding-left: 1.4rem; color: var(--ink-soft); }
.ann-list li { margin: .3rem 0; line-height: 1.7; }
.ann-list li b { color: var(--accent); }

/* Volume nav footer */
.volume-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border);
  font-size: 0.92rem;
}
.volume-nav .nav-up { color: var(--muted); }
.volume-nav a:hover { color: var(--accent); text-decoration: none; }

/* Reader pill — two mini buttons; grid button expands to jump panel */
.reader-pill {
  position: fixed;
  right: 1.2rem; bottom: 1.2rem;
  z-index: 80;
  font-family: var(--font-sans);
}
.pill-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: opacity .18s ease, transform .18s ease;
}
.reader-pill.open .pill-buttons {
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
}
.pill-mini {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: all .16s ease;
  text-decoration: none;
}
.pill-mini:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
  text-decoration: none;
}
.pill-status { color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.pill-status #pill-pct { color: var(--accent); font-weight: 500; }

.pill-panel {
  position: absolute;
  right: 0; bottom: calc(100% + .5rem);
  width: 320px;
  max-height: 60vh;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
  animation: pillIn .18s ease;
}
.pill-panel[hidden] { display: none; }
@keyframes pillIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pill-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.pill-vol { font-family: var(--font-serif); font-weight: 600; letter-spacing: 0.06em; color: var(--ink); font-size: 0.95rem; }
.pill-close {
  color: var(--muted);
  padding: .2rem .5rem;
  border-radius: 4px;
  font-size: 1rem;
}
.pill-close:hover { color: var(--accent); background: var(--bg-elev); }
.pill-actions {
  display: flex; gap: .5rem;
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--border);
}
.pill-btn {
  flex: 1;
  padding: .45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--ink-soft);
  font-size: 0.85rem;
  transition: all .16s ease;
}
.pill-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-soft); }
.pill-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  padding: .8rem .9rem 1rem;
  overflow-y: auto;
}
.pill-cell {
  display: flex; align-items: center; justify-content: center;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  transition: all .12s ease;
}
.pill-cell:hover { border-color: var(--accent); color: var(--accent); background: var(--bg-soft); text-decoration: none; }
.pill-cell.current {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}

@media (max-width: 640px) {
  .reader-pill {
    right: max(.8rem, env(safe-area-inset-right));
    bottom: max(.8rem, calc(env(safe-area-inset-bottom) + .5rem));
  }
  .pill-mini { width: 44px; height: 44px; } /* Apple HIG minimum tap size */
  .pill-panel { width: min(88vw, 320px); max-height: 65vh; }
  .pill-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; padding: .8rem; }
  .pill-cell { height: 34px; font-size: 0.82rem; }
  .pill-head { flex-wrap: wrap; gap: .3rem; }
  .pill-status { flex-basis: 100%; order: 3; font-size: 0.75rem; }
}

/* Glossary page */
.glossary { max-width: 60rem; margin: 0 auto; }
.page-head { margin-bottom: 1.5rem; }
.gloss-search {
  display: block; width: 100%; max-width: 480px;
  padding: .6rem .9rem; margin-top: 1rem;
  font-size: 0.95rem; font-family: var(--font-sans);
  background: var(--bg-elev); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.gloss-search:focus { border-color: var(--accent); outline: none; }
.gloss-category h2 { color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: .3rem; }
.gloss-letter h3 { color: var(--accent-soft); font-family: var(--font-mono); }
.gloss-letter dl { margin: .5rem 0 1rem; }
.gloss-letter dt { font-family: var(--font-serif); font-weight: 600; margin-top: .8rem; color: var(--ink); }
.gloss-letter dd { margin: .2rem 0 0 1.6rem; color: var(--ink-soft); font-size: 0.94rem; line-height: 1.75; }

/* Appendix page */
.appendix { max-width: var(--measure); margin: 0 auto; }
.appendix-toc {
  display: flex; flex-wrap: wrap; gap: .5rem;
  margin: 1rem 0 2rem;
  padding: .8rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.appendix-toc a { font-size: 0.86rem; color: var(--ink-soft); padding: 2px 8px; border-radius: 4px; background: var(--bg-soft); }
.appendix-toc a:hover { background: var(--accent-soft); color: white; text-decoration: none; }
.appendix-sec h2 { color: var(--accent); margin-top: 3rem; }
.appendix-sec p { font-family: var(--font-serif); font-size: 1rem; line-height: 1.85; text-indent: 2em; margin: 0 0 1rem; }

/* About page */
.about { max-width: var(--measure); margin: 0 auto; font-family: var(--font-serif); }
.front-sec h2 { color: var(--accent); margin-top: 2.5rem; }
.front-sec p { line-height: 1.9; text-indent: 2em; margin: 0 0 1rem; }
.front-sec p:first-of-type { }

/* Search page */
.search { max-width: 60rem; margin: 0 auto; }
#q { width: 100%; padding: .8rem 1rem; font-size: 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); color: var(--ink); }
#q:focus { border-color: var(--accent); outline: none; }
.search-results { margin-top: 1.5rem; }
.search-result {
  padding: .8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .6rem;
  background: var(--bg-elev);
}
.search-result:hover { border-color: var(--accent); }
.search-result-meta { font-size: 0.82rem; color: var(--muted); margin-bottom: .3rem; }
.search-result-snippet { font-family: var(--font-serif); font-size: 0.95rem; line-height: 1.75; color: var(--ink-soft); }
.search-result-snippet mark { background: rgba(184, 134, 11, 0.2); color: var(--accent); padding: 0 2px; font-weight: 500; }

.not-found { text-align: center; padding: 4rem 1rem; }
.not-found h1 { font-size: 5rem; color: var(--accent); margin-bottom: 0; }

/* Mobile tweaks */
@media (max-width: 640px) {
  .home-title { font-size: 2rem; }
  .home-intro { padding: 0 .2rem; }
  .volume-title { font-size: 1.5rem; }
  .entry {
    padding-bottom: 1.5rem;
    margin-bottom: 1.8rem;
    scroll-margin-top: 64px;
  }
  .entry p.original { font-size: 1.02rem; line-height: 1.85; }
  .entry p.translation { font-size: 0.96rem; padding-left: .7rem; line-height: 1.75; }
  .entry-num { font-size: 0.88rem; }
  .toc-grid { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .toc-card { padding: .6rem .7rem; }
  .toc-card-title { font-size: 0.92rem; }

  /* Volume navigation: stack when tight */
  .volume-nav { flex-direction: column; gap: .6rem; align-items: stretch; text-align: center; }
  .volume-nav a { padding: .4rem .6rem; border-radius: 6px; background: var(--bg-soft); }

  /* Reader mode buttons — allow wrap */
  .reader-modes { flex-wrap: wrap; }
  .mode-btn { padding: 6px 14px; } /* larger tap target */

  /* Search results: cleaner tap targets */
  .search-result { padding: .7rem .8rem; }

  /* Annotations foldout on mobile: reduce visual weight */
  .annotations { padding: .5rem .7rem; font-size: 0.86rem; }
  .ann-list { padding-left: 1.1rem; }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
