:root {
  --bg-top: #041024;
  --bg-mid: #102a50;
  --bg-bot: #1d3f71;
  --card: #f5fbff;
  --ink: #102a43;
  --accent: #f66b0e;
  --accent-2: #00a8cc;
  --good: #0f9d58;
  --warn: #d93025;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 10%, #24497a 0%, var(--bg-mid) 35%, var(--bg-top) 100%);
}

body {
  padding: 12px;
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.card {
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff 0%, var(--card) 100%);
  border: 2px solid rgba(12, 41, 82, 0.15);
  box-shadow: 0 16px 24px rgba(3, 18, 39, 0.2);
}

.intro-card {
  max-width: 780px;
  margin: 8vh auto;
  padding: 24px;
}

.intro-card h1 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: clamp(2rem, 5vw, 3rem);
}

.intro-card p,
.intro-card li {
  font-size: 1.1rem;
  line-height: 1.45;
}

.start-scene {
  position: relative;
  min-height: calc(100vh - 24px);
  display: grid;
  align-items: center;
  padding: 12px 0;
  overflow: hidden;
}

.start-sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.spark {
  position: absolute;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95) 0 7%, rgba(255, 255, 255, 0.15) 8% 24%, transparent 25%);
  filter: drop-shadow(0 0 14px rgba(255, 255, 255, 0.4));
  animation: pulse-pop 3.8s ease-in-out infinite;
}

.spark-a {
  top: 6%;
  left: 8%;
  animation-delay: 0s;
}

.spark-b {
  top: 10%;
  right: 12%;
  width: 100px;
  height: 100px;
  animation-delay: 0.8s;
}

.spark-c {
  bottom: 14%;
  left: 10%;
  width: 95px;
  height: 95px;
  animation-delay: 1.6s;
}

.spark-d {
  bottom: 8%;
  right: 16%;
  width: 120px;
  height: 120px;
  animation-delay: 2.4s;
}

.spark-e {
  top: 34%;
  right: 42%;
  width: 80px;
  height: 80px;
  animation-delay: 3.2s;
}

.kid-intro-card {
  position: relative;
  z-index: 2;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 28px;
  border: 4px solid rgba(255, 255, 255, 0.55);
  background: linear-gradient(180deg, #fff9e9 0%, #f4f9ff 52%, #eef6ff 100%);
  box-shadow: 0 18px 34px rgba(2, 20, 46, 0.35);
}

.welcome-pill {
  display: inline-flex;
  margin: 0 0 8px;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.95rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #0c3d73;
  background: linear-gradient(135deg, #ffe28a, #ffd1ef);
}

.kid-intro-card h1 {
  margin-top: 0;
  margin-bottom: 10px;
  color: #0c2f57;
  font-family: "Chalkboard SE", "Marker Felt", "Trebuchet MS", sans-serif;
  font-size: clamp(2.25rem, 6vw, 4rem);
  line-height: 1.05;
}

.hero-text {
  margin: 0 0 14px;
  font-size: clamp(1.2rem, 2.4vw, 1.6rem);
  font-weight: 700;
  color: #153c66;
}

.start-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.step-badge {
  border-radius: 14px;
  border: 2px solid #b8dbff;
  background: linear-gradient(160deg, #ffffff, #dff0ff);
  padding: 10px;
  text-align: center;
  box-shadow: 0 6px 12px rgba(29, 66, 104, 0.12);
}

.step-badge p {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: #10375f;
}

.step-number {
  width: 34px;
  height: 34px;
  margin: 0 auto 6px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(140deg, #ff8a00, #ff4d6d);
}

.choose-text {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 800;
  color: #0e3b67;
}

.sound-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.sound-toggle-btn {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 0.95rem;
  font-weight: 800;
  background: linear-gradient(135deg, #d7e7f8, #c8def5);
  color: #11365f;
}

.sound-toggle-btn[aria-pressed="false"] {
  background: #d8e1ec;
  color: #4c6782;
}

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

.choice-btn {
  min-height: 64px;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 14px rgba(7, 31, 61, 0.23);
}

.choice-btn:hover {
  transform: translateY(-1px) scale(1.01);
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 46px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #ff9f43);
}

.btn-secondary {
  color: #fff;
  background: linear-gradient(135deg, #1f6aa5, var(--accent-2));
}

.btn-ghost {
  color: #0f345f;
  background: #e4f0fb;
}

.hud-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  margin-bottom: 10px;
}

.hud-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hud-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-title-group h2 {
  margin: 0;
  font-size: 1.35rem;
  color: #0c2f57;
}

.hud-title-group p {
  margin: 0;
  font-weight: 700;
  color: #3b5a7a;
}

.hud-progress {
  font-size: 0.95rem;
}

.hud-info>p#level-instructions {
  margin: 0;
  font-size: 0.95rem;
  color: #4a6fa5;
}

.hud-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.hud-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.btn-sm {
  min-height: 32px;
  padding: 6px 14px;
  font-size: 0.85rem;
}

.hud-stars {
  margin-left: 6px;
  font-size: 1.1rem;
  letter-spacing: -2px;
}

.save-status {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: #1d4f80;
}

.concept-pill {
  display: inline-flex;
  margin: 0;
  font-weight: 800;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #0a4a82;
  background: #dceeff;
  border-radius: 999px;
  padding: 6px 10px;
}

.game-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
}

.canvas-card,
.panel-card {
  padding: 12px;
}

.canvas-card {
  display: flex;
  flex-direction: column;
}

#show-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: #020817;
}

#show-canvas:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
}

#show-canvas:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
}

