* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  min-height: 64px;
  padding: 12px 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ui-text-soft);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

.brand-name {
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}

.local-guest {
  flex: none;
  padding-left: 8px;
  border-left: 1px solid var(--ui-border);
  color: var(--ui-text-muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
}

.guest-space-badge {
  padding-block: 2px;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  background: transparent;
  cursor: pointer;
}

.guest-space-badge:hover {
  color: var(--ui-focus);
}

.guest-access-unavailable {
  color: var(--ui-danger);
}

.guest-access-dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 20px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 5px;
  background: var(--ui-surface);
  color: var(--ui-text);
}

.guest-access-dialog::backdrop {
  background: var(--ui-backdrop);
}

.guest-access-dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.guest-access-dialog-heading .button {
  min-height: 32px;
  padding-block: 4px;
}

.guest-access-explanation {
  margin-top: 14px;
  color: var(--ui-text-soft);
  font-size: 13px;
  line-height: 1.7;
}

.guest-access-model,
.guest-access-code-help {
  margin-top: 10px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.6;
}

.guest-access-recovery {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--ui-border);
}

.guest-access-recovery .guest-access-code-help {
  margin-top: 0;
}

.guest-access-code {
  display: block;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  user-select: all;
}

.guest-access-code:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
}

.guest-access-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.guest-access-rotation {
  margin-top: 12px;
  padding-left: 10px;
  border-left: 2px solid var(--ui-warning);
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.6;
}

.guest-access-status {
  min-height: 20px;
  margin-top: 10px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.6;
}

.guest-access-status[data-kind="error"] {
  color: var(--ui-danger);
}

.guest-access-recover-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--ui-focus);
  font-size: 12px;
  line-height: 1.6;
}

@media (max-width: 480px) {
  .guest-access-dialog {
    padding: 16px;
  }

  .guest-access-actions .button {
    min-height: 42px;
  }
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--ui-border-strong);
  color: var(--ui-primary);
  font-size: 11px;
  letter-spacing: 0.04em;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

h2 {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
}

h3 {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
}

.header-controls {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.theme-control {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ui-text-soft);
  font-size: 12px;
}

#theme-select {
  min-width: 0;
  max-width: 160px;
  min-height: 36px;
  padding: 6px 28px 6px 9px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
  cursor: pointer;
}

.language-toggle {
  flex: none;
  min-width: 40px;
}

.button {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--ui-control-border);
  border-radius: 3px;
  background: var(--ui-control-bg);
  color: var(--ui-text);
  line-height: 20px;
  text-align: center;
  cursor: pointer;
}

.button:hover:not(:disabled) {
  border-color: var(--ui-control-hover-border);
  background: var(--ui-surface-subtle);
}

.button:active:not(:disabled) {
  background: var(--ui-control-pressed-bg, var(--ui-surface-muted));
}

.button-primary {
  border-color: var(--ui-primary);
  background: var(--ui-primary);
  color: var(--ui-on-primary);
}

.button-primary:hover:not(:disabled) {
  border-color: var(--ui-primary-hover);
  background: var(--ui-primary-hover);
}

.button-secondary {
  background: var(--ui-surface);
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ui-text-soft);
}

.button-icon {
  width: 36px;
  padding: 4px;
  font-size: 18px;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  white-space: nowrap;
}

.app-status {
  min-height: 40px;
  padding: 8px 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-info-bg);
  color: var(--ui-text-soft);
}

.app-status[data-kind="error"] {
  border-color: var(--ui-danger-status-border);
  background: var(--ui-danger-bg);
  color: var(--ui-danger);
}

.app-status[data-kind="success"] {
  border-color: var(--ui-success-border);
  background: var(--ui-success-bg);
  color: var(--ui-success);
}

.status-retry {
  padding: 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(200px, 240px) minmax(360px, 1fr) minmax(280px, 340px);
  min-height: calc(100vh - 65px);
  align-items: stretch;
}

.documents-panel,
.notes-panel {
  background: var(--ui-surface);
  min-width: 0;
}

.documents-panel {
  border-right: 1px solid var(--ui-border);
}

.notes-panel {
  border-left: 1px solid var(--ui-border);
}

.panel-heading,
.reader-heading-row {
  min-height: 64px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--ui-border);
}

.empty-state {
  padding: 24px 16px;
  color: var(--ui-text-muted);
  line-height: 1.7;
}

.empty-state .button {
  margin-top: 16px;
}

.documents-list,
.notes-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.document-item {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--ui-border);
}

.document-open {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 36px;
  padding: 8px 12px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--ui-text);
  text-align: left;
  cursor: pointer;
}

.document-menu-button {
  flex: none;
  align-self: center;
  width: 40px;
  min-height: 40px;
  margin-right: 6px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--ui-text-soft);
  font-size: 20px;
  cursor: pointer;
}

.document-menu-button:hover,
.document-menu-button[aria-expanded="true"] {
  border-color: var(--ui-control-border);
  background: var(--ui-surface-subtle);
}

.sample-open-button { display: inline-flex; align-items: center; gap: 8px; }
.sample-open-button svg { width: 16px; height: 16px; flex: 0 0 auto; }

.document-actions-menu {
  position: fixed;
  z-index: 1000;
  min-width: 160px;
  padding: 4px;
  display: grid;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 16%);
}

.document-actions-menu .button {
  justify-content: flex-start;
  text-align: left;
}

.document-actions-menu [data-action="trash-document"] {
  color: var(--ui-danger);
}

.library-trash {
  margin: 12px 16px 0;
  border-top: 1px solid var(--ui-border);
}

.library-trash > summary {
  padding: 12px 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ui-text-soft);
  font-weight: 650;
  cursor: pointer;
}

.library-trash-help,
.library-trash-status,
.library-trash-empty {
  padding: 0 0 10px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.55;
}

.library-trash-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.library-trash-status[data-kind="error"] {
  color: var(--ui-danger);
}

.library-trash-status[data-kind="success"] {
  color: var(--ui-success);
}

.library-trash-item {
  padding: 8px 0;
  display: block;
}

.library-trash-actions {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.library-trash-item .button {
  min-height: 40px;
  padding-inline: 0;
}

.library-trash-item [data-action="purge-document"] {
  color: var(--ui-danger);
}

.document-rename-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 5px;
  background: var(--ui-surface);
  color: var(--ui-text);
}

.document-rename-dialog::backdrop {
  background: rgb(0 0 0 / 35%);
}

.document-rename-dialog label {
  display: block;
  margin: 18px 0 6px;
  color: var(--ui-text-soft);
  font-size: 12px;
  font-weight: 650;
}

#document-rename-title {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.document-rename-status {
  min-height: 20px;
  margin-top: 10px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.document-rename-status[data-kind="error"] {
  color: var(--ui-danger);
}

.document-rename-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.document-open:hover {
  background: var(--ui-sidebar-hover-bg);
}

.document-item[data-active="true"] .document-open {
  border-left-color: var(--ui-primary);
  background: var(--ui-selected);
}

.document-name {
  display: block;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.document-meta {
  display: block;
  margin-top: 4px;
  color: var(--ui-text-muted);
  font-size: 12px;
}

#documents-list .document-item {
  height: 58px;
  min-width: 0;
  overflow: hidden;
}

