/* TỨ PHỦ — Legend manuscript reader */

.reader-progress {
  position: fixed;
  top: var(--header-h, 64px);
  left: 0;
  right: 0;
  z-index: 45;
  height: 3px;
  background: transparent;
  pointer-events: none;
}

.reader-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #742b32, #c49a59);
  transition: width 0.08s linear;
}

@media (prefers-reduced-motion: reduce) {
  .reader-progress-bar {
    transition: none;
  }
}

/* Toolbar */
.reader-toolbar {
  position: sticky;
  top: var(--header-h, 64px);
  z-index: 40;
  border-bottom: 1px solid rgba(98, 68, 60, 0.55);
  background: rgba(25, 15, 18, 0.92);
  backdrop-filter: blur(10px);
}

.reader-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0;
}

.reader-tool-group {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(98, 68, 60, 0.55);
  background: rgba(42, 26, 28, 0.75);
}

.reader-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  min-width: 2rem;
  padding: 0 0.55rem;
  border-radius: 0.375rem;
  border: 0;
  background: transparent;
  color: #d5ba99;
  font-size: 0.75rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.reader-tool-btn:hover,
.reader-tool-btn:focus-visible {
  background: rgba(53, 35, 38, 0.95);
  color: #e4c58c;
  outline: none;
}

.reader-tool-btn.is-active {
  background: rgba(116, 43, 50, 0.55);
  color: #f4e6d1;
}

.reader-tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.reader-settings-panel {
  display: none;
  width: 100%;
  padding: 0.65rem 0 0.35rem;
  border-top: 1px solid rgba(98, 68, 60, 0.4);
  margin-top: 0.35rem;
}

.reader-settings-panel.is-open {
  display: block;
}

@media (min-width: 768px) {
  .reader-settings-mobile-only {
    display: none !important;
  }
}

@media (max-width: 767px) {
  .reader-settings-desktop-only {
    display: none !important;
  }
}

/* Layout */
.reader-shell {
  --reader-max: 720px;
  --reader-font-size: 1.0625rem;
}

.reader-shell[data-reader-width="narrow"] {
  --reader-max: 620px;
}

.reader-shell[data-reader-width="wide"] {
  --reader-max: 860px;
}

.reader-shell[data-reader-font="sm"] {
  --reader-font-size: 0.95rem;
}

.reader-shell[data-reader-font="md"] {
  --reader-font-size: 1.0625rem;
}

.reader-shell[data-reader-font="lg"] {
  --reader-font-size: 1.2rem;
}

.reader-shell[data-reader-font="xl"] {
  --reader-font-size: 1.35rem;
}

.reader-layout {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 1100px) {
  .reader-layout {
    grid-template-columns: 200px minmax(0, 1fr) 220px;
    align-items: start;
  }
}

.reader-toc {
  display: none;
}

.reader-toc.is-visible-desktop {
  display: none;
}

@media (min-width: 1100px) {
  .reader-toc.is-visible-desktop {
    display: block;
  }
}

.reader-toc-sticky {
  position: sticky;
  top: calc(var(--header-h, 64px) + 3.5rem);
  max-height: calc(100vh - var(--header-h, 64px) - 4.5rem);
  overflow-y: auto;
  padding: 0.85rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(98, 68, 60, 0.5);
  background: rgba(42, 26, 28, 0.85);
}

.reader-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.reader-toc-link {
  display: block;
  border-radius: 0.375rem;
  padding: 0.4rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.35;
  color: #d5ba99;
  text-decoration: none;
}

.reader-toc-link:hover,
.reader-toc-link:focus-visible {
  color: #e4c58c;
  background: rgba(53, 35, 38, 0.8);
  outline: none;
}

.reader-toc-link.is-active {
  color: #f4e6d1;
  background: rgba(116, 43, 50, 0.4);
  border-left: 2px solid #c49a59;
  padding-left: calc(0.55rem - 2px);
}

.reader-toc-link.is-h3 {
  padding-left: 1rem;
  font-size: 0.75rem;
}

