:root {
  --ink: #201927;
  --panel: #fff9e8;
  --panel-dark: #332747;
  --sky: #8fd7ff;
  --mint: #61d394;
  --gold: #ffd166;
  --coral: #ef476f;
  --aqua: #00b4d8;
  --violet: #7b5cff;
  --shadow: #14101b;
  --pixel: 4px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(143, 215, 255, 0.92), rgba(255, 249, 232, 0.85)),
    repeating-linear-gradient(
      45deg,
      rgba(32, 25, 39, 0.06) 0 8px,
      transparent 8px 16px
    );
  font-family: "Space Mono", monospace;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1240px, calc(100% - 24px));
  margin: 0 auto;
  padding: 12px 0 16px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(280px, 0.78fr) minmax(360px, 1.22fr);
  gap: 16px;
  align-items: stretch;
  min-height: 150px;
  margin-bottom: 14px;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 150px;
}

.eyebrow,
.screen-top,
.score-tile span,
.select-label,
.toggle-row,
.quest-meta,
.quest-title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: #006d77;
  font-size: 0.74rem;
}

h1 {
  max-width: 680px;
  margin: 0;
  color: var(--panel-dark);
  font-family: "Press Start 2P", system-ui;
  font-size: clamp(1.45rem, 3.7vw, 3.15rem);
  line-height: 1.05;
  text-shadow: 4px 4px 0 var(--gold);
}

.subtitle {
  max-width: 600px;
  margin: 10px 0 0;
  color: #41364c;
  font-size: clamp(0.88rem, 1.6vw, 1rem);
  line-height: 1.4;
}

.pixel-scene {
  position: relative;
  --runner-x: 28px;
  min-height: 150px;
  overflow: hidden;
  border: var(--pixel) solid var(--shadow);
  background:
    linear-gradient(180deg, #76cfff 0 62%, #64c270 62% 100%);
  box-shadow: 8px 8px 0 var(--shadow);
  image-rendering: pixelated;
}

.pixel-scene.celebrating {
  animation: sceneCelebrate 620ms steps(4, end) 2;
}

.pixel-scene::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 19px, rgba(255, 255, 255, 0.28) 19px 20px),
    linear-gradient(180deg, transparent 0 19px, rgba(255, 255, 255, 0.22) 19px 20px);
  background-size: 20px 20px;
  opacity: 0.28;
}

.sun {
  position: absolute;
  top: 18px;
  right: 34px;
  width: 42px;
  height: 42px;
  background: var(--gold);
  box-shadow:
    0 0 0 8px rgba(255, 209, 102, 0.35),
    6px 6px 0 #d98d00;
}

.cloud {
  position: absolute;
  width: 86px;
  height: 24px;
  background: #fff9e8;
  box-shadow:
    20px -16px 0 #fff9e8,
    44px -8px 0 #fff9e8,
    8px 8px 0 rgba(32, 25, 39, 0.15);
}

.cloud-a {
  top: 42px;
  left: 48px;
  animation: drift 10s linear infinite;
}

.cloud-b {
  top: 76px;
  right: 150px;
  transform: scale(0.72);
  animation: drift 14s linear infinite reverse;
}

.castle {
  position: absolute;
  right: 64px;
  bottom: 40px;
  display: flex;
  align-items: end;
  gap: 8px;
}

.pixel-scene.celebrating .castle {
  animation: castleGlow 720ms steps(2, end) 2;
}

.castle span {
  display: block;
  width: 34px;
  height: 54px;
  background: #6d597a;
  border: var(--pixel) solid var(--shadow);
  box-shadow: inset 0 14px 0 #b56576;
}

.castle span:nth-child(2) {
  height: 78px;
  background: #355070;
}

.finish-flag {
  position: absolute;
  right: 180px;
  bottom: 40px;
  width: 12px;
  height: 76px;
  background: var(--shadow);
}

.finish-flag span {
  position: absolute;
  top: 6px;
  left: 12px;
  width: 46px;
  height: 28px;
  background:
    repeating-linear-gradient(45deg, #fff9e8 0 8px, var(--coral) 8px 16px);
  border: 3px solid var(--shadow);
  transform-origin: left center;
}

.pixel-scene.celebrating .finish-flag span {
  animation: flagWave 240ms steps(2, end) infinite;
}

.runner {
  position: absolute;
  left: var(--runner-x);
  bottom: 46px;
  width: 70px;
  height: 76px;
  animation: bob 0.55s steps(2, end) infinite;
  transition: left 220ms steps(8, end);
  z-index: 2;
}

.pixel-scene.celebrating .runner {
  animation:
    bob 0.24s steps(2, end) infinite,
    victoryJump 520ms steps(4, end) 2;
}

.runner-head,
.runner-body,
.runner-arm,
.runner-leg {
  position: absolute;
  background: var(--coral);
  border: var(--pixel) solid var(--shadow);
}

.runner-head {
  top: 0;
  left: 25px;
  width: 28px;
  height: 28px;
  background: #ffd6a5;
}

.runner-head::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 4px;
  width: 6px;
  height: 6px;
  background: var(--shadow);
}

