/* ============================================================
   Highlights, notes and the character glossary (js/annotate.js, js/glossary.js)
   ============================================================ */

/* Highlight colours: the Society's own. Bands are translucent so the narration's pill
   and the page's dimming still read through; dots are solid. */
:root {
  --hl-gold: rgba(232, 176, 44, .34);   --hl-gold-dot: #DDA52C;
  --hl-red: rgba(222, 78, 84, .24);     --hl-red-dot: #D2474E;
  --hl-green: rgba(96, 168, 92, .28);   --hl-green-dot: #58A055;
  --hl-blue: rgba(74, 142, 222, .25);   --hl-blue-dot: #4A8BD8;
  --hl-violet: rgba(156, 98, 210, .24); --hl-violet-dot: #9A62D0;
}
:root[data-theme="sepia"] {
  --hl-gold: rgba(214, 152, 26, .32);   --hl-gold-dot: #C98F1E;
  --hl-red: rgba(196, 66, 66, .24);     --hl-red-dot: #B94343;
  --hl-green: rgba(92, 150, 74, .28);   --hl-green-dot: #5A8E47;
  --hl-blue: rgba(64, 120, 186, .24);   --hl-blue-dot: #4677B4;
  --hl-violet: rgba(140, 88, 178, .24); --hl-violet-dot: #8A5BB1;
}
:root[data-theme="dark"], :root[data-theme="oled"] {
  --hl-gold: rgba(236, 188, 92, .30);   --hl-gold-dot: #E8B95A;
  --hl-red: rgba(240, 104, 110, .30);   --hl-red-dot: #EE6A70;
  --hl-green: rgba(124, 196, 120, .26); --hl-green-dot: #7DC47A;
  --hl-blue: rgba(108, 164, 240, .30);  --hl-blue-dot: #73A8F0;
  --hl-violet: rgba(186, 138, 240, .30); --hl-violet-dot: #B98CF0;
}
:root[data-theme="oled"] {
  --hl-gold: rgba(236, 188, 92, .26); --hl-red: rgba(240, 104, 110, .26); --hl-green: rgba(124, 196, 120, .22);
  --hl-blue: rgba(108, 164, 240, .26); --hl-violet: rgba(186, 138, 240, .26);
}
:root[data-theme="hearth"] {
  --hl-gold: rgba(240, 186, 96, .28);   --hl-gold-dot: #EDB860;
  --hl-red: rgba(236, 110, 84, .30);    --hl-red-dot: #EC7458;
  --hl-green: rgba(150, 190, 110, .24); --hl-green-dot: #A2C278;
  --hl-blue: rgba(120, 166, 214, .26);  --hl-blue-dot: #86ACD6;
  --hl-violet: rgba(190, 140, 210, .26); --hl-violet-dot: #C196D6;
}
.hl-gold, .hlc-gold, .hlq-gold { --hlc: var(--hl-gold); --dot: var(--hl-gold-dot); }
.hl-red, .hlc-red, .hlq-red { --hlc: var(--hl-red); --dot: var(--hl-red-dot); }
.hl-green, .hlc-green, .hlq-green { --hlc: var(--hl-green); --dot: var(--hl-green-dot); }
.hl-blue, .hlc-blue, .hlq-blue { --hlc: var(--hl-blue); --dot: var(--hl-blue-dot); }
.hl-violet, .hlc-violet, .hlq-violet { --hlc: var(--hl-violet); --dot: var(--hl-violet-dot); }

/* ---------- on the page: bands behind the words (one per line, like the pill) ---------- */
.hl-layer { position: absolute; z-index: 0; inset: 0; pointer-events: none; }
.hl-band {
  position: absolute; left: 0; top: 0;
  border-radius: .3em;
  background: var(--hlc);
  transform-origin: 0 50%;
  transition: background-color .3s ease;
}
.hl-band.hl-new { animation: hl-sweep .42s cubic-bezier(.3, .7, .2, 1) both; animation-delay: calc(var(--n, 0) * 90ms); }
@keyframes hl-sweep { from { transform: scaleX(0); opacity: .4; } }
.flow span.hl-note { position: relative; }
.flow span.hl-note::after {
  content: ""; position: absolute; right: -.34em; top: -.14em;
  width: .36em; height: .36em; border-radius: 50%;
  background: var(--dot); box-shadow: 0 0 0 .1em var(--bg);
  pointer-events: none;
}
.flow span.hl[data-hl] { cursor: pointer; }
/* the page's own selection, in theme colours */
.flow ::selection { background: color-mix(in oklab, var(--gold) 30%, transparent); }

/* phones: let a long press select words in a narrated book (mobile.css switches selection off for tap-to-seek) */
@media (pointer: coarse) {
  html .pages.has-audio .flow { -webkit-user-select: text; user-select: text; }
}

