:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --ink: #0f172a;
  --muted: #64748b;
  --card: rgba(255, 255, 255, 0.86);
  --line: #dbe3ef;
  --primary: #4f46e5;
  --primary-ink: #f8faff;
  --ok: #0f766e;
  --error: #b91c1c;
  --soft: #eef2ff;
  --soft-2: #f8fafc;
  --input-bg: #ffffff;
  --code-inline-bg: #eef2ff;
  --code-inline-color: #312e81;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --card: rgba(22, 28, 45, 0.88);
  --line: #2a3349;
  --primary: #818cf8;
  --primary-ink: #0f1117;
  --ok: #34d399;
  --error: #f87171;
  --soft: rgba(99, 102, 241, 0.14);
  --soft-2: rgba(30, 38, 60, 0.85);
  --input-bg: #1a2035;
  --code-inline-bg: rgba(99, 102, 241, 0.15);
  --code-inline-color: #a5b4fc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Segoe UI, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  transition: background 0.25s ease, color 0.25s ease;
}

:root:not([data-theme="dark"]) body {
  background: radial-gradient(circle at 15% 15%, #dbe8ff 0%, var(--bg) 45%);
}

[data-theme="dark"] body {
  background: radial-gradient(circle at 15% 15%, #141c33 0%, var(--bg) 55%);
}

body.app-busy {
  overflow: hidden;
}

.bg-glow {
  position: fixed;
  inset: auto -160px -200px auto;
  width: 480px;
  height: 480px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(79, 70, 229, 0.22), rgba(79, 70, 229, 0));
  pointer-events: none;
}

.app-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 18px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-copy {
  min-width: 0;
}

.brand-emblem-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  padding: 8px;
  flex: 0 0 auto;
  border-radius: 18px;
  border: 1px solid rgba(79, 70, 229, 0.12);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(238, 242, 255, 0.9));
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.brand-emblem-link:hover,
.brand-emblem-link:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(79, 70, 229, 0.16);
  border-color: rgba(79, 70, 229, 0.28);
  outline: none;
}

.brand-emblem {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

[data-theme="dark"] .brand-emblem {
  filter: invert(1) brightness(1.18) contrast(1.02);
}

[data-theme="dark"] .brand-emblem-link {
  background: linear-gradient(180deg, rgba(30, 38, 60, 0.92), rgba(22, 28, 45, 0.92));
  border-color: rgba(129, 140, 248, 0.2);
}

.brand-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 12px);
  width: min(320px, 70vw);
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
  font-size: 0.82rem;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 20;
}

.brand-emblem-link:hover .brand-tooltip,
.brand-emblem-link:focus-visible .brand-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
}

