:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #68747d;
  --line: #dbe4e8;
  --paper: #f7faf9;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #047857;
  --shadow: 0 18px 45px rgba(23, 32, 38, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #e7f1ef 0%, var(--paper) 36%);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 16px 32px;
}

.topbar,
.section-head,
.button-row,
.grade-row,
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.9rem;
  line-height: 1.08;
}

h2 {
  font-size: 1.25rem;
  line-height: 1.25;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--accent);
  font-size: 1.4rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 22px 0 16px;
}

.stats-grid article {
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.stats-grid strong {
  display: block;
  font-size: 1.45rem;
  line-height: 1.1;
}

.stats-grid span,
.card-meta,
.import-panel p,
.field-label {
  color: var(--muted);
  font-size: 0.88rem;
}

.tabs,
.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.tabs {
  grid-template-columns: repeat(4, 1fr);
}

.mode-switch {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 10px;
}

.tab,
.pill {
  min-height: 38px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab.active,
.pill.active {
  background: var(--ink);
  color: #fff;
}

.view {
  display: none;
  margin-top: 16px;
}

.view.active {
  display: block;
}

.review-card,
.import-panel,
.notes-panel {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.review-card h2 {
  min-height: 128px;
  margin: 18px 0;
  font-size: clamp(1.35rem, 5vw, 2.05rem);
}

.answer-panel {
  margin: 0 0 16px;
  padding: 14px;
  border-left: 4px solid var(--accent);
  background: #eef8f5;
  line-height: 1.55;
}

.answer-panel p {
  margin-bottom: 0;
}

.thinking-snippet {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(15, 118, 110, 0.25);
}

.thinking-snippet strong {
  display: block;
  margin-bottom: 4px;
}

.primary-action,
.grade,
.section-head button,
.button-row button {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-action {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
}

.primary-action.compact {
  width: auto;
  padding: 0 18px;
}

.grade-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.grade {
  padding: 0 8px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.grade.again {
  color: var(--danger);
}

.grade.hard {
  color: var(--warn);
}

.grade.good,
.grade.easy {
  color: var(--ok);
}

.section-head {
  margin: 4px 0 12px;
}

.section-head h2 {
  margin: 0;
}

.field-label {
  display: block;
  margin: 0 0 6px;
  font-weight: 800;
}

.topic-select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.compact-select {
  width: min(52%, 240px);
}

.section-head button,
.button-row button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}

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

.topic-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.topic-item strong,
.topic-item span {
  display: block;
}

.topic-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.topic-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.topic-actions button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
  font-weight: 800;
}

.notes-panel {
  display: block;
  overflow: hidden;
  padding: 0;
  background: #fffdf8;
}

.notes-cover {
  padding: 22px 20px 18px;
  border-bottom: 1px solid #d9ded8;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbfa 100%);
}

.notes-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.notes-cover h2 {
  max-width: 24ch;
  margin: 0;
  color: #111827;
  font-size: clamp(1.45rem, 5vw, 2rem);
  line-height: 1.08;
}

.notes-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
}

.notes-meta span {
  padding: 5px 8px;
  border: 1px solid #cfd9dc;
  border-radius: 999px;
  background: #ffffff;
  color: #3d4a52;
  font-size: 0.78rem;
  font-weight: 800;
}

.notes-section {
  padding: 20px;
  border-bottom: 1px solid #dfe6e2;
}

.notes-section:last-child {
  border-bottom: 0;
}

.notes-section h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  color: #102027;
  font-size: 1.08rem;
  line-height: 1.25;
}

.notes-section h3::before {
  content: "";
  width: 5px;
  height: 24px;
  border-radius: 999px;
  background: var(--accent);
  flex: 0 0 auto;
}

.note-subheading {
  margin: 18px 0 8px;
  color: #23313a;
  font-size: 0.96rem;
  line-height: 1.3;
}

.notes-section p,
.notes-section li {
  color: #344149;
  line-height: 1.62;
}

.notes-section p {
  margin: 0 0 12px;
}

.notes-section p:last-child {
  margin-bottom: 0;
}

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

.note-keyline {
  display: grid;
  gap: 3px;
  margin: 0 0 10px;
  padding: 9px 11px;
  border-left: 3px solid #7aa7a1;
  background: #f5faf8;
}

.note-keyline strong {
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.note-keyline span {
  color: #344149;
}

.note-list,
.note-ordered,
.numbered-thinking {
  margin: 0 0 14px;
  padding-left: 0;
  list-style: none;
}

.note-list li,
.note-ordered li,
.numbered-thinking li {
  position: relative;
  margin: 0 0 8px;
  padding-left: 20px;
}

.note-list li::before {
  content: "";
  position: absolute;
  top: 0.75em;
  left: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.note-ordered,
.numbered-thinking {
  counter-reset: thinking;
}

.note-ordered li,
.numbered-thinking li {
  padding-left: 34px;
}

.note-ordered li::before,
.numbered-thinking li::before {
  counter-increment: thinking;
  content: counter(thinking);
  position: absolute;
  top: 0.1em;
  left: 0;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: #172026;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 900;
}

.note-ordered li::before {
  background: var(--accent);
}

.note-callout,
.consultant-section {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid #d8c68f;
  border-left: 5px solid #b88912;
  border-radius: 8px;
  background: #fffaf0;
}

.note-callout h4 {
  margin: 0 0 6px;
  color: #6b4d08;
  font-size: 0.86rem;
  text-transform: uppercase;
}

.note-callout p,
.consultant-section p,
.consultant-section li {
  color: #3f321a;
}

.case-list {
  display: grid;
  gap: 12px;
}

.case-item {
  padding: 14px;
  border: 1px solid #dce5e2;
  border-radius: 8px;
  background: #ffffff;
}

.case-prompt {
  display: block;
  margin-bottom: 9px;
  font-size: 0.98rem;
  line-height: 1.45;
}

.case-label {
  display: inline-flex;
  margin-bottom: 6px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #e7f3f1;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.import-panel textarea {
  width: 100%;
  min-height: 260px;
  margin: 10px 0 12px;
  padding: 12px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
  line-height: 1.45;
}

.mcq-options {
  margin: 10px 0 0;
  padding-left: 0;
  list-style: none;
}

.mcq-options li {
  margin: 5px 0;
}

.option-button {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
}

.option-button.selected {
  border-color: var(--accent);
  background: #e7f6f3;
}

.option-button.correct {
  border-color: var(--ok);
  background: #e8f7ef;
}

.option-button.incorrect {
  border-color: var(--danger);
  background: #fff1f1;
}

@media (min-width: 680px) {
  .app-shell {
    padding-top: 40px;
  }

  h1 {
    font-size: 2.4rem;
  }
}

body.dark {
  --ink: #e9f1ef;
  --muted: #a7b5b1;
  --line: #2a413e;
  --paper: #0f1817;
  --panel: #162321;
  --accent: #53c7b8;
  --accent-ink: #071312;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
  background: linear-gradient(180deg, #102523 0%, var(--paper) 42%);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.subtle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.stats-grid {
  grid-template-columns: repeat(4, 1fr);
}

.tabs,
.mode-switch {
  display: flex;
  grid-template-columns: none;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab,
.pill {
  flex: 1 0 auto;
  padding: 0 12px;
}

.panel {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.quick-grid button,
.exam-toolbar button,
.question-actions button,
.note-actions button,
.related-group button,
.search-result button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.search-input {
  width: 100%;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.search-input.large {
  min-height: 52px;
  font-size: 1.02rem;
}

.control-grid {
  display: grid;
  gap: 10px;
}

.control-grid.two {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--muted);
  font-weight: 800;
}

.exam-toolbar {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
}

.exam-toolbar.visible {
  display: flex;
}

.timer-label,
.count-label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.recommendation-list,
.activity-list {
  display: grid;
  gap: 10px;
}

.recommendation-item,
.activity-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.recommendation-item strong,
.recommendation-item span,
.activity-item strong,
.activity-item span {
  display: block;
}

.recommendation-item span,
.activity-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.notes-panel {
  background: #fffdf8;
}

.note-heading-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.note-actions button {
  min-height: 34px;
  font-size: 0.82rem;
}

.inline-meta {
  margin: 0 0 12px;
}

.status-chip {
  text-transform: capitalize;
}

.status-chip.draft,
.status-chip.needs-review {
  border-color: #efd394;
  background: #fff8e5;
  color: #7a5207;
}

.status-chip.reviewed {
  border-color: #b9e2d1;
  background: #ecfdf5;
  color: #047857;
}

.draft-warning {
  padding: 10px 12px;
  border: 1px solid #edd28d;
  border-radius: 8px;
  background: #fff9e8;
  color: #7a5207 !important;
  font-size: 0.9rem;
}

.link-row {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.related-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.related-label,
.result-type {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.empty-state {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.empty-state strong {
  display: block;
  margin-bottom: 4px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.answer-panel strong {
  display: block;
  margin-bottom: 8px;
}

.answer-panel p {
  margin-bottom: 10px;
}

.distractor-list {
  margin: 8px 0 0;
  padding-left: 20px;
}

.option-button:disabled {
  opacity: 1;
}

.search-results,
.search-group {
  display: grid;
  gap: 12px;
}

.search-group {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.search-group h3 {
  margin: 0;
  font-size: 1rem;
}

.search-result {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.search-result:first-of-type {
  border-top: 0;
}

.search-result button {
  justify-self: start;
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-align: left;
}

.search-result p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

body.dark .tabs,
body.dark .mode-switch,
body.dark .stats-grid article,
body.dark .empty-state {
  background: rgba(22, 35, 33, 0.78);
}

body.dark .notes-panel {
  background: #14201e;
}

body.dark .notes-cover {
  border-bottom-color: var(--line);
  background: linear-gradient(180deg, #1a2a27 0%, #14201e 100%);
}

body.dark .notes-cover h2,
body.dark .notes-section strong {
  color: var(--ink);
}

body.dark .notes-section,
body.dark .search-result {
  border-color: var(--line);
}

body.dark .notes-section p,
body.dark .notes-section li {
  color: #c7d4d0;
}

body.dark .notes-meta span,
body.dark .quick-grid button,
body.dark .exam-toolbar button,
body.dark .question-actions button,
body.dark .note-actions button,
body.dark .related-group button,
body.dark .topic-actions button,
body.dark .section-head button,
body.dark .button-row button,
body.dark .option-button {
  background: #172927;
  color: var(--ink);
}

body.dark .answer-panel,
body.dark .note-keyline {
  background: #102a27;
}

body.dark .option-button.selected {
  background: #123b37;
}

body.dark .option-button.correct {
  background: #103222;
}

body.dark .option-button.incorrect {
  background: #341a1a;
}

body.dark .note-callout,
body.dark .consultant-section,
body.dark .draft-warning {
  border-color: #715a1f;
  border-left-color: #c49422;
  background: #2b2414;
  color: #f5d58a !important;
}

@media (min-width: 680px) {
  .control-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .quick-grid,
  .control-grid.two {
    grid-template-columns: 1fr;
  }

  .compact-select {
    width: 100%;
  }

  .section-head,
  .note-heading-row {
    align-items: stretch;
    flex-direction: column;
  }
}
