:root {
  --bg: #0e1014;
  --bg-elev: #161a21;
  --bg-soft: #1c222c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8e6e1;
  --muted: #9a958c;
  --accent: #c9a66b;
  --accent-dim: rgba(201, 166, 107, 0.15);
  --pos: #6ecf8e;
  --pos-dim: rgba(110, 207, 142, 0.15);
  --neg: #e07a6a;
  --neg-dim: rgba(224, 122, 106, 0.15);
  --radius: 14px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(201, 166, 107, 0.07), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(90, 140, 180, 0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 3vw, 2.5rem);
  background: rgba(14, 16, 20, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  width: 100%;
}

.brand {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-bodhi {
  color: var(--accent);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.nav-link {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--accent-dim);
}

.lang {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.lang-btn {
  min-width: 2.5rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.lang-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  width: 100%;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 3.5rem) 3rem;
}

.cats {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 1rem 0 0.75rem;
  margin: 0 -0.25rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-dim) transparent;
  -webkit-overflow-scrolling: touch;
}

.cat-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.cat-btn:hover {
  color: var(--text);
  border-color: rgba(201, 166, 107, 0.35);
}

.cat-btn.active {
  color: var(--text);
  background: var(--accent-dim);
  border-color: rgba(201, 166, 107, 0.45);
}

.cat-btn .done-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--pos);
  opacity: 0.85;
}

.stage {
  min-width: 0;
}

.stage-head {
  padding: 0.5rem 0 1.25rem;
  animation: fadeUp 0.35s ease both;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.stage-head h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.lede {
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.98rem;
  max-width: 40rem;
}

.progress-line {
  margin-top: 0.65rem;
  font-size: 0.9rem;
  color: var(--accent);
  font-weight: 500;
}

.exercise-panel {
  animation: fadeUp 0.3s ease both;
}

.ex-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem clamp(1rem, 3vw, 1.6rem);
  max-width: 42rem;
}