.topbar h1 a {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.topbar h1 a:hover {
  opacity: 0.75;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  width: auto;
  max-width: 400px;
}

.compact-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.card {
  backdrop-filter: blur(12px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 35px rgba(15, 23, 42, 0.08);
  padding: 18px;
}

.stack {
  display: grid;
  gap: 14px;
}

.row {
  display: flex;
  align-items: center;
}

.gap-sm {
  gap: 10px;
}

.wrap {
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
}

.spread {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.small {
  font-size: 0.88rem;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

input,
textarea,
select,
button {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
}

textarea {
  min-height: 130px;
  resize: vertical;
}

button {
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

button.primary {
  background: linear-gradient(120deg, var(--primary), #7c3aed);
  color: var(--primary-ink);
  border: none;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.list-item small {
  color: var(--muted);
}

.suggestion-grid {
  display: grid;
  gap: 12px;
}

.suggestion-card {
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
}

.suggestion-card:hover {
  border-color: var(--primary);
  box-shadow: 0 14px 30px rgba(79, 70, 229, 0.12);
  transform: translateY(-2px);
}

.suggestion-card:active {
  transform: translateY(0);
}

.suggestion-card.selected {
  border-color: rgba(79, 70, 229, 0.45);
  box-shadow: 0 14px 30px rgba(79, 70, 229, 0.14);
  background: linear-gradient(180deg, rgba(238, 242, 255, 0.98), rgba(255, 255, 255, 0.98));
}

.suggestion-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.suggestion-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.suggestion-deepen {
  color: #4338ca;
  background: rgba(99, 102, 241, 0.12);
}

.suggestion-broaden {
  color: #0f766e;
  background: rgba(20, 184, 166, 0.12);
}

.suggestion-generate-hint {
  color: var(--muted);
  font-size: 0.82rem;
  opacity: 0.6;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.suggestion-card:hover .suggestion-generate-hint {
  opacity: 1;
  color: var(--primary);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: var(--card);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat strong {
  font-size: 1.2rem;
}

.lecture-body {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--input-bg);
  padding: 24px;
  line-height: 1.72;
  overflow-x: auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.lecture-layout {
  display: grid;
  grid-template-columns: minmax(0, 290px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.lecture-sidebar {
  position: sticky;
  top: 18px;
}

.lecture-main {
  min-width: 0;
}

.lecture-header h2,
.sidebar-heading {
  margin: 0;
}

.lecture-mode-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0 10px;
}

.lecture-mode-tab {
  border: 1px solid var(--line);
  background: var(--soft-2);
  color: var(--muted);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

.lecture-mode-tab[aria-selected="true"] {
  color: var(--ink);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(79, 70, 229, 0.2);
}

.toggle-row input[type="checkbox"] {
  margin-top: 2px;
}

.meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.meta-pill {
  border: 1px solid var(--line);
  background: var(--soft-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

.toc-nav {
  display: grid;
  gap: 8px;
}

.toc-link {
  display: block;
  color: var(--ink);
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 10px;
  transition: background 0.18s ease, color 0.18s ease;
}

.toc-link:hover {
  background: var(--soft);
  color: var(--primary);
}

.toc-subitem {
  margin-left: 14px;
  font-size: 0.92rem;
}

.prose {
  font-size: 1rem;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  line-height: 1.2;
  margin-top: 1.3em;
  margin-bottom: 0.55em;
  letter-spacing: -0.025em;
}

.prose h1:first-child,
.prose h2:first-child,
.prose h3:first-child {
  margin-top: 0;
}

.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose table,
.prose pre {
  margin: 0.95em 0;
}

.prose strong {
  color: var(--ink);
}

.prose hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.5em 0;
}

.prose img {
  max-width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
}

.prose code {
  background: var(--code-inline-bg);
  border-radius: 6px;
  padding: 0.12em 0.35em;
  color: var(--code-inline-color);
  font-size: 0.94em;
}

.prose pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.prose ul,
.prose ol {
  padding-left: 1.2rem;
}

.prose li + li {
  margin-top: 0.35rem;
}

.prose ul.task-list {
  list-style: none;
  padding-left: 0;
}

.prose li.task-list-item {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
}

.prose li.task-list-item > .task-list-checkbox {
  width: auto;
  height: 1rem;
  margin-top: 0.25rem;
  flex: 0 0 auto;
  accent-color: var(--primary);
  pointer-events: none;
}

.prose li.task-list-item > p {
  margin: 0;
}

.prose a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px solid rgba(79, 70, 229, 0.22);
}

.prose a:hover {
  border-bottom-color: rgba(79, 70, 229, 0.65);
}

.heading-anchor {
  margin-left: 8px;
  color: #cbd5e1;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.18s ease, color 0.18s ease;
}

.prose h1:hover .heading-anchor,
.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.prose h4:hover .heading-anchor {
  opacity: 1;
}

.heading-anchor:hover {
  color: var(--primary);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--input-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}

.prose th,
.prose td {
  padding: 12px 14px;
  border-bottom: 1px solid #e5ebf4;
  text-align: left;
  vertical-align: top;
}

.prose thead th {
  background: var(--soft-2);
  font-size: 0.9rem;
  color: var(--ink);
}

.prose tbody tr:nth-child(even) {
  background: var(--soft-2);
}

.callout {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 14px;
  padding: 14px 16px;
  margin: 1em 0;
  background: var(--soft-2);
}

.callout-title {
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.callout-note,
.callout-info {
  border-left-color: #3b82f6;
  background: rgba(59, 130, 246, 0.06);
}

.callout-tip {
  border-left-color: #10b981;
  background: rgba(16, 185, 129, 0.08);
}

.callout-warning,
.callout-caution {
  border-left-color: #f59e0b;
  background: rgba(245, 158, 11, 0.09);
}

.callout-important {
  border-left-color: #8b5cf6;
  background: rgba(139, 92, 246, 0.08);
}

.code-shell {
  margin: 1.05em 0;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid #1e293b;
  background: #0b1120;
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.18);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

.code-language {
  color: #cbd5e1;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.code-copy-btn {
  width: auto;
  min-width: 86px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(203, 213, 225, 0.18);
  color: #e2e8f0;
  border-radius: 10px;
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.code-shell pre {
  background: transparent;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 0;
  margin: 0;
  overflow-x: auto;
}

.lecture-body .katex-display,
.question-card .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
}

.question-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--card);
}

.question-title {
  margin: 0 0 10px;
  font-weight: 600;
}

.question-title p {
  margin: 0;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.option-text p {
  margin: 0;
}

.option-item input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.result-box {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--card);
}

.actions-inline {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions-inline button {
  width: auto;
  min-width: 180px;
}

.segmented-control {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.segmented-control button {
  width: auto;
  border: none;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 8px 12px;
  background: #fff;
  font-size: 0.84rem;
  color: var(--muted);
}

.segmented-control button:last-child {
  border-right: none;
}

.segmented-control button.active {
  background: var(--soft);
  color: var(--primary);
  font-weight: 700;
}

.activity-chart-wrap {
  display: grid;
  gap: 10px;
}

.activity-legend {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.85rem;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.dot-new {
  background: #4f46e5;
}

.dot-repeat {
  background: #14b8a6;
}

.activity-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 160px;
}

.activity-bar-col {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.activity-bar-col small {
  color: var(--muted);
  font-size: 0.72rem;
}

.activity-bar {
  width: 100%;
  max-width: 24px;
  height: 120px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--soft-2);
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
}

.segment-new {
  background: linear-gradient(180deg, #6366f1, #4f46e5);
}

.segment-repeat {
  background: linear-gradient(180deg, #2dd4bf, #14b8a6);
}

.action-list {
  display: grid;
  gap: 10px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card);
}

.action-btn span:first-child {
  font-size: 1.2rem;
}

.action-btn span:last-child {
  display: grid;
  gap: 2px;
}

.action-btn small {
  color: var(--muted);
}

.action-btn-recommended {
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.18), 0 14px 28px rgba(79, 70, 229, 0.16);
}

.recommendation-inline-tag {
  display: inline-flex;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.recommendation-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--line));
  background: color-mix(in srgb, var(--soft) 75%, var(--input-bg));
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.recommendation-score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.recommendation-score {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft-2);
  padding: 8px 10px;
}

.recommendation-score span {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.recommendation-score strong {
  font-size: 1rem;
}

.recommendation-points {
  margin: 10px 0 0;
  padding-left: 1.1rem;
}

.recommendation-points li + li {
  margin-top: 6px;
}

.fatigue-bar-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.fatigue-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fatigue-label {
  font-size: 0.80rem;
  color: var(--muted);
  flex: 0 0 88px;
  white-space: nowrap;
}

.fatigue-bar-track {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.fatigue-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.fatigue-bar-fill.fatigue-low  { background: var(--ok); }
.fatigue-bar-fill.fatigue-mid  { background: #f59e0b; }
.fatigue-bar-fill.fatigue-high { background: var(--error); }

.fatigue-value {
  font-size: 0.80rem;
  color: var(--muted);
  min-width: 28px;
  text-align: right;
}

.fatigue-horizons {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  padding-left: 96px;
  font-size: 0.76rem;
  color: var(--muted);
}

.repetition-banner {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--soft-2);
  padding: 12px;
  margin-top: 8px;
}

.repetition-banner h3 {
  margin: 0 0 6px;
}

.ok-text {
  color: var(--ok);
}

.error-text {
  color: var(--error);
}

.topbar-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background 0.2s;
}

.topbar-btn:hover {
  background: rgba(79, 70, 229, 0.1);
}

.provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.provider-section {
  margin-top: 12px;
}

.provider-section h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.provider-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--card);
}

.provider-card-managed {
  border-color: rgba(79, 70, 229, 0.35);
  background: linear-gradient(180deg, var(--soft-2), var(--card));
}

.provider-card h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  text-transform: capitalize;
}

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

.provider-card-header h3 {
  margin: 0;
}

.shared-quota-tooltip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  color: #4338ca;
  background: rgba(99, 102, 241, 0.16);
  border: 1px solid rgba(99, 102, 241, 0.35);
  cursor: help;
  user-select: none;
}

.provider-help-link {
  margin: 0 0 10px;
  font-size: 0.82rem;
}

.provider-help-link a {
  color: var(--primary);
  text-decoration: none;
}

.provider-help-link a:hover {
  text-decoration: underline;
}

.settings-info-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--soft-2);
  color: var(--muted);
  font-size: 0.9rem;
}

.provider-card label {
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.provider-card input[type="checkbox"] {
  width: auto;
  margin-right: 6px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(10px);
  z-index: 1200;
  opacity: 1;
  transition: opacity 0.18s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.warn-text {
  color: #b45309;
}

.improve-actions {
  gap: 8px !important;
}

.improve-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--soft-2);
  border: 1px solid var(--line);
  line-height: 1.3;
}

.improve-btn:hover {
  background: var(--soft);
  border-color: rgba(79, 70, 229, 0.3);
}

.improve-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.improve-btn small {
  color: var(--muted);
  font-size: 0.82rem;
}

.review-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.25);
  backdrop-filter: blur(4px);
  z-index: 1050;
}

.review-backdrop.hidden {
  display: none;
}

.generation-error-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(4px);
  z-index: 1200;
}

.generation-error-backdrop.hidden {
  display: none;
}

.generation-error-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 28px));
  max-height: 86vh;
  overflow-y: auto;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.24);
  z-index: 1250;
}

