:root {
  color-scheme: light;
  --bg: #f7fbff;
  --paper: #ffffff;
  --ink: #263238;
  --muted: #667085;
  --line: #dbe8ef;
  --blue: #2d9cdb;
  --blue-dark: #1677aa;
  --coral: #ff715b;
  --coral-dark: #dc4d38;
  --green: #27ae60;
  --green-dark: #168347;
  --yellow: #ffc857;
  --shadow: 0 18px 45px rgba(35, 61, 77, 0.12);
  font-family: "Segoe UI", "Arial", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 200, 87, 0.2), transparent 24%),
    linear-gradient(135deg, #f7fbff 0%, #eef9f3 100%);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.lesson-shell {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.25fr);
  gap: 24px;
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  padding: 24px;
  overflow: hidden;
}

.home-screen,
.syllables-screen {
  min-height: 100vh;
  padding: 28px;
}

.home-hero,
.syllables-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(219, 232, 239, 0.9);
  box-shadow: var(--shadow);
  padding: 24px;
}

.home-title {
  margin: 4px 0 0;
  font-size: clamp(48px, 7vw, 86px);
  line-height: 1;
}

.home-star {
  color: var(--yellow);
  font-size: clamp(72px, 10vw, 128px);
  line-height: 1;
  text-shadow: 0 8px 0 rgba(153, 100, 0, 0.15);
}

.alphabet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 14px;
}

.letter-button,
.syllable-button {
  min-height: 86px;
  border-radius: 24px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--line);
  box-shadow: 0 8px 0 rgba(38, 50, 56, 0.1);
  font-size: 42px;
  font-weight: 950;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.letter-button:active,
.syllable-button:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 rgba(38, 50, 56, 0.1);
}

.letter-button:nth-child(4n + 1),
.syllable-button:nth-child(4n + 1) {
  background: #fff8e6;
}

.letter-button:nth-child(4n + 2),
.syllable-button:nth-child(4n + 2) {
  background: #eaf6fc;
}

.letter-button:nth-child(4n + 3),
.syllable-button:nth-child(4n + 3) {
  background: #eaf8f0;
}

.letter-button:nth-child(4n + 4),
.syllable-button:nth-child(4n + 4) {
  background: #fff0ed;
}

.letter-title {
  margin: 0;
  font-size: clamp(70px, 10vw, 128px);
  line-height: 0.9;
}

.syllables-prompt {
  margin: 0 0 16px;
  color: var(--ink);
  font-size: 34px;
  font-weight: 950;
}

.syllables-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 18px;
}

.syllable-button {
  min-height: 150px;
  font-size: clamp(48px, 9vw, 86px);
}

.back-button {
  min-width: 130px;
}

.lesson-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.home-button {
  min-width: 112px;
}

.lesson-panel,
.writing-panel {
  min-width: 0;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 232, 239, 0.9);
  box-shadow: var(--shadow);
}

.lesson-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: auto;
  border-radius: 28px;
  padding: 24px;
}

.brand-row,
.writing-head,
.sample-row,
.canvas-actions,
.word-actions {
  display: flex;
  align-items: center;
}

.brand-row,
.writing-head,
.sample-row,
.canvas-actions {
  justify-content: space-between;
  gap: 16px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 24px;
  background: var(--yellow);
  color: #603a00;
  font-size: 28px;
  font-weight: 900;
}

.stars {
  display: flex;
  gap: 8px;
  font-size: 35px;
  color: var(--yellow);
  text-shadow: 0 3px 0 rgba(153, 100, 0, 0.18);
}

.star.muted {
  color: #dce7ed;
  text-shadow: none;
}

.syllable-card {
  display: grid;
  place-items: center;
  min-height: 280px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(45, 156, 219, 0.08), rgba(39, 174, 96, 0.08)),
    var(--paper);
  border: 2px solid var(--line);
  padding: 24px;
  text-align: center;
}

.small-title {
  margin: 0;
  color: var(--muted);
  font-size: 20px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin: 6px 0 2px;
  font-size: clamp(92px, 12vw, 148px);
  line-height: 0.94;
  letter-spacing: 0;
}

.equation {
  margin: 0;
  color: var(--blue-dark);
  font-size: 32px;
  font-weight: 900;
}

.handwritten {
  margin: 8px 0 0;
  color: var(--coral);
  font-family: "Comic Sans MS", "Segoe Print", cursive;
  font-size: 66px;
  line-height: 1;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.action-button,
.secondary-button,
.mode {
  min-height: 56px;
  border-radius: 18px;
  font-size: 20px;
  font-weight: 900;
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px;
  color: #fff;
  box-shadow: 0 10px 0 rgba(38, 50, 56, 0.12);
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}

.action-button:active {
  transform: translateY(4px);
  box-shadow: 0 5px 0 rgba(38, 50, 56, 0.12);
}

.primary {
  background: var(--blue);
}

.coral {
  background: var(--coral);
}

.green {
  background: var(--green);
}

.ink {
  background: #334155;
}

.compact {
  min-width: 150px;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
}

.button-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
}