.runner-body {
  top: 30px;
  left: 20px;
  width: 36px;
  height: 30px;
  background: var(--violet);
}

.runner-arm {
  top: 35px;
  left: 50px;
  width: 28px;
  height: 14px;
  background: var(--gold);
}

.runner-leg {
  top: 58px;
  width: 15px;
  height: 28px;
  background: #118ab2;
}

.runner-leg-a {
  left: 22px;
}

.runner-leg-b {
  left: 44px;
  transform: translateY(7px);
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40px;
  background:
    repeating-linear-gradient(90deg, #2a9d8f 0 28px, #21867a 28px 56px),
    #2a9d8f;
  border-top: var(--pixel) solid var(--shadow);
}

.scene-banner {
  position: absolute;
  left: 18px;
  top: 16px;
  z-index: 3;
  max-width: 230px;
  padding: 8px 10px;
  border: 3px solid var(--shadow);
  background: var(--panel);
  color: var(--panel-dark);
  font-family: "Press Start 2P", system-ui;
  font-size: 0.62rem;
  line-height: 1.45;
  box-shadow: 4px 4px 0 var(--shadow);
}

.pixel-scene.celebrating .scene-banner {
  background: var(--gold);
  animation: bannerPop 420ms steps(3, end) 2;
}

.coin-burst {
  position: absolute;
  left: calc(var(--runner-x) + 44px);
  bottom: 94px;
  width: 1px;
  height: 1px;
  pointer-events: none;
  z-index: 4;
  transition: left 220ms steps(8, end);
}

.coin {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 3px solid var(--shadow);
  background: var(--gold);
  box-shadow: inset -3px -3px 0 #d98d00;
  animation: coinFly 760ms steps(7, end) forwards;
}

.coin:nth-child(1) {
  --coin-x: -72px;
  --coin-y: -68px;
}

.coin:nth-child(2) {
  --coin-x: -38px;
  --coin-y: -96px;
}

.coin:nth-child(3) {
  --coin-x: 0;
  --coin-y: -76px;
}

.coin:nth-child(4) {
  --coin-x: 38px;
  --coin-y: -102px;
}

.coin:nth-child(5) {
  --coin-x: 74px;
  --coin-y: -64px;
}

.coin:nth-child(6) {
  --coin-x: 104px;
  --coin-y: -24px;
}

.trainer {
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.control-panel,
.screen,
.score-tile {
  border: var(--pixel) solid var(--shadow);
  box-shadow: 8px 8px 0 var(--shadow);
}

.control-panel {
  position: sticky;
  top: 12px;
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--panel);
}

.panel-block {
  display: grid;
  gap: 8px;
}

.panel-block h2 {
  margin: 0;
  color: var(--panel-dark);
  font-family: "Press Start 2P", system-ui;
  font-size: 0.68rem;
  line-height: 1.4;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: var(--pixel) solid var(--shadow);
  background: var(--shadow);
  gap: var(--pixel);
}

.mode-button,
.pixel-button,
select {
  min-height: 38px;
  border: 0;
  color: var(--ink);
  background: #f7f0d7;
}

.mode-button {
  padding: 8px;
  font-weight: 700;
}

.mode-button.active {
  background: var(--mint);
}

select {
  width: 100%;
  padding: 8px 10px;
  border: var(--pixel) solid var(--shadow);
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--shadow) 50%) right 14px top 18px / 8px 8px
      no-repeat,
    linear-gradient(135deg, var(--shadow) 50%, transparent 50%) right 6px top 18px / 8px 8px
      no-repeat,
    #f7f0d7;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  font-size: 0.72rem;
}

.toggle-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--mint);
}

.quest-meta {
  display: grid;
  gap: 5px;
  color: #6b5f73;
  font-size: 0.66rem;
  line-height: 1.35;
}

.pixel-button {
  border: var(--pixel) solid var(--shadow);
  background: var(--coral);
  color: #fff9e8;
  font-weight: 700;
  box-shadow: 5px 5px 0 var(--shadow);
}

.pixel-button:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 var(--shadow);
}

.stage {
  min-width: 0;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.score-tile {
  min-height: 62px;
  padding: 9px 11px;
  background: var(--panel);
}

.score-tile span {
  display: block;
  color: #6b5f73;
  font-size: 0.64rem;
}

.score-tile strong {
  display: block;
  margin-top: 5px;
  color: var(--panel-dark);
  font-family: "Press Start 2P", system-ui;
  font-size: clamp(0.9rem, 2vw, 1.25rem);
  line-height: 1.2;
}

.screen {
  min-height: 408px;
  padding: 14px;
  color: #fff9e8;
  background:
    linear-gradient(180deg, rgba(32, 25, 39, 0.9), rgba(32, 25, 39, 0.96)),
    repeating-linear-gradient(0deg, transparent 0 18px, rgba(255, 255, 255, 0.08) 18px 20px);
}

.screen-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.72rem;
}

#feedback {
  color: var(--gold);
  text-align: right;
}

.quest-status {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.quest-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #fff9e8;
  font-size: 0.7rem;
}