#documents-list .document-open {
  height: 58px;
  min-height: 0;
  overflow: hidden;
}

#documents-list .document-name,
#documents-list .document-meta {
  min-width: 0;
  overflow: hidden;
  overflow-wrap: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#documents-list .document-name {
  line-height: 20px;
}

#documents-list .document-meta {
  line-height: 18px;
}

#documents-list .document-menu-button {
  height: 40px;
  min-height: 40px;
}

#documents-list :is(.document-open, .document-menu-button):focus-visible {
  outline-offset: -3px;
}

#review-explainer,
#study-review-explainer {
  display: none;
}

.reader-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--ui-bg);
}

.reader-heading-row {
  background: var(--ui-surface);
}

.reader-title-wrap {
  min-width: 0;
}

.document-title {
  max-width: 100%;
  margin-top: 4px;
  overflow: hidden;
  color: var(--ui-text-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-count {
  flex: none;
  color: var(--ui-text-muted);
  font-size: 12px;
}

.reader-toolbar {
  min-height: 52px;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface-subtle);
}

.page-controls,
.zoom-controls,
.reader-source-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.text-annotation-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.text-annotation-toolbar[data-contextual="true"] {
  position: fixed;
  z-index: 50;
  width: max-content;
  max-width: calc(100vw - 16px);
  padding: 6px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-surface);
  box-shadow: 0 6px 22px rgb(0 0 0 / 20%);
}

.text-annotation-colors {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.text-annotation-colors label {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 32px;
  padding: 2px 4px;
  color: var(--ui-text-soft);
  font-size: 12px;
  cursor: pointer;
}

.reader-text-status {
  padding: 8px 16px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-info-bg);
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.export-reading-record {
  flex: none;
  margin-left: auto;
}

.annotated-pdf-export {
  display: flex;
  flex: 0 1 auto;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 8px;
  min-width: 0;
}

.page-label {
  display: flex;
}

#page-input {
  width: 56px;
  height: 36px;
  padding: 4px 6px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
  text-align: center;
  appearance: textfield;
}

#page-input::-webkit-inner-spin-button,
#page-input::-webkit-outer-spin-button {
  appearance: none;
}

#zoom-label {
  min-width: 48px;
  color: var(--ui-text-soft);
  font-size: 12px;
  text-align: center;
}

.reader-stage {
  position: relative;
  flex: 1;
  min-height: 480px;
  padding: 24px;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.reader-stage[data-view-mode="continuous"],
.reader-stage[data-reader-layout-locked="true"] {
  overflow-anchor: none;
}

.reader-loading {
  align-self: center;
  width: min(360px, 100%);
  padding: 40px 16px;
  color: var(--ui-text-soft);
  font-size: 14px;
  line-height: 1.55;
  text-align: center;
}

.reader-loading-progress {
  display: block;
  width: 100%;
  height: 8px;
  margin-top: 14px;
  accent-color: var(--ui-primary);
}

.reader-loading-hint {
  margin-top: 16px;
  color: var(--ui-text-muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
}

.reader-loading-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 12px;
  margin-top: 8px;
}

.reader-loading-actions .button {
  text-decoration: none;
}

.reader-error-reference {
  padding: 6px 16px;
  color: var(--ui-text-muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.reader-empty {
  align-self: center;
  max-width: 320px;
  padding: 48px 16px;
  color: var(--ui-text-muted);
  line-height: 1.7;
  text-align: center;
}

.reader-open-original {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  text-decoration: none;
}

.reader-open-original[hidden] {
  display: none;
}

.page-surface {
  position: relative;
  flex: none;
  background: var(--ui-surface);
  box-shadow: 0 0 0 1px var(--ui-border-strong);
}

.page-surface > canvas {
  display: block;
  max-width: none;
  background: #ffffff;
}

.textLayer {
  z-index: 1;
  pointer-events: none;
}

.textLayer :is(span, br) {
  pointer-events: auto;
}

.textLayer ::selection {
  background: rgb(49 115 154 / 18%);
  background: color-mix(in srgb, var(--ui-primary) 18%, transparent);
}

.reader-image-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.reader-image-layer canvas {
  pointer-events: auto;
}

.reader-link-layer {
  z-index: 2;
}

.reader-link-layer .linkAnnotation > a:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: -2px;
}

.text-annotations-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.text-annotation {
  position: absolute;
  pointer-events: none;
}

.text-annotation[data-kind="highlight"] {
  background: rgb(250 204 21 / 32%);
}

.text-annotation[data-kind="highlight"][data-color="green"] {
  background: rgb(74 222 128 / 32%);
}

.text-annotation[data-kind="highlight"][data-color="blue"] {
  background: rgb(96 165 250 / 30%);
}

.text-annotation[data-kind="highlight"][data-color="pink"] {
  background: rgb(244 114 182 / 28%);
}

.text-annotation[data-kind="underline"] {
  border-bottom: 2px solid #ca8a04;
}

.text-annotation[data-kind="underline"][data-color="green"] {
  border-bottom-color: #16a34a;
}

.text-annotation[data-kind="underline"][data-color="blue"] {
  border-bottom-color: #2563eb;
}

.text-annotation[data-kind="underline"][data-color="pink"] {
  border-bottom-color: #db2777;
}

.region-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.region-overlay[data-active="true"] {
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}

.active-selection,
.source-highlight {
  position: absolute;
  border: 2px solid var(--ui-focus);
  background: color-mix(in srgb, var(--ui-focus) 14%, transparent);
  pointer-events: none;
}

.source-highlight[data-whole-page="true"] {
  border-width: 3px;
  background: transparent;
}

.source-highlight[data-text-annotation="true"] {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.source-highlight-line {
  position: absolute;
  border: 1px solid var(--ui-focus);
  background: transparent;
  pointer-events: none;
}

.notes-panel {
  padding-bottom: 24px;
}

.note-editor {
  padding: 16px;
  border-bottom: 1px solid var(--ui-border);
}

.source-heading {
  min-height: 24px;
  margin-bottom: 8px;
}

.active-source {
  color: var(--ui-text-soft);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.5;
}

.source-options {
  margin: 0 0 12px;
  color: var(--ui-text-muted);
  font-size: 12px;
}

.source-options > summary {
  width: max-content;
  min-height: 32px;
  cursor: pointer;
}

.source-options .anchor-actions {
  margin-top: 4px;
}

.anchor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

#reader-region-mode[aria-pressed="true"] {
  border-color: var(--ui-focus);
  background: var(--ui-selected);
  color: var(--ui-text);
}

.anchor-help {
  margin: 8px 0 16px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.6;
}

.region-draft {
  margin: 0 0 16px;
  padding: 8px;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-surface-subtle);
}

.region-draft-preview canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 320px;
  margin: 0 auto;
  box-shadow: 0 0 0 1px var(--ui-border);
}

.region-draft-footer {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
}

#region-draft-status {
  margin: 8px 0 0;
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.5;
}

#region-draft-status[data-kind="error"] {
  color: var(--ui-danger);
}

.note-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ui-text-soft);
  font-size: 12px;
  font-weight: 650;
}

#note-text {
  display: block;
  width: 100%;
  min-height: 136px;
  padding: 12px;
  resize: vertical;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
  line-height: 1.6;
}

