:root {
  --bg: #e8eef6;
  --ink: #152033;
  --muted: #5e6e86;
  --board: #ffffff;
  --line: #cfd8e6;
  --pen: #2458e6;
  --pen-soft: rgba(36, 88, 230, 0.14);
  --ok: #0b8f6a;
  --ok-soft: rgba(11, 143, 106, 0.14);
  --shadow: 0 18px 44px rgba(21, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 480px at 50% -8%, #f7fafc, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: Sora, "Trebuchet MS", sans-serif;
}

body {
  min-height: 100dvh;
}

.app {
  width: min(440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
  display: grid;
  gap: 18px;
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.wordmark {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.score {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.day-bar {
  display: grid;
  gap: 8px;
}

.day-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 16px;
  text-align: left;
  line-height: 1.2;
}

.day-open .when {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.day-open .what {
  display: block;
  margin-top: 2px;
  font-size: 0.95rem;
  font-weight: 500;
}

.day-open-hint {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.78rem;
}

.today-jump {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--pen);
  font-size: 0.88rem;
}

.today-jump:hover {
  background: none;
  text-decoration: underline;
}

.archive[hidden] {
  display: none;
}

.archive {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
}

.archive-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(21, 32, 51, 0.28);
}

.archive-panel {
  position: relative;
  width: min(440px, 100%);
  max-height: min(86dvh, 720px);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  padding: 18px 16px 12px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--board);
  box-shadow: var(--shadow);
}

.archive-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.archive-top h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.archive-close {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.88rem;
}

.archive-close:hover {
  background: none;
  color: var(--ink);
}

.archive-search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
}

.archive-search:focus {
  outline: 2px solid var(--pen);
  outline-offset: 1px;
}

.topic-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.topic-chip {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
}

.topic-chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--board);
  border-color: var(--ink);
}

.topic-chip[aria-pressed="true"]:hover {
  background: var(--ink);
}

.archive-list {
  overflow: auto;
  min-height: 0;
  padding-bottom: 12px;
}

.archive-month {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.archive-month:first-child {
  margin-top: 0;
}

.archive-day {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
}

.archive-day:hover {
  background: var(--bg);
}

.archive-day[aria-current="date"] {
  background: var(--bg);
}

.archive-day .meta {
  display: grid;
  gap: 2px;
}

.archive-day .when {
  font-size: 0.78rem;
  color: var(--muted);
}

.archive-day .what {
  font-size: 0.95rem;
  font-weight: 500;
}

.archive-day .done {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.archive-empty {
  margin: 24px 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.task {
  margin: 0;
  font-size: clamp(1.35rem, 4.8vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.25;
  text-wrap: pretty;
}

.board {
  position: relative;
  aspect-ratio: 1;
  background: var(--board);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.grid {
  position: absolute;
  inset: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  pointer-events: none;
}

.cell {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  font-size: clamp(1.45rem, 6.2vw, 2.15rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  transition:
    color 160ms ease,
    background 160ms ease,
    transform 200ms ease;
}

.cell.expr,
.cell.exp,
.cell.abs {
  font-size: clamp(1.1rem, 5vw, 1.6rem);
}

.cell.frac {
  font-size: 1.35rem;
}

.cell.root {
  font-size: clamp(1.25rem, 5.4vw, 1.8rem);
}

.cell.plot,
.cell.shape {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.cell.plot svg,
.cell.shape svg {
  width: 78%;
  height: auto;
  max-height: 64%;
  display: block;
}

.cell.plot .caption {
  line-height: 1;
}

.cell.plot .caption .katex {
  font-size: 0.72em;
}

.cell .axis {
  stroke: #c5cedb;
  stroke-width: 1;
}

.cell .katex,
.task .katex,
.note .katex {
  font-size: 1.08em;
  color: inherit;
}

.task .katex {
  font-size: 1.02em;
}

.note .katex {
  font-size: 1em;
}

.note {
  background: var(--board);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px 16px;
}

.note h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.note p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  text-wrap: pretty;
}

.cell.selected {
  color: var(--pen);
  background: radial-gradient(circle, var(--pen-soft) 0%, transparent 68%);
}

.cell.correct {
  color: var(--ok);
  background: radial-gradient(circle, var(--ok-soft) 0%, transparent 68%);
}

.cell.wrong {
  color: #c81e3a;
  animation: nope 420ms ease;
}

.board.success .cell.selected {
  color: var(--ok);
  background: radial-gradient(circle, var(--ok-soft) 0%, transparent 68%);
}

.board.shake {
  animation: shake 420ms ease;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.play-bar {
  display: grid;
  gap: 8px;
}

.status {
  min-height: 1.4em;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.skip {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.88rem;
}

.skip:hover {
  background: none;
  color: var(--pen);
  text-decoration: underline;
}

.skip:active {
  transform: none;
}

.skip:disabled {
  color: var(--muted);
  opacity: 0.55;
  text-decoration: none;
  cursor: default;
}

.skip:disabled:hover {
  color: var(--muted);
  text-decoration: none;
}

.skip-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.status.ok {
  color: var(--ok);
}

.status.bad {
  color: #c81e3a;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--board);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

button:hover {
  background: #f3f6fb;
}

button:active {
  transform: translateY(1px);
}

@keyframes nope {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-3px);
  }
  40% {
    transform: translateX(3px);
  }
  60% {
    transform: translateX(-2px);
  }
  80% {
    transform: translateX(2px);
  }
}

@media (max-width: 480px) {
  .app {
    width: min(100%, calc(100% - 20px));
    padding-top: 18px;
  }

  .grid {
    inset: 6px;
    gap: 6px;
  }
}
