:root {
  --navy: #4f354e;
  --navy-2: #7b4c80;
  --teal: #6f4775;
  --green: #77607e;
  --gold: #785a18;
  --cream: #f5eaf4;
  --paper: #fffaf4;
  --blue-soft: #efe1ef;
  --green-soft: #eee6f2;
  --gold-soft: #f5ead4;
  --rose-soft: #f3e1ed;
  --gray-50: #fbf7fb;
  --gray-100: #f2e8f2;
  --gray-200: #dfcfdf;
  --gray-300: #cab5cb;
  --gray-500: #756777;
  --gray-700: #493e4b;
  --ink: #201820;
  --danger: #a33a3a;
  --shadow: 0 22px 60px rgba(63, 34, 70, 0.14);
  --shadow-small: 0 9px 28px rgba(63, 34, 70, 0.09);
  --radius: 14px;
  --radius-small: 9px;
  --max-width: 1560px;
  --brand-ink: #4f354e;
  --brand-cream: #fff8f1;
  --heading-color: var(--navy);
  --app-background: #e9d9ea;
  --surface-strong: #fff8f1;
  --input-bg: #fffaf4;
  --row-hover: #fcf2fb;
  --tabbar-bg: rgba(255, 248, 241, 0.9);
  --dialog-chrome: rgba(255, 250, 244, 0.96);
  --danger-soft: #fffafa;
  --danger-border: #e6b5bd;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --navy: #7b4c80;
  --navy-2: #b68ab7;
  --teal: #c28dcb;
  --gold: #d1ad56;
  --paper: #241329;
  --cream: #2d1d31;
  --blue-soft: #34203c;
  --green-soft: #38243f;
  --gold-soft: #3b3021;
  --rose-soft: #3b2033;
  --gray-50: #201424;
  --gray-100: #2b1d30;
  --gray-200: #49324f;
  --gray-300: #67486e;
  --gray-500: #bcaabd;
  --gray-700: #e1d5e1;
  --ink: #fff7ec;
  --heading-color: #fff7ec;
  --app-background: #160d18;
  --surface-strong: #2a1830;
  --input-bg: #1d1120;
  --row-hover: #301c36;
  --tabbar-bg: rgba(22, 13, 24, 0.92);
  --dialog-chrome: rgba(36, 19, 41, 0.97);
  --danger-soft: #351922;
  --danger-border: #744151;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  --shadow-small: 0 8px 24px rgba(0, 0, 0, 0.26);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

:root[data-text-scale="large"] {
  font-size: 112.5%;
}

body {
  margin: 0;
  overflow-x: clip;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 7%, rgba(123, 76, 128, 0.28), transparent 31rem),
    radial-gradient(circle at 87% 18%, rgba(120, 90, 24, 0.12), transparent 25rem),
    linear-gradient(180deg, #f7efe6 0%, var(--app-background) 54%, #d9c3dd 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

.skip-link {
  position: fixed;
  z-index: 200;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.7rem 0.9rem;
  color: white;
  background: var(--navy);
  border-radius: 10px;
  transform: translateY(-180%);
  transition: transform 140ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

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

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

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(123, 76, 128, 0.36);
  outline-offset: 2px;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 0.75rem;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1.06;
  letter-spacing: -0.035em;
  color: var(--heading-color);
}

h3 {
  margin-bottom: 0.4rem;
  color: var(--heading-color);
  font-size: 1.2rem;
  letter-spacing: -0.015em;
}

small {
  display: block;
  color: var(--gray-500);
  line-height: 1.45;
}

.app-shell {
  min-height: 100vh;
}

.not-found-card {
  width: min(620px, calc(100% - 2rem));
  margin: clamp(3rem, 12vh, 8rem) auto;
  padding: clamp(1.5rem, 5vw, 3rem);
  background: var(--paper);
  border: 1px solid var(--gray-200);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
}

.not-found-card h1 {
  margin-bottom: 0.75rem;
  color: var(--heading-color);
  font-size: clamp(2rem, 7vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  min-height: 82px;
  padding: 1rem clamp(1rem, 4vw, 3.5rem);
  color: white;
  background: rgba(47, 33, 54, 0.97);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.brand-lockup,
.topbar-actions,
.section-heading,
.section-actions,
.panel-heading,
.dialog-heading,
.dialog-actions,
.filter-row,
.form-actions,
.toggle-line {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 0.85rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  color: var(--brand-ink);
  background: var(--brand-cream);
  border-radius: 9px;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  overflow: hidden;
}

.brand-mark img {
  display: block;
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.topbar .eyebrow,
.topbar h1 {
  color: white;
}

.topbar .eyebrow {
  margin-bottom: 0.18rem;
  opacity: 0.72;
}

.topbar-actions {
  justify-content: flex-end;
  gap: 0.75rem;
}

.clarity-control {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 38px;
  padding: 0.28rem 0.35rem 0.28rem 0.7rem;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 800;
}

.clarity-control select {
  width: auto;
  min-height: 30px;
  padding: 0.2rem 1.7rem 0.2rem 0.55rem;
  color: white;
  background-color: rgba(7, 14, 21, 0.36);
  border: 0;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 800;
}

.tabbar {
  position: sticky;
  top: 82px;
  z-index: 40;
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  padding: 0.65rem clamp(1rem, 4vw, 3.5rem);
  background: var(--tabbar-bg);
  border-bottom: 1px solid var(--gray-200);
  backdrop-filter: blur(15px);
  scrollbar-width: none;
}

.tabbar::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: 0.7rem 1rem;
  color: var(--gray-500);
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-weight: 750;
  white-space: nowrap;
}

.tab:hover {
  color: var(--heading-color);
  background: var(--gray-100);
}

.tab.is-active {
  color: white;
  background: var(--navy);
}

.main-content {
  width: min(var(--max-width), 100%);
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 3rem);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
  animation: viewIn 180ms ease-out;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.eyebrow {
  margin-bottom: 0.45rem;
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.subtle {
  color: var(--gray-500);
}

.small {
  font-size: 0.88rem;
}

.hero-card {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  padding: clamp(1.5rem, 4vw, 3.25rem);
  color: white;
  background:
    radial-gradient(circle at 10% 20%, rgba(209, 173, 86, 0.42) 0 1px, transparent 2px),
    radial-gradient(circle at 24% 72%, rgba(223, 183, 228, 0.42) 0 1px, transparent 2px),
    radial-gradient(circle at 72% 18%, rgba(209, 173, 86, 0.36) 0 1px, transparent 2px),
    radial-gradient(circle at 90% 64%, rgba(223, 183, 228, 0.44) 0 1px, transparent 2px),
    linear-gradient(132deg, #2f2136 0%, #5a315d 55%, #7b4c80 100%);
  border: 1px solid rgba(255, 247, 236, 0.16);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hero-card h2 {
  color: white;
}

.hero-card .eyebrow {
  color: #d1ad56;
}

.hero-card h2 {
  max-width: 980px;
}

.hero-copy {
  max-width: 900px;
  margin-bottom: 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: clamp(1rem, 1.5vw, 1.15rem);
}

.local-first-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 0 0;
  padding: 0.9rem 1rem;
  color: var(--gray-700);
  background: var(--paper);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow-small);
}

.local-first-note strong {
  display: block;
  color: var(--heading-color);
}

.local-first-note span {
  font-size: 0.9rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.metric-card {
  padding: 1.25rem;
  background: var(--paper);
  border: 1px solid rgba(90, 49, 93, 0.15);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow-small);
}

.metric-label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--gray-500);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-value {
  color: var(--heading-color);
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
}

.metric-detail {
  margin-top: 0.45rem;
  color: var(--gray-500);
  font-size: 0.88rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

.panel {
  min-width: 0;
  padding: 1.35rem;
  background: var(--paper);
  border: 1px solid rgba(90, 49, 93, 0.16);
  border-radius: var(--radius);
  box-shadow: var(--shadow-small);
}

.panel-large {
  grid-column: span 2;
}

.panel-heading,
.section-heading,
.dialog-heading {
  justify-content: space-between;
  gap: 1rem;
}

.panel-heading {
  margin-bottom: 1rem;
}

.section-heading {
  margin-bottom: 1.5rem;
}

.section-heading > div:first-child {
  max-width: 950px;
}

.section-actions,
.form-actions,
.dialog-actions {
  gap: 0.7rem;
  flex-wrap: wrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 43px;
  padding: 0.72rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.button-primary {
  color: white;
  background: var(--teal);
  box-shadow: 0 8px 20px rgba(90, 49, 93, 0.24);
}

.button-primary:hover {
  background: #4f354e;
}

.button-secondary {
  color: var(--heading-color);
  background: var(--surface-strong);
  border-color: var(--gray-300);
}

.button-secondary:hover,
.button-quiet:hover {
  border-color: var(--teal);
  background: var(--blue-soft);
}

.button-light {
  color: var(--brand-ink);
  background: var(--brand-cream);
}

.button-light:hover {
  background: var(--surface-strong);
}

.button-quiet {
  color: var(--heading-color);
  background: transparent;
  border-color: var(--gray-200);
}

.button-danger {
  color: white;
  background: var(--danger);
}

.button-left {
  margin-right: auto;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 800;
}

.status-neutral {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.1);
}

.status-ready {
  color: #dff7e4;
  background: rgba(93, 174, 110, 0.22);
}

.status-draft {
  color: #ffefc3;
  background: rgba(200, 155, 60, 0.2);
}

.thread-summary {
  display: grid;
  gap: 1rem;
}

.thesis-block {
  padding: 1.2rem;
  background: var(--cream);
  border-left: 5px solid var(--gold);
  border-radius: 14px;
}

.thesis-block p {
  margin: 0;
  color: var(--heading-color);
  font-size: 1.1rem;
  font-weight: 650;
}

.thread-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
}

.thread-card {
  padding: 1rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 14px;
}

.thread-card strong {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--heading-color);
}

.thread-card p {
  margin-bottom: 0;
  color: var(--gray-700);
  font-size: 0.92rem;
}

.bar-list,
.ranked-list {
  display: grid;
  gap: 0.78rem;
}

.panel-note {
  margin: -0.35rem 0 1rem;
  color: var(--gray-500);
  font-size: 0.82rem;
  line-height: 1.5;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.85fr) minmax(100px, 1.5fr) minmax(68px, auto);
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.58rem 0.65rem;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.bar-row:hover {
  background: var(--blue-soft);
  border-color: var(--gray-200);
  transform: translateX(2px);
}

.bar-label {
  overflow: hidden;
  color: var(--gray-700);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  background: var(--gray-100);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(90, 49, 93, 0.05);
}

.bar-fill {
  display: block;
  height: 100%;
  min-width: 6px;
  background: linear-gradient(90deg, #5a315d, #b68ab7);
  border-radius: 999px;
}

.bar-count {
  color: var(--gray-500);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rank-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--gray-100);
}

.rank-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.rank-item.rank-link,
.rank-item.rank-link:last-child {
  width: 100%;
  padding: 0.68rem 0.72rem;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  font: inherit;
  text-align: left;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.rank-item.rank-link:hover {
  background: var(--blue-soft);
  border-color: var(--gray-200);
  transform: translateX(2px);
}

.rank-name {
  color: var(--gray-700);
  font-weight: 750;
}

.rank-count {
  display: inline-flex;
  min-width: 34px;
  justify-content: center;
  padding: 0.2rem 0.5rem;
  color: var(--heading-color);
  background: var(--blue-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 900;
}

.rank-action {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  flex: 0 0 auto;
}

.rank-arrow {
  color: var(--teal);
  font-size: 1rem;
  font-weight: 900;
  transition: transform 150ms ease;
}

.rank-link:hover .rank-arrow {
  transform: translateX(3px);
}

.donut-wrap {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) 1.2fr;
  align-items: center;
  gap: 1.2rem;
}

.donut {
  position: relative;
  width: min(180px, 100%);
  aspect-ratio: 1;
  margin: auto;
  border-radius: 50%;
}

.donut-slice-hit {
  position: absolute;
  z-index: 1;
  inset: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 50%;
  transition: background-color 150ms ease, filter 150ms ease;
}

.donut-slice-hit:hover,
.donut-slice-hit:focus-visible {
  background: rgba(255, 255, 255, 0.24);
  filter: saturate(1.15);
}

.donut-center {
  position: absolute;
  z-index: 2;
  inset: 23%;
  display: grid;
  place-content: center;
  padding: 0;
  color: var(--heading-color);
  background: var(--paper);
  border: 0;
  border-radius: 50%;
  font: inherit;
  text-align: center;
  transition: background-color 150ms ease, transform 150ms ease;
}

.donut-center:hover {
  background: var(--blue-soft);
  transform: scale(1.03);
}

.donut-center strong {
  font-size: 1.65rem;
  line-height: 1;
}

.donut-center span {
  margin-top: 0.25rem;
  color: var(--gray-500);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.legend-list {
  display: grid;
  gap: 0.55rem;
}

.legend-row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 0.6rem;
  color: var(--gray-700);
  font-size: 0.86rem;
}

.legend-button {
  width: 100%;
  padding: 0.48rem 0.55rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  text-align: left;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.legend-button:hover {
  background: var(--blue-soft);
  border-color: var(--gray-200);
  transform: translateX(2px);
}

.legend-button strong {
  font-variant-numeric: tabular-nums;
}

.legend-more {
  display: grid;
  gap: 0.35rem;
  padding-left: 1rem;
}

.legend-more[hidden] {
  display: none;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.filter-row {
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-row input,
.filter-row select,
.editor-grid input,
.editor-grid textarea,
.intake-form textarea,
.intake-form input,
select {
  width: 100%;
  color: var(--ink);
  background: var(--input-bg);
  border: 1px solid var(--gray-300);
  border-radius: 12px;
}

.search-field {
  flex: 1 1 340px;
}

.filter-row input,
.filter-row select {
  min-height: 44px;
  padding: 0.68rem 0.8rem;
}

.filter-row select {
  width: auto;
  min-width: 170px;
}

.table-shell {
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-small);
}

.library-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.library-table th {
  padding: 0.85rem 0.9rem;
  color: var(--heading-color);
  background: var(--blue-soft);
  border-bottom: 1px solid var(--gray-200);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
}

.library-table td {
  padding: 1rem 0.9rem;
  vertical-align: top;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.91rem;
}

.library-table tr:last-child td {
  border-bottom: 0;
}

.library-table tbody tr:hover {
  background: var(--row-hover);
}

.library-table th:nth-child(1) { width: 19%; }
.library-table th:nth-child(2) { width: 22%; }
.library-table th:nth-child(3) { width: 22%; }
.library-table th:nth-child(4) { width: 13%; }
.library-table th:nth-child(5) { width: 20%; }
.library-table th:nth-child(6) { width: 4%; }

.book-title {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--heading-color);
  font-weight: 900;
  line-height: 1.3;
}

.book-author {
  color: var(--gray-500);
  font-size: 0.84rem;
}

.cell-clamp {
  display: -webkit-box;
  overflow: hidden;
  color: var(--gray-700);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.tag-list {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  padding: 0.28rem 0.5rem;
  color: var(--heading-color);
  background: var(--green-soft);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
}

.tag-domain {
  color: #6b4f08;
  background: var(--gold-soft);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--heading-color);
  background: var(--surface-strong);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  font-size: 1.25rem;
  font-weight: 900;
}

.icon-button:hover {
  color: white;
  background: var(--navy);
}

.empty-state {
  padding: 4rem 1rem;
  text-align: center;
}

.empty-state p {
  color: var(--gray-500);
}

.two-column-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 1.25rem;
  align-items: start;
}

.intake-form,
.guidance-panel {
  padding: clamp(1.25rem, 3vw, 2rem);
}

.field-label,
.editor-grid label > span,
.editor-grid label {
  display: block;
}

.field-label,
.editor-grid label > span {
  margin-bottom: 0.42rem;
  color: var(--heading-color);
  font-size: 0.83rem;
  font-weight: 850;
}

.intake-form textarea,
.editor-grid textarea,
.editor-grid input {
  padding: 0.85rem 0.9rem;
  resize: vertical;
}

.intake-form textarea {
  margin-bottom: 1rem;
}

.option-card {
  margin: 0.3rem 0 1.1rem;
  padding: 1rem;
  background: var(--blue-soft);
  border-radius: 14px;
}

.research-mode-status {
  margin: -0.45rem 0 1.1rem;
  padding: 0.72rem 0.82rem;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.research-mode-status.is-ready {
  color: #285f37;
  background: var(--green-soft);
}

.research-mode-status.is-warning {
  color: #6b4f08;
  background: var(--gold-soft);
}

.research-mode-status a {
  color: inherit;
  font-weight: 850;
}

.toggle-line input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.toggle-line {
  align-items: flex-start;
  gap: 0.75rem;
}

.toggle-line input {
  width: 18px;
  height: 18px;
  margin-top: 0.15rem;
  accent-color: var(--navy-2);
}

.toggle-line strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--heading-color);
}

.progress-box,
.status-banner,
.note-box {
  padding: 1rem;
  border-radius: 14px;
}

.progress-box {
  margin-top: 1rem;
  color: var(--heading-color);
  background: var(--gold-soft);
}

.note-box {
  margin-top: 1.5rem;
  background: var(--cream);
  border-left: 4px solid var(--gold);
}

.note-box strong {
  color: var(--heading-color);
}

.note-box p {
  margin: 0.35rem 0 0;
  color: var(--gray-700);
  font-size: 0.91rem;
}

.check-list {
  display: grid;
  gap: 0.75rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.check-list li {
  position: relative;
  padding-left: 1.55rem;
  color: var(--gray-700);
}

.check-list li::before {
  position: absolute;
  left: 0;
  top: 0.07rem;
  content: "✓";
  color: var(--teal);
  font-weight: 900;
}

.synthesis-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.15rem;
}

.synthesis-card {
  padding: 1.35rem;
  background: var(--paper);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-small);
}

.synthesis-card-wide {
  grid-column: span 2;
}

.synthesis-card ul,
.synthesis-card ol {
  margin: 0.75rem 0 0;
  padding-left: 1.25rem;
}

.synthesis-card li {
  margin-bottom: 0.55rem;
  color: var(--gray-700);
}

.synthesis-card li:last-child {
  margin-bottom: 0;
}

.status-banner {
  margin-bottom: 1rem;
  color: var(--heading-color);
  background: var(--blue-soft);
  border: 1px solid var(--gray-300);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

.comfort-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 1.1rem;
}

.comfort-grid select {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.75rem;
  color: var(--ink);
  background: var(--input-bg);
  border: 1px solid var(--gray-300);
  border-radius: 12px;
}

.stacked-actions {
  display: grid;
  gap: 0.65rem;
}

.file-drop {
  display: grid;
  place-items: center;
  min-height: 130px;
  padding: 1.2rem;
  color: var(--heading-color);
  background: var(--gray-50);
  border: 2px dashed var(--gray-300);
  border-radius: 16px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}

.file-drop:hover {
  border-color: var(--teal);
  background: var(--blue-soft);
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.danger-panel {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.book-dialog {
  width: min(1100px, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 0;
  border-radius: 24px;
  box-shadow: 0 35px 100px rgba(47, 24, 55, 0.34);
}

.book-dialog::backdrop {
  background: rgba(27, 13, 31, 0.7);
  backdrop-filter: blur(6px);
}

.confirm-dialog {
  width: min(480px, calc(100% - 2rem));
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(47, 24, 55, 0.36);
}

.confirm-dialog::backdrop {
  background: rgba(22, 13, 24, 0.78);
  backdrop-filter: blur(6px);
}

.confirm-card {
  padding: clamp(1.25rem, 5vw, 2rem);
  background: var(--paper);
  border: 1px solid var(--gray-200);
  border-radius: 20px;
}

.confirm-card h2 {
  font-size: clamp(1.5rem, 5vw, 2rem);
}

.confirm-card > p:not(.eyebrow) {
  color: var(--gray-700);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1.25rem;
}

.dialog-card {
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: clamp(1rem, 3vw, 2rem);
  background: var(--paper);
}

.dialog-heading {
  position: sticky;
  top: -2rem;
  z-index: 2;
  margin: -2rem -2rem 1.2rem;
  padding: 1.5rem 2rem 1rem;
  background: var(--dialog-chrome);
  border-bottom: 1px solid var(--gray-200);
  backdrop-filter: blur(14px);
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.editor-grid .span-two {
  grid-column: span 2;
}

.dialog-actions {
  position: sticky;
  bottom: -2rem;
  z-index: 2;
  margin: 1.25rem -2rem -2rem;
  padding: 1rem 2rem 1.5rem;
  background: var(--dialog-chrome);
  border-top: 1px solid var(--gray-200);
  backdrop-filter: blur(14px);
}

.source-section {
  margin-top: 1.25rem;
  padding: 1rem;
  background: var(--blue-soft);
  border: 1px solid var(--gray-200);
  border-radius: 14px;
}

.source-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.source-link {
  width: fit-content;
  max-width: 100%;
  color: var(--teal);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.draft-disclaimer {
  margin: 0.9rem 0 0;
  color: var(--gray-500);
  font-size: 0.88rem;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 1.25rem;
  bottom: 1.25rem;
  max-width: min(430px, calc(100% - 2.5rem));
  padding: 0.95rem 1rem;
  color: white;
  background: var(--navy);
  border-radius: 14px;
  box-shadow: var(--shadow);
  font-weight: 700;
}

.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;
}


.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 38px;
  padding: 0.5rem 0.72rem;
  color: white;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 800;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.18);
}

.theme-icon {
  display: inline-grid;
  place-items: center;
  width: 1rem;
  font-size: 1rem;
  line-height: 1;
}

#themePreference {
  min-height: 44px;
  padding: 0.68rem 0.8rem;
  color: var(--ink);
  background: var(--input-bg);
  border: 1px solid var(--gray-300);
  border-radius: 12px;
}

:root[data-clarity="essential"] .dashboard-grid > .panel:not(.panel-large),
:root[data-clarity="essential"] .guidance-panel,
:root[data-clarity="essential"] .metric-detail {
  display: none;
}

:root[data-clarity="essential"] .library-table th:nth-child(2),
:root[data-clarity="essential"] .library-table td:nth-child(2),
:root[data-clarity="essential"] .library-table th:nth-child(4),
:root[data-clarity="essential"] .library-table td:nth-child(4),
:root[data-clarity="essential"] .library-table th:nth-child(5),
:root[data-clarity="essential"] .library-table td:nth-child(5) {
  display: none;
}

:root[data-clarity="essential"] .library-table th:nth-child(1) { width: 34%; }
:root[data-clarity="essential"] .library-table th:nth-child(3) { width: 61%; }
:root[data-clarity="essential"] .library-table th:nth-child(6) { width: 5%; }

:root[data-clarity="studio"] .panel,
:root[data-clarity="studio"] .synthesis-card,
:root[data-density="compact"] .panel,
:root[data-density="compact"] .synthesis-card {
  padding: 1rem;
}

:root[data-clarity="studio"] .library-table td,
:root[data-density="compact"] .library-table td {
  padding-block: 0.72rem;
}

:root[data-density="compact"] .metric-grid,
:root[data-density="compact"] .dashboard-grid,
:root[data-density="compact"] .settings-grid,
:root[data-density="compact"] .synthesis-layout {
  gap: 0.75rem;
}

:root[data-motion="reduced"] *,
:root[data-motion="reduced"] *::before,
:root[data-motion="reduced"] *::after {
  scroll-behavior: auto !important;
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at 16% 8%, rgba(153, 92, 164, 0.34), transparent 31rem),
    radial-gradient(circle at 82% 34%, rgba(90, 49, 93, 0.28), transparent 28rem),
    linear-gradient(180deg, var(--app-background), #2b1d30 62%, var(--app-background));
}

:root[data-theme="dark"] .topbar {
  background: rgba(16, 12, 18, 0.97);
}

:root[data-theme="dark"] .tabbar {
  border-bottom-color: var(--gray-200);
}

:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .metric-card,
:root[data-theme="dark"] .table-shell,
:root[data-theme="dark"] .synthesis-card {
  border-color: rgba(223, 183, 228, 0.18);
}

:root[data-theme="dark"] .button-primary {
  color: #201820;
  background: #c28dcb;
}

:root[data-theme="dark"] .button-primary:hover {
  background: #dfb7e4;
}

:root[data-theme="dark"] .button-secondary,
:root[data-theme="dark"] .button-quiet,
:root[data-theme="dark"] .icon-button {
  color: var(--heading-color);
}

:root[data-theme="dark"] .button-light:hover {
  background: #ffffff;
}

:root[data-theme="dark"] .library-table th {
  color: #f1dff2;
}

:root[data-theme="dark"] .tag-domain {
  color: #f3d98e;
}

:root[data-theme="dark"] .status-banner {
  border-color: #67486e;
}

:root[data-theme="dark"] .book-dialog::backdrop {
  background: rgba(0, 0, 0, 0.78);
}

:root[data-theme="dark"] code {
  color: #dfb7e4;
}

:root[data-theme="dark"] .research-mode-status.is-ready {
  color: #c9efd1;
}

:root[data-theme="dark"] .research-mode-status.is-warning {
  color: #f0d694;
}

@media (max-width: 1100px) {
  .library-table th:nth-child(4),
  .library-table td:nth-child(4),
  .library-table th:nth-child(5),
  .library-table td:nth-child(5) {
    display: none;
  }

  .library-table th:nth-child(1) { width: 24%; }
  .library-table th:nth-child(2) { width: 33%; }
  .library-table th:nth-child(3) { width: 35%; }
  .library-table th:nth-child(6) { width: 8%; }
}

@media (max-width: 900px) {
  .metric-grid,
  .dashboard-grid,
  .settings-grid,
  .synthesis-layout,
  .two-column-layout {
    grid-template-columns: 1fr;
  }

  .panel-large,
  .synthesis-card-wide {
    grid-column: span 1;
  }

  .thread-grid {
    grid-template-columns: 1fr;
  }

  .hero-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
  }

  .comfort-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions .status-pill {
    display: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: center;
    min-height: 72px;
    padding: 0.8rem 1rem;
  }

  #quickAddButton {
    display: none;
  }

  .tabbar {
    top: 72px;
    padding-inline: 0.75rem;
  }

  .main-content {
    padding: 1rem;
  }

  .section-heading,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-actions,
  .section-actions .button,
  .form-actions,
  .form-actions .button {
    width: 100%;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .local-first-note {
    align-items: stretch;
    flex-direction: column;
  }

  .local-first-note .button {
    width: 100%;
  }

  .filter-row select,
  .filter-row .button {
    flex: 1 1 140px;
    width: auto;
  }

  .bar-row {
    grid-template-columns: minmax(105px, 1fr) minmax(70px, 1fr) auto;
    gap: 0.5rem;
  }

  .table-shell {
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .library-table,
  .library-table tbody,
  .library-table tr,
  .library-table td {
    display: block;
    width: 100%;
  }

  .library-table {
    min-width: 0;
  }

  .library-table thead {
    display: none;
  }

  .library-table tbody {
    display: grid;
    gap: 0.8rem;
  }

  .library-table tr {
    position: relative;
    padding: 1rem 3.5rem 1rem 1rem;
    background: var(--paper);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow-small);
  }

  .library-table td {
    padding: 0.75rem 0 0;
    border: 0;
  }

  .library-table td:first-child {
    padding-top: 0;
  }

  .library-table td:last-child {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: auto;
    padding: 0;
  }

  .library-table td[data-label]::before {
    display: block;
    margin-bottom: 0.2rem;
    color: var(--gray-500);
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  .library-table th:nth-child(4),
  .library-table td:nth-child(4),
  .library-table th:nth-child(5),
  .library-table td:nth-child(5) {
    display: block;
  }

  :root[data-clarity="essential"] .library-table td:nth-child(2),
  :root[data-clarity="essential"] .library-table td:nth-child(4),
  :root[data-clarity="essential"] .library-table td:nth-child(5) {
    display: none;
  }

  .editor-grid {
    grid-template-columns: 1fr;
  }

  .editor-grid .span-two {
    grid-column: span 1;
  }

  .dialog-heading,
  .dialog-actions {
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .dialog-heading {
    top: -1rem;
    margin-top: -1rem;
  }

  .dialog-actions {
    bottom: -1rem;
    margin-bottom: -1rem;
  }

  .donut-wrap {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .bar-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .bar-label {
    white-space: normal;
  }

  .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .rank-count {
    font-size: 0.72rem;
  }

  .brand-lockup .eyebrow {
    display: none;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand-mark img {
    width: 38px;
    height: 38px;
  }

  .topbar-actions .button,
  .theme-toggle {
    min-height: 40px;
    padding: 0.6rem 0.75rem;
  }

  .clarity-control > span {
    display: none;
  }

  .clarity-control {
    padding-left: 0.3rem;
  }

  .clarity-control select {
    max-width: 94px;
  }

  .theme-toggle-label {
    display: none;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .confirm-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .confirm-actions .button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