#note-text::placeholder {
  color: var(--ui-text-muted);
}

.note-editor-footer {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.note-save-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.character-count,
.notes-count {
  flex: none;
  color: var(--ui-text-muted);
  font-size: 12px;
}

.saved-notes-heading {
  padding: 16px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.notes-empty {
  padding: 12px 16px;
  color: var(--ui-text-muted);
  font-size: 13px;
  line-height: 1.6;
}

.note-item {
  margin: 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ui-border);
}

.note-open {
  width: 100%;
  padding: 12px 0;
  border: 0;
  background: transparent;
  color: var(--ui-text);
  text-align: left;
  cursor: pointer;
}

.note-open:hover .note-text-preview {
  color: var(--ui-primary);
}

.note-source {
  display: block;
  margin-bottom: 4px;
  color: var(--ui-text-muted);
  font-size: 12px;
}

.note-text-preview {
  display: block;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.55;
}

.excerpt-preview {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 0;
  border: 1px solid var(--ui-border);
  border-radius: 3px;
  background: var(--ui-surface-subtle);
  cursor: pointer;
}

.excerpt-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 320px;
  margin: 0 auto;
}

.note-excerpt-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.excerpt-download {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--ui-control-border);
  border-radius: 3px;
  background: var(--ui-control-bg);
  color: var(--ui-text);
  line-height: 20px;
  text-decoration: none;
}

.excerpt-download:hover {
  border-color: var(--ui-control-hover-border);
  background: var(--ui-surface-subtle);
}

.edit-mode-label {
  margin-bottom: 8px;
  padding: 6px 8px;
  border-left: 3px solid var(--ui-primary);
  background: var(--ui-selected);
  color: var(--ui-text-soft);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.5;
}

.review-explainer,
.deleted-notes-help {
  padding: 0 16px 8px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.55;
}

.note-review-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
}

.review-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 7px;
  border: 1px solid var(--ui-border);
  border-radius: 3px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 18px;
}

.review-badge[data-status="source_checked"] {
  border-color: var(--ui-success-border);
  background: var(--ui-success-bg);
  color: var(--ui-success);
}

.note-annotation-quote {
  display: block;
  margin: 4px 0 8px;
  padding-left: 8px;
  border-left: 3px solid var(--ui-border-strong);
  color: var(--ui-text-soft);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.5;
}

.annotation-style-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 6px;
}

.annotation-style-control {
  display: grid;
  gap: 3px;
  color: var(--ui-text-muted);
  font-size: 11px;
}

.annotation-style-control select {
  max-width: 100%;
  min-height: 34px;
  padding: 4px 24px 4px 7px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding-top: 6px;
}

.note-actions .button {
  min-height: 34px;
  padding: 5px 9px;
  font-size: 12px;
}

.note-actions [data-action="delete-note"],
.note-actions [data-action="purge-note"] {
  color: var(--ui-danger);
}

.deleted-notes {
  margin: 16px 16px 0;
  border-top: 1px solid var(--ui-border);
}

.deleted-notes summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 0;
  color: var(--ui-text-soft);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.deleted-notes-help {
  padding-inline: 0;
}

.deleted-note-item {
  padding: 8px 0 12px;
  border-bottom: 1px solid var(--ui-border);
}

.deleted-note-item .note-open {
  padding-top: 4px;
}

.deleted-note-item .note-text-preview {
  color: var(--ui-text-muted);
}

.library-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--ui-border);
}

.library-search-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ui-text-soft);
  font-size: 13px;
  font-weight: 650;
}

.library-search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#library-search-input {
  flex: 1 1 120px;
  min-width: 0;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.library-search-row .button {
  padding-inline: 9px;
}

.library-search-status {
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--ui-border);
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.library-search-status[data-kind="error"] {
  color: var(--ui-danger);
}

.library-search-results {
  border-bottom: 1px solid var(--ui-border);
}

.search-group-heading {
  padding: 12px 16px 4px;
  color: var(--ui-text-soft);
}

.search-result-item {
  border-bottom: 1px solid var(--ui-border);
}

.search-result-open {
  width: 100%;
  padding: 12px 16px;
  border: 0;
  background: transparent;
  color: var(--ui-text);
  text-align: left;
  cursor: pointer;
}

.search-result-open:hover {
  background: var(--ui-sidebar-hover-bg);
}