.generation-error-popup.hidden {
  display: none;
}

.generation-error-inner {
  padding: 20px;
}

.generation-error-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.generation-error-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.generation-error-head h3 {
  margin: 0 0 4px;
}

.generation-error-tip {
  margin: 0 0 12px;
}

.generation-error-details {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft-2);
  padding: 10px 12px;
  margin: 10px 0 14px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
  font-size: 0.85rem;
}

.generation-error-details.hidden {
  display: none;
}

.review-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(580px, calc(100vw - 32px));
  max-height: 82vh;
  overflow-y: auto;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.22);
  z-index: 1100;
}

.review-popup.hidden {
  display: none;
}

.review-popup-inner {
  padding: 24px;
}

.review-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.review-popup-header h3 {
  margin: 0;
}

.review-close-btn {
  width: auto;
  padding: 6px 10px;
  background: var(--soft-2);
  border: none;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.95rem;
}

.review-score-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.review-score {
  font-size: 2rem;
  font-weight: 800;
}

.review-section {
  margin-top: 12px;
}

.review-label {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.review-section ul {
  margin: 0;
  padding-left: 1.2rem;
}

.review-section li + li {
  margin-top: 4px;
}

.loading-panel {
  width: min(460px, 100%);
  padding: 28px 24px;
  border-radius: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.22);
  text-align: center;
}

