:root {
  --bg: #F7F9FC;
  --paper: #F7F9FC;
  --surface: #FFFFFF;
  --surface-soft: #F8FBFF;
  --surface-muted: #EEF4FF;
  --chrome: #FFFFFF;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-soft: #EAF1FF;
  --word-tab-line: #D7E2F8;
  --word-ribbon: #FFFFFF;
  --word-ribbon-hover: #EEF5FF;
  --word-selected: #EAF1FF;
  --focus: rgba(37, 99, 235, .18);
  --panel: #F7F9FC;
  --panel-2: #EEF4FF;
  --line: #E4EAF5;
  --line-strong: #C8D8FF;
  --line-soft: #EDF2FA;
  --border: #DDE7F6;
  --hover: #F0F6FF;
  --active-soft: #EAF1FF;
  --ink: #1C1C1C;
  --ink-2: #2F2D29;
  --muted: #6F6A60;
  --muted-2: #817B70;
  --warn: #9A6A12;
  --danger: #B42318;
  --success: #0E7C68;
  --success-soft: #DDEFEA;
  --source-canvas: #F7F9FC;
  --source-surface: #FFFFFF;
  --source-line: #E3E7ED;
  --source-control: #D7DCE3;
  --source-blue: #2563EB;
  --source-blue-soft: #EAF1FF;
  --source-chip-active: #111111;
  --shadow-sm: 0 1px 2px rgba(28, 28, 28, .06);
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --font-display: Aptos, "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 var(--font-display);
}

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

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  font-weight: 600;
  line-height: 1;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .08s ease;
}

button:hover {
  border-color: transparent;
  background: var(--word-ribbon-hover);
  color: var(--ink);
}

button:active { transform: translateY(1px); }
button:disabled { cursor: default; opacity: .55; transform: none; }
button:focus { outline: none; }
button:focus-visible {
  outline: 2px solid rgba(10, 10, 10, .18);
  outline-offset: 2px;
}

button.is-loading {
  position: relative;
}

button.is-loading::after {
  content: "";
  width: 5px;
  height: 5px;
  margin-left: 2px;
  border-radius: 999px;
  background: currentColor;
  opacity: .85;
  animation: button-loading-dot .75s ease-in-out infinite;
}

.icon-only.is-loading::after {
  position: absolute;
  right: 5px;
  bottom: 5px;
  margin-left: 0;
}

@keyframes button-loading-dot {
  0%, 100% {
    opacity: .25;
    transform: scale(.72);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 7px 10px;
  outline: none;
  box-shadow: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--focus);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
}

.research-root,
.research-shell {
  height: 100vh;
  min-height: 0;
}

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

.hidden-control {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.auth-view {
  display: grid;
  align-content: start;
  gap: 14px;
  height: 100vh;
  padding: 22px;
  background: var(--bg);
}

.auth-mark {
  font-size: 18px;
  font-weight: 750;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.research-shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: var(--bg);
}

.status-text {
  min-height: 17px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
}

.status-text.is-error { color: var(--danger); }
.status-text.is-good { color: var(--success); }
.status-text.is-warn { color: var(--warn); }

.icon-button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
}

.icon-only {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 750;
}

.ui-icon,
.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.nav-icon {
  width: 18px;
  height: 18px;
}

.ui-icon svg,
.nav-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 2.35;
}

.icon-only > svg {
  display: block;
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2.35;
}

.nav-refresh {
  flex: 0 0 34px;
  margin-left: auto;
  border-color: transparent;
  background: transparent;
  color: #526077;
}

.nav-refresh:hover,
.nav-refresh:focus-visible {
  border-color: transparent;
  background: #F3F7FF;
  color: var(--accent);
}

.research-body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.research-rail {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  padding: 5px 7px 0;
  border-bottom: 1px solid var(--word-tab-line);
  background: #FFFFFF;
}

.rail-tab {
  position: relative;
  flex: 0 0 auto;
  justify-content: center;
  width: auto;
  min-width: 0;
  height: 32px;
  min-height: 32px;
  padding: 0 9px 4px;
  border-color: transparent;
  border-radius: 5px 5px 0 0;
  background: transparent;
  color: #526077;
  text-align: center;
  font-size: 12px;
  font-weight: 650;
}

