:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --ink: #17202a;
  --muted: #687384;
  --line: #dce3eb;
  --accent: #176b87;
  --accent-2: #2f8f6f;
  --accent-soft: #dff1f4;
  --warn: #b35c2e;
  --bad: #a94442;
  --good: #337a4a;
  --shadow: 0 12px 32px rgba(25, 40, 56, 0.12);
  --radius: 8px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15191d;
  --surface: #20262b;
  --surface-2: #262d33;
  --ink: #edf2f4;
  --muted: #a7b0ba;
  --line: #3a444d;
  --accent: #72c2d3;
  --accent-2: #7bd5a9;
  --accent-soft: #203a42;
  --warn: #e5a064;
  --bad: #e17e78;
  --good: #8bd29e;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.eyebrow,
.section-label,
.section-heading p,
.flash-face span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions,
.button-row,
.tabs,
.segmented,
.rating-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(420px, 1fr) 360px;
}

.source-panel,
.practice-panel,
.map-panel {
  min-width: 0;
  overflow: auto;
}

.source-panel,
.practice-panel {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
}

.practice-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.panel-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-section.compact {
  padding: 14px 18px;
}

.section-heading h1 {
  margin: 4px 0 16px;
  font-size: 1.45rem;
  line-height: 1.18;
  letter-spacing: 0;
}

.drop-zone {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--ink);
}

.drop-zone input {
  display: none;
}

.drop-title {
  font-weight: 800;
}

.drop-subtitle {
  color: var(--muted);
  font-size: 0.86rem;
}

textarea {
  width: 100%;
  min-height: 220px;
  margin: 12px 0;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  color: var(--ink);
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.segment,
.tab,
.rating-row button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
  padding: 0 13px;
  font-weight: 750;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover,
.segment:hover,
.tab:hover,
.rating-row button:hover {
  border-color: var(--accent);
}

.full {
  width: 100%;
}

.spaced {
  justify-content: space-between;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-grid div {
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-grid span {
  display: block;
  font-size: 1.4rem;
  font-weight: 850;
  color: var(--accent);
}

.metric-grid p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.plan-list {
  margin: 10px 0 0;
  padding-left: 22px;
}

.plan-list li {
  margin: 0 0 10px;
}

.map-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.map-header h2 {
  margin: 2px 0 0;
  font-size: 1.35rem;
}

.segmented,
.tabs {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
}

.segment,
.tab {
  border-color: transparent;
  background: transparent;
}

.segment.active,
.tab.active {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 4px 16px rgba(20, 33, 45, 0.08);
}

.view,
.practice-view {
  display: none;
}

.view.active,
.practice-view.active {
  display: block;
}

#mapView {
  min-height: 0;
  overflow: auto;
  padding: 22px;
}

.mind-map {
  min-height: 420px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.root-node,
.branch-row {
  display: grid;
  gap: 12px;
}

.root-node {
  justify-items: center;
}

.node {
  width: min(100%, 720px);
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 13px 14px;
  text-align: left;
  box-shadow: 0 8px 20px rgba(20, 33, 45, 0.06);
}

.node strong {
  display: block;
  margin-bottom: 3px;
}

.node em {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.76rem;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.branch-row {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.node.child {
  width: 100%;
  min-height: 188px;
  border-left-color: var(--accent-2);
}

.node.active {
  outline: 3px solid var(--accent-soft);
  background: var(--surface);
}

.detail-panel,
.notes-card,
.flashcard,
.quiz-box,
.weakness-item,
.chat-message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.detail-panel {
  margin-top: 18px;
  padding: 18px;
}

.detail-panel h3 {
  margin: 4px 0 8px;
}

.detail-panel ul {
  margin-bottom: 0;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  padding: 22px;
}

.notes-card {
  padding: 16px;
}

.notes-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.tabs {
  margin: 18px;
  justify-content: stretch;
}

.tab {
  flex: 1;
}

.practice-view {
  padding: 0 18px 18px;
}

.flashcard {
  min-height: 250px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.flash-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 22px;
}

.flash-face h3 {
  margin: 8px 0 0;
}

.flash-face.back {
  transform: rotateY(180deg);
}

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

.quiz-box {
  padding: 18px;
  margin-bottom: 12px;
}

.quiz-option {
  display: block;
  width: 100%;
  margin: 8px 0;
  text-align: left;
}

.quiz-option.correct {
  border-color: var(--good);
  color: var(--good);
}

.quiz-option.wrong {
  border-color: var(--bad);
  color: var(--bad);
}

.weakness-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.weakness-item {
  padding: 14px;
}

.weakness-item b {
  display: block;
}

.weakness-item span {
  color: var(--muted);
  font-size: 0.88rem;
}

.chat-log {
  height: calc(100vh - 190px);
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  padding: 14px;
  max-width: 760px;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--accent-soft);
}

.tutor-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px 22px 22px;
  border-top: 1px solid var(--line);
}

.tutor-form input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 300px 1fr;
  }

  .practice-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .topbar,
  .map-header {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    display: block;
  }

  .source-panel,
  .practice-panel,
  .map-panel {
    max-height: none;
    overflow: visible;
  }

  .section-heading h1 {
    font-size: 1.25rem;
  }
}
