:root {
  --ink: #38210f;
  --cream: #fff6d8;
  --panel: rgba(255, 246, 216, 0.92);
  --line: #6b3c1c;
  --gold: #ffd44f;
  --coral: #ff7a5c;
  --green: #62c66a;
  --blue: #45b6d6;
  --shadow: 0 18px 44px rgba(71, 39, 18, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: #ffe08a url("assets/fairytale-path-bg.png") center / cover no-repeat fixed;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  caret-color: transparent;
  user-select: none;
}

.game-shell {
  position: relative;
  min-height: 100dvh;
  padding: clamp(12px, 2vw, 22px);
  background:
    linear-gradient(180deg, rgba(255, 250, 220, 0.18), rgba(255, 230, 155, 0.18)),
    linear-gradient(90deg, rgba(255, 246, 216, 0.64), transparent 28%, transparent 72%, rgba(255, 246, 216, 0.42));
}

.hud {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
}

.home-link,
.icon-button,
.start-back {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--cream);
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 950;
  text-decoration: none;
  box-shadow: 4px 5px 0 rgba(75, 42, 18, 0.82);
}

.start-back {
  width: auto;
  min-width: 94px;
  padding: 0 14px;
  background: linear-gradient(180deg, #fff6b7, #ffc94d);
  font-size: 1.15rem;
}

.hud-actions {
  display: flex;
  gap: 10px;
}

.play-only {
  display: none;
}

body.playing .play-only {
  display: grid;
}

.score {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 22px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff6b7, #ffc94d);
  color: #553100;
  font-size: clamp(1.3rem, 3vw, 2rem);
  font-weight: 950;
  box-shadow: 4px 5px 0 rgba(75, 42, 18, 0.82);
}

.screen {
  display: none;
}

.screen.active {
  display: grid;
}

.start-screen {
  min-height: calc(100dvh - 94px);
  grid-template-columns: minmax(0, 1fr) minmax(220px, 36vw);
  align-items: center;
  gap: clamp(14px, 3vw, 40px);
  padding: 0 clamp(6px, 5vw, 74px) 30px;
}

.start-copy {
  max-width: 680px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 9ch;
  color: #fff9ca;
  font-size: clamp(4rem, 10vw, 8.8rem);
  line-height: 0.86;
  letter-spacing: 0;
  text-shadow:
    0 5px 0 #9c431f,
    0 10px 22px rgba(60, 30, 10, 0.38);
}

h1 span {
  display: block;
  white-space: nowrap;
}

.start-copy p {
  width: fit-content;
  margin: 18px 0 26px;
  padding: 10px 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 246, 216, 0.92);
  font-size: clamp(1.2rem, 3vw, 2rem);
  font-weight: 900;
  box-shadow: 4px 5px 0 rgba(75, 42, 18, 0.82);
}

.menu-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 250px));
  gap: 14px;
}