.search-result-title,
.search-result-meta,
.search-result-note {
  display: block;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.search-result-meta {
  margin-top: 4px;
  color: var(--ui-text-muted);
  font-size: 12px;
}

.search-result-note {
  margin-top: 4px;
  white-space: pre-wrap;
}

.search-more {
  padding: 8px 16px 12px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.metadata-panel {
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface);
}

.metadata-panel > summary {
  padding: 10px 16px;
  color: var(--ui-text-soft);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.metadata-form {
  padding: 0 16px 12px;
}

.metadata-fields {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 10px 12px;
}

.metadata-field {
  min-width: 0;
  color: var(--ui-text-soft);
  font-size: 12px;
  font-weight: 650;
}

.metadata-field input,
.metadata-doi-candidates select {
  display: block;
  width: 100%;
  min-height: 36px;
  margin-top: 5px;
  padding: 7px 9px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
  font-weight: 400;
}

.metadata-doi-candidates {
  margin-top: 10px;
}

.metadata-lookup-source {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.metadata-lookup-source[hidden] {
  display: none;
}

.metadata-lookup-warnings {
  flex-basis: 100%;
}

.metadata-field input[readonly] {
  border-color: transparent;
  background: var(--ui-surface-subtle);
}

.metadata-footer {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.metadata-status {
  flex: 1 1 220px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.metadata-status[data-kind="error"] {
  color: var(--ui-danger);
}

.metadata-status[data-kind="success"] {
  color: var(--ui-success);
}

.metadata-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.metadata-latest {
  margin-top: 10px;
  padding: 10px;
  border-left: 3px solid var(--ui-border-strong);
  background: var(--ui-surface-subtle);
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.6;
}

.metadata-latest dl {
  margin: 6px 0 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 3px 10px;
}

.metadata-latest dt {
  color: var(--ui-text-muted);
}

.metadata-latest dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 480px) {
  .note-editor-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .note-save-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (min-width: 821px) {
  body {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  .workspace {
    flex: 1;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);
  }

  .documents-panel,
  .reader-panel,
  .notes-panel,
  .data-workspace {
    min-height: 0;
  }

  .documents-panel,
  .notes-panel {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .notes-panel {
    scrollbar-gutter: stable;
  }

  .reader-stage {
    min-height: 0;
  }
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 200px minmax(320px, 1fr) 280px;
  }

  .reader-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 820px) {
  .app-header {
    padding: 12px 16px;
    grid-template-columns: 1fr auto;
  }

  .app-header h1 {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 16px;
  }

  .brand {
    min-width: 0;
  }

  .brand > .brand-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-controls {
    grid-column: 2;
    grid-row: 1;
  }

  .app-status {
    padding-inline: 16px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .documents-panel,
  .notes-panel {
    border: 0;
    border-bottom: 1px solid var(--ui-border);
  }

  .documents-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .document-item {
    border-right: 1px solid var(--ui-border);
  }

  .reader-stage {
    min-height: 420px;
    max-height: none;
    padding: 16px;
  }

  .reader-toolbar {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .note-item {
    margin-inline: 16px;
  }
}

@media (max-width: 480px) {
  .panel-heading,
  .reader-heading-row,
  .reader-toolbar {
    padding-inline: 12px;
  }

  .library-search {
    padding-inline: 12px;
  }

  .metadata-panel > summary {
    padding-inline: 12px;
  }

  .metadata-form {
    padding-inline: 12px;
  }

  .metadata-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .metadata-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .reader-stage {
    padding: 12px;
  }

  .text-annotation-toolbar[data-contextual="true"] {
    width: calc(100vw - 16px);
    min-width: 0;
  }

  #zoom-fit {
    display: none;
  }

  .anchor-actions .button {
    flex: 1;
  }
}

.reader-reading-controls,
.reader-view-label,
.reader-find-row,
.notes-filter-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.reader-view-label {
  color: var(--ui-text-soft);
  font-size: 12px;
}

.reader-view-label select,
.notes-filter-grid select,
.notes-filter-grid input,
#reader-find-input {
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.reader-find-panel {
  padding: 8px 16px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface);
}

#reader-find-input {
  flex: 1;
  width: 160px;
  min-width: 120px;
}

.reader-find-status,
.notes-filter-status {
  margin: 6px 0 0;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.reader-find-status[data-kind="error"],
.notes-filter-status[data-kind="error"] {
  color: var(--ui-danger);
}

.reader-find-results {
  max-height: 180px;
  margin: 6px 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.reader-find-results:empty {
  display: none;
}

.reader-find-result button {
  width: 100%;
  padding: 5px 8px;
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--ui-text);
  text-align: left;
  cursor: pointer;
}

.reader-find-result button:hover,
.reader-find-result[data-active="true"] button {
  border-left-color: var(--ui-primary);
  background: var(--ui-selected);
}

.reader-find-result-page {
  margin-right: 8px;
  color: var(--ui-text-muted);
  font-size: 12px;
}

.reader-find-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.reader-find-match {
  position: absolute;
  background: rgb(250 204 21 / 42%);
  box-shadow: 0 0 0 1px rgb(202 138 4 / 65%);
  pointer-events: none;
}

.reader-find-match[data-find-active="true"] {
  background: rgb(249 115 22 / 48%);
  box-shadow: 0 0 0 2px #c2410c;
}

.reader-pages {
  width: 100%;
  min-width: 0;
}

.reader-stage[data-view-mode="continuous"] {
  display: block;
  overscroll-behavior: contain;
}

.reader-stage[data-view-mode="continuous"] .reader-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.reader-stage[data-view-mode="single"] .reader-pages {
  display: flex;
  justify-content: center;
}

.reader-page-wrap {
  position: relative;
  flex: none;
}

.reader-page-status {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  color: var(--ui-text-muted);
  background: var(--ui-surface);
  text-align: center;
  font-size: 12px;
}

.reader-page-status[hidden] {
  display: none;
}

.notes-filter-panel {
  margin: 0 16px 8px;
  padding: 10px;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  background: var(--ui-surface-subtle);
}

.notes-filter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(90px, 0.6fr);
  gap: 8px;
}

.notes-filter-grid label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--ui-text-muted);
  font-size: 11px;
}

.notes-filter-grid label:first-child {
  grid-column: 1 / -1;
}

.notes-filter-grid input,
.notes-filter-grid select {
  width: 100%;
  min-width: 0;
}

.notes-filter-actions {
  margin-top: 8px;
}

.note-selection-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding-top: 10px;
}

.note-selection-row input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
}

.note-selection-row .note-open {
  flex: 1;
  width: auto;
  min-width: 0;
  padding-top: 0;
}

@media (max-width: 820px) {
  .reader-stage[data-view-mode="continuous"] {
    max-height: 72dvh;
  }
}

@media (max-width: 480px) {
  .reader-find-panel {
    padding-inline: 12px;
  }

  .reader-reading-controls {
    width: 100%;
  }

  .reader-find-row {
    align-items: stretch;
  }

  #reader-find-input {
    flex-basis: 100%;
  }

  .notes-filter-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .notes-filter-grid label:first-child {
    grid-column: auto;
  }
}

.reader-progress-status {
  margin: 0;
  padding: 6px 16px;
  color: var(--ui-text-muted);
  background: var(--ui-surface);
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 480px) {
  .reader-progress-status {
    padding-inline: 12px;
  }
}

.selected-annotation-toolbar {
  position: fixed;
  z-index: 55;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  width: max-content;
  max-width: min(620px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-surface);
  box-shadow: 0 6px 22px rgb(0 0 0 / 20%);
}

.selected-annotation-toolbar[hidden],
.reader-navigation-panel[hidden] {
  display: none;
}

.selected-annotation-toolbar select {
  min-height: 32px;
  max-width: 112px;
}

.reader-navigation-panel {
  position: fixed;
  z-index: 40;
  inset: auto;
  width: min(300px, calc(100% - 24px));
  padding: 8px;
  overflow: auto;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-surface);
  box-shadow: 0 6px 22px rgb(0 0 0 / 20%);
}

.reader-navigation-heading,
.reader-navigation-tabs,
.reader-thumbnail-pages {
  display: flex;
  align-items: center;
  gap: 4px;
}

.reader-navigation-heading {
  justify-content: space-between;
  margin-bottom: 8px;
}

.reader-navigation-tabs [aria-selected="true"] {
  color: var(--ui-accent);
  font-weight: 600;
}

.reader-navigation-status {
  color: var(--ui-text-muted);
  font-size: 12px;
}

.reader-outline-list {
  display: grid;
  gap: 4px;
}

.reader-outline-link {
  width: 100%;
  padding: 6px;
  border: 0;
  background: transparent;
  color: var(--ui-text);
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.reader-outline-link:hover,
.reader-outline-link:focus-visible {
  background: var(--ui-surface-subtle);
}

.reader-thumbnails {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: calc(100dvh - 260px);
  overflow: auto;
}

.reader-thumbnail {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-subtle);
  color: var(--ui-text);
  cursor: pointer;
}

.reader-thumbnail[aria-current="page"] {
  border-color: var(--ui-accent);
  outline: 2px solid var(--ui-focus);
}

.reader-thumbnail canvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: #fff;
}

.reader-thumbnail-pages {
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
}

.reader-panel:fullscreen {
  width: 100vw;
  height: 100dvh;
}

.reader-panel:fullscreen .reader-stage {
  min-height: 0;
}

@media (max-width: 480px) {
  .selected-annotation-toolbar {
    width: calc(100vw - 16px);
  }

  .reader-navigation-panel {
    position: fixed;
    inset: 8px;
    width: auto;
  }

  .reader-thumbnails {
    max-height: calc(100dvh - 130px);
  }
}

.reader-find-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.reader-find-icon {
  flex: none;
  width: 16px;
  height: 16px;
  color: currentColor;
}

.reader-object-copy-preview {
  position: absolute;
  z-index: 5;
  box-sizing: border-box;
  border: 2px dashed var(--ui-primary);
  outline: 2px solid #ffffff;
  outline-offset: 1px;
  background: transparent;
  pointer-events: none;
}

