:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --paper: rgba(255, 255, 255, 0.78);
  --paper-strong: #ffffff;
  --ink: #151515;
  --muted: #63615d;
  --line: rgba(20, 20, 20, 0.12);
  --soft: rgba(20, 20, 20, 0.055);
  --accent: #0f7a5f;
  --accent-2: #d44f2f;
  --accent-3: #2864b7;
  --good: #0f8f5f;
  --bad: #c43d3d;
  --shadow: 0 24px 70px rgba(20, 18, 14, 0.12);
  --radius: 8px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111111;
  --paper: rgba(27, 27, 27, 0.78);
  --paper-strong: #181818;
  --ink: #f4f1ea;
  --muted: #aaa39a;
  --line: rgba(244, 241, 234, 0.14);
  --soft: rgba(244, 241, 234, 0.08);
  --accent: #55c7a7;
  --accent-2: #ff7a59;
  --accent-3: #80aef2;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(15, 122, 95, 0.13), transparent 34rem),
    radial-gradient(circle at 90% 24rem, rgba(212, 79, 47, 0.11), transparent 30rem),
    var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.ambient {
  position: fixed;
  inset: auto;
  pointer-events: none;
  opacity: 0.18;
  z-index: -1;
}

.ambient-a {
  width: 42vw;
  height: 42vw;
  left: -22vw;
  top: 8rem;
  background: conic-gradient(from 20deg, transparent, rgba(15, 122, 95, 0.34), transparent);
  filter: blur(48px);
}

.ambient-b {
  width: 36vw;
  height: 36vw;
  right: -18vw;
  bottom: 8rem;
  background: conic-gradient(from 120deg, transparent, rgba(40, 100, 183, 0.28), transparent);
  filter: blur(52px);
}

.topbar {
  position: sticky;
  top: 18px;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  width: min(1120px, calc(100vw - 32px));
  margin: 18px auto 0;
}

.brand,
.pill-nav,
.theme-toggle,
.floating-notes,
.notes-popover,
.solver,
.example-list-panel,
.graph-card,
.graph-controls,
.quiz-panel,
.feedback-card,
.definition-stage {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 42px;
  padding: 0 0.95rem;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 26px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.8rem;
}

.pill-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 44px;
  padding: 0.25rem;
  border-radius: 999px;
  background: var(--paper);
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  min-height: 34px;
  padding: 0 0.95rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 180ms ease, background 180ms ease, transform 180ms ease;
}

.nav-link:hover,
.nav-link.active {
  background: var(--ink);
  color: var(--bg);
}

.nav-link:active,
.primary-button:active,
.icon-button:active,
.finish-button:active {
  transform: scale(0.96);
}

.theme-toggle {
  justify-self: end;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  width: 72px;
  height: 42px;
  padding: 0.22rem;
  border-radius: 999px;
  background: var(--paper);
  border-color: var(--line);
  cursor: pointer;
}

.theme-toggle span {
  display: grid;
  place-items: center;
  height: 32px;
  border-radius: 999px;
  font-size: 0.85rem;
}

[data-theme="dark"] .moon,
:root:not([data-theme="dark"]) .sun {
  background: var(--ink);
  color: var(--bg);
}

main {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 42px 0 96px;
}

.section {
  scroll-margin-top: 96px;
  margin-top: 40px;
}

.hero-section {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 1.25rem;
  align-items: center;
  min-height: calc(100vh - 128px);
}

.hero-copy,
.definition-stage,
.power-card,
.solver-left,
.solver-right,
.graph-card,
.graph-controls,
.quiz-panel,
.feedback-card {
  min-width: 0;
}

.hero-copy h1 {
  max-width: 820px;
  margin: 0;
  font-size: 6rem;
  line-height: 0.92;
  letter-spacing: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.hero-copy p:last-child,
.section-title p,
.feedback-section p {
  max-width: 620px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
}

.eyebrow,
.mini-label {
  margin: 0 0 0.8rem;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.definition-stage {
  min-height: 430px;
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--paper);
  overflow: hidden;
}

.power-card {
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-strong);
  transition: transform 500ms ease, opacity 500ms ease;
  animation: breathe 3.8s ease-in-out infinite;
}

