:root {
  --ink: #172033;
  --panel: rgba(255, 255, 255, 0.92);
  --line: rgba(23, 32, 51, 0.16);
  --mint: #63f2c6;
  --sky: #69d7ff;
  --gold: #ffcf4a;
  --coral: #ff6b6b;
  --grape: #755cff;
  --shadow: 0 18px 44px rgba(15, 22, 40, 0.22);
  font-family: Inter, ui-rounded, "Trebuchet MS", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 207, 74, 0.62), transparent 18rem),
    radial-gradient(circle at 82% 10%, rgba(105, 215, 255, 0.5), transparent 16rem),
    linear-gradient(135deg, #fc8f8f 0%, #82e8b6 48%, #79c9ff 100%);
  overscroll-behavior-y: auto;
  touch-action: pan-y manipulation;
}

html {
  scrollbar-gutter: stable;
}

body {
  -webkit-text-size-adjust: 100%;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.maze-app {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 78px 0 36px;
}

.screen {
  animation: riseIn 220ms ease both;
}

.overworld-screen {
  max-height: calc(100dvh - 86px);
  overflow-y: auto;
  padding-right: 8px;
  padding-bottom: 42px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.hidden {
  display: none !important;
}

.title-row,
.section-heading,
.maze-hud,
.endless-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.title-row {
  padding: 18px 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: #005f79;
  font-size: 0.78rem;
  font-weight: 1000;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.5rem, 7vw, 5.8rem);
  line-height: 0.9;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.5rem, 3.8vw, 2.4rem);
}

h3 {
  margin-bottom: 5px;
}

.intro {
  max-width: 780px;
  margin-bottom: 0;
  color: rgba(23, 32, 51, 0.76);
  font-size: clamp(1rem, 2vw, 1.22rem);
  line-height: 1.45;
}

.save-card,
.info-panel,
.planet-panel,
.shop-panel,
.endless-panel,
.maze-hud {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.save-card {
  min-width: 220px;
  padding: 14px;
}

.save-card span,
.stat-strip span,
.maze-hud span,
.upgrade-card span,
.difficulty-picker {
  display: block;
  color: rgba(23, 32, 51, 0.62);
  font-size: 0.74rem;
  font-weight: 1000;
  text-transform: uppercase;
}

.save-card strong,
.stat-strip strong,
.maze-hud strong {
  display: block;
  margin-top: 3px;
  font-size: 1.05rem;
}

.overworld-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 16px;
}

.planet-panel,
.info-panel,
.shop-panel,
.endless-panel {
  padding: 16px;
}

.world-map {
  display: grid;
  gap: 14px;
}

