:root {
  --bg: #f6ead8;
  --ink: #20312d;
  --muted: #5e6d65;
  --leaf: #2f8f68;
  --sky: #7ec8da;
  --sun: #f4b942;
  --danger: #c64b42;
  --panel: rgba(255, 252, 244, 0.94);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(180deg, rgba(126, 200, 218, 0.58), rgba(246, 234, 216, 0.96)),
    url("family_zoom.jpg") center 12% / cover fixed;
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
}

button {
  border: 0;
  border-radius: 14px;
  background: var(--leaf);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 48px;
  padding: 0 18px;
  touch-action: manipulation;
}

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

.sound-btn {
  background: #236b86;
  border-radius: 999px;
  font-size: 13px;
  min-height: 38px;
  min-width: 86px;
  padding: 8px 10px;
}

.app {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.game-shell {
  width: min(1120px, 100%);
  display: grid;
  gap: 10px;
}

.topbar,
.lesson-bar,
.touch-controls {
  background: var(--panel);
  border: 2px solid rgba(32, 49, 45, 0.12);
  box-shadow: 0 12px 28px rgba(42, 66, 58, 0.15);
}

.topbar {
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
}

.kicker {
  color: var(--leaf);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0 0 2px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(22px, 4vw, 38px);
  line-height: 1;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stats span {
  background: white;
  border: 2px solid rgba(47, 143, 104, 0.18);
  border-radius: 999px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  min-width: 76px;
  padding: 8px 10px;
  text-align: center;
}

.stats .sound-btn {
  box-shadow: none;
}

.stage-wrap {
  position: relative;
  display: grid;
  justify-items: center;
}

canvas {
  background: #8ed3e5;
  border: 4px solid rgba(32, 49, 45, 0.78);
  border-radius: 18px;
  box-shadow: 0 24px 40px rgba(35, 50, 46, 0.24);
  display: block;
  width: min(100%, calc((100svh - 226px) * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: calc(100svh - 226px);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(28, 51, 47, 0.38);
  border-radius: 18px;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(430px, 92%);
  background: var(--panel);
  border: 3px solid rgba(32, 49, 45, 0.18);
  border-radius: 18px;
  padding: 22px;
  text-align: center;
}

.panel-character {
  width: 78px;
  height: 78px;
  object-fit: contain;
  image-rendering: auto;
}

.panel h2 {
  font-size: clamp(24px, 5vw, 36px);
  line-height: 1.05;
  margin: 8px 0;
}

.panel p {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.42;
  margin-bottom: 16px;
}

.lesson-bar {
  border-radius: 16px;
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 14px;
}

.lesson-bar img {
  width: 42px;
  height: 48px;
  object-fit: contain;
}

.lesson-bar p {
  font-size: clamp(15px, 2.3vw, 19px);
  font-weight: 850;
  line-height: 1.25;
}

.touch-controls {
  border-radius: 18px;
  display: none;
  grid-template-columns: 1fr 1.1fr 1fr;
  gap: 10px;
  padding: 10px;
}

.touch-controls button {
  background: #236b86;
  font-size: 16px;
  min-height: 58px;
}

.touch-controls button:nth-child(2) {
  background: var(--sun);
  color: #3a2a06;
}

@media (pointer: coarse), (max-width: 760px) {
  body {
    background-attachment: scroll;
  }

  .app {
    align-items: start;
    padding-left: 8px;
    padding-right: 8px;
  }

  .game-shell {
    gap: 8px;
  }

  .topbar {
    align-items: flex-start;
    border-radius: 14px;
    padding: 10px;
  }

  .stats {
    max-width: 148px;
  }

  .stats span {
    font-size: 12px;
    min-width: 62px;
    padding: 6px 8px;
  }

  .sound-btn {
    font-size: 12px;
    min-height: 34px;
    min-width: 70px;
    padding: 6px 8px;
  }

  canvas {
    border-radius: 14px;
    border-width: 3px;
    max-height: calc(100svh - 238px);
  }

  .lesson-bar {
    border-radius: 14px;
    min-height: 58px;
    padding: 6px 10px;
  }

  .touch-controls {
    display: grid;
  }
}

@media (max-width: 460px) {
  .topbar {
    gap: 8px;
  }

  .kicker {
    font-size: 11px;
  }

  h1 {
    font-size: 22px;
  }

  .panel {
    padding: 16px;
  }

  .touch-controls button {
    min-height: 54px;
    padding: 0 10px;
  }
}