.button-icon svg path:first-child:last-child {
  fill: currentColor;
  stroke: none;
}

.feedback {
  min-height: 72px;
  border-radius: 20px;
  padding: 18px 20px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.25;
}

.feedback.positive {
  background: #eaf8f0;
  color: #126238;
}

.feedback.try {
  background: #fff6df;
  color: #8a5a00;
}

.word-task {
  margin-top: auto;
  border-radius: 22px;
  background: #f7fbff;
  border: 2px dashed #bfd9e8;
  padding: 18px;
}

.word-task.locked {
  filter: grayscale(0.25);
}

.word-task p {
  margin-bottom: 14px;
  font-size: 24px;
  font-weight: 900;
}

.word-actions {
  flex-wrap: wrap;
  gap: 12px;
}

.fallback {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.fallback input {
  width: 100%;
  min-height: 52px;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  color: var(--ink);
  font-size: 22px;
}

.hidden {
  display: none !important;
}

.writing-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  border-radius: 30px;
  padding: 24px;
}

.writing-head h2 {
  margin: 2px 0 0;
  font-size: 52px;
  line-height: 1;
}

.mode-switch {
  display: flex;
  gap: 8px;
  border-radius: 18px;
  background: #edf4f8;
  padding: 6px;
}

.mode {
  min-height: 48px;
  padding: 0 18px;
  color: var(--muted);
  background: transparent;
}

.mode.active {
  color: #fff;
  background: var(--blue-dark);
}

.sample-row {
  min-height: 72px;
  border-radius: 20px;
  background: #fff8e6;
  padding: 8px 20px;
}

.print-word {
  font-size: 44px;
  font-weight: 950;
}

.script-word {
  color: var(--coral-dark);
  font-family: "Comic Sans MS", "Segoe Print", cursive;
  font-size: 48px;
  font-weight: 800;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 300px;
  overflow: hidden;
  border: 3px solid #b7d5e5;
  border-radius: 26px;
  background:
    linear-gradient(#e7f0f5 2px, transparent 2px) 0 68% / 100% 96px no-repeat,
    #fff;
}

#writingCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 3;
}

.trace-word,
.copy-sample {
  position: absolute;
  pointer-events: none;
  user-select: none;
  font-family: "Comic Sans MS", "Segoe Print", cursive;
  line-height: 1;
}

.trace-word {
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  color: rgba(38, 50, 56, 0.13);
  font-size: clamp(112px, 17vw, 210px);
  font-weight: 900;
  z-index: 1;
}

.copy-sample {
  left: 28px;
  top: 36px;
  color: rgba(255, 113, 91, 0.65);
  font-size: clamp(72px, 10vw, 130px);
  font-weight: 900;
}

.secondary-button {
  min-width: 150px;
  padding: 0 22px;
  color: var(--blue-dark);
  background: #eaf6fc;
}

.reward-modal {
  max-width: 420px;
  border: 0;
  border-radius: 30px;
  padding: 32px;
  text-align: center;
  box-shadow: var(--shadow);
}

.reward-modal::backdrop {
  background: rgba(19, 32, 42, 0.35);
}

.reward-star {
  margin: 0 auto 12px;
  color: var(--yellow);
  font-size: 96px;
  line-height: 1;
}

.reward-modal h3 {
  margin-bottom: 8px;
  font-size: 36px;
}

.reward-modal p {
  font-size: 21px;
  font-weight: 700;
}

@media (max-width: 860px) {
  .home-screen,
  .syllables-screen {
    padding: 14px;
  }

  .home-hero,
  .syllables-head {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .alphabet-grid {
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  }

  .letter-button {
    min-height: 72px;
    border-radius: 18px;
    font-size: 34px;
  }

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

  .syllable-button {
    min-height: 120px;
  }

  .lesson-shell {
    grid-template-columns: 1fr;
    width: 100vw;
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 14px;
  }

  .lesson-panel,
  .writing-panel {
    border-radius: 22px;
    padding: 16px;
  }

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

  .brand-row {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .stars {
    flex-shrink: 0;
    margin-left: auto;
    font-size: 30px;
  }

  .lesson-panel,
  .writing-panel,
  .syllable-card,
  .word-task {
    width: 100%;
    max-width: 100%;
  }

  .word-task p,
  .feedback {
    overflow-wrap: anywhere;
  }

  .writing-head,
  .sample-row,
  .canvas-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-switch,
  .canvas-actions {
    width: 100%;
  }

  .mode,
  .canvas-actions button {
    flex: 1;
  }

  .canvas-wrap {
    min-height: 320px;
  }
}

@media (max-width: 640px) {
  .lesson-shell {
    width: min(100vw, 390px);
    max-width: 390px;
    margin: 0;
  }

  .lesson-panel,
  .writing-panel {
    padding: 16px;
  }

  .brand-mark {
    width: 76px;
    height: 76px;
  }

  .stars {
    font-size: 28px;
    gap: 4px;
  }

  .word-task p,
  .feedback {
    font-size: 20px;
  }
}