.world-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  border: 2px solid rgba(23, 32, 51, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.world-card.locked {
  opacity: 0.54;
}

.world-badge {
  width: 68px;
  height: 68px;
  border: 4px solid rgba(255, 255, 255, 0.65);
  border-radius: 50%;
  background: var(--planet-bg, linear-gradient(135deg, #69d7ff, #63f2c6));
  box-shadow: inset -10px -12px 0 rgba(23, 32, 51, 0.16), 0 8px 18px rgba(23, 32, 51, 0.18);
}

.world-card h3 {
  margin: 0 0 8px;
}

.maze-dots {
  display: grid;
  grid-template-columns: repeat(10, minmax(28px, 1fr));
  gap: 7px;
}

.maze-dot {
  min-height: 32px;
  border: 2px solid rgba(23, 32, 51, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  font-weight: 1000;
}

.maze-dot.done {
  background: var(--mint);
}

.maze-dot.current {
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(255, 207, 74, 0.26);
}

.maze-dot.locked {
  cursor: not-allowed;
  opacity: 0.44;
}

.map-actions,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: var(--ink);
  font-weight: 1000;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--gold), #ff8b45 58%, var(--coral));
  box-shadow: 0 8px 0 #b8435a, 0 16px 28px rgba(184, 67, 90, 0.24);
}

.secondary-button {
  border: 2px solid rgba(23, 32, 51, 0.14);
  background: #fff;
  box-shadow: 0 8px 16px rgba(23, 32, 51, 0.12);
}

.primary-button:hover,
.secondary-button:hover,
.maze-dot:not(.locked):hover {
  transform: translateY(-2px);
}

.primary-button:active,
.secondary-button:active,
.maze-dot:not(.locked):active {
  transform: translateY(1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.compact {
  min-height: 40px;
  padding: 0 12px;
}

.planet-preview {
  position: relative;
  min-height: 210px;
  overflow: hidden;
  border-radius: 8px;
  background:
    radial-gradient(circle at 24% 28%, #fff 0 2px, transparent 3px),
    radial-gradient(circle at 70% 38%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 42% 68%, #fff 0 2px, transparent 3px),
    linear-gradient(145deg, #172033, #3b2f79 58%, #115b84);
}

.orbit-ring,
.planet-orb,
.tiny-ship {
  position: absolute;
  display: block;
}

.orbit-ring {
  inset: 36px 44px;
  border: 2px dashed rgba(255, 255, 255, 0.34);
  border-radius: 50%;
  transform: rotate(-12deg);
}

.planet-orb {
  left: 50%;
  top: 50%;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: var(--planet-bg, linear-gradient(135deg, #69d7ff, #63f2c6));
  box-shadow: inset -18px -16px 0 rgba(23, 32, 51, 0.22);
  transform: translate(-50%, -50%);
}

.tiny-ship {
  right: 52px;
  top: 50px;
  width: 0;
  height: 0;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-left: 30px solid var(--gold);
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.2));
}

.twist-list {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.twist-pill {
  border-radius: 8px;
  padding: 10px;
  background: rgba(105, 215, 255, 0.16);
  font-weight: 900;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.stat-strip div {
  border: 2px solid rgba(23, 32, 51, 0.1);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.shop-panel,
.endless-panel {
  margin-top: 16px;
}

.section-heading p {
  max-width: 520px;
  margin-bottom: 0;
  color: rgba(23, 32, 51, 0.68);
  line-height: 1.4;
}

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

.upgrade-card {
  display: grid;
  gap: 10px;
  min-height: 210px;
  border: 2px solid rgba(23, 32, 51, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.78);
}

.upgrade-icon {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: var(--upgrade-bg, linear-gradient(135deg, var(--sky), var(--mint)));
  box-shadow: inset -8px -7px 0 rgba(23, 32, 51, 0.16);
}

.upgrade-card p {
  margin: 0;
  color: rgba(23, 32, 51, 0.7);
  font-size: 0.92rem;
  line-height: 1.35;
}

.upgrade-card button {
  align-self: end;
}

.endless-panel {
  align-items: end;
  background:
    radial-gradient(circle at 76% 40%, rgba(255, 255, 255, 0.12), transparent 8rem),
    linear-gradient(135deg, #101624, #3d2b72 55%, #0b0d14);
  color: #fff;
}

.endless-panel p {
  color: rgba(255, 255, 255, 0.78);
}

.endless-panel .eyebrow,
.endless-panel .difficulty-picker {
  color: var(--gold);
}

.difficulty-picker select {
  display: block;
  min-width: 150px;
  min-height: 46px;
  margin-top: 6px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 0 12px;
}

.maze-screen {
  display: grid;
  gap: 10px;
  min-height: calc(100vh - 78px);
  padding-bottom: 42px;
}

.maze-hud {
  position: relative;
  z-index: 2;
  flex-wrap: wrap;
  min-height: 62px;
  padding: 8px;
}

.maze-hud div {
  min-width: 82px;
  border-right: 2px solid rgba(23, 32, 51, 0.08);
  padding: 0 10px;
}

.maze-board-wrap {
  position: relative;
  display: grid;
  min-height: min(76vh, 760px);
  overflow: hidden;
  border: 3px solid rgba(23, 32, 51, 0.18);
  border-radius: 8px;
  background: #172033;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
}

#mazeCanvas {
  width: 100%;
  height: 100%;
  min-height: min(76vh, 760px);
  display: block;
  touch-action: none;
}

.control-note {
  border: 2px solid rgba(23, 32, 51, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.86);
  color: rgba(23, 32, 51, 0.72);
  font-weight: 900;
  text-align: center;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 5;
  border-radius: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.2);
  font-weight: 1000;
  transform: translateX(-50%);
}

.modal-screen {
  position: fixed;
  z-index: 1100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 76px 16px 20px;
  background: rgba(9, 15, 28, 0.56);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: min(560px, 100%);
  border: 2px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  padding: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-card.small {
  width: min(390px, 100%);
}

.modal-card h2 {
  margin-bottom: 12px;
}

.complete-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

@media (min-width: 681px) {
  body {
    overflow-y: scroll;
  }
}

.complete-stats div {
  border: 2px solid rgba(23, 32, 51, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.complete-stats span {
  display: block;
  color: rgba(23, 32, 51, 0.62);
  font-size: 0.75rem;
  font-weight: 1000;
  text-transform: uppercase;
}

.complete-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1.4rem;
}

.launch-scene {
  position: relative;
  min-height: 150px;
  overflow: hidden;
  border-radius: 8px;
  background:
    radial-gradient(circle at 22% 30%, #fff 0 2px, transparent 3px),
    radial-gradient(circle at 73% 24%, #fff 0 1px, transparent 2px),
    linear-gradient(135deg, #172033, #482b78);
}

.launch-planet,
.launch-ship {
  position: absolute;
  display: block;
}

.launch-planet {
  top: 46px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  box-shadow: inset -12px -12px 0 rgba(23, 32, 51, 0.18);
}

.launch-planet.from {
  left: 42px;
  background: linear-gradient(135deg, var(--sky), var(--mint));
}

.launch-planet.to {
  right: 42px;
  background: linear-gradient(135deg, var(--gold), var(--coral));
}

.launch-ship {
  left: 50%;
  top: 64px;
  width: 0;
  height: 0;
  border-top: 13px solid transparent;
  border-bottom: 13px solid transparent;
  border-left: 38px solid #fff;
  animation: shipPulse 1.2s ease-in-out infinite;
}

@keyframes shipPulse {
  50% {
    transform: translateX(10px) scale(1.08);
  }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .overworld-grid,
  .upgrade-grid {
    grid-template-columns: 1fr;
  }

  .upgrade-card {
    min-height: 0;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }

  .upgrade-card button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .maze-app {
    width: min(100% - 16px, 1180px);
    padding-top: 72px;
  }

  .overworld-screen {
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
  }

  .title-row,
  .section-heading,
  .endless-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .save-card {
    min-width: 0;
  }

  .maze-dots {
    grid-template-columns: repeat(5, minmax(36px, 1fr));
  }

  .world-card {
    grid-template-columns: 1fr;
  }

  .world-badge {
    width: 54px;
    height: 54px;
  }

  .stat-strip,
  .complete-stats {
    grid-template-columns: 1fr;
  }

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

  .maze-hud div {
    min-width: 0;
    border-right: 0;
  }

  .maze-hud button {
    grid-column: 1 / -1;
  }

  .maze-board-wrap,
  #mazeCanvas {
    min-height: min(70vh, 620px);
  }

  .primary-button,
  .secondary-button,
  .map-actions > * {
    width: 100%;
  }
}