.research-rail .rail-tab {
  transition: background .15s ease, color .15s ease, transform .08s ease;
}

.rail-tab:hover {
  border-color: transparent;
  background: #F4F7FC;
  color: var(--accent);
}

.rail-tab.is-active {
  border-color: transparent;
  background: #FFFFFF;
  color: #111827;
  box-shadow: none;
}

.rail-tab.is-active::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 999px 999px 0 0;
  background: var(--accent);
}

.research-rail .rail-tab[aria-pressed="false"] {
  border-color: transparent;
  background: transparent;
  color: #526077;
}

.research-rail .rail-tab[aria-pressed="false"]:hover {
  border-color: transparent;
  background: #F4F7FC;
  color: var(--accent);
}

.research-rail .rail-tab[aria-pressed="true"] {
  border-color: transparent;
  background: #FFFFFF;
  color: #111827;
  box-shadow: none;
}

.research-main {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
}

.view {
  display: none;
  height: 100%;
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.view.is-active {
  display: grid;
  align-content: start;
  gap: 10px;
  animation: view-enter .16s ease-out;
}

@keyframes view-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.view-toolbar,
.inline-form,
.search-row,
.cutter-actions,
.chat-form {
  display: grid;
  gap: 8px;
}

.view-toolbar {
  grid-template-columns: minmax(0, 1fr) auto;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) 116px auto;
}

.starter-slot {
  display: grid;
  gap: 6px;
}

.search-row {
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  padding: 2px;
}

#cards-view .search-row {
  grid-template-columns: minmax(0, 1fr) 34px;
}

#cards-view.is-active {
  grid-template-rows: auto auto auto minmax(0, 1fr);
  align-content: stretch;
  overflow: hidden;
}

#sources-view.is-active {
  grid-template-rows: auto auto auto minmax(0, 1fr);
  align-content: stretch;
  gap: 0;
  overflow: hidden;
  padding: 12px 12px 0;
  background: var(--source-canvas);
}

#cutter-view.is-active,
#cards-view.is-active,
#chat-view.is-active {
  background: var(--source-canvas);
}

#source-search-form,
#card-search-form {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 7px;
  margin: 0 0 8px;
  padding: 0;
}

#source-search-form input,
#card-search-form input {
  height: 34px;
  border-color: var(--source-control);
  border-radius: 6px;
  background: var(--source-surface);
  padding: 7px 10px;
  color: #111827;
  font-size: 12.5px;
}

#source-search-form input:focus,
#card-search-form input:focus {
  border-color: var(--source-blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .12);
}

#source-search-form button,
#card-search-form button {
  position: static;
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #FFFFFF;
  opacity: 1;
  transform: none;
}

#source-search-form button:hover,
#source-search-form button:focus-visible,
#card-search-form button:hover,
#card-search-form button:focus-visible {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
  color: #FFFFFF;
  transform: none;
}

#source-search-form button:active,
#card-search-form button:active {
  transform: translateY(1px);
}

#source-search-form .ui-icon,
#source-search-form .ui-icon svg,
#card-search-form .ui-icon,
#card-search-form .ui-icon svg {
  width: 14px;
  height: 14px;
}

.thinking-indicator {
  position: absolute;
  z-index: 20;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid #C8D8FF;
  border-radius: 999px;
  background: rgba(255, 255, 255, .96);
  color: #1D4ED8;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .08);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.thinking-orb {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(37, 99, 235, .28);
  animation: verba-thinking-pulse 1.05s ease-out infinite;
}

@keyframes verba-thinking-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, .32);
    transform: scale(.92);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(37, 99, 235, 0);
    transform: scale(1);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    transform: scale(.92);
  }
}

.source-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
}

.source-filter-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border: 1px solid var(--source-line);
  border-radius: 999px;
  background: var(--source-surface);
  color: #334155;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1;
}

.source-filter-chip.is-active {
  border-color: var(--source-chip-active);
  background: var(--source-chip-active);
  color: #FFFFFF;
}