/* ---------- the floating toolbar ---------- */
.hlbar {
  position: fixed; z-index: 38; left: 0; top: 0;
  display: flex; flex-direction: column; gap: 4px;
  width: max-content; max-width: min(380px, calc(100vw - 20px));
  padding: 6px;
  background: var(--surface); color: var(--ink);
  border-radius: 18px;
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--line) 85%, transparent), 0 16px 44px -14px rgba(var(--shade), .5), 0 3px 10px -4px rgba(var(--shade), .18);
  font: 14px/1.4 var(--ui);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  opacity: 0; transform: translateY(6px) scale(.94);
  transition: opacity .16s ease, transform var(--spring-d, 280ms) var(--spring, cubic-bezier(.2, .8, .2, 1));
}
.hlbar.below { transform: translateY(-6px) scale(.94); }
.hlbar.in { opacity: 1; transform: none; }
.hlb-row { display: flex; align-items: center; gap: 0; }
.hlb-colors { display: flex; align-items: center; }
.hlb-c { display: grid; place-items: center; width: 36px; height: 38px; border-radius: 12px; }
.hlb-c span {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--dot);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1);
  transition: transform .22s var(--spring, cubic-bezier(.2, .8, .2, 1)), box-shadow .2s;
}
.hlb-c:hover span { transform: scale(1.12); }
.hlb-c:active span { transform: scale(.9); }
.hlb-c[aria-checked="true"] span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--dot); transform: scale(.86); }
.hlb-sep { flex: none; width: 1px; height: 22px; margin: 0 5px; background: var(--line); }
.hlb-b { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: var(--ink-2); transition: background-color .15s, color .15s; }
.hlb-b:hover { background: var(--bg-2); color: var(--ink); }
.hlb-b:active { transform: scale(.94); }
.hlb-b svg { width: 20px; height: 20px; }
.hlb-del:hover { color: var(--crimson); }
.hlb-note {
  display: block; width: 100%; padding: 8px 10px; text-align: left;
  border-radius: 12px; background: color-mix(in oklab, var(--dot) 12%, var(--bg-2));
  font: italic 400 14px/1.45 var(--serif); color: var(--ink-2);
}
.hlb-note span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.hlb-who { display: flex; flex-direction: column; gap: 2px; padding: 4px 2px 2px; border-top: 1px solid var(--line); margin-top: 2px; animation: who-in .28s var(--spring, cubic-bezier(.2, .8, .2, 1)) both; }
@keyframes who-in { from { opacity: 0; transform: translateY(-4px); } }
.who-k { display: flex; align-items: center; gap: 6px; margin: 4px 8px 2px; font-size: 11.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--gold); }
.who-k svg { width: 14px; height: 14px; }
.who { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 7px 8px; border-radius: 12px; text-align: left; }
.who:hover { background: var(--bg-2); }
.who-txt { display: flex; flex-direction: column; min-width: 0; }
.who-n { font: 500 15.5px/1.3 var(--serif); color: var(--ink); }
.who-a { font: 500 12.5px var(--ui); color: var(--ink-3); }
.who-d { font-size: 13px; line-height: 1.4; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.who-more { margin: 2px 10px 4px; font-size: 12px; color: var(--ink-3); }

/* Society colour sigils */
.who-dot { flex: none; width: 12px; height: 12px; margin-top: 5px; border-radius: 50%; background: var(--ink-3); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14), 0 0 0 2px color-mix(in oklab, var(--surface) 70%, transparent); }
.col-gold { background: linear-gradient(135deg, #F0CF6E, #B8892A); }
.col-silver { background: linear-gradient(135deg, #E4E7EC, #9AA1AB); }
.col-white { background: #F4F1EA; }
.col-copper { background: linear-gradient(135deg, #DA9460, #A35D2C); }
.col-blue { background: #3E72BC; }
.col-yellow { background: #E2C443; }
.col-green { background: #3F8D50; }
.col-violet { background: #7E51A9; }
.col-orange { background: #DC7A2C; }
.col-gray { background: #8E8B88; }
.col-brown { background: #7C5435; }
.col-obsidian { background: #1E1A1A; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22); }
.col-pink { background: #E293AA; }
.col-red { background: #B8302C; }

/* ---------- note composer ---------- */
.modal-note .modal-card { width: min(520px, 100%); padding: 18px 20px 18px; gap: 12px; }
.note-head { display: flex; align-items: center; justify-content: space-between; }
.note-head h2 { margin: 0; font: 500 22px/1.2 var(--serif); font-variation-settings: "opsz" 40; }
.note-quote {
  margin: 0; padding: 8px 12px 8px 14px; max-height: 8.5em; overflow: hidden;
  border-left: 3px solid var(--dot); border-radius: 4px 10px 10px 4px;
  background: color-mix(in oklab, var(--hlc) 55%, transparent);
  font: italic 400 15px/1.5 var(--serif); color: var(--ink-2);
  -webkit-mask-image: linear-gradient(#000 75%, transparent); mask-image: linear-gradient(#000 75%, transparent);
}
.note-ta {
  width: 100%; min-height: 120px; resize: vertical; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; outline: none;
  background: var(--bg); color: var(--ink);
  font: 400 16px/1.5 var(--serif);
  transition: border-color .2s, box-shadow .2s;
}
.note-ta:focus { border-color: color-mix(in oklab, var(--gold) 70%, var(--line)); box-shadow: 0 0 0 3px color-mix(in oklab, var(--gold) 18%, transparent); }
.note-ta::placeholder { color: var(--ink-3); font-style: italic; }
.note-actions { display: flex; align-items: center; gap: 8px; }
.note-sp { flex: 1; }
.note-del { color: var(--crimson); }

/* ---------- contents drawer: tabs that may not fit ---------- */
.drawer .tabs { gap: 0; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
.drawer .tabs::-webkit-scrollbar { display: none; }
.drawer .tabs button { flex: none; white-space: nowrap; margin-right: 13px; }
.drawer .tabs button:last-child { margin-right: 0; }

/* ---------- contents drawer: Highlights ---------- */
.hl-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 8px 10px 12px; }
.hl-filter { display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 999px; background: var(--bg-2); }
.hl-filter button { display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 9px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.hl-filter button span { width: 14px; height: 14px; border-radius: 50%; background: var(--dot); }
.hl-filter button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(var(--shade), .14); }
.hli { position: relative; }
.hli::before { content: ""; position: absolute; left: 3px; top: 12px; bottom: 12px; width: 3px; border-radius: 2px; background: var(--dot); }
.hli .bm-go { padding-left: 16px; }
.hli-q {
  font: italic 400 15px/1.55 var(--serif); color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.hli-q mark {
  color: inherit; background: var(--hlc); padding: .05em .2em; border-radius: .22em;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.hli-note { display: flex; gap: 6px; align-items: flex-start; margin-top: 2px; font-size: 14px; line-height: 1.45; color: var(--ink-2); white-space: pre-line; }
.hli-note svg { flex: none; width: 15px; height: 15px; margin-top: 2px; color: var(--ink-3); }
.hli-note > span { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.hli-acts { display: flex; flex-direction: column; align-items: center; padding-top: 4px; }
.hli-acts .ibtn { opacity: .55; }
.hli-acts .ibtn svg { width: 16px; height: 16px; }
.hli:hover .hli-acts .ibtn, .hli-acts .ibtn:focus-visible { opacity: 1; }
.hli.elsewhere .hli-q { opacity: .6; }
.hl-empty { text-align: left; }
.hl-empty-ico { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 10px; border-radius: 14px; background: color-mix(in oklab, var(--hl-gold-dot) 18%, transparent); color: var(--gold); }
.hl-empty-ico svg { width: 24px; height: 24px; }

/* ---------- contents drawer: Characters ---------- */
.gx-top { position: sticky; top: -14px; z-index: 1; margin: -14px -12px 6px; padding: 12px 12px 8px; background: var(--surface); }
.gx-q {
  width: 100%; height: 40px; padding: 0 14px 0 38px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg) no-repeat 13px 50% / 16px 16px; color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23998a86' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='10.8' cy='10.8' r='6.3'/%3E%3Cpath d='M15.5 15.5 20 20'/%3E%3C/svg%3E");
  font: 15px var(--ui); outline: none;
}
.gx-q:focus { border-color: color-mix(in oklab, var(--gold) 70%, var(--line)); box-shadow: 0 0 0 3px color-mix(in oklab, var(--gold) 16%, transparent); }
.gx-q::-webkit-search-cancel-button { filter: grayscale(1); opacity: .6; }
.gx-g h3 { margin: 14px 12px 4px; font-size: 12px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--crimson); }
.gx-g ul { list-style: none; margin: 0; padding: 0; }
.gx-e { display: flex; gap: 12px; padding: 9px 12px; border-radius: 10px; transition: background-color .4s; }
.gx-e .who-dot { margin-top: 6px; }
.gx-txt { min-width: 0; }
.gx-n { margin: 0; font: 500 16px/1.35 var(--serif); }
.gx-a { font: 500 12.5px var(--ui); color: var(--ink-3); }
.gx-d { margin: 2px 0 0; font-size: 13.5px; line-height: 1.45; color: var(--ink-2); }
.gx-flash { animation: gx-flash 2.4s ease-out; }
@keyframes gx-flash { 0%, 30% { background: color-mix(in oklab, var(--gold) 22%, transparent); } }
.gx-wait, .gx-none { padding: 18px 12px; margin: 0; color: var(--ink-3); font: italic 15px/1.5 var(--serif); }
.gx-src { margin: 18px 12px 4px; font-size: 12px; color: var(--ink-3); }

@media (max-width: 720px), (pointer: coarse) and (max-height: 500px) {
  .drawer .tabs button { margin-right: 8px; padding-inline: 1px; }
  .hlb-c { width: 36px; height: 42px; }
  .hlb-b { width: 38px; height: 42px; }
  .hli-acts .ibtn { width: 44px; height: 44px; opacity: .75; }
  .gx-e { padding: 10px 12px; }
  .modal-note .modal-card { padding: 16px 16px 14px; }
  .note-actions .btn.sm { height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .hlbar, .hlbar.below { transform: none; transition: opacity .12s; }
  .hl-band.hl-new, .hlb-who, .gx-flash { animation: none; }
}