.quest-title strong {
  color: var(--gold);
}

.quest-progress {
  height: 16px;
  border: 3px solid #fff9e8;
  background: #18111f;
}

.level-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--gold));
  transition: width 180ms steps(6, end);
}

.reward-shelf {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 28px;
}

.badge {
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 28px;
  padding: 0 7px;
  border: 3px solid #fff9e8;
  background: #42335b;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 700;
  box-shadow: 0 4px 0 #17111f;
}

.badge.new {
  animation: popBadge 360ms steps(3, end);
}

.letter-view,
.word-view {
  min-height: 286px;
}

.letter-view {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 14px;
}

.target-letter {
  display: grid;
  place-items: center;
  min-height: 138px;
  color: var(--gold);
  font-family: "Press Start 2P", system-ui;
  font-size: clamp(4.2rem, 13vw, 7.5rem);
  text-shadow:
    7px 7px 0 #ef476f,
    14px 14px 0 #118ab2;
}

.keyboard {
  display: grid;
  gap: 7px;
  justify-items: center;
}

.key-row {
  display: flex;
  gap: 7px;
  justify-content: center;
  width: 100%;
}

.key {
  display: grid;
  place-items: center;
  width: clamp(30px, 4.2vw, 44px);
  aspect-ratio: 1;
  border: 3px solid #fff9e8;
  background: #42335b;
  color: #fff9e8;
  font-weight: 700;
  box-shadow: 0 5px 0 #17111f;
}

.key.active {
  background: var(--gold);
  color: var(--shadow);
  transform: translateY(-4px);
}

.key.correct {
  background: var(--mint);
  color: var(--shadow);
}

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

.word-view {
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 4px 0 16px;
}

.target-word {
  min-height: 92px;
  overflow-wrap: anywhere;
  text-align: center;
  color: var(--gold);
  font-family: "Press Start 2P", system-ui;
  font-size: clamp(1.9rem, 5.6vw, 4.2rem);
  line-height: 1.25;
  text-shadow:
    5px 5px 0 #ef476f,
    10px 10px 0 #118ab2;
}

#word-input {
  width: min(640px, 100%);
  min-height: 54px;
  margin: 0 auto;
  padding: 10px 16px;
  border: var(--pixel) solid #fff9e8;
  outline: 0;
  background: #fff9e8;
  color: var(--ink);
  text-align: center;
  font-size: clamp(1.15rem, 3vw, 1.7rem);
  font-weight: 700;
  box-shadow: 7px 7px 0 #17111f;
}

#word-input:focus {
  border-color: var(--gold);
}

.progress-shell {
  width: min(640px, 100%);
  height: 20px;
  margin: 0 auto;
  border: var(--pixel) solid #fff9e8;
  background: #18111f;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--gold), var(--coral));
  transition: width 120ms steps(4, end);
}

.hidden {
  display: none;
}

.flash-good {
  animation: flashGood 160ms steps(2, end);
}

.flash-bad {
  animation: flashBad 160ms steps(2, end);
}

@keyframes drift {
  from {
    transform: translateX(-12px);
  }
  to {
    transform: translateX(24px);
  }
}

@keyframes bob {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-8px);
  }
}

@keyframes flashGood {
  0%,
  100% {
    filter: none;
  }
  50% {
    filter: drop-shadow(0 0 16px var(--mint));
  }
}

@keyframes flashBad {
  0%,
  100% {
    filter: none;
  }
  50% {
    filter: drop-shadow(0 0 16px var(--coral));
  }
}

@keyframes sceneCelebrate {
  0%,
  100% {
    filter: none;
  }
  50% {
    filter: saturate(1.4) brightness(1.12);
  }
}

@keyframes castleGlow {
  0%,
  100% {
    filter: none;
  }
  50% {
    filter: drop-shadow(0 0 12px var(--gold));
  }
}

@keyframes flagWave {
  0%,
  100% {
    transform: skewY(0deg);
  }
  50% {
    transform: skewY(-10deg);
  }
}

@keyframes victoryJump {
  0%,
  100% {
    transform: translateY(0);
  }
  45% {
    transform: translateY(-24px);
  }
}

@keyframes bannerPop {
  0% {
    transform: scale(0.92);
  }
  70% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes coinFly {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.6);
  }
  18% {
    opacity: 1;
  }
  78% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--coin-x), var(--coin-y)) scale(1);
  }
}

@keyframes popBadge {
  0% {
    transform: scale(0.6);
  }
  70% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 840px) {
  .hero,
  .trainer {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

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

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

  .hero-copy {
    min-height: 190px;
  }

  .pixel-scene {
    min-height: 210px;
  }

  .score-grid {
    gap: 10px;
  }

  .score-tile {
    min-height: 74px;
    padding: 10px;
  }

  .screen {
    min-height: 470px;
    padding: 12px;
  }

  .screen-top {
    align-items: flex-start;
    flex-direction: column;
  }

  #feedback {
    text-align: left;
  }

  .key-row {
    gap: 5px;
  }

  .key {
    width: clamp(24px, 8.2vw, 36px);
    font-size: 0.84rem;
  }
}