.source-results-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 8px;
  color: #64748B;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .08em;
  line-height: 1;
}

.source-results-meta span:last-child {
  color: #334155;
  letter-spacing: 0;
}

#source-results {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--source-line);
}

.research-source,
.library-result {
  display: grid;
  gap: 7px;
  position: relative;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.research-source:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--border));
  background: var(--surface);
  box-shadow: none;
}

.library-result:hover {
  border-color: color-mix(in srgb, var(--accent) 32%, var(--border));
  background: var(--surface);
  box-shadow: none;
}

.library-result.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

#cards-view .library-result {
  display: block;
  padding: 10px 2px 11px 16px;
  padding-left: 16px;
  border: 0;
  border-bottom: 1px solid var(--source-line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#cards-view .library-result:hover,
#cards-view .library-result:focus,
#cards-view .library-result:focus-within {
  border-bottom-color: var(--source-line);
  background: transparent;
  box-shadow: none;
}

#cards-view .library-result.is-selected {
  border-bottom-color: #A9C5FF;
  background: var(--source-blue-soft);
}

#cards-view .library-result .result-row-top {
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: start;
}

#cards-view .library-result .result-title {
  display: -webkit-box;
  max-height: 34px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

#cards-view .library-result .result-actions {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity .12s ease, transform .12s ease;
}

#cards-view .library-result:hover .result-actions,
#cards-view .library-result:focus-within .result-actions,
#cards-view .library-result.show-actions .result-actions {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.result-title {
  min-width: 0;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.result-meta {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.source-meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  font-family: var(--font-display);
  font-size: 11px;
}

.source-quality-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface-soft);
  color: var(--ink-2);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.1;
}

.source-quality-badge[data-quality="strong"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #08483D;
}

.source-quality-badge[data-quality="good"] {
  border-color: #79B8A9;
  background: #EFF8F5;
  color: #0A6656;
}

.source-quality-badge[data-quality="maybe"] {
  border-color: #C7A95B;
  background: #FFFDF4;
  color: #6A4A00;
}

.source-quality-badge[data-quality="thin"] {
  border-color: #C9CED6;
  background: #FAFAFB;
  color: #5D646F;
}

.result-excerpt {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.result-row-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 7px;
  align-items: start;
}

.result-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  position: static;
  z-index: 2;
  justify-content: flex-end;
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  box-shadow: none;
}

.research-source .result-actions {
  position: static;
  justify-content: flex-end;
}

#sources-view .research-source {
  display: block;
  padding: 13px 5px 13px 0;
  border: 0;
  border-bottom: 1px solid var(--source-line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#sources-view .research-source:hover,
#sources-view .research-source:focus,
#sources-view .research-source:focus-within {
  border-bottom-color: var(--source-line);
  background: transparent;
  box-shadow: none;
}

.source-result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

.source-result-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.source-result-side {
  display: grid;
  align-content: start;
  justify-items: end;
  min-height: 32px;
  gap: 6px;
}

.source-result-kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: baseline;
  min-height: 16px;
  color: #111827;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

.source-year {
  color: #64748B;
  font-weight: 500;
}

.source-result-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  margin-top: 2px;
}

.source-result-chips .source-result-kicker {
  min-height: 0;
}

.source-publication,
.source-year {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  max-width: 100%;
  padding: 2px 6px;
  border: 1px solid var(--source-line);
  border-radius: 4px;
  background: var(--source-surface);
  color: #475569;
  font-size: 10px;
  font-weight: 650;
  line-height: 1;
}

#sources-view .result-title {
  color: #0F172A;
  font-size: 12.5px;
  font-weight: 750;
  line-height: 1.28;
  overflow-wrap: anywhere;
}

