:root {
  --ink: #182234;
  --muted: #5d6879;
  --paper: #fff8ea;
  --panel: rgba(255, 251, 239, 0.96);
  --line: rgba(24, 34, 52, 0.16);
  --teal: #2d9b88;
  --coral: #df5d50;
  --blue: #4768b5;
  --gold: #f1bd4f;
  --green: #4c8d59;
  --floor: #d3a165;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #233044;
  color: var(--ink);
}

button,
a {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.snake-app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(350px, 28vw, 440px);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(116, 190, 203, 0.46), transparent 46%),
    #22334c;
}

.snake-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  padding: 18px;
}

.stage-hud {
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(170px, 260px) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.objective-chip,
.score-strip,
.stage-feedback {
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  background: rgba(255, 248, 234, 0.92);
  box-shadow: 0 14px 34px rgba(13, 21, 34, 0.18);
  backdrop-filter: blur(10px);
}

.objective-chip {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
}

.objective-chip span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.objective-chip strong {
  color: #263145;
  font-size: clamp(1rem, 1.5vw, 1.38rem);
  line-height: 1.08;
}

.stage-feedback {
  grid-column: 1 / -1;
  min-height: 42px;
  margin: -2px 0 0;
  padding: 10px 12px;
  color: #263145;
  font-size: clamp(0.9rem, 1vw, 1rem);
  font-weight: 780;
  line-height: 1.28;
}

.stage-feedback.is-correct {
  border-color: rgba(45, 155, 136, 0.52);
  background: rgba(232, 250, 244, 0.95);
}

.stage-feedback.is-wrong {
  border-color: rgba(223, 93, 80, 0.5);
  background: rgba(255, 238, 234, 0.95);
}

.stage-feedback.is-warning {
  border-color: rgba(154, 103, 0, 0.42);
  background: rgba(255, 248, 223, 0.95);
}

.progress-rail {
  height: 13px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 999px;
  background: rgba(255, 248, 234, 0.6);
}

.progress-rail span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 260ms ease;
}

.score-strip {
  display: flex;
  gap: 7px;
  padding: 7px;
}

.score-strip span {
  min-width: 78px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff;
  font-size: 0.82rem;
  font-weight: 850;
  text-align: center;
}

.snake-scene {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background:
    linear-gradient(180deg, #9fd5df 0%, #f7df9f 45%, #eeb973 76%, #af7149 100%);
  box-shadow: 0 28px 80px rgba(13, 21, 34, 0.34);
  isolation: isolate;
  touch-action: none;
}

.snake-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 8;
  opacity: 0;
  pointer-events: none;
}

.snake-scene.flash-correct::after {
  animation: correct-flash 520ms ease-out;
}

.snake-scene.flash-wrong::after {
  animation: wrong-flash 520ms ease-out;
}

.scene-sky {
  position: absolute;
  inset: 0 0 auto;
  height: 42%;
  background:
    linear-gradient(92deg, transparent 0 14%, rgba(255, 255, 255, 0.28) 14.3% 15%, transparent 15.3% 34%, rgba(255, 255, 255, 0.22) 34.3% 35%, transparent 35.3% 65%, rgba(255, 255, 255, 0.22) 65.3% 66%, transparent 66.3% 85%, rgba(255, 255, 255, 0.28) 85.3% 86%, transparent 86.3%),
    linear-gradient(180deg, #c5edf2, #f5da9a);
  opacity: 0.84;
}

.scene-art {
  position: absolute;
  z-index: 2;
  object-fit: contain;
  opacity: 0.76;
  pointer-events: none;
  filter: drop-shadow(0 8px 10px rgba(13, 21, 34, 0.16));
}

.scene-tree {
  left: 3%;
  bottom: 12%;
  width: clamp(58px, 10vw, 110px);
}

.scene-flower {
  right: 22%;
  bottom: 4%;
  width: clamp(58px, 8vw, 92px);
}

.scene-bird {
  right: 24%;
  top: 10%;
  width: clamp(44px, 7vw, 78px);
}

#gameCanvas {
  position: relative;
  z-index: 3;
  display: block;
  width: min(92%, 74dvh, 620px);
  aspect-ratio: 1;
  border: 2px solid rgba(38, 49, 69, 0.88);
  border-radius: 8px;
  background: rgba(255, 248, 234, 0.42);
  box-shadow: 0 18px 40px rgba(13, 21, 34, 0.22);
}

