.content-viewer {
  --viewer-highlight-gold-bg: rgba(214, 168, 78, 0.34);
  --viewer-highlight-red-bg: rgba(229, 122, 104, 0.28);
  --viewer-highlight-amber-bg: rgba(227, 170, 77, 0.31);
  --viewer-highlight-green-bg: rgba(87, 192, 160, 0.27);
  --viewer-highlight-blue-bg: rgba(91, 141, 220, 0.3);
  --viewer-highlight-neutral-bg: rgba(151, 142, 125, 0.28);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 18px;
  align-items: start;
}

[data-theme="light"] .content-viewer {
  --viewer-highlight-gold-bg: rgba(214, 151, 32, 0.38);
  --viewer-highlight-red-bg: rgba(177, 63, 46, 0.2);
  --viewer-highlight-amber-bg: rgba(190, 127, 14, 0.26);
  --viewer-highlight-green-bg: rgba(28, 122, 93, 0.2);
  --viewer-highlight-blue-bg: rgba(58, 112, 190, 0.22);
  --viewer-highlight-neutral-bg: rgba(111, 104, 90, 0.2);
}

.viewer-main,
.viewer-notes {
  min-width: 0;
}

.viewer-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 14px 0 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.viewer-eyebrow {
  margin: 0 0 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--gold);
}

.viewer-toolbar h3,
.viewer-notes-head h3 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.viewer-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.viewer-stats span,
.viewer-note-kind,
.viewer-note-origin,
.viewer-ref {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font-mono);
}

.viewer-context-menu[hidden] {
  display: none;
}

.viewer-context-menu {
  position: fixed;
  z-index: 120;
  min-width: 168px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}

.viewer-context-section[hidden] {
  display: none;
}

.viewer-context-menu--mixed [data-annotation-actions] {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.viewer-context-menu button {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  border: 0;
  border-radius: 5px;
  background: transparent;
  padding: 8px 10px;
  text-align: left;
  color: var(--text);
}

.viewer-context-menu button:hover {
  background: var(--gold-soft);
  color: var(--text-strong);
}

.viewer-context-menu button.viewer-context-danger {
  color: var(--red);
}

.viewer-context-menu button.viewer-context-danger:hover {
  background: var(--red-soft);
  color: var(--red);
}

.viewer-hover-card[hidden] {
  display: none;
}

.viewer-hover-card {
  position: fixed;
  z-index: 140;
  width: min(320px, calc(100vw - 24px));
  max-height: min(260px, calc(100vh - 24px));
  overflow: auto;
  pointer-events: none;
  padding: 11px 12px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.viewer-hover-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 6px;
}

.viewer-hover-card-top strong {
  color: var(--text-strong);
  font-size: 13px;
  line-height: 1.25;
}

.viewer-hover-card-top span {
  flex: none;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.viewer-hover-card p {
  margin: 0;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.4;
}

.viewer-modal[hidden] {
  display: none;
}

.viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 160;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: clamp(12px, 3vh, 24px);
}

.viewer-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 4, 0.58);
}

.viewer-modal-panel {
  position: relative;
  z-index: 1;
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 32px));
  max-height: min(760px, calc(100dvh - 32px));
  overflow: auto;
  display: grid;
  gap: 13px;
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
}

.viewer-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.viewer-modal-head h3 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
}

.viewer-modal-panel blockquote {
  margin: 0;
  max-height: 120px;
  overflow: auto;
  padding: 10px 12px;
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  background: var(--bg-grain);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.viewer-modal-grid {
  display: grid;
  grid-template-columns: minmax(130px, 0.7fr) minmax(190px, 1fr);
  gap: 10px;
}

.viewer-modal-panel label {
  display: grid;
  gap: 5px;
}

.viewer-modal-panel label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.viewer-modal-panel select,
.viewer-modal-panel input,
.viewer-modal-panel textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-grain);
  color: var(--text);
  padding: 9px 10px;
}

.viewer-modal-panel textarea {
  resize: vertical;
  min-height: 126px;
}

.viewer-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 2px;
}

.viewer-body {
  display: grid;
  gap: 14px;
}

.viewer-page {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.viewer-page-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  user-select: none;
  -webkit-user-select: none;
}

.viewer-page-head span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-page-head strong,
.viewer-page-link,
.viewer-page-head em {
  color: var(--gold);
  font-style: normal;
  font-weight: 600;
}

