:root {
  color-scheme: light;
  --ink: #173d55;
  --muted: #667d89;
  --paper: #fffdf8;
  --line: #d8d3c4;
  --green: #4ca580;
  --green-dark: #26755c;
  --gold: #f5c657;
  --coral: #ef775d;
  --sea: #7bd3e3;
  --sand: #c9f0f3;
  --shadow: 0 16px 0 rgba(37, 48, 91, 0.13);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 14% 14%, rgba(116, 208, 232, 0.2), transparent 24rem),
    radial-gradient(circle at 86% 18%, rgba(133, 112, 213, 0.15), transparent 28rem),
    #f5f5ed;
}

button {
  font: inherit;
}

button,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 54px;
}

.loading-card {
  margin-top: 120px;
  padding: 48px;
  border: 3px solid var(--line);
  border-radius: 38px;
  background: var(--paper);
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
}

.page {
  display: grid;
  gap: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 3px solid #c7ded2;
  border-radius: 18px;
  background: #ecf7ef;
  font-size: 1.65rem;
  transform: rotate(-3deg);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.2rem;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-note {
  padding: 11px 16px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 253, 247, 0.88);
  color: var(--muted);
  font-weight: 800;
}

.hero,
.game-shell,
.result-card {
  border: 3px solid var(--line);
  border-radius: 42px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.82fr);
  min-height: 520px;
  overflow: hidden;
}

.hero-copy {
  min-width: 0;
  align-self: center;
  padding: 54px 24px 54px 54px;
}

.eyebrow {
  display: block;
  margin-bottom: 12px;
  color: #287963;
  font-family: Georgia, serif;
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 680px;
  margin-bottom: 20px;
  font-size: clamp(2.65rem, 5vw, 4.6rem);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.hero p,
.route-card p,
.task-subtitle,
.result-card p {
  color: var(--muted);
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.55;
}

.hero-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 28px;
}

.primary-button,
.secondary-button,
.route-button,
.control-button,
.hint-button,
.next-button {
  min-height: 54px;
  border-radius: 18px;
  padding: 13px 20px;
  font-weight: 900;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.primary-button,
.route-button,
.next-button {
  border: 2px solid var(--green);
  color: #fff;
  background: var(--green);
  box-shadow: 0 8px 0 var(--green-dark);
}

.primary-button:hover,
.route-button:hover,
.next-button:hover {
  background: #438f70;
}

.primary-button:focus-visible,
.secondary-button:focus-visible,
.route-button:focus-visible,
.control-button:focus-visible,
.hint-button:focus-visible,
.next-button:focus-visible,
.brand:focus-visible {
  outline: 4px solid rgba(241, 188, 69, 0.7);
  outline-offset: 3px;
}

.secondary-button,
.control-button,
.hint-button {
  border: 2px solid var(--line);
  color: var(--ink);
  background: #fffdf8;
}

.secondary-button:hover,
.control-button:hover,
.hint-button:hover {
  border-color: #c7af72;
  background: #fff7df;
}

.hero-art {
  min-width: 0;
  min-height: 100%;
  background: #d8f0ed;
}

.hero-art img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 53% center;
}

.routes-section {
  padding: 28px 0 4px;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.section-head h2 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  letter-spacing: -0.035em;
}

.section-head p {
  max-width: 420px;
  margin-bottom: 2px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
  text-align: right;
}

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

.route-card {
  --route-color: #4da37e;
  display: flex;
  min-height: 350px;
  flex-direction: column;
  padding: 26px;
  border: 3px solid var(--line);
  border-radius: 30px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--route-color) 12%, white), #fffdf7 58%);
  box-shadow: 0 10px 0 rgba(113, 91, 44, 0.14);
}

.route-symbol {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 22px;
  place-items: center;
  border: 3px solid color-mix(in srgb, var(--route-color) 45%, white);
  border-radius: 19px;
  background: #fff;
  font-size: 1.75rem;
}

.route-card h3 {
  margin-bottom: 12px;
  font-size: 1.65rem;
  line-height: 1.08;
}

.route-card p {
  margin-bottom: 22px;
}

.route-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  margin-bottom: 18px;
  color: var(--muted);
  font-weight: 900;
}

.route-progress-track {
  height: 10px;
  flex: 1;
  overflow: hidden;
  border-radius: 99px;
  background: #e5e0d3;
}