.primary-button,
.read-button,
.check-button,
.level-grid button {
  min-height: 68px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffe889, #ffb43d);
  color: #3b210c;
  font-size: clamp(1.18rem, 2.3vw, 1.55rem);
  font-weight: 950;
  box-shadow: 5px 6px 0 rgba(75, 42, 18, 0.86);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.primary-button:hover,
.read-button:hover,
.check-button:hover,
.level-grid button:hover {
  transform: translate(2px, 2px);
  box-shadow: 3px 4px 0 rgba(75, 42, 18, 0.86);
  filter: saturate(1.08);
}

.primary-button.secondary {
  background: linear-gradient(180deg, #9eea89, #4fbd63);
}

.primary-button.expert {
  background: linear-gradient(180deg, #86d9ff, #38a9d0);
}

.primary-button.quiet {
  background: linear-gradient(180deg, #fff6d8, #ffd6a4);
}

.start-dragon {
  justify-self: center;
  width: min(36vw, 430px);
  max-height: 72dvh;
  object-fit: contain;
  filter: drop-shadow(0 18px 20px rgba(73, 38, 13, 0.28));
  animation: floaty 2.8s ease-in-out infinite;
}

.play-screen {
  width: min(1180px, 100%);
  min-height: calc(100dvh - 90px);
  margin: 0 auto;
  grid-template-rows: auto auto minmax(260px, 1fr) auto auto;
  gap: 12px;
}

.top-task {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.level-tag {
  display: inline-block;
  margin-bottom: 4px;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--green);
  color: #173812;
  font-weight: 950;
}

.top-task h2 {
  font-size: clamp(1.6rem, 4vw, 3.1rem);
  line-height: 1.05;
}

.read-button {
  flex: 0 0 auto;
  min-width: 132px;
  min-height: 62px;
  background: linear-gradient(180deg, #b5f0ff, #4fb7d4);
}

.read-button.is-speaking {
  animation: speakerPulse 780ms ease-in-out infinite;
  background: linear-gradient(180deg, #fff6b7, #ffc94d);
}

.progress-wrap {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 246, 216, 0.9);
  font-weight: 950;
}

.progress-bar {
  height: 22px;
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fff8cf;
}

.progress-bar span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue), var(--gold));
  transition: width 320ms ease;
}

.path-stage {
  position: relative;
  overflow: hidden;
  min-height: 300px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.number-path {
  position: absolute;
  inset: 0;
}

.number-path.countdown-path {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(78px, 118px));
  gap: clamp(8px, 1.3vw, 14px);
  align-content: start;
  justify-content: center;
  width: min(100%, 560px);
  margin: 32px auto 0;
  padding: clamp(8px, 1.4vw, 16px);
}

.tile {
  position: absolute;
  display: grid;
  place-items: center;
  width: clamp(64px, 11vw, 116px);
  height: clamp(58px, 9vw, 94px);
  border: 4px solid #74411d;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff9d8, #ffd166);
  color: #3b210c;
  font-size: clamp(1.55rem, 4vw, 3rem);
  font-weight: 950;
  box-shadow: 0 8px 0 #a85b2a, 0 15px 18px rgba(73, 38, 13, 0.18);
  caret-color: transparent;
  user-select: none;
}

.countdown-path .tile {
  position: static;
  width: 100%;
  height: clamp(70px, 8vw, 92px);
  min-width: 0;
  border: 3px solid #2d76b9;
  border-radius: 8px;
  background: #ffffff;
  color: #154b83;
  font-size: clamp(2rem, 4.2vw, 3.2rem);
  box-shadow: none;
}

.countdown-path .tile.filled {
  background: linear-gradient(180deg, #3479c8, #1f58ac);
  color: #ffffff;
  border-color: #1d5ba8;
}

.tile.mystery {
  background: linear-gradient(180deg, #fef8ff, #d9a9ff);
}

.countdown-path .tile.mystery {
  background: #ffffff;
}

.tile.correct-glow {
  animation: glow 540ms ease;
}

.dragon {
  position: absolute;
  left: 50%;
  top: 52%;
  width: clamp(118px, 18vw, 205px);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  transform: translate(-50%, -58%);
  filter: drop-shadow(0 15px 12px rgba(65, 35, 12, 0.28));
  transition: left 360ms ease, top 360ms ease;
  z-index: 3;
}

.dragon.hop {
  animation: hop 440ms ease;
}

.countdown-stage .dragon {
  width: clamp(92px, 14vw, 150px);
}

.feedback {
  min-height: 42px;
  padding: 8px 14px;
  font-size: clamp(1.05rem, 2.4vw, 1.35rem);
  font-weight: 900;
  text-align: center;
  text-shadow: 0 2px 10px rgba(255, 246, 216, 0.95);
}

.answer-area {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.answer-button {
  min-height: clamp(76px, 14vw, 116px);
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff4a8, #ffc94d);
  color: var(--ink);
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 950;
  box-shadow: 0 8px 20px rgba(75, 42, 18, 0.24);
  outline: 0;
  caret-color: transparent;
  user-select: none;
}

.answer-button:focus-visible {
  box-shadow:
    0 8px 20px rgba(75, 42, 18, 0.24),
    0 0 0 5px rgba(69, 182, 214, 0.48);
}

.answer-button.correct {
  background: linear-gradient(180deg, #d6ffba, #58d36c);
}

.answer-button.wrong,
.expert-form input.wrong {
  animation: shake 360ms ease;
  background: linear-gradient(180deg, #ffe5e0, #ff917b);
}

.expert-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.expert-form input {
  min-height: 76px;
  min-width: 0;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 950;
  text-align: center;
}

.check-button {
  min-width: 190px;
}

.hidden {
  display: none !important;
}

dialog {
  width: min(620px, calc(100% - 24px));
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(60, 34, 14, 0.42);
}

.dialog-card {
  position: relative;
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: var(--cream);
  box-shadow: var(--shadow);
}

.dialog-card h2 {
  font-size: 2rem;
}

.close-button {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 44px;
  height: 44px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 1.6rem;
  font-weight: 950;
}

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

.level-grid button {
  display: grid;
  align-content: center;
  gap: 4px;
  min-height: 86px;
}

.level-grid span {
  display: block;
  font-size: 0.9rem;
  font-weight: 800;
}

.toggle-row,
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 64px;
  padding: 10px 0;
  font-size: 1.35rem;
  font-weight: 900;
}

.toggle-row input {
  width: 34px;
  height: 34px;
}

.setting-row select {
  min-width: 150px;
  min-height: 48px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.reward {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.reward-message {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 18px 22px;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 246, 216, 0.96);
  box-shadow: var(--shadow);
  animation: pop 700ms ease;
}

.reward-message::before {
  content: "♛";
  position: absolute;
  margin-top: -18px;
  color: #ffcf30;
  font-size: 4rem;
  text-shadow: 0 3px 0 #8e4c19;
}

.reward-message img {
  width: 160px;
  height: 140px;
  object-fit: contain;
}

.reward-message strong {
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 1;
}

.reward-message span {
  font-size: 1.2rem;
  font-weight: 900;
}

.confetti,
.confetti::before,
.confetti::after {
  position: absolute;
  inset: 0;
  content: "";
  background-image:
    radial-gradient(circle, #ffd44f 0 6px, transparent 7px),
    radial-gradient(circle, #ff7a5c 0 5px, transparent 6px),
    radial-gradient(circle, #45b6d6 0 5px, transparent 6px),
    radial-gradient(circle, #62c66a 0 6px, transparent 7px);
  background-size: 160px 160px, 190px 190px, 220px 220px, 260px 260px;
  animation: confetti 1.8s linear infinite;
}

@keyframes floaty {
  0%,
  100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

@keyframes hop {
  0%,
  100% { transform: translate(-50%, -58%); }
  45% { transform: translate(-50%, -88%) rotate(-3deg); }
}

@keyframes shake {
  0%,
  100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-5px); }
}

@keyframes glow {
  0%,
  100% { filter: brightness(1); }
  50% { filter: brightness(1.35) drop-shadow(0 0 18px #fff17a); }
}

@keyframes speakerPulse {
  0%,
  100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

@keyframes pop {
  0% { transform: scale(0.72); opacity: 0; }
  70% { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes confetti {
  from { transform: translateY(-140px); }
  to { transform: translateY(140px); }
}

@media (max-width: 800px) {
  body {
    overflow: auto;
  }

  .game-shell {
    min-height: 100vh;
  }

  .start-screen {
    grid-template-columns: 1fr;
    align-content: center;
    text-align: center;
  }

  .start-copy {
    justify-self: center;
  }

  .start-copy p {
    margin-inline: auto;
  }

  .menu-buttons {
    grid-template-columns: 1fr;
  }

  .start-dragon {
    grid-row: 1;
    width: min(50vw, 230px);
    max-height: 28vh;
  }

  h1 {
    max-width: 12ch;
    font-size: clamp(3.25rem, 15vw, 4.6rem);
  }

  .top-task {
    align-items: stretch;
    flex-direction: column;
  }

  .read-button {
    width: 100%;
  }

  .path-stage {
    min-height: 270px;
  }

  .answer-area,
  .expert-form,
  .level-grid {
    grid-template-columns: 1fr;
  }

  .check-button {
    min-width: 0;
  }
}

@media (max-height: 720px) and (min-width: 801px) {
  .play-screen {
    gap: 8px;
  }

  .path-stage {
    min-height: 250px;
  }

  .answer-button {
    min-height: 72px;
  }
}
