/* ── My Notes: bookmarks, highlights and notes (pairs with marks.js) ── */
/* Uses the reader's own tokens from styles.css (:root). Load AFTER styles.css. */

/* Highlights in the chapter */
.chapter-content mark.fg-hl {
  background: #FBE7A1;
  color: inherit;
  cursor: pointer;
  padding: 1px 0;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.chapter-content mark.fg-hl.has-note {
  border-bottom: 2px solid var(--terra-400);
}

.chapter-content mark.fg-hl.fg-hl-last.has-note::after {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-left: 4px;
  background: var(--terra-400);
  /* a small folded-corner note */
  clip-path: polygon(0 0, 100% 0, 100% 65%, 65% 100%, 0 100%);
  vertical-align: baseline;
}

.chapter-content .fg-flash {
  animation: fg-flash 1.6s ease-out;
}

@keyframes fg-flash {
  0%,
  35% {
    box-shadow: 0 0 0 6px rgba(201, 117, 80, 0.35);
  }
  100% {
    box-shadow: 0 0 0 6px rgba(201, 117, 80, 0);
  }
}

/* Bookmark ribbon beside each heading */
.chapter-content .fg-bm {
  display: inline-block;
  width: 24px;
  height: 28px;
  margin-left: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  vertical-align: middle;
  position: relative;
  opacity: 0.4;
  transition: opacity 0.15s ease;
}

.chapter-content .fg-bm::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 5px;
  width: 11px;
  height: 17px;
  background: var(--stone-200);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 72%, 0 100%);
}

.chapter-content h1:hover .fg-bm,
.chapter-content h2:hover .fg-bm,
.chapter-content h3:hover .fg-bm,
.chapter-content .fg-bm:hover,
.chapter-content .fg-bm:focus-visible,
.chapter-content .fg-bm.is-on {
  opacity: 1;
}

.chapter-content .fg-bm:hover::before {
  background: var(--terra-400);
}

.chapter-content .fg-bm.is-on::before {
  background: var(--terra-600);
}

.chapter-content .fg-bm.has-note::after {
  content: "";
  position: absolute;
  right: 1px;
  top: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--terra-400);
}

/* Floating toolbar on a text selection */
.fg-toolbar {
  position: absolute;
  z-index: 30;
  display: flex;
  background: var(--stone-900);
  box-shadow: 0 10px 30px rgba(36, 31, 27, 0.28);
}

.fg-toolbar-button {
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--neutral-50);
  padding: 0 16px;
  font-size: 14px;
  font-weight: 500;
}

.fg-toolbar-button + .fg-toolbar-button {
  border-left: 1px solid rgba(251, 246, 241, 0.25);
}

.fg-toolbar-button:hover {
  background: var(--terra-600);
}

/* Note editor */
.fg-popover {
  position: absolute;
  z-index: 30;
  width: min(340px, calc(100vw - 16px));
  border: 1px solid var(--stone-200);
  background: var(--neutral-50);
  box-shadow: 0 18px 50px rgba(36, 31, 27, 0.22);
  padding: 14px;
}

.fg-popover-label {
  display: block;
  margin-bottom: 6px;
  color: var(--stone-600);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.fg-note-field {
  width: 100%;
  border: 1px solid var(--stone-200);
  background: #fff;
  color: var(--neutral-900);
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: vertical;
}

.fg-popover-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.fg-link-button {
  border: 0;
  background: transparent;
  color: var(--neutral-600);
  padding: 4px 0;
  font-size: 13px;
  text-decoration: underline;
}

.fg-link-button:hover {
  color: var(--terra-600);
}

.fg-done-button {
  min-height: 36px;
  border: 0;
  background: var(--terra-600);
  color: var(--neutral-50);
  padding: 0 18px;
  font-weight: 500;
}

/* Toast */
.fg-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 60;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  background: var(--stone-900);
  color: var(--neutral-50);
  padding: 10px 16px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(36, 31, 27, 0.28);
}

/* Top-bar button */
.fg-open-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* "New" tag on the My Notes button — Q4 2026 only. REMOVE for Q1 2027. */
.fg-new {
  border: 1px solid var(--terra-600);
  border-radius: 10px;
  color: var(--terra-600);
  padding: 0 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  line-height: 16px;
  text-transform: uppercase;
}

.fg-count {
  min-width: 20px;
  border-radius: 10px;
  background: var(--terra-600);
  color: var(--neutral-50);
  padding: 0 6px;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

/* My Notes panel */
.fg-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: start center;
  background: rgba(36, 31, 27, 0.28);
  padding: 82px 18px 18px;
}

.fg-shell {
  width: min(760px, 100%);
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--stone-200);
  background: var(--neutral-50);
  box-shadow: 0 24px 80px rgba(36, 31, 27, 0.22);
}

