/* Highlights: marks, selection toolbar, edit popover, definition popover, toast,
   highlight rows on the Highlights screen. Flat washes from the five tokens. */
[hidden] { display: none !important; }

mark[data-highlight] {
  --hl: var(--hl-yellow);
  background-color: var(--hl);
  color: inherit;
  border-radius: 3px;
  padding: .06em 0;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  cursor: pointer;
  scroll-margin-top: 96px;
  transition: background-color var(--t-base) var(--ease), box-shadow var(--t-fast) var(--ease);
}
mark[data-color="yellow"] { --hl: var(--hl-yellow); }
mark[data-color="green"]  { --hl: var(--hl-green); }
mark[data-color="blue"]   { --hl: var(--hl-blue); }
mark[data-color="pink"]   { --hl: var(--hl-pink); }
mark[data-color="orange"] { --hl: var(--hl-orange); }
/* Text on a wash is always --ink: --ink2 (blockquotes) and --accent (links) drop under 4.5:1 on the
   pink, blue and orange washes. Links keep their underline. */
mark[data-highlight]:not([data-color="definition"]), mark[data-highlight]:not([data-color="definition"]) a { color: var(--ink); }
@media (hover: hover) { mark[data-highlight]:hover { box-shadow: 0 2px 0 color-mix(in srgb, var(--hl) 100%, var(--ink) 22%); } }

/* Creation feedback: the wash sweeps in left to right */
mark[data-highlight].hl-new {
  background-color: transparent;
  background-image: linear-gradient(var(--hl), var(--hl));
  background-repeat: no-repeat;
  background-size: 100% 100%;
  animation: hlSweep .45s var(--ease) backwards;
}
@keyframes hlSweep { from { background-size: 0% 100%; } }

mark[data-highlight].hl-focus { animation: hlFocus 1.8s var(--ease) forwards; }
@keyframes hlFocus {
  0%, 55% { box-shadow: 0 0 0 3px rgba(45,91,255,.45); }
  100% { box-shadow: 0 0 0 3px rgba(45,91,255,0); }
}

/* Annotated: a small accent dot, no emoji */
mark[data-highlight].has-annotation::after {
  content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 1px 0 3px;
  border-radius: 50%; background: var(--accent); vertical-align: super;
}

/* Dictionary lookups: dotted accent underline, no fill */
mark[data-color="definition"] {
  background: transparent;
  border-bottom: 2px dotted rgba(45,91,255,.55);
  border-radius: 0;
  padding: 0;
}
mark[data-color="definition"]:hover { background: var(--accent-soft); box-shadow: none; }

/* ---------- Swatches (toolbar, popover, filters) ---------- */
.color-yellow { --sw: var(--hl-yellow); }
.color-green  { --sw: var(--hl-green); }
.color-blue   { --sw: var(--hl-blue); }
.color-pink   { --sw: var(--hl-pink); }
.color-orange { --sw: var(--hl-orange); }
.color-btn { position: relative; display: grid; place-items: center; width: 40px; height: 44px; border-radius: 10px; }
.color-btn::before {
  content: ""; width: 24px; height: 24px; border-radius: 50%; background: var(--sw);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--sw) 100%, var(--ink) 20%);
  transition: transform var(--t-fast) var(--spring), box-shadow var(--t-fast) var(--ease);
}
.color-btn:hover::before { transform: scale(1.15); }
.color-btn:active::before { transform: scale(.88); }

/* ---------- Selection toolbar: a dark floating pill ---------- */
.highlight-toolbar {
  position: absolute; z-index: 100; display: none; align-items: center; gap: 0;
  padding: 2px 4px; border-radius: 14px; background: var(--ink);
  box-shadow: 0 14px 30px -12px rgba(0,0,0,.45);
}
.highlight-toolbar.visible { display: flex; animation: popIn .22s var(--spring) backwards; }
@keyframes popIn { from { opacity: 0; transform: translateY(-4px) scale(.96); } }
.highlight-toolbar .color-btn::before { box-shadow: none; }
.highlight-toolbar .color-btn:hover { background: rgba(255,255,255,.08); }
.tb-sep { width: 1px; height: 22px; background: rgba(255,255,255,.18); margin: 0 4px; }
.define-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 12px 0 10px;
  border-radius: 10px; color: #fff; font-size: 13.5px; font-weight: 700;
  transition: background var(--t-fast) var(--ease);
}
.define-btn svg.i { width: 18px; height: 18px; }
.define-btn:hover { background: rgba(255,255,255,.1); }

