:root {
  color-scheme: light;
  --ink: #202225;
  --muted: #68707a;
  --paper: #fffdf7;
  --panel: #ffffff;
  --line: #d9dde2;
  --sky: #8ed2ff;
  --grass: #41a867;
  --earth: #9a6845;
  --gold: #f7bd37;
  --coral: #ef6b62;
  --teal: #1a9da5;
  --blue: #3b74d7;
  --shadow: 0 18px 45px rgba(36, 43, 54, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, #f3fbff 0%, #fff8e9 54%, #eef8ef 100%);
}

button,
select {
  font: inherit;
}

.app-shell {
  display: flex;
  justify-content: center;
  height: 100svh;
  padding: 12px;
}

.game-stage {
  position: relative;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(138, 151, 166, 0.28);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.game-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 520px);
  height: calc(100svh - 24px);
  overflow: hidden;
}

.bonus-round-active .game-stage {
  grid-template-rows: minmax(0, 1fr);
}

.bonus-round-active .top-bar,
.bonus-round-active .control-strip {
  display: none;
}

.splash-screen,
.intro-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  opacity: 1;
  transition:
    opacity 700ms ease,
    visibility 700ms ease;
}

.splash-screen {
  display: grid;
  align-content: start;
  grid-template-rows: 1fr auto 1.15fr;
  gap: 30px;
  justify-items: center;
  padding: min(12svh, 82px) 34px 34px;
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 255, 255, 0.18), transparent 30%),
    linear-gradient(180deg, #064ea2 0%, #07356f 46%, #06152e 100%);
}

.splash-brand {
  align-self: end;
  display: grid;
  gap: 18px;
  justify-items: center;
}

.splash-logo {
  width: min(54%, 230px);
  max-height: 210px;
  object-fit: contain;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.3));
}

.splash-brand p {
  max-width: 380px;
  margin: 0;
  color: #fff;
  font-size: clamp(0.78rem, 2.5vw, 1rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.35;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.36);
}

.splash-brand p span {
  white-space: nowrap;
}

.intro-screen.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.splash-screen.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.intro-art {
  position: absolute;
  inset: 0;
  background: url("./assets/intro-background.png") center / cover no-repeat;
}

.intro-spark {
  display: none;
}

.intro-actions {
  position: absolute;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 14px;
  display: grid;
  padding: 0;
  background: transparent;
}

#splashStartButton,
#introStartButton {
  min-height: 58px;
  border: 2px solid rgba(255, 229, 117, 0.84);
  background:
    linear-gradient(180deg, #ffdc52, #f98a12);
  color: #321502;
  font-size: 1.1rem;
  font-weight: 950;
  box-shadow:
    0 0 18px rgba(255, 213, 73, 0.5),
    0 10px 24px rgba(0, 0, 0, 0.28);
  text-transform: uppercase;
}

#splashStartButton {
  align-self: start;
  width: min(100%, 300px);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 5vw, 1.8rem);
  line-height: 1;
}

.stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.stats strong {
  color: var(--ink);
  font-size: 1rem;
}

.playfield {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #a4ddff;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #a4ddff;
  touch-action: none;
}

.control-strip {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 10px;
  border: 1px solid rgba(138, 151, 166, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 28px rgba(36, 43, 54, 0.16);
}

button,
select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

button {
  cursor: pointer;
  font-weight: 800;
}

button:hover,
button:focus-visible,
select:focus-visible {
  border-color: var(--blue);
  outline: 3px solid rgba(59, 116, 215, 0.18);
}

#jumpButton {
  display: none;
  color: #12426c;
  background: #e4f4ff;
}

#duckButton {
  display: none;
}

#quitRunButton {
  display: none;
}

.game-active .control-strip {
  grid-template-columns: 1fr auto auto;
}

.game-active #jumpButton,
.game-active #quitRunButton {
  display: block;
}

#startButton {
  min-width: 112px;
  color: #fff;
  border-color: #255eb9;
  background: var(--blue);
}

