:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #647084;
  --line: #d9e2ed;
  --paper: #ffffff;
  --wash: #f4f8fb;
  --teal: #047c86;
  --teal-dark: #075b66;
  --coral: #df5267;
  --saffron: #f3b23c;
  --leaf: #2f9b70;
  --indigo: #4457a6;
  --violet: #7a4fb1;
  --shadow: 0 18px 44px rgba(23, 32, 51, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #eef6f8;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(140deg, rgba(243, 178, 60, 0.16), transparent 32%),
    linear-gradient(220deg, rgba(4, 124, 134, 0.14), transparent 40%),
    #f5fafb;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overflow-x: hidden;
}

button {
  font: inherit;
}

svg {
  display: block;
}

h1,
h2,
p,
strong,
span,
button {
  overflow-wrap: anywhere;
}

.game-app {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(217, 226, 237, 0.92);
  border-radius: var(--radius);
  box-shadow: 0 10px 26px rgba(23, 32, 51, 0.08);
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-copy {
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  place-items: center;
  color: #fff;
  background: var(--teal);
  border: 3px solid var(--saffron);
  border-radius: var(--radius);
  font-family: "Noto Serif Devanagari", Georgia, serif;
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.brand-copy p,
.section-kicker {
  margin: 0;
  color: var(--teal-dark);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.35rem, 2.6vw, 2.25rem);
  line-height: 1.05;
}

.hud-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-stat {
  display: grid;
  min-width: 72px;
  height: 52px;
  place-items: center;
  padding: 5px 8px;
  background: #f8fbfc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.hud-stat strong {
  color: var(--indigo);
  font-size: 1.16rem;
  line-height: 1;
}

.hud-stat span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
}

.icon-button,
.action-button,
.ghost-button,
.listen-button,
.choice-button,
.touch-action,
.move-pad button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    border-color 150ms ease,
    background 150ms ease;
}

.icon-button {
  width: 52px;
  height: 52px;
  padding: 0;
}

.icon-button svg,
.listen-button svg,
.touch-action svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.move-pad svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-button:hover,
.action-button:hover,
.ghost-button:hover,
.listen-button:hover,
.choice-button:hover,
.touch-action:hover,
.move-pad button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(23, 32, 51, 0.14);
}

.icon-button:active,
.action-button:active,
.ghost-button:active,
.listen-button:active,
.choice-button:active,
.touch-action:active,
.move-pad button:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 5px 12px rgba(23, 32, 51, 0.12);
}

.icon-button:focus-visible,
.action-button:focus-visible,
.ghost-button:focus-visible,
.listen-button:focus-visible,
.choice-button:focus-visible,
.touch-action:focus-visible,
.move-pad button:focus-visible {
  outline: 3px solid rgba(243, 178, 60, 0.72);
  outline-offset: 3px;
}

.adventure-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 360px);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.stage-panel,
.side-panel {
  min-width: 0;
}

.canvas-shell {
  position: relative;
  overflow: hidden;
  background: #dceff2;
  border: 1px solid rgba(217, 226, 237, 0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  touch-action: none;
}

.nearby-chip {
  position: absolute;
  left: var(--chip-x, 14px);
  top: var(--chip-y, 14px);
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: min(360px, calc(100% - 20px));
  padding: 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(217, 226, 237, 0.96);
  border-radius: var(--radius);
  box-shadow: 0 14px 30px rgba(23, 32, 51, 0.18);
  transform: translateX(-50%);
  animation: chipRise 220ms ease-out both;
}

.nearby-chip::before {
  position: absolute;
  top: -8px;
  left: 50%;
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.94);
  border-left: 1px solid rgba(217, 226, 237, 0.96);
  border-top: 1px solid rgba(217, 226, 237, 0.96);
  content: "";
  transform: translateX(-50%) rotate(45deg);
}

.nearby-chip.locked {
  background: rgba(248, 251, 252, 0.95);
}

.nearby-chip.locked strong {
  color: var(--muted);
}

.nearby-chip[hidden] {
  display: none;
}

.nearby-chip .action-button[hidden] {
  display: none;
}

.nearby-chip span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.nearby-chip strong {
  display: block;
  margin-top: 1px;
  font-family: "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  font-size: 1.38rem;
  line-height: 1.12;
}

.action-button,
.listen-button {
  min-width: 96px;
  padding: 0 14px;
  color: #fff;
  background: var(--indigo);
  border-color: var(--indigo);
  font-weight: 900;
}

.ghost-button {
  min-width: 112px;
  padding: 0 14px;
  color: var(--teal-dark);
  background: #f6fbfc;
  font-weight: 900;
}

.touch-controls {
  position: absolute;
  inset: auto 14px 14px auto;
  display: none;
  align-items: end;
  gap: 12px;
  pointer-events: none;
}

.move-pad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 5px;
  pointer-events: auto;
}

.move-pad button {
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  color: #fff;
  background: rgba(7, 91, 102, 0.86);
  border-color: rgba(255, 255, 255, 0.34);
  backdrop-filter: blur(9px);
}

