:root {
  color-scheme: light;
  font-family: "Tahoma", "Arial", sans-serif;
  color: #183b32;
  background: #f4fbf3;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --green: #258354;
  --dark-green: #174d39;
  --light-green: #eaf6e9;
  --yellow: #ffd76a;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 8% 9%, #e0f3da 0, transparent 28rem),
    radial-gradient(ellipse at 95% 77%, #fff2cc 0, transparent 25rem),
    #f4fbf3;
}

button {
  font: inherit;
}

.game-shell {
  width: min(100% - 28px, 760px);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 0 max(20px, env(safe-area-inset-bottom));
}

.topbar,
.brand,
.sound-toggle,
.maze-heading,
.progress-copy,
.topbar-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
}

.topbar-actions {
  gap: 8px;
}

.brand {
  gap: 8px;
  color: var(--dark-green);
  font-size: 0.95rem;
  font-weight: 900;
  text-decoration: none;
}

.brand-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 13px;
  background: #ffedb0;
  font-size: 1.2rem;
}

.sound-toggle {
  min-height: 40px;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid #dcebd9;
  border-radius: 999px;
  background: #fff;
  color: var(--dark-green);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.levels-button {
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid #dcebd9;
  border-radius: 999px;
  background: #fff;
  color: var(--dark-green);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.intro {
  padding: 18px 4px 17px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 800;
}

h1 {
  margin: 0;
  color: #173f32;
  font-size: clamp(1.55rem, 6vw, 2.3rem);
  font-weight: 900;
  line-height: 1.4;
}

.intro > p:last-child {
  margin: 7px auto 0;
  color: #567267;
  font-size: clamp(0.86rem, 3.3vw, 1rem);
  line-height: 1.8;
}

.game-card {
  overflow: hidden;
  border: 1px solid #e6eee1;
  border-radius: 26px;
  background: #fff;
  box-shadow: 0 16px 45px #24583712, 0 3px 9px #24583708;
}

.level-screen {
  overflow: hidden;
  padding: 20px;
  border: 1px solid #e6eee1;
  border-radius: 26px;
  background: #fff;
  box-shadow: 0 16px 45px #24583712, 0 3px 9px #24583708;
}

.level-screen[hidden],
.game-card[hidden] {
  display: none;
}

.level-screen-heading {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 17px;
}

.level-screen-emoji {
  display: grid;
  flex: 0 0 50px;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 17px;
  background: #fff3d1;
  font-size: 1.7rem;
}

.level-screen-heading h2 {
  margin: 0;
  color: #183b32;
  font-size: 1.15rem;
  font-weight: 900;
}

.level-screen-heading p {
  margin: 2px 0 0;
  color: #698074;
  font-size: 0.83rem;
  font-weight: 600;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.level-card {
  display: flex;
  min-width: 0;
  min-height: 139px;
  flex-direction: column;
  align-items: flex-start;
  padding: 12px;
  overflow: hidden;
  border: 2px solid #e7efe2;
  border-radius: 18px;
  background: #f7fbf4;
  color: var(--dark-green);
  text-align: right;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.level-card:not(:disabled):hover {
  transform: translateY(-2px);
  border-color: #9bcf98;
  box-shadow: 0 5px 14px #21563813;
}

.level-card:focus-visible,
.levels-button:focus-visible,
.answer-button:focus-visible,
.primary-button:focus-visible,
.restart-button:focus-visible,
.sound-toggle:focus-visible {
  outline: 3px solid #f2bd42;
  outline-offset: 2px;
}

.level-card.locked {
  border-color: #edf0e9;
  background: #f5f6f3;
  color: #87968a;
  cursor: not-allowed;
}

.level-card.coral:not(.locked) { border-color: #f0d8cb; background: #fff7f2; }
.level-card.blue:not(.locked) { border-color: #d5e4f5; background: #f3f8ff; }
.level-card.green:not(.locked) { border-color: #d5ead8; background: #f3fbf3; }
.level-card.purple:not(.locked) { border-color: #e5daf1; background: #faf6ff; }
.level-card.gold:not(.locked) { border-color: #eee3c6; background: #fffbf0; }
.level-card.pink:not(.locked) { border-color: #f1d9e1; background: #fff6f9; }

.level-number {
  font-size: 0.72rem;
  font-weight: 800;
}

.level-card-icon {
  margin-top: 3px;
  font-size: 1.55rem;
  line-height: 1.2;
}

.level-name {
  margin-top: 2px;
  font-size: clamp(0.83rem, 3.6vw, 1rem);
  font-weight: 900;
}

.level-stars {
  margin-top: 2px;
  color: #eaaa32;
  font-size: 0.84rem;
  letter-spacing: 1px;
  line-height: 1.25;
}

.level-info {
  margin-top: 2px;
  color: #698074;
  font-size: 0.67rem;
  font-weight: 700;
  line-height: 1.35;
}

.level-screen-tip {
  margin: 15px 0 0;
  color: #587467;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.7;
  text-align: center;
}

.game-status {
  padding: 17px 20px 12px;
}

.level-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 13px;
}

.level-icon {
  font-size: 1.3rem;
}

.level-heading {
  color: #315849;
  font-size: 0.82rem;
  font-weight: 900;
}

.level-chip {
  margin-right: auto;
  padding: 4px 10px;
  border-radius: 99px;
  background: #f1f6ed;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
}

.progress-copy {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  color: #587467;
  font-size: 0.82rem;
  font-weight: 800;
}

#progress-count {
  color: var(--green);
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: #edf3e9;
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #63bd6c, #2f9b61);
  transition: width 500ms ease;
}

.maze-wrap {
  padding: 11px 16px 15px;
  background: linear-gradient(180deg, #f8fcf6, #f1f8ed);
}

.maze-heading {
  justify-content: space-between;
  gap: 4px;
  margin: 0 auto 10px;
  color: #668072;
  font-size: clamp(0.65rem, 2.9vw, 0.78rem);
  font-weight: 800;
}

.maze {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  gap: clamp(2px, 0.8vw, 5px);
  width: min(100%, 420px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: clamp(5px, 1.8vw, 9px);
  border: 2px solid #d5e8d0;
  border-radius: 18px;
  background: #dcebd6;
  box-shadow: inset 0 2px 5px #315f3610;
}

.maze-cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border-radius: 6px;
  background: #9fbd9a;
}

.maze-cell.path {
  background: #fffdf5;
  box-shadow: inset 0 0 0 1px #e9e5d6;
}

.maze-cell.exit {
  background: #fff1bd;
  box-shadow: inset 0 0 0 2px #f2cb58;
  font-size: clamp(0.85rem, 4.4vw, 1.35rem);
}

.checkpoint {
  color: #e7b944;
  font-size: clamp(0.65rem, 3.4vw, 1rem);
  opacity: 0.55;
}

.checkpoint.current {
  color: #f2a900;
  opacity: 1;
  animation: twinkle 1.2s ease-in-out infinite alternate;
}

.heroes {
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: visible;
  border-radius: 7px;
  background: #ffedaf;
  box-shadow: 0 1px 5px #594b1e32;
  animation: arrive 450ms cubic-bezier(.2, .9, .3, 1.3);
}

.hero-faces {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.8rem, 4.5vw, 1.25rem);
  line-height: 1;
}

.hero-names {
  overflow: hidden;
  max-width: 100%;
  color: #57451b;
  font-size: clamp(0.38rem, 1.6vw, 0.52rem);
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
}

.quiz {
  padding: 18px 20px 21px;
  text-align: center;
}

.question-number {
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 900;
}

.question-category {
  width: fit-content;
  margin: 4px auto 0;
  padding: 3px 10px;
  border-radius: 99px;
  background: #f0f7ed;
  color: #438354;
  font-size: 0.72rem;
  font-weight: 800;
}

.quiz h2 {
  margin: 4px auto 15px;
  color: #183b32;
  font-size: clamp(1.15rem, 4.4vw, 1.55rem);
  font-weight: 900;
  line-height: 1.55;
}

.answers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

.answer-button {
  min-height: 51px;
  padding: 8px 7px;
  border: 2px solid #dcebdd;
  border-radius: 15px;
  background: #fff;
  color: #315849;
  font-size: clamp(0.83rem, 3.1vw, 1rem);
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

.answer-button:not(:disabled):active,
.primary-button:active,
.restart-button:active {
  transform: scale(0.97);
}

.answer-button:not(:disabled):hover {
  border-color: #71b978;
  background: #f3fbf1;
}

.answer-button:focus-visible,
.primary-button:focus-visible,
.restart-button:focus-visible,
.sound-toggle:focus-visible,
.levels-button:focus-visible {
  outline: 3px solid #f2bd42;
  outline-offset: 2px;
}

.answer-button:disabled {
  cursor: default;
}

.answer-button.correct {
  border-color: #67b879;
  background: #eaf8eb;
  color: #20643b;
}

.answer-button.incorrect {
  border-color: #ef9d83;
  background: #fff0eb;
  color: #9d412b;
  animation: shake 300ms ease-in-out;
}

.feedback {
  min-height: 26px;
  margin: 10px 0 2px;
  color: #38804f;
  font-size: 0.9rem;
  font-weight: 800;
}

.feedback.error {
  color: #a84d35;
}

.primary-button,
.restart-button {
  min-height: 52px;
  padding: 10px 24px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, #37a766, #27834f);
  box-shadow: 0 5px 0 #1d6d40, 0 8px 15px #24874d24;
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

.primary-button:hover,
.restart-button:hover {
  filter: brightness(1.05);
}

.primary-button[hidden],
.restart-button[hidden],
.next-level-button[hidden],
.answers:empty {
  display: none;
}

.restart-button {
  background: linear-gradient(135deg, #f4bd43, #e99c27);
  box-shadow: 0 5px 0 #bf791a, 0 8px 15px #bc801f24;
  color: #513b13;
}

footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 12px;
  padding: 15px 4px 0;
  color: #678073;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
}

.privacy-link {
  color: #567267;
  font-size: 0.73rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.privacy-link:focus-visible {
  outline: 3px solid #f2bd42;
  outline-offset: 3px;
}

@keyframes arrive {
  from { transform: scale(0.75); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes twinkle {
  from { transform: scale(0.9); }
  to { transform: scale(1.2); }
}

@keyframes shake {
  25% { transform: translateX(4px); }
  75% { transform: translateX(-4px); }
}

@media (min-width: 600px) {
  .game-shell {
    padding-top: 20px;
  }

  .intro {
    padding: 24px 4px 22px;
  }

  .maze-wrap {
    padding: 15px 24px 20px;
  }

  .quiz {
    padding: 22px 36px 27px;
  }

  .level-screen {
    padding: 26px;
  }

  .level-grid {
    gap: 14px;
  }

  .level-card {
    min-height: 152px;
    padding: 15px;
  }
}

@media (max-width: 380px) {
  .game-shell {
    width: calc(100% - 20px);
  }

  .brand {
    gap: 6px;
    font-size: 0.82rem;
  }

  .topbar-actions {
    gap: 5px;
  }

  .levels-button,
  .sound-toggle {
    min-height: 38px;
    padding: 5px 9px;
    font-size: 0.71rem;
  }

  .level-screen {
    padding: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