.answer-layer {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  width: min(92%, 74dvh, 620px);
  aspect-ratio: 1;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.answer-card {
  position: absolute;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  align-items: center;
  align-content: center;
  justify-content: center;
  gap: 2px;
  overflow-wrap: anywhere;
  padding: 4px;
  border: 2px solid #263145;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 255, 255, 0.95), rgba(255, 248, 234, 0.96) 64%),
    rgba(255, 248, 234, 0.96);
  color: #182234;
  text-align: center;
  box-shadow:
    inset 0 -5px 0 rgba(13, 21, 34, 0.06),
    0 12px 22px rgba(13, 21, 34, 0.22);
}

.answer-card img {
  justify-self: center;
  width: clamp(30px, 5.5vw, 54px);
  height: clamp(26px, 5vw, 48px);
  object-fit: contain;
  filter: drop-shadow(0 5px 6px rgba(13, 21, 34, 0.18));
}

.answer-place {
  color: var(--teal);
  font-size: clamp(0.52rem, 1.2vw, 0.66rem);
  font-weight: 950;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.answer-card strong {
  align-self: start;
  color: #182234;
  font-size: clamp(0.62rem, 1.45vw, 0.84rem);
  font-weight: 950;
  line-height: 1.05;
}

.answer-card.is-correct {
  border-color: var(--teal);
  background: #e8faf4;
}

.answer-card.is-wrong {
  border-color: var(--coral);
  background: #ffeeea;
}

.runner-shadow {
  position: absolute;
  left: 50%;
  bottom: 3%;
  z-index: 2;
  width: 120px;
  height: 20px;
  border-radius: 50%;
  background: rgba(13, 21, 34, 0.22);
  filter: blur(4px);
  transform: translateX(-50%);
}

.helper-avatar {
  position: absolute;
  left: 50%;
  bottom: -12px;
  z-index: 2;
  width: clamp(64px, 9vw, 104px);
  height: clamp(104px, 16vw, 164px);
  object-fit: contain;
  transform: translateX(-50%);
  filter: drop-shadow(0 12px 18px rgba(13, 21, 34, 0.2));
}

.touch-controls {
  display: none;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 48px);
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.touch-controls button {
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 8px;
  background: var(--paper);
  color: #182234;
  font-size: 1.28rem;
  font-weight: 900;
  box-shadow: 0 8px 16px rgba(13, 21, 34, 0.14);
}

.touch-controls button[data-direction="up"] {
  grid-column: 2;
  grid-row: 1;
}

.touch-controls button[data-direction="left"] {
  grid-column: 1;
  grid-row: 2;
}

.touch-controls button[data-direction="down"] {
  grid-column: 2;
  grid-row: 2;
}

.touch-controls button[data-direction="right"] {
  grid-column: 3;
  grid-row: 2;
}

.snake-panel {
  display: grid;
  align-content: start;
  gap: 18px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 28px clamp(24px, 2vw, 34px);
  overflow-y: auto;
  border-left: 1px solid rgba(255, 255, 255, 0.34);
  background:
    linear-gradient(180deg, rgba(255, 248, 234, 0.96), rgba(238, 242, 209, 0.96)),
    var(--paper);
  box-shadow: -20px 0 50px rgba(25, 33, 46, 0.16);
}

.prototype-title h1 {
  margin: 0;
  font-size: 2.35rem;
  line-height: 1.05;
}

.prototype-title p,
.start-card p,
.completion-card p {
  margin: 0 0 7px;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.prototype-title span,
.coach-note span,
.rule-board p,
.empty-mistake,
.mistake-list li,
.completion-card > span,
.result-misses li {
  color: var(--muted);
  line-height: 1.45;
}

.coach-note,
.rule-board,
.mistake-board {
  padding: 16px;
  border: 1px solid rgba(22, 34, 55, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.coach-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.coach-note img {
  width: 64px;
  height: 94px;
  object-fit: contain;
  filter: drop-shadow(0 9px 12px rgba(25, 33, 46, 0.18));
}

.coach-note div {
  display: grid;
  gap: 5px;
}

.coach-note strong {
  color: #26384f;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.05rem;
}

.panel-heading span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(46, 159, 135, 0.12);
  color: #287b6d;
  font-size: 0.75rem;
  font-weight: 900;
}

.mistake-list {
  display: grid;
  gap: 8px;
}

.mistake-list ul,
.result-misses ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.panel-actions,
.completion-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 900;
}

.primary-action {
  background: var(--teal);
  color: #fff;
}

.secondary-action {
  background: rgba(22, 34, 55, 0.08);
  color: #26384f;
}

.start-panel,
.completion-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(13, 21, 34, 0.62);
}

.start-panel.is-hidden,
.completion-panel.is-hidden {
  display: none;
}

.start-card,
.completion-card {
  display: grid;
  gap: 16px;
  width: min(100%, 430px);
  max-height: min(92dvh, 760px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 58px rgba(13, 21, 34, 0.24);
}

.start-art {
  position: relative;
  height: 118px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(167, 220, 229, 0.72), rgba(244, 214, 145, 0.82)),
    #fff8ea;
}

.start-art img {
  position: absolute;
  bottom: -16px;
  height: 138px;
  object-fit: contain;
  filter: drop-shadow(0 12px 16px rgba(13, 21, 34, 0.18));
}

.start-art img:first-child {
  left: 44px;
}

.start-art img:nth-child(2) {
  right: 44px;
  transform: scaleX(-1);
}

.start-card h2,
.completion-card h2 {
  font-size: clamp(1.8rem, 7vw, 2.45rem);
  line-height: 1.02;
}

.completion-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.completion-stats strong,
.completion-stats span {
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
}

.result-misses {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.result-misses h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

@keyframes correct-flash {
  0% {
    opacity: 0;
    background: rgba(45, 155, 136, 0);
  }
  35% {
    opacity: 1;
    background: rgba(45, 155, 136, 0.34);
  }
  100% {
    opacity: 0;
    background: rgba(45, 155, 136, 0);
  }
}

@keyframes wrong-flash {
  0% {
    opacity: 0;
    background: rgba(223, 93, 80, 0);
  }
  35% {
    opacity: 1;
    background: rgba(223, 93, 80, 0.36);
  }
  100% {
    opacity: 0;
    background: rgba(223, 93, 80, 0);
  }
}

@media (max-width: 980px) {
  .snake-app {
    display: block;
    min-height: 100dvh;
    overflow: auto;
  }

  .snake-stage {
    min-height: 100dvh;
    gap: 9px;
    padding: 10px;
  }

  .stage-hud {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 0;
  }

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

  .score-strip span {
    min-width: 0;
    min-height: 38px;
    padding: 6px;
    font-size: 0.74rem;
  }

  .snake-scene {
    min-height: auto;
    aspect-ratio: 1;
  }

  #gameCanvas,
  .answer-layer {
    width: min(94vw, 48dvh, 430px);
  }

  .helper-avatar {
    display: none;
  }

  .touch-controls {
    display: grid;
  }

  .snake-panel {
    min-height: 0;
    padding: 18px;
    border-left: 0;
    box-shadow: none;
  }
}

@media (max-width: 520px) {
  .objective-chip strong {
    font-size: clamp(0.96rem, 4.4vw, 1.16rem);
  }

  .answer-card {
    padding: 3px;
  }

  .answer-card img {
    width: clamp(28px, 9vw, 42px);
    height: clamp(24px, 8vw, 38px);
  }

  .answer-place {
    font-size: clamp(0.48rem, 2.2vw, 0.58rem);
  }

  .answer-card strong {
    font-size: clamp(0.56rem, 2.75vw, 0.72rem);
  }

  .touch-controls {
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(2, 44px);
    gap: 7px;
  }

  .touch-controls button {
    min-height: 44px;
  }
}

@media (max-height: 700px) and (max-width: 980px) {
  .snake-stage {
    gap: 6px;
    padding: 8px;
  }

  .objective-chip {
    padding: 8px 10px;
  }

  .stage-feedback {
    min-height: 36px;
    padding: 8px 10px;
  }

  #gameCanvas,
  .answer-layer {
    width: min(92vw, 39dvh, 390px);
  }
}