.viewer-page-link:hover,
.viewer-page-link:focus-visible {
  color: var(--gold-bright);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.viewer-page-body {
  position: relative;
  --viewer-page-pad-x: 21px;
  --viewer-comment-gutter: 46px;
  --viewer-comment-icon-size: 28px;
  --viewer-comment-icon-offset: 4px;
  padding: 19px var(--viewer-page-pad-x) 22px calc(var(--viewer-page-pad-x) + var(--viewer-comment-gutter));
  color: var(--text);
  font-size: 15px;
  line-height: 1.72;
}

.viewer-page-body p {
  margin: 0 0 1.05em;
}

.viewer-page-body p:last-child,
.viewer-list:last-child {
  margin-bottom: 0;
}

.viewer-heading {
  margin: 0 0 0.75em;
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.22;
}

.viewer-list {
  margin: 0 0 1.05em;
  padding-left: 21px;
}

.viewer-list li {
  margin: 0 0 0.45em;
}

.viewer-muted {
  color: var(--muted);
}

.viewer-mark {
  --viewer-mark-color: var(--gold);
  --viewer-mark-bg: var(--gold-soft);
  background: transparent;
  color: inherit;
  border: 0;
  border-radius: 3px;
  padding: 0 1px;
  cursor: pointer;
  text-decoration: none;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: background 0.14s var(--ease), box-shadow 0.14s var(--ease), text-decoration-color 0.14s var(--ease);
}

.viewer-mark--gold {
  --viewer-mark-color: var(--gold);
  --viewer-mark-bg: var(--gold-soft);
  --viewer-highlight-bg: var(--viewer-highlight-gold-bg);
}

.viewer-mark--red {
  --viewer-mark-color: var(--red);
  --viewer-mark-bg: var(--red-soft);
  --viewer-highlight-bg: var(--viewer-highlight-red-bg);
}

.viewer-mark--amber {
  --viewer-mark-color: var(--amber);
  --viewer-mark-bg: var(--amber-soft);
  --viewer-highlight-bg: var(--viewer-highlight-amber-bg);
}

.viewer-mark--green {
  --viewer-mark-color: var(--green);
  --viewer-mark-bg: var(--green-soft);
  --viewer-highlight-bg: var(--viewer-highlight-green-bg);
}

.viewer-mark--blue {
  --viewer-mark-color: #5b8ddc;
  --viewer-mark-bg: rgba(91, 141, 220, 0.16);
  --viewer-highlight-bg: var(--viewer-highlight-blue-bg);
}

.viewer-mark--neutral {
  --viewer-mark-color: var(--line-strong);
  --viewer-mark-bg: var(--panel-2);
  --viewer-highlight-bg: var(--viewer-highlight-neutral-bg);
}

.viewer-mark-kind--highlight {
  background: var(--viewer-highlight-bg, var(--viewer-mark-bg));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--viewer-mark-color) 38%, transparent);
  padding: 0 2px;
}

.viewer-mark-kind--comment {
  text-decoration-line: underline;
  text-decoration-color: var(--viewer-mark-color);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  background: transparent;
}

.viewer-mark-kind--reference,
.viewer-mark-kind--question,
.viewer-mark-kind--risk,
.viewer-mark-kind--todo {
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--viewer-mark-color);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  background: transparent;
}

.viewer-mark.active {
  box-shadow: 0 2px 0 var(--viewer-mark-color);
}

.viewer-commented-range {
  display: inline;
}

.viewer-comment-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: calc(var(--viewer-page-pad-x) + var(--viewer-comment-icon-offset));
  top: 0;
  z-index: 1;
  width: var(--viewer-comment-icon-size);
  height: var(--viewer-comment-icon-size);
  margin: 0;
  padding: 0;
  border: 1px solid var(--gold-line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--gold);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.viewer-comment-anchor:hover,
.viewer-comment-anchor:focus-visible,
.viewer-comment-anchor.active {
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--gold-bright);
}

.viewer-comment-anchor svg {
  display: block;
  flex: none;
  width: 17px;
  height: 17px;
}

.viewer-notes {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 58px);
  overflow: auto;
  display: grid;
  gap: 10px;
  padding-right: 2px;
}

.viewer-notes-head {
  padding: 12px 0 4px;
  border-bottom: 1px solid var(--line);
}

.viewer-note {
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.14s var(--ease), background 0.14s var(--ease), transform 0.12s var(--ease);
}

.viewer-note:hover,
.viewer-note.active {
  background: var(--panel-hover);
  border-color: var(--line-strong);
}

.viewer-note.active {
  transform: translateX(-2px);
}

.viewer-note--red {
  border-left-color: var(--red);
}

.viewer-note--amber {
  border-left-color: var(--amber);
}

.viewer-note--green {
  border-left-color: var(--green);
}

.viewer-note--blue {
  border-left-color: #5b8ddc;
}

.viewer-note--neutral {
  border-left-color: var(--line-strong);
}

.viewer-note.unresolved {
  opacity: 0.82;
}

.viewer-note.unresolved blockquote {
  border-left-color: var(--red);
}

.viewer-note-top,
.viewer-note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.viewer-note-top {
  margin-bottom: 8px;
}

.viewer-note h4 {
  margin: 0 0 6px;
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.25;
}

.viewer-note blockquote {
  margin: 7px 0;
  padding: 7px 9px;
  border-left: 2px solid var(--line-strong);
  background: var(--bg-grain);
  color: var(--muted);
  font-size: 12px;
}

.viewer-note p {
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.45;
}

.viewer-note-meta {
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
}

.viewer-note-meta a,
.viewer-note-meta button {
  font-size: 11px;
  padding: 2px 7px;
}

.viewer-note-meta button {
  margin-left: auto;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.viewer-note-meta button:hover {
  color: var(--red);
  background: var(--red-soft);
  border-color: var(--red-line);
}

.viewer-empty-note {
  color: var(--muted);
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
}

@media (max-width: 980px) {
  .content-viewer {
    grid-template-columns: 1fr;
  }

  .viewer-notes {
    position: static;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .viewer-toolbar,
  .viewer-stats {
    display: grid;
    justify-content: stretch;
  }

  .viewer-modal-grid {
    grid-template-columns: 1fr;
  }

  .viewer-page-body {
    --viewer-page-pad-x: 15px;
    --viewer-comment-gutter: 38px;
    --viewer-comment-icon-offset: 2px;
    padding: 15px var(--viewer-page-pad-x) 15px calc(var(--viewer-page-pad-x) + var(--viewer-comment-gutter));
  }
}
