:root {
  color-scheme: light;
  --bg: #fff8e6;
  --ink: #222029;
  --muted: #6d6474;
  --primary: #f4a62a;
  --primary-dark: #9b5600;
  --mint: #66c7a8;
  --pink: #f7789a;
  --blue: #59a9f7;
  --card: #ffffff;
  --line: #ecdcbf;
  --shadow: 0 12px 30px rgba(119, 78, 20, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 207, 90, 0.55), transparent 30rem),
    linear-gradient(180deg, #fff3ce 0%, var(--bg) 38%, #f3fff9 100%);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 980px;
  margin: 0 auto;
  padding: 1.1rem 1rem 0.8rem;
}

.eyebrow,
h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2rem, 8vw, 3.2rem);
  line-height: 1;
}

h2 {
  font-size: 1.4rem;
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.ghost-button,
.wide-button,
.ghost-mini,
.answer-row button {
  min-height: 44px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  padding: 0.7rem 1rem;
}

.ghost-button {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
}

.ghost-mini {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--ink);
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin: 0.5rem 0 1rem;
}

.score-strip div {
  min-width: 0;
  border: 2px solid rgba(34, 32, 41, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
  padding: 0.8rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.score-strip span {
  display: block;
  font-size: 1.65rem;
  font-weight: 900;
}

.score-strip small {
  color: var(--muted);
  font-weight: 700;
}

.game-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.tab {
  min-height: 46px;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  border: 2px solid var(--line);
  font-weight: 850;
}

.tab.active {
  background: var(--primary);
  border-color: var(--ink);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}

.game-panel {
  display: none;
  background: rgba(255, 255, 255, 0.88);
  border: 2px solid rgba(34, 32, 41, 0.1);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.game-panel.active {
  display: block;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head p {
  color: var(--muted);
  margin-top: 0.25rem;
}

.badge {
  align-self: flex-start;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #eaf8f1;
  color: #1f7359;
  font-size: 0.8rem;
  font-weight: 850;
  padding: 0.35rem 0.65rem;
}

.math-problem {
  display: grid;
  place-items: center;
  min-height: 145px;
  border-radius: 8px;
  background: #fff0bf;
  color: var(--ink);
  font-size: clamp(2.7rem, 15vw, 5.4rem);
  font-weight: 950;
  margin-bottom: 1rem;
}

.vertical-problem {
  width: min(240px, 82vw);
  display: grid;
  gap: 0.1rem;
  justify-items: stretch;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.number-row {
  text-align: right;
}

.second-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: end;
}

.result-line {
  border-top: 0.11em solid var(--ink);
  margin-top: 0.05em;
}

.division-problem {
  position: relative;
  display: grid;
  grid-template-columns: auto auto;
  align-items: start;
  justify-content: center;
  gap: 0;
  width: min(360px, 88vw);
  min-height: 190px;
  padding-top: 3.1rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.division-dividend,
.division-divisor,
.division-quotient {
  font-size: clamp(2rem, 10vw, 3.4rem);
  font-weight: 950;
  letter-spacing: 0.12em;
}

.division-dividend {
  padding: 0.55rem 1.05rem 0 0;
}

.division-box {
  min-width: 7.3rem;
  border-left: 0.12em solid var(--mint);
}

.division-divisor {
  padding: 0 0 0.55rem 0.7rem;
  border-bottom: 0.12em solid var(--mint);
}

.division-quotient {
  padding: 0.55rem 0 0 0.7rem;
  color: var(--primary-dark);
}

.division-label {
  position: absolute;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 950;
  letter-spacing: 0.02em;
}

.division-label::after {
  content: "";
  position: absolute;
  width: 2.1rem;
  height: 0.12rem;
  background: var(--mint);
  transform-origin: left center;
}

.dividend-label {
  top: 0.3rem;
  left: 0.25rem;
}

.dividend-label::after {
  left: 4.2rem;
  top: 1.45rem;
  transform: rotate(48deg);
}

.divisor-label {
  top: 0;
  right: 0.2rem;
}

.divisor-label::after {
  right: 3.4rem;
  top: 1.7rem;
  transform: rotate(145deg);
}

.quotient-label {
  right: 0;
  bottom: 2.15rem;
}

.quotient-label::after {
  right: 4.8rem;
  top: 0.25rem;
  transform: rotate(205deg);
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
}

.answer-row input {
  min-width: 0;
  min-height: 50px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0 1rem;
  font-size: 1.25rem;
  font-weight: 800;
}

.letter-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 0.25rem;
  margin: 0 auto 1rem;
  max-width: 560px;
}

.letter,
.cell,
.memory-card {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  font-weight: 900;
  user-select: none;
}

.letter {
  aspect-ratio: 1;
  font-size: clamp(0.9rem, 5vw, 1.3rem);
}

.letter.selected {
  background: #d8f5ec;
  border-color: var(--mint);
}

.letter.found {
  background: #ffdf87;
  border-color: var(--primary);
}

.letter.found.selected {
  background: #c9f1e4;
  border-color: var(--mint);
}

.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.word-list span {
  border-radius: 999px;
  background: #f1f3ff;
  color: #34406e;
  font-weight: 850;
  padding: 0.45rem 0.7rem;
}

.word-list .found {
  background: #dff6ea;
  color: #206f53;
  text-decoration: line-through;
}

.crossword-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.24rem;
  max-width: 430px;
  margin: 0 auto 1rem;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
}

.cell.block {
  background: #2b2832;
  border-color: #2b2832;
}

.cell input {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: center;
  text-transform: uppercase;
  font-size: clamp(1rem, 5.8vw, 1.45rem);
  font-weight: 950;
}

.cell small {
  position: absolute;
  top: 0.12rem;
  left: 0.24rem;
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 850;
}

.cell.correct {
  background: #dff6ea;
  border-color: var(--mint);
}

.cell.wrong {
  background: #ffe1e8;
  border-color: var(--pink);
}

.clues {
  margin: 0 0 1rem;
  padding-left: 1.35rem;
  color: var(--muted);
}

.clues li {
  margin-bottom: 0.45rem;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
}

.memory-card {
  min-height: 92px;
  background: #eaf5ff;
  border-color: #bddcf8;
  color: transparent;
  font-size: 0.92rem;
  padding: 0.45rem;
  text-align: center;
  transition: transform 160ms ease;
}

.memory-card span {
  display: none;
}

.memory-card.open,
.memory-card.matched {
  color: var(--ink);
  background: #fff;
}

.memory-card.open span,
.memory-card.matched span {
  display: block;
}

.memory-image {
  width: 3.2rem;
  height: 3.2rem;
  font-size: 2.2rem;
  line-height: 1.05;
  margin-bottom: 0.25rem;
}

.memory-image svg {
  display: block;
  width: 100%;
  height: 100%;
}

.memory-card.matched {
  background: #e1f8ec;
  border-color: var(--mint);
}

.memory-card:active {
  transform: scale(0.97);
}

.feedback {
  min-height: 1.5rem;
  margin-top: 0.9rem;
  color: var(--primary-dark);
  font-weight: 850;
}

.fraction-visual {
  display: grid;
  gap: 0.35rem;
  width: min(280px, 82vw);
  margin: 0 auto 1rem;
  padding: 0.8rem;
  border-radius: 8px;
  background: #fff7d8;
  border: 2px solid var(--line);
}

.fraction-piece {
  min-height: 56px;
  border-radius: 8px;
  background: #fff;
  border: 2px dashed #d8c6a4;
}

.fraction-piece.filled {
  background: var(--mint);
  border-style: solid;
  border-color: #2f9d72;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.option-button,
.word-chip {
  min-height: 44px;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  font-weight: 900;
  padding: 0.6rem 0.75rem;
}

.option-button:active,
.word-chip:active {
  transform: scale(0.98);
}

.sentence-answer,
.sentence-bank {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 74px;
  border-radius: 8px;
  border: 2px solid var(--line);
  padding: 0.75rem;
}

.sentence-answer {
  background: #fff7d8;
  margin-bottom: 0.75rem;
}

.sentence-bank {
  background: #eef8ff;
}

.selected-word {
  background: #dff6ea;
  border-color: var(--mint);
}

.sentence-placeholder {
  color: var(--muted);
  font-weight: 800;
}

.sentence-actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-end;
  }

  .panel-head {
    display: block;
  }

  .badge {
    display: inline-block;
    margin-top: 0.7rem;
  }

  .answer-row {
    grid-template-columns: 1fr;
  }

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

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

  .sentence-actions {
    grid-template-columns: 1fr;
  }
}