.source-result-excerpt {
  color: #334155;
  font-size: 11.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.source-result-authors {
  color: #64748B;
  font-size: 10.8px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.source-result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  max-width: 72px;
  padding: 2px 6px;
  border: 1px solid #A9C5FF;
  border-radius: 4px;
  background: var(--source-blue-soft);
  color: var(--source-blue);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

#sources-view .research-source .result-actions {
  display: flex;
  position: static;
  justify-content: flex-end;
  min-height: 28px;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity .12s ease, transform .12s ease;
}

#sources-view .research-source:hover .result-actions,
#sources-view .research-source:focus-within .result-actions,
#sources-view .research-source.show-actions .result-actions {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.source-cut-link,
.source-open-link {
  min-height: 28px;
  padding: 0;
  border: 1px solid var(--source-line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.1;
}

.source-cut-link:hover,
.source-cut-link:focus-visible,
.source-open-link:hover,
.source-open-link:focus-visible {
  border-color: #C8D8FF;
  background: #F4F7FF;
  color: var(--accent);
  text-decoration: none;
}

.source-open-link {
  border-color: var(--source-line);
  background: var(--surface);
  color: var(--ink-2);
}

.source-cut-link:active,
.source-open-link:active {
  transform: translateY(1px);
}

.result-actions button {
  min-height: 28px;
  padding: 3px;
  font-size: 11px;
  font-weight: 600;
}

.result-actions .icon-only {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
}

.row-primary {
  border-color: var(--source-line);
  background: var(--surface);
  color: var(--ink-2);
}

.row-primary:hover {
  border-color: #C8D8FF;
  background: #F4F7FF;
  color: var(--accent);
}

#cut-source {
  justify-self: start;
  width: auto;
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 750;
}

#cut-source:hover,
#cut-source:focus-visible {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
  color: #FFFFFF;
  text-decoration: none;
}

#cut-source:active {
  transform: translateY(1px);
}

#insert-current-card {
  border-color: var(--source-line);
  background: var(--surface);
  color: var(--ink-2);
}

#insert-current-card:hover {
  border-color: #C8D8FF;
  background: #F4F7FF;
  color: var(--accent);
}

.source-cut-link,
.source-open-link,
#insert-current-card {
  border-color: var(--source-line);
  background: var(--surface);
  color: var(--ink-2);
}

.source-cut-link:hover,
.source-cut-link:focus-visible,
.source-open-link:hover,
.source-open-link:focus-visible,
#insert-current-card:hover,
#insert-current-card:focus-visible {
  border-color: #C8D8FF;
  background: #F4F7FF;
  color: var(--accent);
}

#chat-form button[type="submit"] {
  border-color: var(--source-blue);
  background: var(--source-blue);
  color: #FFFFFF;
}

#chat-form button[type="submit"]:hover {
  border-color: #1D4ED8;
  background: #1D4ED8;
  color: #FFFFFF;
}

.load-more-row {
  width: 100%;
  min-height: 32px;
  border: 1px solid transparent;
  background: transparent;
  color: #526077;
  font-size: 11.5px;
}

.load-more-row:hover {
  border-color: var(--source-line);
  background: #F4F7FF;
  color: var(--accent);
}

.card-cutter {
  display: grid;
  gap: 10px;
}

.cutter-fields {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 0;
  background: var(--surface);
  box-shadow: none;
}

.cutter-actions {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 6px;
  margin-top: -10px;
  padding: 0 10px 10px;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--surface);
}

#save-current-card,
#insert-current-card {
  display: none;
}

.card-cutter.has-card #insert-current-card {
  display: inline-flex;
}

.cut-control {
  min-height: 30px;
  padding: 4px 8px;
  border-color: var(--source-line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11.5px;
}

.cut-control:hover {
  border-color: #C8D8FF;
  background: #F4F7FF;
  color: var(--accent);
}

.cut-stage-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 30px;
  padding: 5px 7px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface);
}

.cut-stage-strip[hidden] {
  display: none;
}

.cut-stage-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
}

.cut-stage {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1;
}

.cut-stage.is-active {
  border-color: rgba(14, 124, 104, .42);
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-weight: 700;
}

.cut-stage.is-complete {
  border-color: rgba(4, 120, 87, .24);
  background: var(--success-soft);
  color: var(--success);
}

.cut-stage-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.source-preview-panel {
  display: grid;
  gap: 6px;
}

.source-preview-panel:empty {
  display: none;
}