/* ---------- Edit popover ---------- */
.highlight-popover {
  position: absolute; z-index: 101; display: none; width: 280px; padding: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--float);
  font-family: var(--font);
}
.highlight-popover.visible { display: block; animation: popIn .22s var(--spring) backwards; }
.highlight-popover .color-row { display: flex; justify-content: space-between; margin: -4px -2px 6px; }
.highlight-popover .color-btn[aria-pressed="true"]::before { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.highlight-popover .annotation-input {
  display: block; width: 100%; min-height: 76px; resize: vertical; padding: 10px 12px;
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-2);
  font-size: 16px; line-height: 1.45; color: var(--ink); outline: none; caret-color: var(--accent);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.highlight-popover .annotation-input::placeholder { color: var(--ink2); }
.highlight-popover .annotation-input:focus { border-color: var(--accent); box-shadow: var(--focus); }
.highlight-popover .popover-actions { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 10px; }
.highlight-popover .popover-actions > div { display: flex; gap: 6px; }
.highlight-popover .btn-delete, .highlight-popover .btn-copy, .highlight-popover .btn-save {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px;
  border-radius: var(--r-sm); font-size: 14px; font-weight: 700;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--spring);
}
.highlight-popover .btn-delete { padding: 0 10px; color: var(--hot); }
.highlight-popover .btn-delete svg.i { width: 17px; height: 17px; }
.highlight-popover .btn-delete:hover { background: var(--hot-soft); }
.highlight-popover .btn-copy { background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.highlight-popover .btn-copy:hover { border-color: var(--line-strong); }
.highlight-popover .btn-save { background: var(--ink); color: #fff; }
.highlight-popover .btn-save:hover { background: var(--ink-hover); }
.highlight-popover button:active { transform: scale(.96); }

/* ---------- Definition popover ----------
   Centring uses left/right insets + margin-inline:auto (set in toolbar.js), never an
   inline translateX: the keyframe animation below would override it. */
.definition-popover {
  position: absolute; z-index: 160; display: none; width: 300px; max-height: 420px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--float);
  font-family: var(--font);
  animation: defPopIn .28s var(--spring) both;
}
.definition-popover.visible { display: block; }
@keyframes defPopIn { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
.def-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--line-soft); }
.def-title-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex-wrap: wrap; }
.def-word { font-size: 18px; font-weight: 700; letter-spacing: -.01em; color: var(--ink); }
.def-phonetic { font-size: 13.5px; color: var(--ink2); }
.def-actions { display: flex; align-items: center; flex: none; }
.def-close, .def-delete {
  display: grid; place-items: center; width: 40px; height: 44px; border-radius: var(--r-sm); color: var(--ink2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.def-close svg.i, .def-delete svg.i { width: 18px; height: 18px; }
.def-close:hover { background: var(--bg); color: var(--ink); }
.def-delete:hover { background: var(--hot-soft); color: var(--hot); }
.def-body { padding: 12px 16px 14px; }
.def-pos { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin: 12px 0 4px; }
.def-pos:first-child { margin-top: 0; }
.def-list { list-style: decimal; padding-left: 1.2em; }
.def-item { font-size: 14px; line-height: 1.5; color: var(--ink); margin-bottom: 6px; }
.def-item::marker { color: var(--ink2); font-weight: 600; }
.def-example { font-size: 13px; color: var(--ink2); margin-top: 2px; }
.def-error { padding: 14px 16px 16px; font-size: 14px; color: var(--ink2); }
.def-loading { display: flex; justify-content: center; gap: 6px; padding: 20px 16px; }
.def-loading-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: defDot 1.1s var(--ease) infinite; }
.def-loading-dot:nth-child(2) { animation-delay: .15s; }
.def-loading-dot:nth-child(3) { animation-delay: .3s; }
@keyframes defDot { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1.1); } }

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 200; left: 16px; right: 16px; margin-inline: auto;
  width: max-content; max-width: calc(100% - 32px);
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  padding: 12px 18px; border-radius: var(--r-pill); background: var(--ink); color: #fff;
  font-family: var(--font); font-size: 14px; font-weight: 600; box-shadow: var(--float);
  pointer-events: none; opacity: 0; transform: translateY(12px);
  transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--spring);
}
#toast.visible { opacity: 1; transform: none; }
@media (max-width: 860px) {
  #toast { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  body.is-reading #toast { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Highlight rows (Highlights screen) ---------- */
.hl-card { padding: 14px 0 10px; border-top: 1px solid var(--line-soft); }
.hl-card:first-of-type { border-top: 0; }
.hl-text { display: block; font-family: var(--font-read); font-size: 16px; line-height: 1.6; color: var(--ink); text-decoration: none; }
[data-font="source-serif"] .hl-text { font-family: var(--font-serif); }
.hl-wash { --hl: var(--hl-yellow); background: var(--hl); border-radius: 3px; padding: .06em 0; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.hl-wash[data-color="green"]  { --hl: var(--hl-green); }
.hl-wash[data-color="blue"]   { --hl: var(--hl-blue); }
.hl-wash[data-color="pink"]   { --hl: var(--hl-pink); }
.hl-wash[data-color="orange"] { --hl: var(--hl-orange); }
.hl-text:hover .hl-wash { box-shadow: 0 2px 0 color-mix(in srgb, var(--hl) 100%, var(--ink) 22%); }
.hl-annotation { margin-top: 8px; padding: 8px 12px; border-radius: var(--r-sm); background: var(--bg); font-size: 14px; color: var(--ink2); }
.hl-card-foot { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.hl-meta { font-size: 12.5px; font-weight: 600; color: var(--ink2); min-width: 0; }
.hl-card-actions { margin-left: auto; }

@media (max-width: 860px) {
  .highlight-popover { width: calc(100vw - 32px); max-width: 320px; left: 16px !important; }
  .definition-popover { width: calc(100vw - 24px); max-width: 340px; left: 12px !important; }
}
