:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-alt: #eef2f7;
  --text: #1a2333;
  --text-muted: #5a6b82;
  --accent: #2d6a4f;
  --accent-strong: #1b4332;
  --accent-soft: #d8f3dc;
  --border: #dbe2ea;
  --correct: #2d6a4f;
  --correct-bg: #d8f3dc;
  --wrong: #b23a48;
  --wrong-bg: #fde2e4;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-icon {
  font-size: 30px;
  line-height: 1;
}

.brand h1 {
  font-size: 18px;
  margin: 0;
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.mastery-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.mastery-badge {
  font-size: 16px;
}

/* Main */
.app-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.view-intro {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 15px;
}

/* Topic grid */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.topic-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  box-shadow: var(--shadow);
}

.topic-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 6px 16px rgba(16, 24, 40, 0.10);
}

.topic-card-icon {
  font-size: 26px;
  margin-bottom: 10px;
}

.topic-card-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 6px;
}

.topic-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 12px;
}

.topic-mastery-badge {
  font-size: 14px;
}

.topic-progress-track {
  flex: 1;
  height: 6px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
}

.topic-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s ease;
}

/* Topic detail */
.back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 18px;
}

.back-btn:hover {
  background: var(--surface-alt);
}

.topic-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.topic-detail-header .topic-detail-icon {
  font-size: 30px;
}

.topic-detail-header h2 {
  margin: 0;
  font-size: 22px;
}

.concept-box {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 28px;
}

.concept-box h3 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--accent-strong);
}

.concept-box p {
  margin: 0;
  font-size: 15px;
}

/* SMILES diagrams (rendered by SmilesDrawer) */
.diagram-box {
  margin-top: 16px;
}

.diagram-canvas {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  min-height: 120px;
}

.diagram-canvas svg {
  max-width: 100%;
  height: auto;
}

.diagram-caption {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
}

.diagram-fallback {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  color: var(--text-muted);
}

/* Curated resources */
.resources-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.resources-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-strong);
  margin-bottom: 8px;
}

.resources-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

.resources-list a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.resources-list a:hover {
  text-decoration: underline;
}

/* Questions */
.questions-heading {
  font-size: 18px;
  margin: 0 0 16px;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.question-prompt {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
}

.question-type {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 12px;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 16px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  transition: border-color 0.1s ease, background 0.1s ease;
}

.option:hover {
  border-color: var(--accent);
}

.option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.option.correct {
  border-color: var(--correct);
  background: var(--correct-bg);
}

.option.wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
}

.option input[type="radio"] {
  margin-top: 2px;
  accent-color: var(--accent);
}

.short-answer-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 8px 0 16px;
  font-family: inherit;
}

.short-answer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
}

.check-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.check-btn:hover {
  background: var(--accent-strong);
}

.check-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.feedback {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 15px;
  display: none;
}

.feedback.visible {
  display: block;
}

.feedback.correct {
  background: var(--correct-bg);
  border: 1px solid var(--correct);
}

.feedback.wrong {
  background: var(--wrong-bg);
  border: 1px solid var(--wrong);
}

.feedback-head {
  font-weight: 700;
  margin-bottom: 6px;
}

.feedback-head.correct {
  color: var(--correct);
}

.feedback-head.wrong {
  color: var(--wrong);
}

.feedback .worked {
  color: var(--text-muted);
  margin: 0;
}

/* Mastery Pack upsell */
.upsell-section {
  margin-top: 32px;
}

.upsell-inner {
  background: linear-gradient(135deg, #1b4332 0%, #2d6a4f 60%, #40916c 100%);
  border-radius: var(--radius);
  padding: 26px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  box-shadow: 0 8px 24px rgba(27, 67, 50, 0.22);
}

.upsell-copy {
  flex: 1;
  min-width: 240px;
}

.upsell-title {
  color: #fff;
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.3;
}

.upsell-desc {
  color: rgba(255, 255, 255, 0.88);
  margin: 0;
  font-size: 15px;
}

.upsell-cta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.upsell-btn {
  display: inline-block;
  background: #fff;
  color: var(--accent-strong);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 22px;
  border-radius: 10px;
  white-space: nowrap;
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}

.upsell-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.upsell-btn-soon {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.upsell-link {
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  text-decoration: none;
}

.upsell-link:hover {
  color: #fff;
  text-decoration: underline;
}

.upsell-soon-note {
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
}

/* Footer */
.app-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer p {
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 20px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 560px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .mastery-chip {
    align-self: flex-start;
  }
  .brand h1 {
    font-size: 16px;
  }
}