.reader-notes {
  display: none;
}

@media (min-width: 1100px) {
  .reader-notes {
    display: block;
  }
}

.reader-notes-sticky {
  position: sticky;
  top: calc(var(--header-h, 64px) + 3.5rem);
  max-height: calc(100vh - var(--header-h, 64px) - 4.5rem);
  overflow-y: auto;
  padding: 0.85rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(98, 68, 60, 0.5);
  background: rgba(42, 26, 28, 0.85);
}

/* Article paper */
.reader-article {
  margin-inline: auto;
  width: 100%;
  max-width: var(--reader-max);
  border-radius: 0.85rem;
  border: 1px solid rgba(98, 68, 60, 0.35);
  padding: 1.35rem 1.15rem 2rem;
  scroll-margin-top: calc(var(--header-h, 64px) + 4.25rem);
}

.reader-shell[data-reader-theme="paper"] .reader-article {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 28%),
    #f5ebdd;
  color: #33241f;
  box-shadow: inset 0 0 0 1px rgba(196, 154, 89, 0.12);
}

.reader-shell[data-reader-theme="light"] .reader-article {
  background: #faf7f2;
  color: #2a221c;
  border-color: rgba(98, 68, 60, 0.22);
}

.reader-shell[data-reader-theme="dark"] .reader-article {
  background: #241618;
  color: #f4e6d1;
  border-color: rgba(98, 68, 60, 0.55);
}

.reader-article .reader-section {
  scroll-margin-top: calc(var(--header-h, 64px) + 4.5rem);
}

.reader-article .reader-section + .reader-section {
  margin-top: 2.25rem;
  padding-top: 1.75rem;
  border-top: 1px solid rgba(98, 68, 60, 0.22);
}

.reader-shell[data-reader-theme="dark"] .reader-article .reader-section + .reader-section {
  border-top-color: rgba(98, 68, 60, 0.45);
}

.reader-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.reader-section-title {
  font-family: "Noto Serif", Georgia, serif;
  font-size: 1.35rem;
  line-height: 1.35;
  font-weight: 600;
}

.reader-copy-link {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  color: inherit;
  opacity: 0.55;
}

.reader-copy-link:hover,
.reader-copy-link:focus-visible {
  opacity: 1;
  border-color: rgba(196, 154, 89, 0.55);
  outline: none;
}

.reader-prose {
  font-family: "Noto Serif", Georgia, serif;
  font-size: var(--reader-font-size);
  line-height: 1.8;
}

.reader-prose p {
  margin: 0 0 1em;
}

.reader-prose h3 {
  font-family: "Noto Serif", Georgia, serif;
  font-size: 1.12em;
  font-weight: 600;
  margin: 1.4em 0 0.65em;
  scroll-margin-top: calc(var(--header-h, 64px) + 4.5rem);
}

.reader-callout,
.reader-empty,
.reader-status,
.reader-ui-sample {
  border-radius: 0.65rem;
  padding: 0.9rem 1rem;
  margin: 0 0 1.1em;
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  font-size: 0.9em;
  line-height: 1.6;
}

.reader-callout {
  border: 1px solid rgba(196, 154, 89, 0.4);
  background: rgba(196, 154, 89, 0.08);
}

.reader-empty,
.reader-status {
  border: 1px dashed rgba(98, 68, 60, 0.45);
  background: rgba(255, 255, 255, 0.28);
}

.reader-shell[data-reader-theme="dark"] .reader-empty,
.reader-shell[data-reader-theme="dark"] .reader-status {
  background: rgba(53, 35, 38, 0.45);
}

.reader-ui-sample {
  border: 1px dashed rgba(116, 43, 50, 0.45);
  background: rgba(116, 43, 50, 0.06);
}

.reader-ui-label {
  display: inline-flex;
  margin-bottom: 0.45rem;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(196, 154, 89, 0.45);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  color: #742b32;
}

.reader-shell[data-reader-theme="dark"] .reader-ui-label {
  color: #e4c58c;
}