.move-pad [data-dir="up"] {
  grid-column: 2;
  grid-row: 1;
}

.move-pad [data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.move-pad [data-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}

.move-pad [data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.touch-action {
  width: 58px;
  height: 58px;
  min-height: 58px;
  padding: 0;
  color: #fff;
  background: rgba(68, 87, 166, 0.9);
  border-color: rgba(255, 255, 255, 0.34);
  backdrop-filter: blur(9px);
  pointer-events: auto;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chapter-panel,
.mission-panel,
.phrase-panel,
.journal-panel {
  padding: 14px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(217, 226, 237, 0.95);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(23, 32, 51, 0.08);
}

.chapter-panel h2,
.journal-heading h2 {
  margin: 4px 0 0;
  font-size: 1.25rem;
  line-height: 1.12;
}

.chapter-panel > p:not(.section-kicker),
.mission-panel > p:not(.section-kicker),
.phrase-english {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.35;
}

.focus-row {
  display: flex;
  gap: 7px;
  margin-top: 12px;
}

.focus-heart {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: inset 0 -3px 0 rgba(23, 32, 51, 0.18);
}

.focus-heart.empty {
  background: #d9e2ed;
}

.chapter-progress {
  height: 12px;
  margin-top: 12px;
  overflow: hidden;
  background: #e7edf4;
  border-radius: 999px;
}

.chapter-progress div {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--leaf), var(--saffron), var(--coral));
  transition: width 220ms ease;
}

.phrase-panel {
  background: #fff8e4;
  border-color: #f3d17b;
}

.phrase-hindi {
  margin: 8px 0 3px;
  font-family: "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  font-size: clamp(1.7rem, 4vw, 2.55rem);
  font-weight: 950;
  line-height: 1.12;
}

.journal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#journalCount {
  display: grid;
  min-width: 38px;
  height: 38px;
  place-items: center;
  color: #fff;
  background: var(--coral);
  border-radius: var(--radius);
  font-weight: 950;
}

.journal-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 350px;
  margin: 12px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.journal-list li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: 7px;
  background: #f8fbfc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.journal-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #fff;
  background: var(--teal);
  border-radius: var(--radius);
  font-family: "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  font-size: 1.35rem;
  font-weight: 950;
}

.journal-word {
  display: block;
  font-family: "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  font-size: 1.22rem;
  font-weight: 950;
  line-height: 1.1;
}

.journal-meaning {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.challenge-overlay,
.victory-overlay,
.tutorial-overlay,
.path-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, 0.42);
}

.challenge-overlay[hidden],
.victory-overlay[hidden],
.tutorial-overlay[hidden],
.path-overlay[hidden] {
  display: none;
}

.challenge-card,
.victory-panel,
.tutorial-panel,
.path-panel {
  width: min(780px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border: 1px solid rgba(217, 226, 237, 0.98);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.challenge-card {
  padding: 16px;
}

.challenge-topline {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.challenge-topline h2,
.victory-panel h2 {
  margin: 4px 0 0;
  font-size: clamp(1.5rem, 4vw, 2.3rem);
  line-height: 1.08;
}

.close-button {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-height: 44px;
}

.challenge-main {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 124px;
  margin-top: 14px;
  padding: 12px;
  background: #eef8f9;
  border: 1px solid #cfe4e8;
  border-radius: var(--radius);
}

.challenge-art {
  display: grid;
  width: 84px;
  height: 84px;
  place-items: center;
  color: #fff;
  background: var(--teal);
  border: 3px solid var(--saffron);
  border-radius: var(--radius);
  font-family: "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  font-size: 2.35rem;
  font-weight: 950;
}

.challenge-copy p {
  margin: 0;
}

#challengePrompt {
  font-family: "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  font-size: clamp(1.35rem, 3.5vw, 2.2rem);
  font-weight: 950;
  line-height: 1.12;
}

#challengeHint {
  margin-top: 7px;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.35;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.choice-button {
  position: relative;
  justify-content: flex-start;
  min-height: 88px;
  padding: 12px 42px 12px 12px;
  text-align: left;
  background: #fff;
  border-width: 2px;
}

.choice-button[disabled] {
  cursor: default;
}

.choice-button.correct {
  color: #103d2f;
  background: #e8faef;
  border-color: var(--leaf);
  animation: choiceCorrect 520ms ease-out;
}

.choice-button.wrong {
  color: #761f2c;
  background: #fff0f2;
  border-color: var(--coral);
  animation: choiceWrong 420ms ease-out;
}

.choice-main {
  display: block;
  font-family: "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  font-size: clamp(1.35rem, 3vw, 2rem);
  font-weight: 950;
  line-height: 1.08;
}

.choice-sub {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.25;
}

.choice-index {
  position: absolute;
  top: 9px;
  right: 9px;
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  color: #fff;
  background: var(--teal);
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 950;
}

.challenge-feedback {
  min-height: 38px;
  margin: 12px 0 0;
  padding: 9px 10px;
  color: var(--muted);
  background: #f8fbfc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 850;
}

.challenge-feedback.good {
  color: #104a36;
  background: #e8faef;
  border-color: rgba(47, 155, 112, 0.55);
  animation: feedbackPop 520ms ease-out;
}

.challenge-feedback.careful {
  color: #7c2330;
  background: #fff0f2;
  border-color: rgba(223, 82, 103, 0.55);
  animation: feedbackPop 520ms ease-out;
}

.victory-panel {
  padding: 22px;
}

.tutorial-overlay {
  z-index: 30;
  background:
    radial-gradient(circle at 50% 24%, rgba(243, 178, 60, 0.26), transparent 30%),
    rgba(23, 32, 51, 0.48);
}

.tutorial-panel {
  width: min(720px, 100%);
  padding: 18px;
}

.tutorial-topline {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.tutorial-topline h2 {
  margin: 4px 0 0;
  font-size: clamp(1.7rem, 5vw, 2.55rem);
  line-height: 1.05;
}

.tutorial-steps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
  padding: 0;
  list-style: none;
}

.tutorial-steps li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  min-height: 120px;
  padding: 12px;
  background: #f8fbfc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tutorial-steps span {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #fff;
  background: var(--teal);
  border-radius: var(--radius);
  font-weight: 950;
}

.tutorial-steps h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.15;
}

