:root {
  color-scheme: light;
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-soft: #eef6ff;
  --text: #172033;
  --muted: #667085;
  --line: #d8dfec;
  --blue: #2563eb;
  --green: #15803d;
  --amber: #b45309;
  --rose: #be123c;
  --teal: #0f766e;
  --shadow: 0 12px 30px rgba(23, 32, 51, 0.12);
  --radius: 8px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1220;
  --surface: #151b2b;
  --surface-soft: #172842;
  --text: #f2f6ff;
  --muted: #aeb8cc;
  --line: #2b354a;
  --blue: #60a5fa;
  --green: #4ade80;
  --amber: #fbbf24;
  --rose: #fb7185;
  --teal: #5eead4;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.11), rgba(247, 247, 251, 0) 280px),
    var(--bg);
}

[data-theme="dark"] body {
  background:
    linear-gradient(180deg, rgba(96, 165, 250, 0.18), rgba(13, 18, 32, 0) 300px),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 72px;
  margin: -14px -14px 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid rgba(216, 223, 236, 0.9);
  backdrop-filter: blur(14px);
}

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

.brand-avatar,
.brand-mark,
.topic-icon,
.topic-icon-large {
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
  box-shadow: inset 0 -10px 24px rgba(0, 0, 0, 0.12);
}

.brand-avatar,
.brand-mark {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

.brand-avatar {
  display: block;
  object-fit: cover;
  border: 2px solid #fff;
  background: var(--blue);
}

.brand h1,
.topic-hero h2,
.section-heading h2 {
  margin: 0;
  line-height: 1.05;
}

.brand h1 {
  overflow: hidden;
  font-size: 1.16rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow,
.status-label {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: end;
}

.points-pill,
.icon-button,
.theme-toggle {
  border: 1px solid var(--line);
  background: var(--surface);
}

.points-pill {
  display: flex;
  gap: 4px;
  align-items: baseline;
  justify-content: center;
  min-width: 72px;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--blue);
  font-weight: 800;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  color: var(--text);
  font-size: 1.12rem;
  font-weight: 900;
}

.hidden {
  visibility: hidden;
}

.main-content {
  display: grid;
  gap: 18px;
  outline: none;
}

.status-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: stretch;
}

.status-strip > div {
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.status-strip strong {
  display: block;
  font-size: 1.05rem;
}

.teacher-note {
  padding: 16px;
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--surface), var(--surface-soft));
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.06);
}

.teacher-note h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.teacher-note p:last-child {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
}

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

.study-path article {
  display: grid;
  gap: 4px;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.study-path strong {
  color: var(--teal);
  font-size: 0.95rem;
}

.study-path span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.25;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  margin: 0 0 12px;
}

.section-heading p {
  max-width: 190px;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: right;
}

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

.topic-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 7px solid var(--topic-color);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.07);
  text-align: left;
}

.topic-card:active,
.primary-button:active,
.secondary-button:active,
.answer-button:active,
.tab-button:active {
  transform: translateY(1px);
}

.topic-icon {
  position: relative;
  overflow: hidden;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--topic-color);
  font-size: 1.28rem;
}

.topic-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topic-icon em {
  position: absolute;
  right: 3px;
  bottom: 3px;
  min-width: 24px;
  padding: 2px 4px;
  border: 2px solid #fff;
  border-radius: 6px;
  color: #fff;
  background: var(--topic-color);
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 900;
  text-align: center;
}

.topic-card h3 {
  margin: 0 0 8px;
  font-size: 1.14rem;
}

.topic-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.progress-track {
  overflow: hidden;
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: #e8edf5;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--topic-color);
  transition: width 220ms ease;
}

.topic-hero {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

.topic-icon-large {
  position: relative;
  overflow: hidden;
  width: 76px;
  height: 76px;
  border-radius: 8px;
  background: var(--topic-color);
  font-size: 1.7rem;
}

.topic-icon-large img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topic-icon-large em {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 30px;
  padding: 3px 5px;
  border: 2px solid #fff;
  border-radius: 7px;
  color: #fff;
  background: var(--topic-color);
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 900;
  text-align: center;
}

.topic-hero p {
  margin: 6px 0 0;
  color: var(--muted);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-soft) 72%, var(--line));
}