.loading-provider {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  margin-bottom: 10px;
  border-radius: 999px;
  border: 1px solid rgba(79, 70, 229, 0.28);
  background: rgba(79, 70, 229, 0.1);
  color: #4338ca;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.loading-provider.hidden {
  display: none;
}

.loading-panel h3 {
  margin: 10px 0 6px;
  font-size: 1.2rem;
}

.loading-rings {
  position: relative;
  width: 84px;
  height: 84px;
  margin: 0 auto 12px;
}

.loading-rings span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: rgba(79, 70, 229, 0.9);
  border-right-color: rgba(79, 70, 229, 0.35);
  animation: spin 1.15s linear infinite;
}

.loading-rings span:nth-child(2) {
  inset: 10px;
  border-top-color: rgba(20, 184, 166, 0.88);
  border-right-color: rgba(20, 184, 166, 0.35);
  animation-duration: 1.45s;
  animation-direction: reverse;
}

.loading-rings span:nth-child(3) {
  inset: 22px;
  border-top-color: rgba(139, 92, 246, 0.9);
  border-right-color: rgba(139, 92, 246, 0.38);
  animation-duration: 1.75s;
}

.loading-bar {
  height: 8px;
  margin-top: 16px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(226, 232, 240, 0.95);
}

.loading-bar-fill {
  height: 100%;
  width: 40%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4f46e5, #14b8a6, #8b5cf6);
  animation: loading-slide 1.4s ease-in-out infinite;
}

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

@keyframes loading-slide {
  0% {
    transform: translateX(-100%);
  }
  50% {
    transform: translateX(140%);
  }
  100% {
    transform: translateX(-100%);
  }
}