.tutorial-steps p {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 760;
  line-height: 1.35;
}

.tutorial-start {
  width: 100%;
}

.path-overlay {
  z-index: 28;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 248, 228, 0.95), rgba(243, 178, 60, 0.28) 34%, rgba(23, 32, 51, 0.38) 72%);
}

.path-panel {
  width: min(520px, 100%);
  padding: 24px;
  text-align: center;
  animation: pathPop 980ms ease-out both;
}

.path-panel h2 {
  margin: 6px 0 0;
  color: var(--violet);
  font-size: clamp(2rem, 7vw, 3.4rem);
  line-height: 1;
}

.path-panel p:not(.section-kicker) {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 850;
}

.victory-panel p:not(.section-kicker) {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.45;
}

.victory-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.is-playing {
  animation: soundPulse 460ms ease-out;
}

@keyframes soundPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(243, 178, 60, 0.66);
  }

  100% {
    box-shadow: 0 0 0 14px rgba(243, 178, 60, 0);
  }
}

@keyframes chipRise {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(8px) scale(0.98);
  }

  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

@keyframes choiceCorrect {
  0% {
    transform: scale(1);
  }

  45% {
    transform: scale(1.035);
    box-shadow: 0 0 0 6px rgba(47, 155, 112, 0.16);
  }

  100% {
    transform: scale(1);
  }
}

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

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

  55% {
    transform: translateX(5px);
  }
}

@keyframes feedbackPop {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }

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

@keyframes pathPop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.9);
  }

  55% {
    opacity: 1;
    transform: translateY(0) scale(1.04);
  }

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

@media (hover: none), (max-width: 820px) {
  .touch-controls {
    display: flex;
  }
}

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

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

  .journal-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .game-app {
    width: 100%;
    max-width: 100vw;
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    max-width: 100%;
    min-width: 0;
  }

  .hud-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
    gap: 6px;
    width: 100%;
    min-width: 0;
  }

  .hud-stat {
    min-width: 0;
    height: 52px;
    padding-inline: 4px;
  }

  .hud-strip .icon-button {
    width: 100%;
    height: 46px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .adventure-layout,
  .stage-panel,
  .canvas-shell,
  .side-panel {
    max-width: 100%;
    min-width: 0;
  }

  .canvas-shell {
    border-radius: var(--radius);
  }

  #gameCanvas {
    height: clamp(300px, 78vw, 348px);
    min-height: 0;
    aspect-ratio: auto;
  }

  .nearby-chip {
    align-items: stretch;
    flex-direction: column;
    max-width: min(348px, calc(100% - 20px));
    gap: 8px;
    justify-content: space-between;
  }

  .nearby-chip > div {
    min-width: 0;
  }

  .nearby-chip strong {
    font-size: 1.15rem;
  }

  .nearby-chip .action-button {
    width: 100%;
    min-width: 78px;
    padding-inline: 10px;
  }

  .touch-controls {
    left: 10px;
    right: 10px;
    bottom: 10px;
    justify-content: space-between;
    transform: none;
  }

  .move-pad {
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
  }

  .move-pad button {
    width: 42px;
    height: 42px;
    min-height: 42px;
  }

  .touch-action {
    width: 54px;
    height: 54px;
    min-height: 54px;
  }

  .challenge-main,
  .choice-grid,
  .tutorial-steps {
    grid-template-columns: 1fr;
  }

  .challenge-art {
    width: 74px;
    height: 74px;
  }

  .listen-button {
    width: 100%;
  }

  .tutorial-steps li {
    min-height: 0;
  }
}

@media (max-width: 540px) {
  .game-app {
    margin-left: 0;
    margin-right: 0;
    width: min(100%, 390px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