.source-preview-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.source-preview-paragraph {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface);
}

.source-preview-paragraph p {
  margin: 0;
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.35;
}

.source-preview-paragraph button {
  justify-self: start;
  min-height: 26px;
  padding: 3px 8px;
  border-color: var(--line);
  border-radius: 5px;
  background: var(--surface);
  font-size: 11px;
}

.progress-log {
  display: grid;
  gap: 4px;
  min-height: 28px;
  max-height: 112px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.progress-log:empty {
  display: none;
}

.card-preview {
  display: grid;
  gap: 8px;
  min-height: 126px;
  border: 1px solid;
  border-color: var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px;
  box-shadow: none;
}

.card-preview {
  display: none;
}

.library-preview {
  display: grid;
  gap: 8px;
  min-height: 0;
  max-height: min(38vh, 260px);
  overflow: auto;
  align-content: start;
  border: 1px solid;
  border-color: var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px;
  box-shadow: none;
}

.card-cutter.is-cutting .card-preview,
.card-cutter.has-card .card-preview {
  display: grid;
  animation: card-preview-in .16s ease-out;
}

@keyframes card-preview-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.library-preview:empty::before {
  content: none;
}

.library-preview {
  margin-left: 8px;
  overflow: auto;
  align-content: start;
}

.library-preview:empty::before {
  content: none;
}

.library-preview:empty {
  display: none;
}

.library-preview-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.cutter-fields,
.card-preview,
.library-preview,
.chat-composer {
  border-color: var(--source-line);
  border-radius: 6px;
  background: var(--source-surface);
  box-shadow: none;
}

.cutting-animation {
  display: grid;
  gap: 10px;
  min-height: 104px;
  align-content: center;
  color: var(--ink);
}

.cutting-animation-label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.cutting-track {
  position: relative;
  height: 34px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.cutting-track::before {
  content: "";
  position: absolute;
  top: -7px;
  bottom: -7px;
  left: -24px;
  width: 20px;
  border-left: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
  transform: rotate(18deg);
  animation: cutSweep 1.1s ease-in-out infinite;
}

.cutting-lines {
  display: grid;
  gap: 5px;
}

.cutting-lines span {
  display: block;
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, #D9DDE4, #F6F7F9, #D9DDE4);
  background-size: 220% 100%;
  animation: cutPulse 1.3s linear infinite;
}

.cutting-lines span:nth-child(2) {
  width: 78%;
  animation-delay: .12s;
}

.cutting-lines span:nth-child(3) {
  width: 54%;
  animation-delay: .24s;
}

@keyframes cutSweep {
  0% { left: -24px; }
  58%, 100% { left: calc(100% + 24px); }
}

@keyframes cutPulse {
  0% { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}

.cut-history {
  display: grid;
  gap: 2px;
}

.cut-history:empty {
  display: none;
}

.cut-history-card {
  display: grid;
  gap: 5px;
  position: relative;
  padding: 8px 7px;
  border: 1px solid transparent;
  border-bottom-color: var(--line-soft);
  border-radius: 6px;
  background: transparent;
}

.cut-history-card:hover,
.cut-history-card:focus,
.cut-history-card:focus-within {
  border-color: transparent;
  border-bottom-color: var(--line-soft);
  background: var(--surface-soft);
  box-shadow: none;
}

.cut-history-card .result-actions {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity .12s ease, transform .12s ease;
}

.cut-history-card:hover .result-actions,
.cut-history-card:focus .result-actions,
.cut-history-card:focus-within .result-actions,
.cut-history-card.show-actions .result-actions {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.preview-tag {
  color: #000000;
  font-family: Calibri, Arial, sans-serif;
  font-size: 12pt;
  font-weight: 700;
  line-height: 1.2;
}

.cut-draft-status {
  justify-self: start;
  min-height: 20px;
  padding: 2px 7px;
  border: 1px solid rgba(37, 99, 235, .18);
  border-radius: 5px;
  background: #EFF6FF;
  color: #1D4ED8;
  font-size: 10.5px;
  font-weight: 650;
}

.cut-history-card .result-title,
.library-result .result-title {
  font-family: Calibri, Arial, sans-serif;
}

.preview-cite {
  color: #000000;
  font-family: Calibri, Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.28;
}

.preview-cite .cite-prefix {
  font-size: 13pt;
  font-weight: 700;
}

.preview-cite .cite-rest {
  font-size: 11pt;
  font-weight: 400;
}

.quality-review {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.quality-review:empty {
  display: none;
}

.quality-warning {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 6px;
  border: 1px solid rgba(180, 83, 9, .22);
  border-radius: 999px;
  background: #FFFBEB;
  color: var(--warn);
  font-size: 10.5px;
  font-weight: 650;
}

.result-meta.cite-compact {
  color: var(--muted);
  font-family: Calibri, Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.2;
}

.library-result-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  margin-top: 3px;
}

.library-result-chip {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  max-width: 100%;
  padding: 1px 6px;
  border: 1px solid var(--source-line);
  border-radius: 4px;
  background: var(--source-surface);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
}

.library-result-chip.cite-compact {
  font-family: Calibri, Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.05;
}

.preview-body {
  color: #000000;
  font-family: Calibri, Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.preview-body p {
  margin: 0 0 8px;
}

.preview-body b,
.preview-body strong {
  font-weight: 700;
}

.preview-body mark,
.preview-body span[style*="background"] {
  background: #fff176;
  color: #000;
}

.preview-body u {
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.result-list {
  display: grid;
  gap: 2px;
}

.empty-note {
  padding: 8px 2px;
  color: var(--muted);
  font-size: 11.5px;
}

#cards-view .result-list {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

#chat-view.is-active {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-messages {
  display: grid;
  align-content: end;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  padding: 2px 1px 8px;
  box-shadow: none;
}

.chat-message {
  max-width: 86%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 8px 10px;
  color: var(--ink-2);
  white-space: normal;
}

.chat-message.user {
  justify-self: end;
  border-color: var(--accent);
  background: var(--word-selected);
  color: var(--ink);
  white-space: pre-wrap;
}

.chat-message.assistant {
  justify-self: start;
}

.chat-message.assistant p,
.chat-message.assistant ul,
.chat-message.assistant ol {
  margin: 0 0 8px;
}

.chat-message.assistant p:last-child,
.chat-message.assistant ul:last-child,
.chat-message.assistant ol:last-child {
  margin-bottom: 0;
}

.chat-message.assistant ul,
.chat-message.assistant ol {
  padding-left: 18px;
}

.chat-message.assistant code {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  padding: 1px 4px;
  font-family: var(--font-mono);
  font-size: 11px;
}

.chat-composer {
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: end;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 7px;
}

.chat-composer:focus-within {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 2px var(--focus);
}

.chat-composer textarea {
  min-height: 36px;
  max-height: 132px;
  border: 0;
  padding: 7px 5px;
  resize: none;
  box-shadow: none;
}

.chat-composer textarea:focus {
  border: 0;
  box-shadow: none;
}

.chat-messages {
  background: transparent;
  gap: 6px;
}

.chat-composer {
  border-color: var(--source-line);
  border-radius: 6px;
  background: var(--source-surface);
  box-shadow: none;
}

.chat-message {
  border-color: var(--source-line);
  border-radius: 6px;
  background: var(--source-surface);
  box-shadow: none;
}

.chat-message.user {
  border-color: #A9C5FF;
  background: var(--source-blue-soft);
  color: #0F172A;
}

.chat-composer:focus-within {
  border-color: var(--source-blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .12);
}

@media (max-width: 560px) {
  .research-rail {
    display: flex;
    gap: 0;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--word-tab-line);
    background: var(--word-ribbon);
  }

  .rail-tab {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    padding: 0 10px;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
  }

  .result-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 520px) {
  .view {
    padding: 9px;
  }

  .inline-form,
  .view-toolbar,
  .cutter-actions {
    grid-template-columns: 1fr;
  }

  .search-row,
  #cards-view .search-row {
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 6px;
  }

  .chat-composer {
    grid-template-columns: minmax(0, 1fr) 34px;
  }
}