.lesson-panel {
  position: absolute;
  inset: 14px 14px 92px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100% - 28px);
  padding: 14px;
  overflow: auto;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(138, 151, 166, 0.32);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

.game-active .lesson-panel {
  visibility: hidden;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

.results-panel {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 14px;
  padding: 26px;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: linear-gradient(180deg, #fffdf7, #ebf8ff);
  transform: scale(0.98);
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

.results-panel.show {
  visibility: visible;
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.results-panel.bonus-active {
  gap: 10px;
  padding: 18px;
  background: linear-gradient(180deg, #fffdf7 0%, #f2fbff 46%, #eef8ef 100%);
}

.results-panel.bonus-active > .eyebrow,
.results-panel.bonus-active > h2,
.results-panel.bonus-active > .results-grid {
  display: none;
}

.results-panel h2 {
  margin: 0;
  font-size: 2.1rem;
  line-height: 1;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.results-grid span {
  display: grid;
  gap: 4px;
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.results-grid strong {
  color: var(--ink);
  font-size: 1.55rem;
  line-height: 1;
}

#resultsNote {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.verse-puzzle {
  display: grid;
  grid-template-rows: auto minmax(126px, 0.76fr) minmax(170px, 1.05fr) auto auto auto;
  gap: 10px;
  min-height: 0;
}

.results-panel.bonus-active .verse-puzzle {
  flex: 1;
  min-height: 0;
}

.verse-puzzle.hidden {
  display: none;
}

.puzzle-header,
.puzzle-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.puzzle-header span {
  color: #8a4f15;
  font-weight: 900;
}

.puzzle-header strong {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal);
}

.puzzle-answer,
.puzzle-bank {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.puzzle-answer {
  min-height: 132px;
}

.puzzle-bank {
  min-height: 190px;
  overflow: auto;
}

.results-panel.bonus-active .puzzle-bank {
  max-height: none;
}

.puzzle-word {
  min-height: 38px;
  padding: 7px 11px;
  border: 2px solid #d4b35c;
  border-radius: 8px;
  background: #fff3b8;
  color: #5c4413;
  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1;
}

.puzzle-word.chosen {
  border-color: #7cc9bf;
  background: #e3f8f7;
  color: #10656b;
}

.puzzle-word.used {
  opacity: 0.25;
  pointer-events: none;
}

.puzzle-word.wrong {
  border-color: var(--coral);
  background: #ffe9e6;
  animation: puzzleShake 180ms ease;
}

.bonus-result {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #7cc9bf;
  border-radius: 8px;
  background: #e3f8f7;
  color: #10656b;
}

.bonus-result.hidden {
  display: none;
}

.bonus-result.fail {
  border-color: #efaaa4;
  background: #ffe9e6;
  color: #8a302b;
}

.bonus-result span {
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.bonus-result strong {
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1.1;
}

.bonus-result p {
  margin: 0;
  color: inherit;
  font-weight: 800;
  line-height: 1.35;
}

.puzzle-feedback {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.35;
}

.puzzle-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
}

.puzzle-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#puzzleContinueButton:not(:disabled) {
  color: #fff;
  border-color: #255eb9;
  background: var(--blue);
}

@keyframes puzzleShake {
  0%,
  100% {
    transform: translateX(0);
  }

  35% {
    transform: translateX(-5px);
  }

  70% {
    transform: translateX(5px);
  }
}

label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  width: 100%;
  padding: 0 12px;
}

.main-menu-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.menu-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.menu-actions button {
  min-height: 40px;
  color: #374151;
  background: #fff;
}

.menu-actions button[aria-pressed="false"] {
  color: #7a5a18;
  background: #fff6d8;
}

#quitRunButton {
  color: #8a342e;
  background: #fff0ee;
}

#quitRunButton:disabled {
  cursor: default;
  opacity: 0.48;
}

.menu-tab.active {
  border-color: var(--teal);
  background: #e3f8f7;
  color: #10656b;
}

.menu-view {
  display: none;
}

.menu-view.active {
  display: grid;
  gap: 12px;
}

.verse-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.verse-card span {
  display: block;
  margin-bottom: 8px;
  color: #8a4f15;
  font-weight: 900;
}

.verse-card p {
  margin: 0;
  color: #2e3033;
  font-size: 0.95rem;
  line-height: 1.5;
}

.pet-store {
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.store-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.store-heading span {
  color: #8a4f15;
  font-weight: 900;
}

.store-heading p,
.selected-pet,
.store-notice {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.store-notice {
  margin: 0;
  color: #7a5a18;
}

.store-heading strong {
  flex: 0 0 auto;
  color: #5c4413;
  white-space: nowrap;
}

.pet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.pet-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 72px;
  padding: 8px;
  text-align: left;
}

.pet-card.owned {
  border-color: rgba(26, 157, 165, 0.45);
  background: #effafa;
}

.pet-card.selected {
  border-color: var(--gold);
  background: #fff3c9;
}

.pet-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(138, 151, 166, 0.34);
  border-radius: 8px;
  background: #fff;
  font-size: 1.5rem;
  overflow: visible;
}

.pet-avatar img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  object-position: center;
}

.pet-avatar-none img {
  width: 34px;
  height: 34px;
}

.pet-avatar-fish img {
  width: 40px;
  height: 40px;
  transform: translateY(-1px);
}

.pet-avatar-raccoon img {
  width: 38px;
  height: 38px;
}

.pet-avatar-raptor img {
  width: 40px;
  height: 40px;
  transform: translateY(-1px);
}

.pet-avatar-hippo img {
  width: 42px;
  height: 42px;
  transform: translateX(-1px);
}

.pet-avatar-mouse img {
  width: 42px;
  height: 42px;
  transform: translateX(-1px);
}

.pet-card span {
  display: block;
  overflow-wrap: anywhere;
}

.pet-card small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-weight: 700;
}