.reader-object-menu {
  position: fixed;
  z-index: 70;
  display: grid;
  min-width: 190px;
  max-width: calc(100vw - 16px);
  padding: 4px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
}

.reader-object-menu .button {
  justify-content: flex-start;
  text-align: left;
}

.reader-object-menu-status {
  max-width: 280px;
  padding: 6px 12px;
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.reader-object-menu-status[data-kind="error"] {
  color: var(--ui-danger);
}

@media (max-width: 480px) {
  .reader-object-menu .button {
    min-height: 40px;
  }
}

.reader-shape-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.reader-shape-tools .button svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.reader-shape-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.reader-shape-layer[data-drawing="true"] {
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}

.reader-shape-hit {
  pointer-events: stroke;
  cursor: move;
}

.reader-textbox-body {
  fill: #ffffff;
}

.reader-shape[data-kind="textbox"] .reader-shape-hit {
  pointer-events: all;
}

.reader-shape-handle {
  fill: var(--ui-surface);
  stroke: var(--ui-focus);
  stroke-width: 2px;
  pointer-events: all;
  cursor: nwse-resize;
}

.reader-shape-handle:focus-visible,
.reader-shape:focus-visible .reader-shape-visual {
  outline: none;
  filter: drop-shadow(0 0 2px var(--ui-focus));
}

.reader-shape-layer[data-suspended="true"] .reader-shape-hit,
.reader-shape-layer[data-suspended="true"] .reader-shape-handle,
.reader-shape-layer[data-drawing="true"] .reader-shape-hit,
.reader-shape-layer[data-drawing="true"] .reader-shape-handle {
  pointer-events: none;
}

.reader-shape-editor {
  position: fixed;
  z-index: 56;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 16px));
  padding: 10px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-surface);
  box-shadow: 0 6px 22px rgb(0 0 0 / 20%);
  box-sizing: border-box;
  overflow: auto;
  overscroll-behavior: contain;
}

.reader-shape-editor > label {
  display: grid;
  gap: 4px;
  color: var(--ui-text-soft);
  font-size: 12px;
}

.reader-shape-editor > label[hidden] {
  display: none;
}

.reader-shape-editor[data-kind]:not([data-kind="textbox"]) {
  width: min(280px, calc(100vw - 16px));
  padding: 12px;
}

.reader-shape-editor:not([data-kind="textbox"]) .reader-shape-width-picker {
  top: calc(100% + 8px);
  bottom: auto;
}

.reader-shape-editor[data-width-menu-open="true"]:not([data-kind="textbox"]) .reader-shape-style-row {
  padding-bottom: 64px;
}

.reader-shape-editor textarea {
  width: 100%;
  min-height: 54px;
  resize: vertical;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.reader-shape-style-row,
.reader-shape-editor-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.reader-shape-style-row label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ui-text-soft);
  font-size: 12px;
}

.reader-shape-color-palette {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.reader-shape-color-swatch {
  position: relative;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.reader-shape-color-swatch::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 50%;
  background: var(--reader-shape-swatch-color);
}

.reader-shape-color-swatch[aria-checked="true"]::before {
  box-shadow: 0 0 0 2px var(--ui-surface), 0 0 0 4px var(--ui-focus);
}

.reader-shape-color-swatch:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 1px;
}

.reader-shape-color-swatch:disabled {
  opacity: 0.45;
  cursor: default;
}

.reader-shape-width-control {
  position: relative;
  display: inline-flex;
  flex: none;
}

.reader-shape-width-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 1px solid var(--ui-control-border);
  border-radius: 3px;
  background: var(--ui-surface);
  color: var(--ui-text);
  cursor: pointer;
  touch-action: manipulation;
}

.reader-shape-width-toggle[aria-expanded="true"] {
  border-color: var(--ui-focus);
  background: var(--ui-selected);
}

.reader-shape-width-toggle:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 1px;
}

.reader-shape-width-toggle:disabled {
  opacity: 0.45;
  cursor: default;
}

.reader-shape-width-current {
  width: 34px;
  height: 14px;
  flex: none;
}

.reader-shape-width-picker {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-surface);
  box-shadow: 0 4px 14px rgb(0 0 0 / 20%);
}

.reader-shape-width-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 1px solid var(--ui-control-border);
  border-radius: 3px;
  background: var(--ui-surface);
  color: var(--ui-text);
  cursor: pointer;
  touch-action: manipulation;
}

.reader-shape-width-option[aria-checked="true"] {
  border-color: var(--ui-focus);
  background: var(--ui-selected);
  box-shadow: inset 0 0 0 1px var(--ui-focus);
}

.reader-shape-width-option:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 1px;
}

.reader-shape-width-option:disabled {
  opacity: 0.45;
  cursor: default;
}

.reader-shape-width-icon {
  width: 30px;
  height: 12px;
  flex: none;
}

.reader-shape-editor select,
.reader-shape-editor input {
  min-height: 32px;
}

#reader-shape-font-size {
  width: 72px;
  padding: 4px 6px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

#reader-shape-overflow {
  color: var(--ui-danger);
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 480px) {
  .reader-shape-editor {
    width: calc(100vw - 16px);
  }

  .reader-shape-editor .button {
    min-height: 40px;
  }
}

.assistant-reference-add-row {
  display: flex;
  justify-content: flex-start;
  padding: 8px 0 2px;
}

.assistant-resource-reference-help {
  margin: 5px 0;
  color: var(--ui-text-muted);
  font-size: 11px;
  line-height: 1.5;
}

.assistant-resource-references {
  display: grid;
  gap: 5px;
  max-height: 180px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.assistant-resource-references:empty {
  display: none;
}

.assistant-resource-reference {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  background: var(--ui-surface-subtle);
}

.assistant-resource-reference-description {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 2px;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.assistant-resource-reference-description > span {
  color: var(--ui-text-muted);
  font-size: 11px;
}

.assistant-resource-reference-grant {
  display: flex;
  flex: 1 0 100%;
  align-items: flex-start;
  gap: 7px;
  color: var(--ui-text-soft);
  font-size: 11px;
  line-height: 1.5;
  cursor: pointer;
}

.assistant-resource-reference-grant input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 1px 0 0;
}

.assistant-resource-reference-grant:has(input:disabled) {
  cursor: not-allowed;
}

.assistant-resource-reference-remove {
  flex: none;
  min-height: 32px;
  padding: 4px 7px;
  font-size: 11px;
}

.assistant-reference-picker {
  width: min(680px, calc(100vw - 32px));
  max-width: 100%;
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--ui-border-strong);
  border-radius: 6px;
  background: var(--ui-surface);
  color: var(--ui-text);
  box-shadow: 0 14px 40px rgb(0 0 0 / 24%);
}

.assistant-reference-picker::backdrop {
  background: rgb(0 0 0 / 35%);
}

.assistant-reference-picker-layout {
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto;
  max-height: min(760px, calc(100vh - 34px));
  padding: 16px;
  gap: 10px;
}

.assistant-reference-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.assistant-reference-picker-header h2 {
  margin: 0;
  font-size: 18px;
}

.assistant-reference-picker-scope {
  margin: 0;
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.55;
}

.assistant-reference-search {
  display: flex;
  gap: 7px;
}

.assistant-reference-search input {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.assistant-reference-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--ui-border);
}

