:root {
  color-scheme: light;
  --sun: #ffcf4a;
  --sky: #8ed8ff;
  --leaf: #51bf8a;
  --berry: #ff6f91;
  --ink: #263238;
  --paper: #fff9ec;
  --line: #f0dfbd;
  --shadow: 0 16px 40px rgba(77, 58, 23, 0.16);
  font-family: "Tahoma", "Noto Sans Thai", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(142, 216, 255, 0.62), transparent 34rem),
    linear-gradient(180deg, #fff7d7 0%, #eaf9ff 52%, #fff3f0 100%);
  color: var(--ink);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #7a5d00;
  font-size: 0.82rem;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 10vw, 3rem);
  line-height: 1.02;
}

.sound-toggle,
.close-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: white;
  box-shadow: var(--shadow);
}

.welcome-band {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 228, 129, 0.72));
  box-shadow: var(--shadow);
}

.mascot {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 22px;
  background: #ff6f91;
  color: white;
  font-size: 3.6rem;
  font-weight: 900;
}

.welcome-band h2 {
  margin-bottom: 6px;
  font-size: 1.25rem;
  line-height: 1.2;
}

.welcome-band p,
.practice-prompt p,
.letter-info p {
  margin-bottom: 0;
  color: #54646b;
  line-height: 1.5;
}

.lesson-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
  padding: 6px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.65);
}

.tab-button {
  min-height: 48px;
  border-radius: 16px;
  background: transparent;
  font-weight: 800;
}

.tab-button.active {
  background: var(--ink);
  color: white;
  box-shadow: 0 8px 18px rgba(38, 50, 56, 0.18);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

.section-heading span {
  color: #6b777c;
  font-weight: 700;
}

.symbol-grid,
.quick-picks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.symbol-card {
  display: grid;
  min-height: 92px;
  padding: 10px 6px;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 10px 20px rgba(78, 55, 18, 0.1);
  place-items: center;
}

.symbol-card:nth-child(4n + 1) {
  background: #ffe9ef;
}

.symbol-card:nth-child(4n + 2) {
  background: #e9f8ff;
}

.symbol-card:nth-child(4n + 3) {
  background: #ecffe9;
}

.symbol-card:nth-child(4n) {
  background: #fff3c2;
}

.symbol-letter {
  font-size: 2.35rem;
  font-weight: 900;
  line-height: 1;
}

.symbol-label {
  margin-top: 5px;
  color: #58656a;
  font-size: 0.78rem;
  font-weight: 800;
}

.vowel-grid .symbol-card {
  min-height: 86px;
}

.practice-prompt {
  margin-bottom: 14px;
  padding: 18px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.76);
}

.detail-sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
}

.detail-sheet.open {
  display: block;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(38, 50, 56, 0.34);
}

.sheet-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(100%, 520px);
  max-height: 94vh;
  margin: 0 auto;
  overflow: auto;
  padding: 16px 16px max(18px, env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: #fffdfa;
  box-shadow: 0 -24px 54px rgba(0, 0, 0, 0.18);
}

.close-button {
  margin-left: auto;
  font-size: 2rem;
  line-height: 1;
}

.letter-stage {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: center;
  margin-top: 8px;
}

.letter-card {
  display: grid;
  min-height: 154px;
  place-items: center;
  border-radius: 24px;
  background: linear-gradient(160deg, #ffcf4a, #ff8ca5);
  color: white;
  box-shadow: var(--shadow);
}

.letter-icon {
  font-size: 1.9rem;
}

.big-letter {
  font-size: 5.4rem;
  font-weight: 900;
  line-height: 0.9;
}

.letter-info h2 {
  margin-bottom: 6px;
  font-size: 1.7rem;
}

.action-row,
.practice-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0 12px;
}

.primary-action,
.secondary-action,
.practice-controls button {
  min-height: 52px;
  border-radius: 18px;
  font-weight: 900;
}

.primary-action {
  background: var(--leaf);
  color: white;
}

.secondary-action {
  background: var(--sky);
}

.practice-controls button {
  background: #f1f5f7;
}

.practice-controls #doneButton {
  background: var(--sun);
}

.trace-area {
  position: relative;
  width: min(100%, 360px);
  aspect-ratio: 15 / 16;
  margin: 0 auto;
  overflow: hidden;
  border: 2px solid #f1f5f7;
  border-radius: 12px;
  background: #fff;
  touch-action: none;
}

#traceSvg,
#letterImage,
#drawCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#letterImage {
  object-fit: contain;
  padding: 10px;
  z-index: 1;
  user-select: none;
  -webkit-user-drag: none;
}

#drawCanvas {
  z-index: 3;
}

#traceSvg {
  z-index: 2;
  pointer-events: none;
}

.guide-text {
  fill: #111827;
  font-family: "Tahoma", "Noto Sans Thai", system-ui, sans-serif;
  font-size: 236px;
  font-weight: 900;
  dominant-baseline: middle;
  text-anchor: middle;
}

.guide-text {
  stroke: none;
}

.guide-glyph {
  fill: none;
  stroke: #000;
  stroke-linecap: butt;
  stroke-linejoin: miter;
}

.start-dot {
  display: none;
}

.encouragement {
  min-height: 34px;
  margin: 10px 0 0;
  color: #795200;
  font-weight: 900;
  text-align: center;
}

@keyframes pulse {
  50% {
    transform: scale(1.14);
  }
}

@media (max-width: 380px) {
  .symbol-grid,
  .quick-picks {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .letter-stage {
    grid-template-columns: 1fr;
  }

  .letter-card {
    min-height: 132px;
  }
}