.ex-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.ex-badge {
  display: inline-flex;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.ex-prompt {
  font-size: 1.12rem;
  line-height: 1.5;
  margin-bottom: 0.85rem;
}

.ex-prompt .katex {
  font-size: 1.05em;
}

.ex-hint {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.ex-choices {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.choice-btn {
  text-align: left;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
}

.choice-btn:hover {
  border-color: rgba(201, 166, 107, 0.4);
}

.choice-btn.selected {
  border-color: rgba(201, 166, 107, 0.55);
  background: var(--accent-dim);
}

.choice-btn.correct {
  border-color: rgba(110, 207, 142, 0.55);
  background: var(--pos-dim);
}

.choice-btn.wrong {
  border-color: rgba(224, 122, 106, 0.55);
  background: var(--neg-dim);
}

.answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: stretch;
  margin-bottom: 0.85rem;
}

.answer-input {
  flex: 1 1 12rem;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-family: var(--mono);
  font-size: 1.05rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.answer-input:focus {
  border-color: rgba(201, 166, 107, 0.5);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.answer-input.ok {
  border-color: rgba(110, 207, 142, 0.55);
  background: var(--pos-dim);
}

.answer-input.bad {
  border-color: rgba(224, 122, 106, 0.55);
  background: var(--neg-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  transition: background 0.2s, color 0.2s, border-color 0.2s, opacity 0.2s;
}

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

.btn.primary {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(201, 166, 107, 0.4);
}

.btn.primary:hover:not(:disabled) {
  background: rgba(201, 166, 107, 0.25);
}

.btn.ghost {
  background: var(--bg-elev);
  border-color: var(--line);
  color: var(--muted);
}

.btn.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(201, 166, 107, 0.35);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.75rem;
}

.feedback {
  min-height: 1.4em;
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.feedback.ok {
  color: var(--pos);
}

.feedback.bad {
  color: var(--neg);
}

.solution {
  margin-top: 0.5rem;
  padding: 1rem 1.1rem;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.solution h3 {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.65rem;
}

.solution .step {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.35rem 0;
  font-size: 1rem;
}

.solution .step-n {
  flex: 0 0 auto;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
  margin-top: 0.15rem;
}

.exercise-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1rem;
  max-width: 42rem;
}

.tool-toggles {
  display: inline-flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.tool-toggle {
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.tool-toggle:hover {
  color: var(--text);
  border-color: rgba(201, 166, 107, 0.35);
}

.tool-toggle[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: rgba(201, 166, 107, 0.45);
}

.float-panel {
  position: fixed;
  z-index: 50;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  user-select: none;
}

.float-panel.is-closed,
.float-panel[hidden] {
  display: none !important;
}

.float-panel.dragging {
  opacity: 0.95;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}

.fp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  cursor: grab;
  padding: 0.15rem 0.1rem 0.35rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.15rem;
}

.fp-head:active {
  cursor: grabbing;
}

.fp-title {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  pointer-events: none;
}

.fp-tools {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.wb-btn {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.fp-close {
  min-width: 2rem;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0.25rem 0.55rem;
}

.fp-resize {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, rgba(201, 166, 107, 0.55) 50%) no-repeat,
    linear-gradient(135deg, transparent 65%, rgba(201, 166, 107, 0.35) 65%);
  border-radius: 2px;
}

.whiteboard {
  position: fixed;
  right: clamp(0.75rem, 2vw, 1.5rem);
  bottom: calc(1rem + var(--safe-b));
  width: min(360px, calc(100vw - 1.5rem));
  height: min(52vh, 480px);
  min-width: 240px;
  min-height: 260px;
  max-width: calc(100vw - 1rem);
  max-height: calc(100dvh - 5rem);
}

.wb-canvas {
  width: 100%;
  flex: 1 1 auto;
  min-height: 140px;
  height: auto;
  display: block;
  border-radius: 10px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    #12161d;
  background-size: 24px 24px, 24px 24px, auto;
  border: 1px solid var(--line);
  cursor: crosshair;
  touch-action: none;
}

.wb-hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.calculator {
  position: fixed;
  right: clamp(0.75rem, 2vw, 1.5rem);
  top: 4.75rem;
  width: min(280px, calc(100vw - 1.5rem));
  z-index: 51;
}

.calc-display {
  font-family: var(--mono);
  font-size: 1.45rem;
  text-align: right;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  min-height: 2.8rem;
  word-break: break-all;
  color: var(--text);
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.calc-key {
  padding: 0.7rem 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.calc-key:hover {
  border-color: rgba(201, 166, 107, 0.4);
  background: rgba(255, 255, 255, 0.04);
}

.calc-key.op {
  color: var(--accent);
}

.calc-key.fn {
  color: #9ec5e8;
}

.calc-key.eq {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(201, 166, 107, 0.4);
}

.calc-key.wide {
  grid-column: span 1;
}

.calc-key.zero {
  grid-column: span 1;
}

@media (max-width: 640px) {
  .tool-toggles {
    order: 3;
    width: 100%;
    justify-content: flex-end;
  }

  .topbar-right {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.5rem 1.5rem;
  padding: 1.25rem clamp(1rem, 4vw, 3.5rem) calc(1.25rem + var(--safe-b));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  width: 100%;
}

.foot a {
  color: var(--muted);
}

.foot a:hover {
  color: var(--accent);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 900px) {
  .shell {
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 1.5rem;
    padding-top: 1rem;
    align-items: start;
  }

  .cats {
    flex-direction: column;
    overflow-x: visible;
    position: sticky;
    top: 4.5rem;
    max-height: calc(100dvh - 5rem);
    overflow-y: auto;
    padding: 0;
    margin: 0;
  }

  .cat-btn {
    white-space: normal;
    border-radius: 12px;
    justify-content: flex-start;
  }
}