@media (max-width: 920px) {
  .lecture-layout {
    grid-template-columns: 1fr;
  }

  .lecture-sidebar {
    position: static;
    order: 2;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .brand-tooltip {
    width: min(280px, calc(100vw - 40px));
  }

  .topbar-actions {
    max-width: none;
    width: 100%;
    flex-wrap: wrap;
  }

  .lecture-body {
    padding: 18px;
  }

  .recommendation-score-grid {
    grid-template-columns: 1fr;
  }
}

.kg-header {
  flex-shrink: 0;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(8px);
}

.kg-layout {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  z-index: 100;
}


.kg-header-content {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.kg-project-meta {
  min-width: 0;
}

.kg-controls-wrap {
  flex: 1 1 420px;
  display: grid;
  gap: 10px;
  min-width: 240px;
}

.kg-search-wrap {
  justify-self: stretch;
}

.kg-search-wrap input[type="search"] {
  width: 100%;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.kg-search-wrap input[type="search"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.kg-header h2 {
  margin: 0 0 4px;
}

.kg-edge-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.kg-edge-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
  line-height: 1;
  color: var(--ink);
  background: color-mix(in srgb, var(--input-bg) 84%, var(--soft) 16%);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.16s ease, transform 0.12s ease, box-shadow 0.18s ease, opacity 0.16s ease;
}

.kg-edge-filter-chip:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
  transform: translateY(-1px);
}

.kg-edge-filter-chip input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  border-radius: 4px;
  accent-color: var(--primary);
}

.kg-edge-filter-chip small {
  color: var(--muted);
  font-size: 0.75rem;
  min-width: 1.1em;
  text-align: right;
}

.kg-edge-filter-chip.is-off {
  opacity: 0.58;
  border-style: dashed;
}

.kg-edge-filter-chip.edge-builds_on {
  border-color: color-mix(in srgb, #4f46e5 36%, var(--line));
}

.kg-edge-filter-chip.edge-relates_to {
  border-color: color-mix(in srgb, #94a3b8 45%, var(--line));
}

.kg-edge-filter-chip.edge-contrasts_with {
  border-color: color-mix(in srgb, #dc2626 36%, var(--line));
}

.kg-edge-filter-chip.edge-instance_of {
  border-color: color-mix(in srgb, #16a34a 36%, var(--line));
}

.cy-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

.node-popup {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 320px;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
  z-index: 1100;
  opacity: 1;
  transition: opacity 0.15s ease;
}

.node-popup.hidden {
  display: none;
}

.popup-inner {
  padding: 18px;
}

.popup-inner h4 {
  margin: 0 0 10px;
  line-height: 1.3;
}

.popup-inner p {
  margin: 0 0 12px;
  font-size: 0.94rem;
}

.popup-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

@media (max-width: 768px) {
  .kg-layout {
    z-index: 50;
  }

  .node-popup {
    width: calc(100vw - 40px);
    bottom: 12px;
    left: 12px;
  }

  .cy-container {
    border-radius: 20px 20px 0 0;
  }

  .kg-header-content {
    flex-wrap: wrap;
    gap: 12px;
  }

  .kg-header-content > div {
    flex: 1;
    min-width: 0;
  }

  .kg-search-wrap {
    flex: 1 1 auto;
    order: 3;
  }

  .kg-controls-wrap {
    order: 3;
    flex: 1 1 100%;
    min-width: 0;
  }

  .kg-edge-filters {
    max-height: 104px;
    overflow: auto;
    padding-right: 2px;
  }
}

/* ── Landing page ────────────────────────────────────────── */
.landing-hidden {
  display: none !important;
}

.landing {
  margin-bottom: 48px;
}

/* Hero */
.landing-hero {
  text-align: center;
  padding: 56px 24px 52px;
}

.landing-hero-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(79, 70, 229, 0.3);
  background: rgba(79, 70, 229, 0.08);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 24px;
}

.landing-headline {
  margin: 0 0 20px;
  font-size: clamp(2.2rem, 5.5vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.08;
  color: var(--ink);
}

.landing-headline em {
  font-style: normal;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.landing-sub {
  margin: 0 auto 36px;
  max-width: 600px;
  font-size: 1.08rem;
  line-height: 1.7;
  color: var(--muted);
}

.landing-cta {
  display: inline-block;
  padding: 15px 32px;
  border-radius: 14px;
  background: linear-gradient(120deg, var(--primary), #7c3aed);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.3);
}

.landing-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(79, 70, 229, 0.38);
}

/* Feature cards */
.landing-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 56px;
}

.landing-feature-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.landing-feature-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 36px rgba(79, 70, 229, 0.1);
}

.landing-feature-icon {
  font-size: 1.9rem;
  margin-bottom: 14px;
}

.landing-feature-card h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-weight: 700;
}

.landing-feature-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.65;
}

/* Science callout */
.landing-science {
  margin-bottom: 56px;
  padding: 32px 36px;
}

.landing-science-heading {
  margin: 10px 0 16px;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.landing-science-list {
  margin: 0 0 16px;
  padding-left: 1.2rem;
  color: var(--ink);
  line-height: 1.7;
}

.landing-science-list li + li {
  margin-top: 8px;
}

/* How it works */
.landing-section-title {
  margin: 0 0 28px;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-align: center;
}

.landing-how {
  margin-bottom: 56px;
}

.landing-steps {
  display: grid;
  gap: 16px;
  max-width: 740px;
  margin: 0 auto;
}

.landing-step {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 24px;
}

.landing-step-num {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.landing-step h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 700;
}

.landing-step p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.65;
}

/* Topics */
.landing-topics {
  margin-bottom: 56px;
  text-align: center;
}

.landing-topics-sub {
  color: var(--muted);
  margin: -14px auto 24px;
  max-width: 520px;
  font-size: 0.95rem;
  line-height: 1.6;
}

.landing-topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.landing-chip {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 0.88rem;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.12s ease;
}

.landing-chip:hover {
  border-color: var(--primary);
  background: var(--soft);
  transform: translateY(-1px);
}

/* BYOK */
.landing-byok {
  margin-bottom: 48px;
}

.landing-byok-inner {
  text-align: center;
  padding: 38px 36px;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.05), rgba(124, 58, 237, 0.05));
  border-color: rgba(79, 70, 229, 0.16);
}