.help-popover {
  position: absolute;
  inset: 14px;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(18, 30, 45, 0.28);
}

.help-popover.hidden {
  display: none;
}

.help-card {
  display: grid;
  gap: 12px;
  width: min(100%, 430px);
  max-height: 100%;
  padding: 16px;
  overflow: auto;
  border: 1px solid rgba(138, 151, 166, 0.34);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.help-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.help-card p {
  margin: 0;
  color: #2e3033;
  line-height: 1.4;
}

#helpCloseButton {
  justify-self: end;
  min-height: 36px;
  padding: 6px 12px;
}

.help-modes {
  display: grid;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.help-modes span {
  color: #175da8;
  font-weight: 900;
}

@media (max-width: 620px) {
  .app-shell {
    padding: 0;
  }

  .game-stage {
    width: 100%;
    height: 100svh;
    border: 0;
    border-radius: 0;
  }

  .top-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px 9px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 0.68rem;
  }

  h1 {
    font-size: 1.45rem;
  }

  .stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    justify-content: flex-start;
  }

  .stats span {
    justify-content: center;
    min-height: 34px;
    padding: 5px 6px;
    font-size: 0.72rem;
  }

  .stats strong {
    font-size: 0.96rem;
  }

  .control-strip {
    grid-template-columns: 1fr;
  }

  .game-active .control-strip {
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.9fr) minmax(0, 0.9fr);
    gap: 7px;
    padding: 7px;
  }

  .game-active .control-strip button {
    min-width: 0;
    min-height: 48px;
    padding: 8px 6px;
    font-size: 0.86rem;
  }

  .menu-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #startButton {
    grid-column: 1 / -1;
    width: 100%;
  }

  .game-active #startButton {
    grid-column: auto;
    min-width: 0;
    width: auto;
  }

  #gameCanvas {
    min-height: 0;
  }
}

@media (max-width: 380px) {
  .game-active .control-strip {
    gap: 5px;
    padding: 6px;
  }

  .game-active .control-strip button {
    font-size: 0.78rem;
  }
}