.route-progress-track i {
  display: block;
  width: var(--route-progress);
  height: 100%;
  border-radius: inherit;
  background: var(--route-color);
}

.route-button {
  width: 100%;
  border-color: var(--route-color);
  background: var(--route-color);
  box-shadow: 0 7px 0 color-mix(in srgb, var(--route-color) 72%, black);
}

.game-shell {
  padding: 32px;
}

.task-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 20px;
  margin-bottom: 24px;
}

.task-head h1 {
  margin-bottom: 10px;
  font-size: clamp(2.3rem, 4.6vw, 4.25rem);
}

.task-subtitle {
  margin-bottom: 0;
}

.task-progress {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 260px;
  padding-bottom: 8px;
}

.task-progress-track {
  height: 13px;
  flex: 1;
  overflow: hidden;
  border-radius: 99px;
  background: #e5e0d3;
}

.task-progress-track i {
  display: block;
  width: var(--task-progress);
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.task-progress strong {
  white-space: nowrap;
  font-size: 1.2rem;
}

.mission-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
  padding: 15px 20px;
  border: 2px solid #e6c768;
  border-radius: 20px;
  background: #fff5d5;
  font-weight: 900;
}

.mission-items {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.mission-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.78);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 22px;
  align-items: start;
}

.maze-panel {
  min-width: 0;
  padding: 18px;
  border: 3px solid #c8bd9f;
  border-radius: 28px;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.75), transparent 14rem),
    #8ed4dc;
}

.maze-board {
  --size: 7;
  --player-font: 5.429cqi;
  container-type: inline-size;
  display: grid;
  width: min(100%, 690px);
  aspect-ratio: 1;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  margin: 0 auto;
  overflow: hidden;
  border: 6px solid #fff8e6;
  border-radius: 22px;
  background: #171e58;
  box-shadow: 0 9px 0 rgba(25, 31, 81, 0.25);
  touch-action: none;
  user-select: none;
}

.maze-cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 0;
  background: transparent;
}

.maze-cell.wall {
  background:
    radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.17) 0 5%, transparent 6%),
    radial-gradient(circle at 72% 65%, rgba(123, 211, 227, 0.13) 0 10%, transparent 11%),
    linear-gradient(145deg, #313a78, #161c51);
}

.maze-cell.path {
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.42) 0 7%, transparent 8%),
    var(--sand);
}

.maze-cell.path::after {
  content: "";
  position: absolute;
  inset: 14%;
  border: 2px dashed rgba(31, 122, 145, 0.16);
  border-radius: 28%;
}

.maze-cell.trail {
  background: #a9e4ea;
}

.maze-cell.hint {
  z-index: 1;
  box-shadow: inset 0 0 0 5px rgba(241, 188, 69, 0.82);
  animation: hint-glow 1s ease-in-out infinite alternate;
}

@keyframes hint-glow {
  to {
    box-shadow: inset 0 0 0 5px rgba(255, 226, 126, 0.45);
  }
}

.cell-object {
  position: relative;
  z-index: 3;
  display: grid;
  width: 72%;
  aspect-ratio: 1;
  place-items: center;
  line-height: 1;
  font-size: var(--player-font);
  filter: drop-shadow(0 3px 1px rgba(80, 65, 34, 0.2));
}

.cell-object.player {
  width: 64%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--coral);
  font-size: var(--player-font);
}

.cell-object.planet.locked {
  filter: grayscale(0.35) drop-shadow(0 3px 1px rgba(80, 65, 34, 0.2));
  opacity: 0.72;
}

.cell-object.beacon {
  width: 62%;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--gold);
  color: #173d55;
  font-weight: 900;
  box-shadow: 0 0 0 3px rgba(245, 198, 87, 0.3);
}

.cell-object.star,
.cell-object.planet {
  width: 68%;
}

.cell-object.collected {
  display: none;
}

.maze-status {
  min-height: 64px;
  margin-top: 14px;
  padding: 14px 16px;
  border: 2px solid #d9d2bf;
  border-radius: 18px;
  background: #fffdf8;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.35;
}

.maze-status.notice {
  border-color: #e6c768;
  background: #fff5d5;
  color: #745717;
}

.maze-status.success {
  border-color: #85bda5;
  background: #ebf7ef;
  color: var(--green-dark);
}

