/* ============================================================
   Annotations — highlights, notes, bookmarks, collection drawer.
   Same token system as book.css; everything hides in print.
   ============================================================ */
:root {
  --anno-hl: #fbecb3;
  --anno-hl-edge: #e5c65a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --anno-hl: #453a12;
    --anno-hl-edge: #8a7223;
  }
}
:root[data-theme="dark"] {
  --anno-hl: #453a12;
  --anno-hl-edge: #8a7223;
}

mark.anno-hl {
  background: var(--anno-hl);
  color: inherit;
  border-radius: 2px;
  padding: 0.05em 0;
  cursor: pointer;
}
mark.anno-hl.anno-noted {
  border-bottom: 2px dotted var(--anno-hl-edge);
}
mark.anno-hl.anno-flash {
  animation: anno-flash 1.6s ease-out 2;
}
@keyframes anno-flash {
  0% { background: var(--anno-hl-edge); }
  100% { background: var(--anno-hl); }
}

/* ---------- selection toolbar + note popover ---------- */
.anno-toolbar, .anno-pop {
  position: fixed;
  z-index: 90;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.85rem;
}
.anno-toolbar { display: flex; gap: 0; overflow: hidden; }
.anno-toolbar button {
  border: none;
  background: none;
  color: var(--ink);
  font: inherit;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  white-space: nowrap;
}
.anno-toolbar button + button { border-left: 1px solid var(--rule); }
.anno-toolbar button:hover { background: var(--accent-soft); color: var(--accent); }

.anno-pop { padding: 0.6rem; width: min(20rem, calc(100vw - 2rem)); }
.anno-pop textarea {
  width: 100%;
  min-height: 4.5rem;
  resize: vertical;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  line-height: 1.45;
  padding: 0.4rem 0.5rem;
}
.anno-pop textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.anno-pop-row { display: flex; gap: 0.4rem; margin-top: 0.5rem; align-items: center; }
.anno-pop-row .spacer { flex: 1; }
.anno-pop button {
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
}
.anno-pop button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.anno-pop button.danger:hover { border-color: var(--warn-edge); color: var(--warn-edge); }
.anno-pop button:hover { border-color: var(--accent); }

/* ---------- bookmark flags ---------- */
.anno-flag {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--ink-faint);
  opacity: 0;
  margin-left: 0.2rem;
  padding: 0 0.15rem;
}
h3:hover .anno-flag, h4:hover .anno-flag,
h3:focus-within .anno-flag, h4:focus-within .anno-flag,
.chapter-head:hover .anno-flag { opacity: 1; }
.anno-flag[aria-pressed="true"] { opacity: 1; color: var(--accent); }
.anno-flag:hover { color: var(--accent); }
@media (hover: none) { .anno-flag { opacity: 0.4; } .anno-flag[aria-pressed="true"] { opacity: 1; } }

/* ---------- topbar button ---------- */
#annobtn { position: relative; }
#annobtn .anno-count {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  min-width: 1.1rem;
  height: 1.1rem;
  border-radius: 0.55rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.62rem;
  line-height: 1.1rem;
  text-align: center;
  padding: 0 0.2rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
#annobtn .anno-count:empty { display: none; }

/* ---------- collection drawer ---------- */
.anno-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 85;
}
body.anno-open .anno-backdrop { opacity: 1; pointer-events: auto; }
.anno-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(22rem, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--rule);
  transform: translateX(102%);
  transition: transform 0.18s ease;
  z-index: 86;
  display: flex;
  flex-direction: column;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
body.anno-open .anno-drawer { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) {
  .anno-drawer, .anno-backdrop { transition: none; }
}
.anno-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--rule);
}
.anno-drawer-head h2 { margin: 0; font-size: 1rem; font-family: inherit; }
.anno-drawer-head .anno-sync { font-size: 0.72rem; color: var(--ink-faint); margin-left: auto; margin-right: 0.6rem; }
.anno-drawer-body { overflow-y: auto; padding: 0.4rem 1rem 2rem; flex: 1; }
.anno-drawer-body h3 {
  font-size: 0.78rem;
  font-family: inherit;
  text-transform: none;
  color: var(--ink-faint);
  font-weight: 600;
  margin: 1.1rem 0 0.3rem;
  border: none;
  padding: 0;
}
.anno-drawer-body h3 a { color: inherit; text-decoration: none; }
.anno-drawer-body h3 a:hover { color: var(--accent); }
.anno-item {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.85rem;
  line-height: 1.45;
}
.anno-item:last-child { border-bottom: none; }
.anno-item .kind { flex: none; color: var(--ink-faint); font-size: 0.8rem; padding-top: 0.05rem; }
.anno-item a { color: var(--ink); text-decoration: none; flex: 1; min-width: 0; }
.anno-item a:hover { color: var(--accent); }
.anno-item .quote {
  display: block;
  background: var(--anno-hl);
  border-radius: 3px;
  padding: 0.1rem 0.3rem;
  font-family: ui-serif, Georgia, serif;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.anno-item .note {
  display: block;
  color: var(--ink-soft);
  margin-top: 0.2rem;
  white-space: pre-wrap;
}
.anno-item .lost { display: block; color: var(--warn-edge); font-size: 0.75rem; }
.anno-item .del {
  flex: none;
  border: none;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 0.2rem;
}
.anno-item .del:hover { color: var(--warn-edge); }
.anno-empty { color: var(--ink-faint); font-size: 0.85rem; margin-top: 1.2rem; }

/* ---------- toast ---------- */
.anno-toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.8rem;
  z-index: 95;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.anno-toast.show { opacity: 1; }

@media print {
  .anno-toolbar, .anno-pop, .anno-drawer, .anno-backdrop,
  .anno-flag, #annobtn, .anno-toast { display: none !important; }
}
