/* ============================================
   THE LILONG — NAVIGATION
   Top bar, progress, table of contents
   ============================================ */

/* --- TOP BAR --- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 1.25rem var(--w-margin);
  background: linear-gradient(to bottom, var(--paper) 50%, transparent 100%);
  background-color: transparent;
  transition: background 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
  pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.topbar.scrolled {
  background: var(--paper);
  background-color: var(--paper);
  box-shadow: 0 1px 0 var(--ink-5);
  opacity: 0.98;
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  color: var(--ink);
  text-decoration: none;
  font-variation-settings: "opsz" 30, "SOFT" 30;
}

.brand:hover { color: var(--cinnabar); }

.brand-zh {
  font-family: var(--font-ch);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--cinnabar);
  margin-left: 0.3em;
}

.brand-rule {
  width: 24px;
  height: 1px;
  background: var(--ink-5);
  margin: 0 0.4rem;
}

.brand-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-4);
}

.brand a {
  color: inherit;
  text-decoration: none;
}

/* Center: section indicator */
.topsection {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-4);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30ch;
}

.topsection .tnum {
  color: var(--cinnabar);
  font-weight: 500;
}

/* Right: tools */
.toptools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  justify-content: flex-end;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 36px;
  padding: 0 0.85rem;
  border: 1px solid var(--ink-5);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: transparent;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  text-decoration: none;
}

.tool:hover {
  color: var(--ink);
  border-color: var(--ink);
  background: var(--paper-2);
}

.tool.is-on {
  background: var(--cinnabar);
  color: var(--paper);
  border-color: var(--cinnabar);
}

.tool.audio-on {
  background: var(--cinnabar);
  color: var(--paper);
  border-color: var(--cinnabar);
}

.tool.audio-on .audio-bars {
  display: inline-flex;
}

.audio-bars {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.audio-bars span {
  width: 2px;
  background: var(--paper);
  animation: bar 1s ease-in-out infinite;
}
.audio-bars span:nth-child(1) { height: 4px; animation-delay: 0s; }
.audio-bars span:nth-child(2) { height: 8px; animation-delay: 0.15s; }
.audio-bars span:nth-child(3) { height: 6px; animation-delay: 0.3s; }
.audio-bars span:nth-child(4) { height: 10px; animation-delay: 0.45s; }

@keyframes bar {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

.lang-btn {
  font-family: var(--font-ch) !important;
  letter-spacing: 0 !important;
  font-size: 0.85rem !important;
  text-transform: none !important;
}

/* --- PROGRESS BAR --- */

.progress {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 2px;
  z-index: 200;
  background: transparent;
  pointer-events: none;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--cinnabar);
  transition: width 0.1s linear;
}

/* --- TABLE OF CONTENTS — SIDE NAV --- */

.toc {
  position: fixed;
  top: 50%;
  right: 1.25rem;
  transform: translateY(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toc-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0;
  background: transparent;
  border: 0;
  color: var(--ink-4);
  cursor: pointer;
  transition: color 0.2s;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-decoration: none;
}

.toc-item .toc-label {
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.2s, transform 0.2s;
}

.toc-item:hover .toc-label,
.toc-item.is-active .toc-label {
  opacity: 1;
  transform: translateX(0);
}

.toc-item:hover, .toc-item.is-active {
  color: var(--cinnabar);
}

.toc-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-5);
  transition: background 0.2s, transform 0.2s;
}

.toc-item.is-active .toc-dot,
.toc-item:hover .toc-dot {
  background: var(--cinnabar);
  transform: scale(1.5);
}

@media (max-width: 1100px) {
  .toc { display: none; }
}

/* --- MOBILE TOGGLE / DRAWER --- */

.menu-toggle {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink-5);
  border-radius: 50%;
  background: var(--paper);
}

.menu-toggle span {
  display: block;
  width: 14px;
  height: 1.5px;
  background: var(--ink);
  position: relative;
}

.menu-toggle span::before, .menu-toggle span::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 1.5px;
  background: var(--ink);
}

.menu-toggle span::before { top: -4px; }
.menu-toggle span::after { top: 4px; }

@media (max-width: 720px) {
  .menu-toggle { display: inline-flex; }
  .topsection { display: none; }
  .toptools .tool:not(.audio-btn) { display: none; }
}

/* --- TABLE OF CONTENTS DRAWER (mobile) --- */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  padding: 2rem var(--w-margin);
  transform: translateX(100%);
  transition: transform 0.4s var(--ease-smooth);
  overflow-y: auto;
}

.drawer.is-open { transform: translateX(0); }

.drawer-close {
  align-self: flex-end;
  font-size: 1.6rem;
  color: var(--ink-3);
  padding: 0.5rem;
}

.drawer h3 {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cinnabar);
  margin-bottom: 1.5rem;
}

.drawer-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.drawer-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.6rem 0;
  border-bottom: 1px dashed var(--ink-5);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.2rem;
  text-decoration: none;
}

.drawer-list a:hover { color: var(--cinnabar); }

.drawer-list .num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--ink-4);
}