.focus-card {
  animation-delay: 1.2s;
}

.equation-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  min-height: 86px;
  font-size: 4rem;
  font-weight: 500;
}

.base-chip,
.result-chip,
.unknown-chip {
  display: inline-grid;
  place-items: center;
  min-width: 74px;
  height: 74px;
  border-radius: 8px;
  color: #fff;
}

.base-chip {
  background: var(--accent-3);
}

.result-chip {
  background: var(--accent-2);
}

.unknown-chip {
  background: var(--accent);
}

.swap-arrow {
  margin: 0.9rem 0;
  color: var(--muted);
  text-align: center;
  font-size: 1.7rem;
  animation: floatDown 1.6s ease-in-out infinite;
}

.definition-stage p {
  color: var(--muted);
  line-height: 1.55;
}

.learning-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 1rem;
}

.example-list-panel,
.solver {
  border-radius: var(--radius);
  background: var(--paper);
}

.example-list-panel {
  position: sticky;
  top: 84px;
  align-self: start;
  max-height: calc(100vh - 104px);
  padding: 1rem;
  overflow: auto;
}

.panel-heading h2,
.section-title h2,
.feedback-section h2 {
  margin: 0;
  font-size: 3.4rem;
  line-height: 1;
  font-weight: 600;
}

.example-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

.example-item {
  display: grid;
  gap: 0.35rem;
  width: 100%;
  min-height: 76px;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-strong);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border 180ms ease, transform 180ms ease, background 180ms ease;
}

.example-item:hover,
.example-item.active {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  transform: translateY(-1px);
}

.example-item small {
  color: var(--muted);
  font-weight: 500;
}

.example-item strong {
  font-size: 1.02rem;
  font-weight: 600;
}

.solver {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.82fr);
  min-height: 620px;
  overflow: hidden;
}

.solver-left,
.solver-right {
  padding: clamp(1rem, 3vw, 2rem);
}

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

.solver-left h2 {
  min-height: 72px;
  margin: 0 0 1rem;
  font-size: 2.85rem;
  line-height: 1.04;
  font-weight: 600;
}

.equation-board {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  gap: 0.45rem;
  min-height: 240px;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-strong);
}

.token {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 0 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  font-size: 2rem;
  font-weight: 500;
  transition: opacity 220ms ease, transform 220ms ease, background 220ms ease, border 220ms ease;
}

.equation-board.has-focus .token {
  opacity: 0.22;
}

.equation-board.has-focus .token.focus {
  opacity: 1;
  transform: translateY(-4px);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--paper-strong));
}

.condition-box,
.formula-box {
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
  color: var(--muted);
  line-height: 1.5;
}

.solver-right {
  display: flex;
  flex-direction: column;
}

.step-count {
  color: var(--accent);
  font-weight: 600;
}

.solver-right h3 {
  margin: 1rem 0 0;
  font-size: 2.35rem;
  line-height: 1.05;
  font-weight: 600;
}

.solver-right p {
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.58;
}

.step-controls {
  display: grid;
  grid-template-columns: 54px 1fr 54px;
  gap: 0.65rem;
  margin-top: auto;
  padding-top: 1.2rem;
}

.icon-button,
.primary-button,
.ghost-button,
.finish-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-strong);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

.icon-button {
  display: grid;
  place-items: center;
  font-size: 1.35rem;
}

.icon-button.small {
  width: 38px;
  min-height: 38px;
}

.finish-button,
.primary-button {
  background: var(--ink);
  color: var(--bg);
}

.finish-button.pulse {
  animation: finishPulse 560ms ease;
}

.ghost-button {
  background: transparent;
}