.reader-quote {
  margin: 0 0 1.15em;
  padding: 0.85rem 1rem;
  border-left: 3px solid #c49a59;
  background: rgba(196, 154, 89, 0.08);
  font-style: italic;
}

.reader-quote cite {
  display: block;
  margin-top: 0.5rem;
  font-style: normal;
  font-size: 0.85em;
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  opacity: 0.75;
}

.reader-figure {
  margin: 0 0 1.25em;
}

.reader-figure img {
  display: block;
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid rgba(98, 68, 60, 0.3);
}

.reader-figure figcaption {
  margin-top: 0.45rem;
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  font-size: 0.82em;
  opacity: 0.8;
}

.reader-list {
  margin: 0 0 1.1em;
  padding-left: 1.2em;
}

.reader-list li + li {
  margin-top: 0.35em;
}

/* Footnote refs */
.fn-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  margin: 0 0.1rem;
  padding: 0 0.2rem;
  border-radius: 0.25rem;
  border: 1px solid rgba(116, 43, 50, 0.55);
  background: rgba(116, 43, 50, 0.12);
  color: #742b32;
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  font-size: 0.7em;
  font-weight: 600;
  vertical-align: super;
  line-height: 1;
  cursor: pointer;
}

.reader-shell[data-reader-theme="dark"] .fn-ref {
  color: #e4c58c;
  border-color: rgba(196, 154, 89, 0.55);
  background: rgba(196, 154, 89, 0.12);
}

.fn-ref:focus-visible {
  outline: 2px solid #c49a59;
  outline-offset: 2px;
}

.fn-popover {
  position: absolute;
  z-index: 55;
  width: min(320px, calc(100vw - 2rem));
  border-radius: 0.75rem;
  border: 1px solid #62443c;
  background: #2a1a1c;
  color: #f4e6d1;
  padding: 0.9rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  display: none;
}

.fn-popover.is-open {
  display: block;
}

.fn-popover-title {
  font-family: "Noto Serif", Georgia, serif;
  font-size: 0.95rem;
  color: #e4c58c;
}

.fn-popover-body {
  margin-top: 0.45rem;
  font-size: 0.85rem;
  line-height: 1.55;
  color: #d5ba99;
}

.fn-popover-actions {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* TOC drawer mobile */
.toc-drawer {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  visibility: hidden;
}

.toc-drawer.is-open {
  pointer-events: auto;
  visibility: visible;
}

.toc-drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(25, 15, 18, 0.72);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.toc-drawer.is-open .toc-drawer-overlay {
  opacity: 1;
}

.toc-drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: min(100%, 320px);
  background: #2a1a1c;
  border-right: 1px solid #62443c;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

@media (prefers-reduced-motion: reduce) {
  .toc-drawer-overlay,
  .toc-drawer-panel {
    transition: none;
  }
}

/* Variants */
.variant-compare {
  display: grid;
  gap: 0.85rem;
}

@media (min-width: 768px) {
  .variant-compare {
    grid-template-columns: 1fr 1fr;
  }
}

.variant-pane {
  border-radius: 0.75rem;
  border: 1px dashed rgba(196, 154, 89, 0.4);
  background: rgba(42, 26, 28, 0.7);
  padding: 1rem;
  max-height: 280px;
  overflow-y: auto;
}

.variant-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.variant-tab {
  border-radius: 0.5rem;
  border: 1px solid #62443c;
  background: transparent;
  color: #d5ba99;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.variant-tab.is-active {
  border-color: #c49a59;
  color: #e4c58c;
  background: rgba(53, 35, 38, 0.9);
}

@media (min-width: 768px) {
  .variant-tabs-mobile {
    display: none;
  }
}

@media (max-width: 767px) {
  .variant-compare-desktop {
    display: none;
  }
}

.toast-copy {
  position: fixed;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 90;
  border-radius: 999px;
  border: 1px solid #62443c;
  background: #352326;
  color: #f4e6d1;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-copy.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