.canvas-footer {
  margin-top: 10px;
  min-height: 28px;
}

.canvas-footer p {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.panel-section {
  margin-bottom: 12px;
}

.sticker-progress {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 700;
}

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

.sticker-tile {
  border-radius: 12px;
  border: 2px dashed #9bb7d8;
  background: #f0f7ff;
  padding: 8px;
  min-height: 76px;
  display: grid;
  align-content: center;
  gap: 4px;
  text-align: center;
}

.sticker-tile.unlocked {
  border-style: solid;
  color: #052747;
}

.sticker-code {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  color: #fff;
}

.sticker-image {
  width: 100%;
  max-width: 64px;
  height: auto;
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  margin: 0 auto;
}

.locked-image {
  filter: grayscale(100%) brightness(50%) contrast(70%);
  opacity: 0.6;
}

.sticker-name {
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
}

.sticker-lock {
  font-size: 0.72rem;
  font-weight: 700;
  color: #517191;
}

.sticker-screen-card {
  padding: 16px;
}

.sticker-screen-actions {
  margin-top: 14px;
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 13, 30, 0.52);
  padding: 14px;
}

.overlay.active {
  display: flex;
}

.overlay-card {
  width: min(520px, 100%);
  padding: 16px;
}

.overlay-card h3 {
  margin-top: 0;
  margin-bottom: 6px;
}

.overlay-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 2.5rem;
}

.star-icon {
  color: #c9d8e6;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.star-icon.filled {
  color: #ffca3a;
  text-shadow: 0 2px 8px rgba(255, 202, 58, 0.5);
  animation: star-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes star-pop {
  0% {
    transform: scale(0.5) rotate(-20deg);
    opacity: 0;
  }

  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

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

#board-area h3,
.panel-section h3 {
  margin: 0 0 8px;
}

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

.code-grid.compact {
  grid-template-columns: repeat(2, minmax(70px, 1fr));
}

.code-slot {
  border: 2px dashed #8daecc;
  border-radius: 12px;
  min-height: 62px;
  background: #f0f8ff;
  color: #24436a;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  cursor: pointer;
}

.code-slot.selected {
  border-style: solid;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(246, 107, 14, 0.2);
}

.code-slot.error-pulse {
  border-color: #ff4d6d;
  background: #fff0f3;
  color: #c9184a;
  animation: error-shake 0.4s ease-in-out;
  box-shadow: 0 0 0 3px rgba(255, 77, 109, 0.2);
}

@keyframes error-shake {

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

  25% {
    transform: translateX(-4px);
  }

  75% {
    transform: translateX(4px);
  }
}

.loop-card {
  border: 2px solid #bee0ff;
  border-radius: 12px;
  padding: 10px;
  background: #eef7ff;
}

.repeat-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.repeat-controls p {
  margin: 0;
  font-weight: 700;
}

.repeat-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  font-size: 1.25rem;
  color: #fff;
  background: #0a4a82;
  cursor: pointer;
}

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

.tool-btn {
  border-radius: 12px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  min-height: 56px;
  padding: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
}

.tool-btn.active {
  outline: 3px solid rgba(10, 74, 130, 0.45);
}

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

.controls-row:last-child {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.status-good {
  color: var(--good);
}

.status-warn {
  color: var(--warn);
}

@keyframes pulse-pop {
  0% {
    transform: scale(0.7);
    opacity: 0.16;
  }

  30% {
    transform: scale(1);
    opacity: 0.36;
  }

  65% {
    transform: scale(1.15);
    opacity: 0.2;
  }

  100% {
    transform: scale(0.7);
    opacity: 0.16;
  }
}

@media (max-width: 850px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .hud-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .hud-controls {
    align-items: flex-start;
  }

  .hud-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 620px) {
  body {
    padding: 6px;
  }

  .card {
    border-radius: 12px;
  }

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

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

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

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

  .splash-actions {
    grid-template-columns: 1fr;
  }

  .sound-row {
    justify-content: stretch;
  }

  .sound-toggle-btn {
    width: 100%;
  }

  .start-scene {
    min-height: auto;
    padding: 6px 0 10px;
  }

  .kid-intro-card {
    padding: 18px 14px;
  }

  .start-steps {
    grid-template-columns: 1fr;
  }

  .choice-btn {
    min-height: 58px;
    font-size: 1.05rem;
  }

  .spark {
    width: 74px;
    height: 74px;
    opacity: 0.18;
  }

  .overlay-actions {
    grid-template-columns: 1fr;
  }
}