.landing-byok-inner h2 {
  margin: 0 0 12px;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.landing-byok-inner p {
  margin: 0 auto;
  max-width: 560px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.7;
}

.landing-provider-logos {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.landing-provider-logo {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
}

/* Auth intro */
.landing-auth-intro {
  text-align: center;
  padding: 12px 0 8px;
}

/* ── Auth page ───────────────────────────────────────────── */
.auth-page {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 16px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-title {
  margin-bottom: 4px;
}

.auth-tabs {
  margin: 20px 0 16px;
}

.auth-form {
  margin-top: 4px;
}

.auth-form.hidden {
  display: none;
}

/* user badge in topbar */
.auth-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-user-badge {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Ad Container in Loading Screen ──────────────────────────── */
.loading-ad-container {
  margin-top: 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.loading-ad-label {
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.loading-adsense-slot {
  width: 100%;
  min-height: 50px;
}

.loading-ad-container.hidden {
  display: none;
  opacity: 0;
}

.loading-ad-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 380px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--soft-2);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.3s ease;
  user-select: none;
}

.loading-ad-banner:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.15);
}

.loading-ad-emoji {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.loading-ad-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.loading-ad-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}

.loading-ad-description {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.3;
}

/* Animation for ad rotation */
@keyframes ad-entrance {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.loading-ad-banner {
  animation: ad-entrance 0.35s ease-out;
}

/* Settings page navigation */
.settings-nav-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Footer ──────────────────────────────────────────── */
.footer {
  margin-top: 48px;
  padding: 32px 18px 24px;
  border-top: 1px solid var(--line);
  background: var(--soft-2);
  text-align: center;
}

.footer-content {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.footer-content p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
  transition: opacity 0.2s ease;
}

.footer-links a:hover {
  opacity: 0.7;
  text-decoration: underline;
}

.footer-separator {
  color: var(--muted);
  font-size: 0.9rem;
}


/* Achievement celebration styles */
.achievement-celebration {
  background: linear-gradient(135deg, var(--soft) 0%, rgba(99, 102, 241, 0.08) 100%);
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  animation: slideInFromTop 0.5s ease;
}

@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.achievement-header {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 12px;
  text-align: center;
}

.achievement-item {
  background: var(--card);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  margin-bottom: 10px;
  border-radius: 6px;
  animation: fadeIn 0.6s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.achievement-item:last-child {
  margin-bottom: 0;
}

.achievement-label {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.achievement-description {
  font-size: 0.9rem;
  color: var(--muted);
}