.section-title {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.graph-layout,
.test-grid,
.feedback-section {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(310px, 0.7fr);
  gap: 1rem;
  align-items: stretch;
}

.graph-card,
.graph-controls,
.quiz-panel,
.feedback-card {
  border-radius: var(--radius);
  background: var(--paper);
}

.graph-card {
  min-height: 520px;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
}

.graph-controls,
.quiz-panel,
.feedback-card {
  padding: 1rem;
}

.formula-live {
  min-height: 76px;
  padding: 0.9rem;
  border-radius: var(--radius);
  background: var(--paper-strong);
  font-size: 2rem;
  font-weight: 600;
}

.graph-controls label {
  display: grid;
  gap: 0.5rem;
  margin-top: 1rem;
  color: var(--muted);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.preset-row {
  display: grid;
  gap: 0.5rem;
  margin-top: 1rem;
}

.preset-row button,
.choice-list button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.quiz-panel h3 {
  margin: 0 0 1rem;
  font-size: 1.55rem;
}

.quiz-row {
  display: grid;
  gap: 0.5rem;
  padding: 0.8rem 0;
  border-top: 1px solid var(--line);
}

.quiz-row:first-child {
  border-top: 0;
}

.quiz-row label {
  font-weight: 600;
}

.quiz-row input {
  width: 100%;
  min-height: 42px;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--ink);
}

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

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

.choice-list {
  display: grid;
  gap: 0.5rem;
  margin: 1rem 0;
}

.choice-list button.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 13%, var(--paper-strong));
}

.score {
  min-height: 24px;
  color: var(--muted);
  font-weight: 600;
}

.feedback-section {
  align-items: center;
}

.feedback-card textarea,
.notes-popover textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-strong);
  color: var(--ink);
  line-height: 1.5;
}

.feedback-card textarea {
  min-height: 210px;
  padding: 1rem;
}

.feedback-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.feedback-actions button {
  flex: 1;
}

.floating-notes {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 25;
  min-width: 86px;
  min-height: 46px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  border-color: var(--line);
  font-weight: 600;
  cursor: pointer;
}

.notes-popover {
  position: fixed;
  right: 18px;
  bottom: 78px;
  z-index: 30;
  width: min(390px, calc(100vw - 36px));
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--paper);
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

.notes-popover.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.notes-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.notes-head h3 {
  margin: 0;
}

.notes-popover textarea {
  min-height: 260px;
  padding: 0.8rem;
}

.notes-popover p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 50;
  min-width: 190px;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  text-align: center;
  font-weight: 600;
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes breathe {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes floatDown {
  0%,
  100% {
    transform: translateY(-3px);
  }
  50% {
    transform: translateY(4px);
  }
}

@keyframes finishPulse {
  0% {
    transform: scale(1);
  }
  55% {
    transform: scale(1.045);
    background: var(--accent);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .brand {
    display: none;
  }

  .pill-nav {
    justify-self: start;
    max-width: calc(100vw - 118px);
    overflow-x: auto;
  }

  .nav-link {
    min-width: max-content;
  }

  .hero-section,
  .learning-grid,
  .solver,
  .graph-layout,
  .test-grid,
  .feedback-section {
    grid-template-columns: 1fr;
  }

  .hero-section {
    min-height: auto;
  }

  .hero-copy h1 {
    font-size: 4rem;
    line-height: 0.96;
  }

  .equation-line {
    font-size: 3rem;
  }

  .panel-heading h2,
  .section-title h2,
  .feedback-section h2 {
    font-size: 2.6rem;
  }

  .solver-left h2 {
    font-size: 2.35rem;
  }

  .solver-right h3 {
    font-size: 2rem;
  }

  .example-list-panel {
    position: static;
    max-height: none;
  }

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

  .graph-card {
    min-height: 360px;
  }
}

@media (max-width: 560px) {
  .topbar,
  main {
    width: min(1120px, calc(100vw - 20px));
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .pill-nav {
    max-width: 100%;
    justify-self: stretch;
  }

  .nav-link {
    flex: 1 0 auto;
    min-width: 64px;
    padding: 0 0.55rem;
  }

  .theme-toggle {
    position: fixed;
    top: 72px;
    right: 10px;
    width: 62px;
  }

  .hero-copy h1 {
    max-width: 340px;
    font-size: 2.15rem;
    line-height: 1.05;
  }

  .hero-copy p:last-child {
    max-width: 100%;
    font-size: 1rem;
  }

  .equation-line {
    font-size: 2.15rem;
  }

  .base-chip,
  .result-chip,
  .unknown-chip {
    min-width: 60px;
    height: 60px;
  }

  .token {
    font-size: 1.28rem;
    min-height: 40px;
  }

  .formula-live {
    font-size: 1.45rem;
  }
}
