.corpus-list { line-height: 1.8; }

/*
  Corpus reader styling
  - The toolbar holds local-only toggles (vertical/bamboo/punct)
  - The viewbox is the scroll container
  - The textflow holds rendered HTML (ruby, spans, etc.)
*/

.corpus-reader {
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.corpus-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

.corpus-toolbar-spacer {
  flex: 1 1 auto;
}

.corpus-toolbar > .corpus-btn,
.corpus-toolbar > .corpus-toolbar-control-group,
.corpus-toolbar > .corpus-toolbar-traditions,
.corpus-toolbar > .corpus-toolbar-editing {
  flex: 0 0 auto;
}

/* Toolbar actions should share one visual height. Larger editing controls are
   useful inside forms, but they make the reader toolbar look misaligned. */
.corpus-toolbar .corpus-btn-editing:not(.corpus-btn-review-submit) {
  min-height: 0;
  padding: 6px 10px;
  font-size: inherit;
}

.corpus-toolbar-editing {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-left: 0;
}

@media (max-width: 900px) {
  .corpus-toolbar-spacer {
    display: none;
  }

  .corpus-toolbar-editing {
    width: 100%;
    justify-content: flex-end;
  }
}

/* File path + headline metadata (Work / Title / Author) */
.corpus-filebar {
  margin: 8px 0 10px;
}

.corpus-filepath {
  opacity: 0.85;
  margin-bottom: 4px;
}

.corpus-headmeta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.corpus-headmeta-item {
  opacity: 0.95;
  white-space: nowrap;
}

/* --- Ticket test page (infrastructure testing UI) --- */

.cv-panel {
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 14px;
  background: #fff;
}

.cv-muted {
  opacity: 0.75;
}

.cv-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 980px) {
  .cv-grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.cv-card {
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 12px;
  background: #fafafa;
}

.cv-field {
  margin: 10px 0;
}

.cv-field label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

.cv-field input[type="text"],
.cv-field input[type="email"],
.cv-field textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.cv-checkbox {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 600;
}

.cv-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.cv-actions button {
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  cursor: pointer;
}

.cv-output {
  margin-top: 12px;
}

.cv-pre {
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  max-height: 360px;
  overflow: auto;
}

.cv-ticket-list {
  margin: 10px 0 0;
  padding-left: 18px;
}

.cv-ticket-list li {
  margin: 6px 0;
}


.corpus-btn {
  padding: 6px 10px;
  border: 1px solid #bbb;
  background: #f6f6f6;
  border-radius: 4px;
  cursor: pointer;
}

.corpus-btn[aria-pressed="true"] {
  background: #e9e9e9;
  border-color: #999;
}

.corpus-viewbox {
  /* Default theme + typography */
  background: #ffffff;
  color: #111111;
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 12px;
  padding: 16px;
  max-height: calc(100vh - 260px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

/* When vertical: the writing-mode makes columns; scroll sideways */
.corpus-viewbox.is-vertical {
  overflow-x: auto;
  overflow-y: hidden;
  /* Fix: constrain height so vertical text wraps into new columns instead of running off the bottom. */
  height: calc(100vh - 260px);
}

/* JS scrolls to the "first" column based on vflow; no flex tricks needed. */

.corpus-textflow {
  margin: 0;
  white-space: pre-line;
  word-break: break-word;
  line-height: calc(var(--cv-font-size, 20px) * 1.8);
  font-size: var(--cv-font-size, 20px);
  flex: 0 0 auto;
}

.corpus-textflow.has-ruby {
  /* Extra breathing room so ruby never collides with line breaks */
  line-height: calc(var(--cv-font-size, 20px) * 1.8 + 8px);
}

.corpus-textflow.is-vertical {
  writing-mode: vertical-rl; /* default: columns advance right-to-left */
  text-orientation: mixed;
  white-space: pre-line;
  /* Fix: constrain the block size so vertical writing wraps into additional columns. */
  height: 100%;
  max-height: 100%;
  overflow: visible;
  /* Let the vertical layout grow to its natural width so the viewbox
     can actually scroll horizontally when the text spans many columns. */
  display: inline-block;
  inline-size: max-content;
  /* When vertical, "lines" become columns, so we need a little more spacing! Helps with the Chinese comma too. */
  letter-spacing: 0.02em;
  /* Column unit: in vertical-rl, line-height becomes column width */
  --cv-col: calc(var(--cv-font-size, 20px) * 1.8);
  line-height: var(--cv-col);

  /* Ruled grid aligned to column width */
  background-origin: content-box;
  background-clip: content-box;
  background-position: 0 0;
  background: repeating-linear-gradient(
    270deg,
    rgba(0,0,0,0.00) 0,
    rgba(0,0,0,0.00) calc(var(--cv-col) - 0.06em),
    var(--cv-rule-color, rgba(0,0,0,0.12)) calc(var(--cv-col) - 0.06em),
    var(--cv-rule-color, rgba(0,0,0,0.12)) var(--cv-col)
  );

}

.corpus-textflow.is-vertical.has-ruby {
  /* Ruby to the side needs a touch more air */
  letter-spacing: 0.03em;
}

.corpus-textflow.is-vertical.is-vflow-lr {
  writing-mode: vertical-lr;
}

/* Reader themes */
.corpus-viewbox.theme-light {
  background: #ffffff;
  color: #111111;
}

.corpus-viewbox.theme-bamboo {
  background-color: #f2dfb0; /* warm paper */
  color: #111111;
  border-color: #d1b46f;
}

.corpus-viewbox.theme-dark {
  background: #111111;
  color: #f3f3f3;
  border-color: rgba(255,255,255,0.18);
}

/* Ruled grid colours per theme */
.corpus-viewbox.theme-light { --cv-rule-color: rgba(0,0,0,0.12); }
.corpus-viewbox.theme-bamboo { --cv-rule-color: rgba(0,0,0,0.14); }
.corpus-viewbox.theme-dark { --cv-rule-color: rgba(255,255,255,0.10); }


/* Breadcrumb spacing */
.crumbs { margin: 6px 0 12px; }
.crumbs .crumb-sep { margin: 0 6px; opacity: 0.6; }



/* --- Corpus viewer ruby annotations ---
   Reuse the dictionary ruby positioning rules, but scoped to the reader.
*/
.corpus-textflow ruby.ruby-annot {
  position: relative;
  display: inline-block;
}

.corpus-textflow ruby.ruby-annot rt {
  position: absolute;
  top: -1.2em;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.28em;
  font-style: italic;
  opacity: 0.9;
  line-height: 1;
  white-space: normal;
}

.corpus-textflow ruby.ruby-annot.ruby-vertical rt {
  writing-mode: vertical-rl;
  text-orientation: upright;
  white-space: normal;
}

.corpus-textflow ruby.ruby-annot.ruby-vertical.ruby-side-right rt {
  top: 0;
  left: calc(100% + 6px);
  transform: none;
}

.corpus-textflow ruby.ruby-annot.ruby-vertical.ruby-side-left rt {
  top: 0;
  left: -6px;
  transform: translateX(-100%);
}

/* On-demand ruby inserted by right-click */
.corpus-textflow ruby.ruby-ondemand rt {
  pointer-events: none;
}

/* --- Better ruby in vertical writing ---
   The absolute-position ruby used for horizontal text can collapse in vertical writing-mode.
   Prefer native ruby layout: place readings inter-character (to the right of glyphs).
*/
.corpus-textflow.is-vertical ruby.ruby-annot,
.corpus-textflow.is-vertical ruby.ruby-ondemand {
  position: static;
  display: inline;
  ruby-position: inter-character;
  ruby-align: start;
}

.corpus-textflow.is-vertical ruby.ruby-annot rt,
.corpus-textflow.is-vertical ruby.ruby-ondemand rt {
  position: static;
  top: auto;
  left: auto;
  right: auto;
  transform: none;
  font-size: 0.45em;
  line-height: 1;
  white-space: normal;
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0;
}

/* Judou styling (toggleable): keep spacing stable, optionally nudge into gutter */
.corpus-textflow .cv-judou {
  color: var(--cv-judou-color, #b00000);
}

.corpus-textflow.is-vertical.judou-on .cv-judou {
  display: inline-block;
  inline-size: 1em;
  text-align: center;
  position: relative;
  transform: translateX(0.25em);
}

.corpus-textflow.is-vertical.is-vflow-lr.judou-on .cv-judou {
  transform: translateX(-0.25em);
}

/* Punctuation options overlay */
.corpus-punct-overlay[hidden] { display: none !important; }
.corpus-punct-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.14);
  z-index: 9999;
}
.corpus-punct-panel {
  width: min(1100px, 94vw);
  margin: 60px auto 0 auto;
  background: rgba(255,255,255,0.98);
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.28);
  padding: 12px 14px;
}
.theme-dark .corpus-punct-panel { background: rgba(20,20,20,0.98); border-color: rgba(255,255,255,0.18); color: #eee; }
.corpus-punct-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.corpus-punct-title { font-weight: 700; }
.corpus-punct-actions { display: flex; gap: 8px; }
.corpus-btn-ghost { background: transparent; border: 1px solid rgba(0,0,0,0.25); }
.theme-dark .corpus-btn-ghost { border-color: rgba(255,255,255,0.25); color: #eee; }

.corpus-punct-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px 12px;
}
.corpus-fieldset { border: 1px solid rgba(0,0,0,0.14); border-radius: 12px; padding: 10px; }
.theme-dark .corpus-fieldset { border-color: rgba(255,255,255,0.16); }
.corpus-fieldset legend { padding: 0 6px; font-weight: 700; }
.corpus-fieldset label { display: block; margin: 4px 0; }
.preset-box { background: rgba(0,0,0,0.04); }
.theme-dark .preset-box { background: rgba(255,255,255,0.06); }
.corpus-subtitle { margin-top: 6px; font-size: 12px; opacity: 0.85; font-weight: 600; }
.corpus-check { margin-top: 8px; }

.corpus-btn-split { padding-left: 10px; padding-right: 10px; }

.corpus-btn-primary { background: #111; color: #fff; border-color: #111; }
.theme-dark .corpus-btn-primary { background: #f3f3f3; color: #111; border-color: #f3f3f3; }


/* ---------- Named entity annotations ---------- */
/* Colours are CSS variables so users can override (including colourblind presets). */
:root {
  --ne-title: #2b6cb0;
  --ne-person: #d69e2e;
  --ne-place: #2f855a;
  --ne-office: #c53030;
  --ne-note: #2b6cb0;
}

/* Per-character spans for stable offset mapping */
.corpus-textflow .cch {
  display: inline;
}

/* Underline styles (derived from judou-like marking, but without inserting symbols) */
html.cv-annotations-on .corpus-textflow .ne-title,
html.cv-annotations-on .corpus-textflow .ne-title-auto {
  text-decoration: underline;
  text-decoration-color: var(--ne-title);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.15em;
}

.corpus-textflow .ne-person {
  text-decoration: underline;
  text-decoration-color: var(--ne-person);
  text-decoration-style: solid;
  text-decoration-thickness: 3px;
  text-underline-offset: 0.15em;
}

.corpus-textflow .ne-place {
  text-decoration: underline;
  text-decoration-color: var(--ne-place);
  text-decoration-style: double;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.15em;
}

.corpus-textflow .ne-office {
  text-decoration: underline;
  text-decoration-color: var(--ne-office);
  text-decoration-style: wavy;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.15em;
}

/* Auto titles should be visually slightly lighter than manual titles */
.corpus-textflow .ne-title-auto {
  opacity: 0.9;
}

/* Annotation popover menu */
.corpus-annot-menu {
  position: absolute;
  z-index: 9999;
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.25);
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  padding: 10px;
  display: none;
  max-width: 360px;
}

.corpus-annot-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
  flex-wrap: wrap;
}

.corpus-annot-menu button {
  padding: 7px 10px;
  border: 1px solid #bbb;
  background: #f6f6f6;
  border-radius: 6px;
  cursor: pointer;
}

.corpus-annot-menu button.primary {
  background: #111;
  color: #fff;
  border-color: #111;
}

.corpus-annot-menu button.danger {
  background: #fff5f5;
  border-color: #fed7d7;
}

.corpus-annot-menu button.selected {
  outline: 2px solid rgba(0,0,0,0.25);
}

.corpus-annot-label {
  font-size: 12px;
  opacity: 0.8;
}

.corpus-annot-note {
  flex: 1 1 auto;
  min-width: 180px;
  padding: 6px 8px;
  border: 1px solid #bbb;
  border-radius: 6px;
}

.corpus-annot-select {
  padding: 6px 8px;
  border: 1px solid #bbb;
  border-radius: 6px;
}

.corpus-annot-colors {
  border: 1px solid rgba(0,0,0,0.25);
  border-radius: 12px;
  padding: 14px 16px;
}

.corpus-annot-colors h3 {
  margin: 0 0 10px 0;
}

.corpus-annot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin-bottom: 10px;
}

.corpus-annot-grid label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ---------- Notes: smaller + (optionally) multi-column ---------- */
.corpus-note-block {
  font-size: 0.70em;
  line-height: 1.35;
  opacity: 0.95;
  display: inline-block;
  vertical-align: baseline;
  /* Traditional notes often stack; columns makes dense notes more readable. */
  column-count: 2;
  column-gap: 1.2em;
}

/* Give different note types slightly different tint (subtle, not required for meaning) */
.corpus-note-fang { opacity: 0.95; }
.corpus-note-brace { opacity: 0.92; }
.corpus-note-angle { opacity: 0.92; }
.corpus-note-square { opacity: 0.92; }

/* Hide bracket glyphs inside note blocks (keeps corpus indices stable, but removes visual noise). */
.corpus-note-block .note-bracket { display: none; }

/* Columns fight vertical writing-mode and cause large spacing gaps. Disable columns in vertical. */
.corpus-textflow.is-vertical .corpus-note-block {
  column-count: 1;
  display: inline;
}




/* Annotation viewing toggle: default is ON. When OFF, remove underline styling without touching DOM classes. */
html.cv-annotations-off .corpus-textflow .ne-title,
html.cv-annotations-off .corpus-textflow .ne-title-auto,
html.cv-annotations-off .corpus-textflow .ne-person,
html.cv-annotations-off .corpus-textflow .ne-place,
html.cv-annotations-off .corpus-textflow .ne-office {
  text-decoration: none !important;
}


/* Notes layer (footnote-style) */
.corpus-note-block.notes-collapsed {
  display: none;
}

/* Hide bracket glyph spans when notes are shown (keeps indices stable but removes visual clutter) */
html.cv-notes-on .corpus-textflow .note-bracket {
  display: none;
}

.corpus-note-marker {
  display: inline-block;
  font-size: 0.65em;
  line-height: 1;
  vertical-align: super;
  margin-right: 0.1em;
  color: var(--ne-note);
  opacity: 0.95;
}

.corpus-footnotes {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid rgba(0,0,0,0.15);
  font-size: 0.95em;
}

.corpus-footnotes h3 {
  margin: 0 0 10px 0;
  font-size: 1em;
}

.corpus-footnotes-list {
  margin: 0;
  padding-left: 1.4em;
}

.corpus-footnotes-list li {
  margin: 6px 0;
}

.corpus-footnote-n {
  color: var(--ne-note);
  font-weight: 600;
}


.corpus-annot-menu button:hover {
  filter: brightness(0.98);
}

.corpus-annot-menu button:focus {
  outline: 2px solid rgba(43,108,176,0.35);
  outline-offset: 2px;
}

/* Inline corpus note blocks: hide bracket glyph spans to avoid visual gaps */
.corpus-note-block .note-bracket {
  display: none;
}

/* Prevent awkward trailing spacing inside inline notes */
.corpus-note-block {
  white-space: normal;
}

/* Corpus toolbar buttons: clearer on/off states */
.corpus-btn[aria-pressed="true"] {
  font-weight: 600;
}



/* ---- User-added annotation notes (bottom panel) ---- */
.cv-user-note-anchor { position: relative; }
.cv-user-note-anchor::after {
  content: attr(data-note-marker);
  position: absolute;
  top: -0.6em;
  right: -0.3em;
  font-size: 0.6em;
  line-height: 1;
  color: var(--cv-color-title, #1b4fff);
}

.cv-user-notes-panel {
  margin-top: 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(0,0,0,0.15);
}
.cv-user-notes-title { margin: 0 0 0.5rem 0; font-size: 1.05rem; }
.cv-user-notes-list { margin: 0; padding-left: 1.25rem; }
.cv-user-note-marker { color: var(--cv-color-title, #1b4fff); font-weight: 600; }

/* Inline corpus bracket notes: reduce ugly spacing inflation */
.corpus-note-block { white-space: normal; }


/* ---- Annotation popover (edit mode) ---- */
.cv-annotate-popover {
  position: absolute;
  z-index: 9999;
  background: rgba(255,255,255,0.99);
  border: 1px solid rgba(0,0,0,0.25);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 14px 36px rgba(0,0,0,0.22);
  font-size: 16px;
  line-height: 1.45;
  width: min(26rem, calc(100vw - 1.5rem));
  max-width: 26rem;
}
html.dark-mode .cv-annotate-popover {
  background: rgba(20,20,20,0.98);
  color: rgba(255,255,255,0.92);
  border-color: rgba(255,255,255,0.18);
}
.cv-annotate-row { display: flex; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.cv-annotate-row button {
  border: 1px solid rgba(0,0,0,0.25);
  border-radius: 10px;
  padding: 0.7rem 0.95rem;
  background: rgba(255,255,255,0.92);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1.2;
}
html.dark-mode .cv-annotate-row button {
  background: rgba(30,30,30,0.85);
  border-color: rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.92);
}
.cv-annotate-note {
  width: 100%;
  border: 1px solid rgba(0,0,0,0.25);
  border-radius: 10px;
  padding: 0.8rem 0.95rem;
  font-size: 1rem;
  line-height: 1.45;
  min-height: 6.5rem;
}
html.dark-mode .cv-annotate-note {
  background: rgba(30,30,30,0.85);
  border-color: rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.92);
}
.cv-annotate-actions { justify-content: flex-end; }
.cv-annotate-actions .cv-cancel { opacity: 0.9; }



/* User-added note markers (out-of-text notes) */
.corpus-textflow .cv-user-note-anchor {
  position: relative;
}

.corpus-textflow .cv-user-note-anchor::after {
  content: attr(data-note-marker);
  position: absolute;
  top: -0.6em;
  right: -0.4em;
  font-size: 0.65em;
  color: #2b6cb0; /* blue */
  font-weight: 600;
  line-height: 1;
}

.cv-user-notes-panel {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 12px;
  background: rgba(255,255,255,0.9);
}

.cv-user-notes-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

.cv-user-notes-list {
  margin: 0;
  padding-left: 22px;
}

.cv-user-note-marker {
  color: #2b6cb0;
  font-weight: 700;
}

/* Reduce ugly trailing-space widening in inline bracket notes */
.corpus-note-block {
  white-space: normal;
}


/* Judou submenu (punctuation vs underlining) */
.cv-judou-menu{
  position: absolute;
  z-index: 40;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid rgba(0,0,0,0.2);
  background: var(--cv-toolbar-bg, #fff);
  color: var(--cv-toolbar-fg, #111);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.15);
}
.cv-judou-opt{ display:block; margin:4px 0; font-size: 14px; }

.corpus-toolbar{ position: relative; }


/* Annotate popover kind buttons: colour cues */
.cv-annotate-popover .cv-annotate-kinds { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.cv-annotate-popover button.cv-annotate-kind { padding: 0.75rem 0.95rem; border-radius: 10px; border: 1px solid #666; background: rgba(0,0,0,0.08); cursor: pointer; font-size: 1rem; font-weight: 600; }
.cv-annotate-popover button.cv-annotate-kind[data-kind="title"] { border-color: var(--ne-title, #3b82f6); }
.cv-annotate-popover button.cv-annotate-kind[data-kind="person"] { border-color: var(--ne-person, #facc15); }
.cv-annotate-popover button.cv-annotate-kind[data-kind="place"] { border-color: var(--ne-place, #22c55e); }
.cv-annotate-popover button.cv-annotate-kind[data-kind="office"] { border-color: var(--ne-office, #ef4444); }

/* Blue Chinese numerals for out-of-text note anchors */
.ne-note-anchor { position: relative; }
.ne-note-anchor::after { content: attr(data-ne-numeral); position: absolute; top: -0.6em; right: -0.2em; font-size: 0.75em; color: var(--ne-note-marker, #3b82f6); }

/* Reduce trailing-space blowout */
.corpus-textflow { white-space: pre-line; }
.corpus-note-block { white-space: normal; }

/* === Repetition marks (々 / 〻 / 二) === */
.jp-repeat-mark {
  display: inline-block;
  line-height: 1;
}

/* In horizontal flow, show the mark as a subscript (typographic convention). */
.jp-repeat-sub {
  vertical-align: sub;
  font-size: 0.75em;
}

/* --- Ticket-based text edit panel --- */

.hidden { display: none !important; }

.cv-text-edit-panel {
  position: fixed;
  top: 5vh;
  left: 5vw;
  width: 90vw;
  max-height: 88vh;
  overflow: auto;
  background: var(--cv-panel-bg, #fff);
  color: inherit;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.22);
  z-index: 9999;
}

.cv-text-edit-panel h3 { margin: 0 0 8px 0; }

.cv-hint {
  margin: 0 0 12px 0;
  opacity: 0.85;
}

.cv-form-row { margin-bottom: 14px; }
.cv-form-row label { display: block; font-weight: 700; margin-bottom: 6px; }

.cv-input,
.cv-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.8rem 0.95rem;
  border: 1px solid rgba(0,0,0,0.22);
  border-radius: 10px;
  background: inherit;
  color: inherit;
  font-size: 1rem;
  line-height: 1.5;
}

.cv-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

.cv-form-actions { display: flex; gap: 8px; margin-top: 10px; }

.cv-ticket-result { margin-top: 12px; }
.cv-ticket-status { margin-bottom: 6px; font-weight: 600; }
.cv-ticket-kv code { padding: 2px 6px; border-radius: 6px; background: rgba(0,0,0,0.08); }


.cv-pre-wrap {
  white-space: pre-wrap;
  word-break: break-word;
}

.cv-message-card {
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}

.cv-ticket-list {
  padding-left: 20px;
}

.cv-ticket-list li {
  margin-bottom: 8px;
}


.cv-annotation-ticket-panel {
  margin-top: 1rem;
}

.corpus-btn-editing {
  min-height: 2.9rem;
  padding-inline: 1rem;
  font-weight: 600;
}

.corpus-btn-review-submit {
  min-height: 3.2rem;
  min-width: 12.5rem;
  padding-inline: 1.2rem;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,0,0,0.14);
}

.cv-annotation-ticket-card {
  border: 1px solid #d8d8d8;
  border-radius: 0.95rem;
  padding: 1.2rem;
  background: #fff;
  font-size: 1rem;
  line-height: 1.5;
}

.cv-annotation-ticket-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.cv-annotation-preview-list {
  display: grid;
  gap: 0.75rem;
}

.cv-annotation-preview-card {
  border: 1px solid #e3e3e3;
  border-radius: 0.8rem;
  padding: 1rem;
  background: #fafafa;
}

.cv-annotation-preview-head {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.cv-annotation-preview-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.98rem;
  word-break: break-word;
  margin-bottom: 0.55rem;
}

.cv-annotation-preview-note {
  opacity: 0.9;
}

.cv-inline-check {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}


.cv-annotate-kind.active {
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.26);
  transform: translateY(1px);
  font-weight: 700;
  background: rgba(0,0,0,0.14);
}

.corpus-textflow .cv-annotate-selection-preview {
  background: color-mix(in srgb, var(--ne-title, #2b6cb0) 18%, transparent);
  outline: 1px dashed color-mix(in srgb, var(--ne-title, #2b6cb0) 55%, transparent);
  border-radius: 3px;
}

.cv-annotate-selection-preview-row {
  margin-bottom: 0.35rem;
}

.cv-annotate-selection-preview {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.96rem;
  line-height: 1.45;
  padding: 0.7rem 0.8rem;
  border-radius: 0.7rem;
  background: rgba(0,0,0,0.06);
  word-break: break-word;
}

.cv-annotation-preview-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.cv-annotation-preview-row {
  display: block;
}

.cv-annotation-preview-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, auto));
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.75rem;
}

.cv-annotation-preview-controls label,
.cv-annotation-preview-note-editor {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-weight: 600;
}

.cv-annotation-preview-controls input,
.cv-annotation-preview-controls select,
.cv-annotation-preview-note-editor textarea {
  padding: 0.7rem 0.8rem;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 0.65rem;
  background: #fff;
  color: inherit;
  font-size: 1rem;
  line-height: 1.45;
}

.cv-annotation-preview-note-editor textarea {
  width: 100%;
  box-sizing: border-box;
  font-weight: 400;
}

.cv-annotation-ticket-editor {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.cv-annotation-ticket-editor-card {
  border: 1px solid #ddd;
  border-radius: 0.75rem;
  padding: 0.85rem;
  background: #fafafa;
}

.cv-annotation-ticket-editor-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}


@media (max-width: 760px) {
  .cv-annotation-preview-controls {
    grid-template-columns: 1fr 1fr;
  }

  .cv-annotate-popover {
    width: min(30rem, calc(100vw - 1rem));
    max-width: calc(100vw - 1rem);
  }
}

/* narrow usability fix */
.cv-annotate-popover button.cv-annotate-kind,
.cv-annotate-popover .cv-annotate-apply,
.cv-annotate-popover .cv-annotate-cancel {
  touch-action: manipulation;
}


.cv-annotate-head.cv-annotate-drag-handle {
  cursor: move;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -2px 0 6px 0;
  font-weight: 700;
}

.cv-annotation-ticket-panel {
  width: min(70rem, 92vw);
  max-width: 92vw;
}

.cv-annotation-ticket-panel .cv-annotation-ticket-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cv-annotation-ticket-panel .cv-annotation-ticket-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}


.cv-submission-panel { max-width: 920px; }
.cv-submission-page-card { border: 1px solid rgba(0,0,0,0.12); border-radius: 10px; padding: 12px; margin: 10px 0; background: rgba(255,255,255,0.9); }
.cv-submission-panel code { padding: 2px 6px; border-radius: 6px; background: rgba(0,0,0,0.08); }

.corpus-tradition-strip {
  margin: 0 0 12px;
}

.corpus-segmented-control {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border: 1px solid rgba(0,0,0,0.14);
  border-radius: 12px;
  overflow: hidden;
  width: fit-content;
  max-width: 100%;
  background: rgba(255,255,255,0.92);
}

.corpus-segmented-control__btn {
  border-radius: 0;
  border: 0;
  border-right: 1px solid rgba(0,0,0,0.12);
  text-decoration: none;
}

.corpus-segmented-control__btn:last-child {
  border-right: 0;
}

.corpus-segmented-control__btn.is-active {
  background: rgba(0,0,0,0.12);
  font-weight: 700;
}

.corpus-segmented-control__btn.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.cv-kanbun-panel {
  max-width: 1120px;
}

.cv-kanbun-side-by-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.cv-kanbun-pane {
  min-width: 0;
}

.cv-kanbun-keyboard {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
}

.cv-kanbun-key {
  min-height: 2.7rem;
  font-size: 1.15rem;
}

.cch.kanbun-annotation-mark {
  color: #b00020;
  font-weight: 700;
}

@media (max-width: 900px) {
  .cv-kanbun-side-by-side {
    grid-template-columns: 1fr;
  }

  .cv-kanbun-keyboard {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ---------- Companion materials and ambiguous-character flags ---------- */
:root {
  --ne-ambiguous: #7c3aed;
}

.corpus-textflow .ne-ambiguous-character {
  text-decoration: underline;
  text-decoration-color: var(--ne-ambiguous);
  text-decoration-style: dotted;
  text-decoration-thickness: 3px;
  text-underline-offset: 0.18em;
  background: color-mix(in srgb, var(--ne-ambiguous) 10%, transparent);
}

html.cv-annotations-off .corpus-textflow .ne-ambiguous-character {
  text-decoration: none !important;
  background: transparent !important;
}

.cv-annotate-popover button.cv-annotate-kind[data-kind="ambiguous_character"] {
  border-color: var(--ne-ambiguous);
}

.cv-material-provenance {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  border: 1px solid rgba(0,0,0,0.14);
  border-radius: 10px;
  padding: 0.75rem;
}

.cv-material-provenance legend {
  font-weight: 700;
  padding: 0 0.3rem;
}

.cv-material-provenance .cv-hint {
  flex-basis: 100%;
}

.cv-companion-submission-panel {
  max-width: 980px;
}

.corpus-toolbar-control-group {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  min-width: 0;
  white-space: nowrap;
}

.corpus-toolbar-control-group > .corpus-btn {
  margin: 0;
}

.corpus-toolbar-control-group__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 4px 0 0 4px;
}

.corpus-toolbar-control-group__trigger[aria-expanded="true"] {
  background: #e9e9e9;
  border-color: #999;
}

.corpus-toolbar-control-group__trigger:disabled {
  cursor: default;
  opacity: 0.62;
}

.corpus-toolbar-control-group__add {
  min-width: 2.2rem;
  margin-left: -1px !important;
  padding-left: 0.65rem;
  padding-right: 0.65rem;
  border-radius: 0 4px 4px 0;
  font-weight: 700;
}

.corpus-toolbar-control-group--single .corpus-toolbar-control-group__trigger {
  border-radius: 4px;
}

.corpus-toolbar-control-group__chevron {
  font-size: 0.75em;
  line-height: 1;
}

.corpus-toolbar-traditions {
  display: inline-flex;
  align-items: center;
}

.cv-toolbar-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 50;
  min-width: 15rem;
  max-width: min(32rem, 90vw);
  max-height: 24rem;
  overflow: auto;
  display: grid;
  gap: 0.35rem;
  padding: 0.65rem;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 10px;
  background: var(--cv-toolbar-bg, #fff);
  box-shadow: 0 10px 24px rgba(0,0,0,0.16);
}

.cv-toolbar-menu[hidden] {
  display: none;
}

.cv-toolbar-menu .corpus-btn {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  text-decoration: none;
  font: inherit;
  color: inherit;
}

.cv-toolbar-menu .is-active {
  font-weight: 700;
  background: rgba(0,0,0,0.12);
}

.cv-companion-materials {
  margin: 1rem 0 0;
  border: 1px solid rgba(0,0,0,0.14);
  border-radius: 12px;
  padding: 0.85rem;
  background: rgba(255,255,255,0.92);
}

.cv-companion-materials__header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.cv-companion-materials__header h2 {
  margin: 0;
}

.cv-companion-section {
  margin-top: 0.8rem;
}

.cv-companion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.8rem;
  margin-top: 0.65rem;
}

.cv-companion-card {
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  padding: 0.75rem;
  background: #fff;
}

.cv-companion-card h3 {
  margin: 0 0 0.35rem;
}

.cv-companion-byline,
.cv-companion-edition,
.cv-companion-language-code {
  margin: 0.25rem 0;
}

.cv-companion-language-code {
  font-size: 0.84rem;
  opacity: 0.72;
}

.corpus-reader.is-translation-view .corpus-toolbar {
  gap: 0.55rem;
}

.cv-companion-media-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
}

.cv-companion-media-list figure {
  margin: 0;
}

.cv-companion-media-list img {
  display: block;
  width: 100%;
  max-height: 28rem;
  object-fit: contain;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  background: rgba(0,0,0,0.03);
}

.cv-companion-media-list figcaption,
.cv-companion-provenance {
  font-size: 0.88rem;
  opacity: 0.78;
}

.cv-ai-badge {
  display: inline-block;
  margin: 0 0 0.4rem;
  padding: 0.12rem 0.45rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

@media (max-width: 760px) {
  .cv-toolbar-menu {
    position: fixed;
    left: 5vw;
    right: 5vw;
    top: 20vh;
    max-width: none;
  }
}