.fg-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 22px 12px;
}

.fg-head h2 {
  margin: 4px 0 0;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 500;
  line-height: 1.2;
}

.fg-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 4px 22px 10px;
}

.fg-empty p {
  margin: 0 0 8px;
  color: var(--neutral-600);
}

.fg-empty p:first-child {
  color: var(--stone-800);
}

.fg-group + .fg-group {
  margin-top: 22px;
}

.fg-group-title {
  margin: 0 0 8px;
  color: var(--terra-600);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.fg-item {
  border: 1px solid var(--neutral-200);
  padding: 12px 14px;
}

.fg-item + .fg-item {
  margin-top: 8px;
}

.fg-item-jump {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  text-align: left;
}

.fg-item-jump:disabled {
  cursor: default;
}

.fg-item-jump:not(:disabled):hover .fg-item-quote,
.fg-item-jump:not(:disabled):hover .fg-item-text {
  color: var(--terra-600);
}

.fg-item-kind {
  display: block;
  color: var(--neutral-600);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.fg-item-quote {
  display: block;
  margin-top: 4px;
  border-left: 3px solid #F2D56B;
  padding-left: 10px;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.5;
}

.fg-item-text {
  display: block;
  margin-top: 4px;
  color: var(--stone-800);
  font-weight: 500;
}

.fg-item-section {
  display: block;
  margin-top: 6px;
  color: var(--neutral-600);
  font-size: 13px;
}

.fg-item-note {
  margin: 10px 0 0;
  background: var(--terra-50);
  padding: 8px 10px;
  color: var(--neutral-900);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.fg-item-status {
  margin: 8px 0 0;
  color: var(--neutral-600);
  font-size: 13px;
  font-style: italic;
}

.fg-item > .fg-link-button {
  margin-top: 6px;
}

.fg-foot {
  border-top: 1px solid var(--neutral-200);
  padding: 14px 22px 18px;
}

.fg-privacy {
  margin: 0;
  color: var(--neutral-600);
  font-size: 13px;
  line-height: 1.5;
}

.fg-export {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.fg-export {
  align-items: center;
}

.fg-clear-button {
  margin-left: auto;
}

.fg-confirm {
  margin-top: 12px;
  border: 1px solid var(--terra-400);
  background: var(--terra-50);
  padding: 12px 14px;
}

.fg-confirm-text {
  margin: 0;
  color: var(--neutral-900);
  font-size: 14px;
  line-height: 1.5;
}

.fg-confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.fg-danger-button {
  min-height: 38px;
  border: 0;
  background: var(--terra-600);
  color: var(--neutral-50);
  padding: 0 14px;
  font-weight: 500;
}

/* Print: only the notes */
.fg-print {
  display: none;
}

@media print {
  body.fg-printing-notes > *:not(.fg-print) {
    display: none !important;
  }

  body.fg-printing-notes .fg-print {
    display: block;
  }

  body.fg-printing-notes .fg-print pre {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 12pt;
    line-height: 1.5;
    white-space: pre-wrap;
  }
}

@media (max-width: 820px) {
  .fg-panel {
    padding: 66px 8px 8px;
  }

  .fg-shell {
    max-height: calc(100vh - 78px);
  }

  .chapter-content .fg-bm {
    opacity: 0.7;
  }

  /* The phone top bar has no room for another button, so My Notes floats
     at the bottom-right corner instead. */
  .fg-open-button {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 25;
    min-height: 44px;
    border-color: var(--stone-200);
    background: var(--neutral-50);
    box-shadow: 0 8px 24px rgba(36, 31, 27, 0.2);
  }

  .fg-toast {
    bottom: 72px;
  }
}

/* Edition sections and "bring forward" (marks belong to an edition) */
.fg-carry {
  margin: 0 0 22px;
  border: 1px solid var(--terra-400);
  background: var(--terra-50);
  padding: 14px 16px;
}

.fg-carry-text,
.fg-carry-result {
  margin: 0 0 12px;
  color: var(--stone-800);
  font-size: 14px;
  line-height: 1.5;
}

.fg-carry-result {
  font-weight: 500;
}

.fg-carry > :last-child {
  margin-bottom: 0;
}

.fg-carry-button {
  height: auto;
  padding: 8px 18px;
  text-align: left;
  line-height: 1.35;
}

.fg-edition + .fg-edition {
  margin-top: 30px;
  padding-top: 18px;
  border-top: 1px solid var(--neutral-200);
}

.fg-edition-title {
  margin: 0 0 12px;
  color: var(--stone-900);
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 500;
}

.fg-edition-note {
  margin: -6px 0 14px;
  color: var(--neutral-600);
  font-size: 13px;
  font-style: italic;
}

.fg-edition-other .fg-item-jump:disabled {
  cursor: default;
  opacity: 1;
}