.tab-button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.tab-button.active {
  color: var(--blue);
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(23, 32, 51, 0.1);
}

.mode-panel {
  display: grid;
  gap: 12px;
}

.info-card,
.table-card,
.download-card,
.quiz-card,
.flashcard-shell {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.06);
}

.info-card,
.download-card {
  padding: 16px;
}

.info-card h3,
.table-card h3,
.download-card h3,
.quiz-card h3 {
  margin: 0 0 8px;
}

.info-card p,
.download-card p,
.quiz-card p {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
}

.calm-card {
  border-color: rgba(15, 118, 110, 0.28);
  background: color-mix(in srgb, var(--teal) 14%, var(--surface));
}

.calm-card h3 {
  color: var(--teal);
}

.table-card {
  overflow: hidden;
}

.table-card h3 {
  padding: 16px 16px 0;
}

.summary-list {
  display: grid;
}

.summary-row {
  display: grid;
  gap: 4px;
  padding: 13px 16px;
  border-top: 1px solid var(--line);
}

.summary-row strong {
  color: var(--blue);
}

.download-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.primary-button,
.secondary-button,
.answer-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 850;
  text-decoration: none;
}

.primary-button {
  border: 1px solid var(--blue);
  color: #fff;
  background: var(--blue);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
}

.flashcard-shell {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.card-count {
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.study-card {
  position: relative;
  min-height: 260px;
  perspective: 900px;
}

.study-card-inner {
  position: absolute;
  inset: 0;
  transition: transform 260ms ease;
  transform-style: preserve-3d;
}

.study-card.flipped .study-card-inner {
  transform: rotateY(180deg);
}

.study-side {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  border: 2px solid var(--topic-color);
  border-radius: var(--radius);
  background: var(--surface-soft);
  backface-visibility: hidden;
  text-align: center;
}

.study-side.back {
  background: color-mix(in srgb, var(--amber) 18%, var(--surface));
  transform: rotateY(180deg);
}

.study-side p {
  margin: 0;
  font-size: clamp(1.18rem, 6vw, 1.55rem);
  font-weight: 850;
  line-height: 1.25;
}

.study-hint {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.quiz-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.quiz-progress {
  color: var(--muted);
  font-weight: 800;
}

.answers {
  display: grid;
  gap: 8px;
}

.answer-button {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
  text-align: center;
}

.answer-button.correct {
  border-color: rgba(21, 128, 61, 0.4);
  color: var(--green);
  background: #ecfdf3;
}

.answer-button.missed {
  border-color: rgba(190, 18, 60, 0.32);
  color: var(--rose);
  background: #fff1f3;
}

.feedback {
  padding: 12px;
  border-radius: var(--radius);
  color: var(--text);
  background: color-mix(in srgb, var(--green) 16%, var(--surface));
  line-height: 1.45;
}

.feedback.neutral {
  color: var(--text);
  background: var(--surface-soft);
}

.text-answer {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--text);
  background: var(--surface);
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, 0.36);
}

.celebration-card {
  position: relative;
  width: min(100%, 380px);
  overflow: hidden;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.burst {
  height: 54px;
  margin-bottom: 8px;
  background:
    radial-gradient(circle at 20% 30%, #f59e0b 0 4px, transparent 5px),
    radial-gradient(circle at 42% 65%, #2563eb 0 5px, transparent 6px),
    radial-gradient(circle at 66% 25%, #16a34a 0 4px, transparent 5px),
    radial-gradient(circle at 82% 62%, #e11d48 0 5px, transparent 6px);
  animation: pop 680ms ease both;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
  text-align: center;
}

@media (min-width: 700px) {
  .app-shell {
    padding-inline: 22px;
  }

  .topbar {
    margin-inline: -22px;
    padding-inline: 22px;
  }

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

  .mode-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .flashcard-shell,
  .quiz-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 420px) {
  .study-path {
    grid-template-columns: 1fr;
  }
}