.assistant-reference-tabs > button {
  min-height: 36px;
  padding: 6px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ui-text-soft);
  cursor: pointer;
}

.assistant-reference-tabs > button[aria-selected="true"] {
  border-bottom-color: var(--ui-primary);
  color: var(--ui-text);
  font-weight: 650;
}

.assistant-reference-picker-status {
  display: flex;
  min-height: 20px;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--ui-text-soft);
  font-size: 12px;
}

.assistant-reference-picker-status[data-kind="error"] {
  color: var(--ui-danger);
}

.assistant-reference-picker-status[data-kind="success"] {
  color: var(--ui-success);
}

.assistant-reference-results {
  min-height: 100px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.assistant-reference-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--ui-border);
}

.assistant-reference-result-description {
  display: grid;
  min-width: 0;
  gap: 3px;
  overflow-wrap: anywhere;
}

.assistant-reference-result-description > span {
  color: var(--ui-text-muted);
  font-size: 12px;
}

.assistant-reference-result-add {
  flex: none;
}

.assistant-reference-pagination {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

@media (max-width: 480px) {
  .assistant-resource-reference {
    align-items: flex-start;
  }

  .assistant-reference-picker {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
  }

  .assistant-reference-picker-layout {
    max-height: calc(100vh - 18px);
    padding: 12px;
  }

  .assistant-reference-search {
    align-items: stretch;
  }

  .assistant-reference-search .button,
  .assistant-reference-tabs > button,
  .assistant-reference-result-add,
  .assistant-reference-pagination .button,
  .assistant-resource-reference-remove {
    min-height: 40px;
  }

  .assistant-reference-result {
    align-items: flex-start;
  }
}

.translation-controls {
  display: flex;
  align-items: center;
}

.reader-translation-layout {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

.reader-translation-layout[data-translation-open="true"] {
  grid-template-columns: minmax(0, 1fr) minmax(300px, 40%);
}

.reader-translation-layout > .reader-stage {
  min-width: 0;
  min-height: 0;
}

.translation-panel {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 1px solid var(--ui-border);
  background: var(--ui-surface);
  color: var(--ui-text);
  scrollbar-gutter: stable;
}

.translation-panel-content {
  min-width: 0;
}

.translation-header {
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface-subtle);
}

.translation-header h2 {
  color: var(--ui-primary);
}

.translation-header p {
  margin-top: 5px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.translation-close {
  flex: none;
  width: 36px;
  padding: 4px;
  font-size: 20px;
}

.translation-form {
  padding: 14px 16px;
  display: grid;
  gap: 12px;
  border-bottom: 1px solid var(--ui-border);
}

.translation-page-choice {
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  border: 0;
}

.translation-page-choice label {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ui-text-soft);
  cursor: pointer;
}

.translation-page-choice input {
  accent-color: var(--ui-primary);
}

.translation-field {
  display: grid;
  gap: 5px;
  color: var(--ui-text-soft);
  font-size: 12px;
  font-weight: 650;
}

.translation-field input,
.translation-field select,
.translation-saved-row select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.translation-start-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.translation-page-limit,
.translation-retry-hint {
  color: var(--ui-text-muted);
  font-size: 11px;
}

.translation-retry-hint {
  line-height: 1.5;
}

.translation-history-tabs {
  padding: 12px 16px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.translation-history-tabs .button,
.translation-run-form .button,
.translation-run-form input,
.translation-run-form select,
.translation-run-history select,
.translation-run-history .button,
.translation-run-page-picker select,
.translation-run-control-retry .button {
  min-height: 44px;
}

.translation-history-tabs .button[aria-pressed="true"] {
  background: var(--ui-selected);
  color: var(--ui-primary);
  box-shadow: inset 0 0 0 1px var(--ui-primary);
}

.translation-run-form .translation-page-choice label {
  min-height: 44px;
}

.translation-run-confirmation {
  padding: 10px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 4px;
  background: var(--ui-info-bg);
  line-height: 1.55;
}

.translation-run-confirmation p,
.translation-run-progress p,
.translation-run-page-picker small {
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.translation-run-history > div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.translation-run-history select {
  flex: 1;
}

.translation-run-history .button {
  flex: none;
  white-space: nowrap;
}

.translation-run-page-picker {
  margin: 12px 16px;
  max-width: 280px;
}

.translation-run-control-retry {
  margin: 0 16px 12px;
}

.translation-unavailable,
.translation-progress {
  margin: 12px 16px;
  padding: 10px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  background: var(--ui-info-bg);
  line-height: 1.55;
}

.translation-unavailable .button,
.translation-progress .button {
  justify-self: start;
}

.translation-saved-row {
  padding: 14px 16px 8px;
  display: grid;
  gap: 6px;
  color: var(--ui-text-soft);
  font-size: 12px;
  font-weight: 650;
}

.translation-status,
.translation-empty,
.translation-visual-notice {
  margin: 8px 16px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.6;
}

.translation-status[data-kind="error"],
.translation-page-warning {
  color: var(--ui-danger);
}

.translation-job {
  padding-bottom: 16px;
}

.translation-job-summary {
  padding: 10px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--ui-primary);
}

.translation-job-summary p {
  margin-top: 4px;
  color: var(--ui-text-muted);
  font-size: 12px;
}

.translation-progress progress {
  width: 100%;
  height: 8px;
  accent-color: var(--ui-primary);
}

.translation-results {
  padding: 0 16px;
}

.translation-results .translation-empty,
.translation-results .translation-visual-notice {
  margin-inline: 0;
}

.translation-visual-notice {
  padding: 8px 10px;
  border-left: 3px solid var(--ui-primary);
  background: var(--ui-info-bg);
}

.translation-result-page {
  padding: 12px 0;
  border-top: 1px solid var(--ui-border);
}

.translation-page-header {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.translation-page-header h3 {
  color: var(--ui-primary);
}

.translation-source-link {
  min-height: 32px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--ui-primary);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.translation-block {
  position: relative;
  padding: 6px 0;
}

.translation-paragraph,
.translation-translated-title {
  color: var(--ui-text);
  line-height: 1.75;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.translation-translated-title {
  font-size: 15px;
  font-weight: 650;
}

.translation-original-marker {
  padding: 7px 9px;
  border: 1px dashed var(--ui-border-strong);
  border-radius: 3px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.translation-block .translation-source-link {
  display: block;
  margin-top: 2px;
}

.translation-block-footer {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.translation-excerpt-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.translation-excerpt-action {
  width: 44px;
  height: 44px;
  padding: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--ui-primary);
  cursor: pointer;
}

.translation-excerpt-action:hover,
.translation-excerpt-action:focus-visible {
  background: var(--ui-selected);
}

.translation-excerpt-action:disabled {
  opacity: 0.45;
  cursor: wait;
}

.translation-excerpt-action svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) and (pointer: fine) {
  .translation-excerpt-actions {
    opacity: 0;
    transition: opacity 120ms ease;
  }

  .translation-block:hover .translation-excerpt-actions,
  .translation-block:focus-within .translation-excerpt-actions {
    opacity: 1;
  }
}

.translation-page-warning {
  margin: 6px 0;
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 1120px) {
  .reader-translation-layout[data-translation-open="true"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(320px, 1fr) minmax(220px, 45%);
  }

  .translation-panel {
    border-top: 1px solid var(--ui-border);
    border-left: 0;
  }
}

@media (max-width: 820px) {
  .reader-translation-layout {
    overflow: visible;
  }

  .reader-translation-layout[data-translation-open="true"] {
    grid-template-rows: auto auto;
  }

  .translation-panel {
    max-height: 560px;
  }
}

@media (max-width: 480px) {
  .translation-header,
  .translation-form,
  .translation-saved-row,
  .translation-results {
    padding-inline: 12px;
  }

  .translation-status,
  .translation-empty,
  .translation-visual-notice,
  .translation-unavailable,
  .translation-progress {
    margin-inline: 12px;
  }

  .translation-start-row .button,
  .translation-unavailable .button,
  .translation-progress .button {
    min-height: 44px;
  }
}

.translation-controls {
  min-width: 0;
  flex-wrap: wrap;
  gap: 6px 8px;
}

.translation-mode-control {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-subtle);
}

.translation-mode-button {
  min-height: 30px;
  padding: 4px 8px;
  white-space: nowrap;
}

.translation-mode-button[aria-pressed="true"] {
  background: var(--ui-selected);
  color: var(--ui-primary);
  box-shadow: inset 0 0 0 1px var(--ui-primary);
}

.translation-mode-notice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 8px;
  max-width: 440px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.translation-overlay-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.translation-overlay-block {
  position: absolute;
  box-sizing: border-box;
  overflow: hidden;
  padding: 2px;
  background: #ffffff;
  color: #111111;
  pointer-events: auto;
  user-select: text;
}

.translation-overlay-text {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: Arial, "Microsoft YaHei", sans-serif;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.translation-overlay-clipped .translation-overlay-text {
  height: calc(100% - 24px);
}

.translation-overlay-expand {
  position: absolute;
  right: 2px;
  bottom: 2px;
  min-width: 44px;
  min-height: 24px;
  padding: 1px 5px;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-surface);
  color: var(--ui-primary);
  font-size: 11px;
  line-height: 1.2;
  cursor: pointer;
}

.translation-overlay-expanded {
  box-sizing: border-box;
  width: min(680px, calc(100vw - 32px));
  max-height: min(80vh, 760px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--ui-border-strong);
  border-radius: 3px;
  background: var(--ui-surface);
  color: var(--ui-text);
  box-shadow: 0 12px 36px rgb(0 0 0 / 24%);
}

.translation-overlay-expanded::backdrop {
  background: rgb(0 0 0 / 35%);
}

.translation-overlay-expanded header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ui-border);
}

.translation-overlay-expanded h2 {
  font-size: 16px;
}

.translation-overlay-expanded p {
  max-height: calc(80vh - 70px);
  margin: 0;
  padding: 16px;
  overflow: auto;
  line-height: 1.75;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  user-select: text;
}

@media (max-width: 680px) {
  .translation-mode-notice {
    flex-basis: 100%;
    max-width: none;
  }
}

.reader-panel[data-flow-active="true"] :is(
  .page-controls,
  .zoom-controls,
  .reader-source-controls,
  .reader-find-toggle,
  .reader-find-panel,
  #annotation-undo,
  #annotation-redo,
  #translation-controls,
  #export-reading-record,
  .annotated-pdf-export
) {
  display: none;
}

.reader-translation-layout[data-flow-active="true"] {
  grid-template-columns: minmax(0, 1fr);
}

.flow-reader-host {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--ui-bg);
  color: var(--ui-text);
}