.side-panel {
  display: grid;
  gap: 18px;
}

.map-card,
.controls-card {
  padding: 20px;
  border: 2px solid var(--line);
  border-radius: 24px;
  background: #fffdf8;
}

.map-card h2,
.controls-card h2 {
  margin-bottom: 10px;
  font-size: 1.28rem;
}

.map-card p,
.controls-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
}

.key-row,
.coin-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.key-mark,
.coin-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 2px solid #d8cfb9;
  border-radius: 12px;
  background: #eee9dd;
  filter: grayscale(1);
  opacity: 0.55;
}

.key-mark {
  border-radius: 50%;
  color: #173d55;
  font-weight: 900;
}

.key-mark.found,
.coin-mark.found {
  border-color: #e0b23e;
  background: #fff2bd;
  filter: none;
  opacity: 1;
}

.dpad {
  display: grid;
  width: 190px;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 16px auto 0;
}

.control-button {
  display: grid;
  min-height: 56px;
  place-items: center;
  padding: 8px;
  font-size: 1.35rem;
}

.control-button[data-direction="up"] {
  grid-column: 2;
}

.control-button[data-direction="left"] {
  grid-column: 1;
}

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

.control-button[data-direction="right"] {
  grid-column: 3;
}

.hint-button {
  width: 100%;
}

.game-actions {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
}

.next-button {
  display: none;
}

.next-button.visible {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.result-card {
  padding: 62px;
  text-align: center;
}

.result-icon {
  display: grid;
  width: 94px;
  height: 94px;
  margin: 0 auto 22px;
  place-items: center;
  border-radius: 30px;
  background: #fff0b3;
  font-size: 3.4rem;
  transform: rotate(-3deg);
}

.result-card h1 {
  max-width: none;
}

.result-card p {
  max-width: 720px;
  margin-right: auto;
  margin-left: auto;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  max-width: 820px;
  margin: 30px auto;
}

.result-stat {
  padding: 20px 12px;
  border: 2px solid #cfe1d7;
  border-radius: 20px;
  background: #edf7ef;
}

.result-stat strong,
.result-stat span {
  display: block;
}

.result-stat strong {
  margin-bottom: 4px;
  font-size: 1.9rem;
}

.result-stat span {
  color: var(--muted);
  font-weight: 800;
}

.result-actions {
  justify-content: center;
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero-copy {
    padding: 42px;
  }

  .hero-art {
    min-height: 360px;
    order: -1;
  }

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

  .route-card {
    min-height: auto;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

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

  .hint-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding-top: 14px;
  }

  .top-note {
    display: none;
  }

  .hero,
  .game-shell,
  .result-card {
    border-radius: 30px;
  }

  .hero-copy,
  .game-shell,
  .result-card {
    padding: 26px;
  }

  .hero-copy,
  .hero-copy h1,
  .hero-copy p,
  .eyebrow {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .hero-art {
    min-height: 270px;
  }

  .section-head,
  .task-head,
  .mission-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .section-head {
    display: block;
  }

  .section-head p {
    margin-top: 10px;
    text-align: left;
  }

  .task-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .task-progress {
    width: 100%;
    min-width: 0;
  }

  .mission-strip {
    display: flex;
  }

  .mission-items {
    white-space: normal;
  }

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

  .maze-panel {
    padding: 9px;
  }

  .maze-board {
    border-width: 4px;
    border-radius: 16px;
  }

  .maze-cell.path::after {
    display: none;
  }

  .cell-object {
    font-size: clamp(0.66rem, 5.2vw, 1.75rem);
  }

  .cell-object.player {
    border-width: 2px;
    font-size: clamp(0.72rem, 5.6vw, 1.85rem);
  }

  .game-actions {
    flex-direction: column;
  }

  .game-actions > * {
    width: 100%;
  }

  .hero-actions > * {
    max-width: 100%;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .brand strong {
    font-size: 1rem;
  }

  .brand-icon {
    width: 48px;
    height: 48px;
  }

  h1 {
    font-size: 2.45rem;
  }

  .hero-copy,
  .game-shell,
  .result-card {
    padding: 20px;
  }

  .hero-art {
    min-height: 230px;
  }

  .route-card {
    padding: 22px;
  }

  .mission-items {
    flex-direction: column;
    align-items: flex-start;
  }

  .dpad {
    width: 180px;
  }
}

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