.flow-reader-loading {
  margin: 0;
  padding: 32px 20px;
  color: var(--ui-text-muted);
  text-align: center;
}

.flow-reader {
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.flow-header,
.flow-controls,
.flow-footer,
.flow-translation-bar {
  flex: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface);
}

.flow-header {
  justify-content: space-between;
  flex-wrap: nowrap;
}

.flow-heading-wrap {
  flex: 1;
  min-width: 0;
}

.flow-heading-wrap h2 {
  color: var(--ui-primary);
  font-size: 17px;
}

.flow-heading-wrap p {
  max-width: 100%;
  margin-top: 3px;
  overflow: hidden;
  color: var(--ui-text-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flow-controls {
  position: relative;
  justify-content: flex-start;
  gap: 6px 8px;
  padding-block: 6px;
  background: var(--ui-surface-subtle);
}

.flow-text-modes,
.flow-batch-controls,
.flow-utility-controls {
  display: flex;
  align-items: center;
  flex: none;
  flex-wrap: nowrap;
  gap: 4px;
}

.flow-text-modes .button {
  padding-inline: 9px;
  white-space: nowrap;
}

.flow-text-modes .button[aria-pressed="true"] {
  border-color: var(--ui-primary);
  background: var(--ui-info-bg);
  color: var(--ui-primary);
}

.flow-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 7px;
}

.flow-icon {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.flow-batch-label {
  min-width: 0;
  margin-right: auto;
  color: var(--ui-text-soft);
  font-size: 12px;
  white-space: nowrap;
}

.flow-page-jump {
  display: flex;
  align-items: center;
  flex: none;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
  color: var(--ui-text-soft);
  font-size: 12px;
}

.flow-page-jump input {
  width: 52px;
  min-height: 36px;
  padding: 4px 5px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
  text-align: center;
}

.flow-page-jump > span {
  white-space: nowrap;
}

.flow-page-jump-button {
  min-height: 36px;
  padding-inline: 8px;
}

.flow-jump-error {
  flex-basis: 100%;
  color: var(--ui-danger);
  line-height: 1.5;
}

.flow-tool-details {
  position: static;
  flex: none;
}

.flow-tool-details > summary {
  list-style: none;
  cursor: pointer;
}

.flow-tool-details > summary::-webkit-details-marker {
  display: none;
}

.flow-tool-details > summary::marker {
  content: "";
}

.flow-tool-details[open] > summary {
  border-color: var(--ui-primary);
  background: var(--ui-info-bg);
  color: var(--ui-primary);
}

.flow-popover {
  position: absolute;
  z-index: 5;
  top: calc(100% + 1px);
  right: 12px;
  width: min(420px, calc(100% - 24px));
  padding: 12px;
  border: 1px solid var(--ui-border-strong);
  border-radius: 3px;
  background: var(--ui-surface);
  color: var(--ui-text);
  box-shadow: 0 4px 12px var(--ui-backdrop);
}

.flow-preference-row {
  display: grid;
  grid-template-columns: minmax(64px, auto) minmax(90px, 1fr) 44px;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 10px;
  font-size: 12px;
}

.flow-preference-row input[type="range"] {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  margin: 0;
  accent-color: var(--ui-primary);
}

.flow-preference-row output {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.flow-preference-row select {
  grid-column: 2 / 4;
  min-width: 0;
  min-height: 36px;
  padding: 4px 7px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.flow-reset-preferences {
  display: block;
  min-height: 36px;
  margin-left: auto;
}

.flow-search-popover {
  width: min(480px, calc(100% - 24px));
}

.flow-find-scope,
.flow-find-feedback {
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.flow-find-scope {
  margin-bottom: 8px;
}

.flow-find-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.flow-find-row input {
  flex: 1;
  width: auto;
  min-width: 0;
  min-height: 36px;
  padding: 5px 8px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.flow-find-submit {
  flex: none;
  min-height: 36px;
  padding-inline: 10px;
}

.flow-find-feedback {
  margin-top: 8px;
}

.flow-find-feedback.flow-error {
  color: var(--ui-danger);
}

.flow-translation-bar {
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.flow-translation-bar label {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.flow-translation-bar select {
  max-width: min(420px, 60vw);
  min-height: 36px;
  padding: 4px 7px;
  border: 1px solid var(--ui-input-border);
  border-radius: 3px;
  background: var(--ui-input-bg);
  color: var(--ui-text);
}

.flow-translation-bar p {
  margin: 0;
}

.flow-status {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  width: fit-content;
  min-width: 0;
  max-width: min(760px, calc(100% - 32px));
  margin: 10px auto 4px;
  padding: 0;
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.flow-status-message {
  min-width: 0;
  overflow-wrap: anywhere;
}

.flow-status-spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--ui-border);
  border-top-color: var(--ui-primary);
  border-radius: 50%;
  animation: flow-status-spin 800ms linear infinite;
}

.flow-status .button {
  flex: none;
  min-height: 44px;
}

.flow-status-cancel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  padding: 0;
}

.flow-status-cancel svg {
  display: block;
  width: 16px;
  height: 16px;
}

@keyframes flow-status-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .flow-status-spinner {
    animation: none;
  }
}

.flow-status-error,
.flow-error,
.flow-page-warning {
  color: var(--ui-danger);
}

.flow-scroll {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 20px 16px 36px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.flow-order-note,
.flow-page {
  width: min(100%, var(--flow-reading-width, 760px));
  margin-inline: auto;
}

.flow-order-note {
  margin-block: 0 16px;
  color: var(--ui-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.flow-page {
  padding: 18px 0 24px;
  border-top: 1px solid var(--ui-border);
}

.flow-page:first-of-type {
  border-top: 0;
}

.flow-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.flow-page-header h3 {
  color: var(--ui-primary);
  font-size: 14px;
}

.flow-page-warning {
  margin: 8px 0 14px;
  font-size: 12px;
  line-height: 1.5;
}

.flow-blocks {
  display: grid;
  gap: 14px;
}

.flow-block {
  margin: 0;
  color: var(--ui-text);
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: var(--flow-reading-font-size, 17px);
  line-height: var(--flow-reading-line-height, 1.85);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  user-select: text;
}

.flow-block-title {
  font-size: calc(var(--flow-reading-font-size, 17px) + 4px);
  line-height: 1.5;
}

.flow-block-caption {
  color: var(--ui-text-soft);
  font-size: calc(var(--flow-reading-font-size, 17px) - 3px);
  line-height: 1.65;
}

.flow-bilingual-pair,
.flow-bilingual-sentence {
  min-width: 0;
  display: grid;
}

.flow-bilingual-pair {
  gap: 14px;
}

.flow-bilingual-sentence {
  gap: 5px;
}

.flow-sentence-fallback {
  flex-basis: 100%;
  overflow-wrap: anywhere;
}

.flow-bilingual-pair .flow-bilingual-original {
  color: var(--ui-text-soft);
}

.flow-bilingual-pair .flow-bilingual-translation {
  color: var(--ui-text);
}

.flow-find-match {
  padding: 0;
  background: rgb(250 204 21 / 42%);
  color: inherit;
  box-shadow: 0 0 0 1px rgb(202 138 4 / 65%);
}

.flow-find-match[data-active="true"] {
  background: rgb(249 115 22 / 48%);
  box-shadow: 0 0 0 2px #c2410c;
}

.flow-block-code,
.flow-raw-text {
  max-width: 100%;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-subtle);
  color: var(--ui-text);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}

.flow-visual {
  min-width: 0;
  margin: 0;
}

.flow-visual-viewport {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--ui-border);
  background: #ffffff;
  overscroll-behavior: contain;
}

.flow-visual-viewport:focus-visible {
  outline: 2px solid var(--ui-primary);
  outline-offset: 2px;
}

.flow-visual img {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
}

.flow-visual-table img,
.flow-visual-formula img {
  max-width: none;
  margin-inline: 0;
}

.flow-visual-status {
  margin: 6px 0;
  color: var(--ui-text-muted);
  font-size: 12px;
}

.flow-source-link {
  flex: none;
  min-height: 34px;
  font-size: 12px;
}

.flow-footer {
  justify-content: space-between;
  border-top: 1px solid var(--ui-border);
  border-bottom: 0;
}

@media (max-width: 680px) {
  .flow-header,
  .flow-controls,
  .flow-footer,
  .flow-translation-bar {
    padding-inline: 12px;
  }

  .flow-heading-wrap p {
    max-width: 100%;
  }

  .flow-controls {
    align-items: center;
  }

  .flow-batch-label {
    order: 10;
    flex-basis: 100%;
  }

  .flow-utility-controls {
    margin-left: auto;
  }

  .flow-popover {
    width: calc(100% - 24px);
  }

  .flow-scroll {
    padding: 14px 12px 28px;
    scrollbar-gutter: auto;
  }

  .flow-header .button,
  .flow-controls .button,
  .flow-footer .button,
  .flow-translation-bar .button,
  .flow-page-jump input,
  .flow-find-row input,
  .flow-preference-row select,
  .flow-preference-row input[type="range"],
  .flow-translation-bar select,
  .flow-source-link {
    min-height: 44px;
  }

  .flow-icon-button {
    width: 44px;
    min-width: 44px;
  }

  .flow-translation-bar,
  .flow-translation-bar label,
  .flow-translation-bar select {
    width: 100%;
    max-width: none;
  }

  .flow-translation-bar label {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (pointer: coarse) {
  .flow-header .button,
  .flow-controls .button,
  .flow-footer .button,
  .flow-translation-bar .button,
  .flow-page-jump input,
  .flow-find-row input,
  .flow-preference-row select,
  .flow-preference-row input[type="range"],
  .flow-translation-bar select,
  .flow-source-link {
    min-height: 44px;
  }

  .flow-icon-button {
    width: 44px;
    min-width: 44px;
  }
}

@media (max-width: 820px) {
  #reader-panel[data-flow-active="true"] > .reader-heading-row,
  #reader-panel[data-flow-active="true"] > .reader-toolbar,
  #reader-panel[data-flow-active="true"] > .metadata-panel:not([open]) {
    display: none;
  }

  #reader-panel[data-flow-active="true"] .flow-order-note {
    display: none;
  }

  #reader-panel[data-flow-active="true"] .flow-translation-bar {
    width: 100%;
    max-width: none;
    gap: 6px 8px;
    padding-block: 6px;
  }

  #reader-panel[data-flow-active="true"] .flow-translation-bar label {
    flex: 1 1 150px;
    align-items: center;
    flex-direction: row;
    width: auto;
    max-width: 100%;
    font-size: 12px;
  }

  #reader-panel[data-flow-active="true"] .flow-translation-bar select {
    flex: 1 1 80px;
    width: auto;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  #reader-panel[data-flow-active="true"] .flow-translation-bar > .button {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    font-size: 14px;
    white-space: normal;
  }

  #reader-panel[data-flow-active="true"] .flow-translation-bar p {
    flex: 1 1 100%;
  }
}
