:root {
  color-scheme: dark;
  --bg: #070615;
  --panel: rgba(21, 18, 42, 0.82);
  --panel-strong: rgba(34, 27, 66, 0.96);
  --line: rgba(157, 127, 255, 0.28);
  --text: #f8f7ff;
  --muted: #a8a0c7;
  --accent: #8c66ff;
  --accent-2: #ff4f9f;
  --gold: #ffcb55;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(139, 95, 255, 0.2), transparent 34rem),
    radial-gradient(circle at 80% 35%, rgba(255, 67, 145, 0.14), transparent 32rem),
    #070615;
  color: var(--text);
}

body.map-open {
  overflow: hidden;
}

button {
  border: 1px solid rgba(177, 153, 255, 0.34);
  border-radius: 14px;
  background: rgba(34, 28, 64, 0.92);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  padding: 0 18px;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

button:hover {
  border-color: rgba(211, 197, 255, 0.74);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  color: rgba(248, 247, 255, 0.45);
  cursor: not-allowed;
  transform: none;
}

.primary {
  background: linear-gradient(135deg, #7454ff, #a95dff);
  border-color: rgba(221, 211, 255, 0.42);
  box-shadow: 0 18px 36px rgba(100, 63, 255, 0.25);
}

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.2vw, 2.4rem);
  line-height: 1.04;
}

.hud {
  align-items: stretch;
  background: rgba(12, 10, 25, 0.78);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  overflow: hidden;
}

.hud div {
  border-left: 1px solid rgba(177, 153, 255, 0.16);
  padding: 12px 18px;
  text-align: center;
}

.hud div:first-child {
  border-left: 0;
}

.hud span {
  color: var(--muted);
  display: block;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.hud strong {
  color: var(--text);
  display: block;
  font-size: 1.3rem;
  line-height: 1;
}

.stage-panel {
  background:
    linear-gradient(rgba(126, 94, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 94, 255, 0.08) 1px, transparent 1px),
    rgba(9, 7, 21, 0.94);
  background-size: 22px 22px;
  border: 1px solid rgba(177, 153, 255, 0.2);
  border-radius: 24px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.42),
    inset 0 0 0 1px rgba(255, 255, 255, 0.035);
  min-height: 520px;
  overflow: hidden;
  position: relative;
}

#gameCanvas {
  display: block;
  height: min(68vh, 650px);
  min-height: 520px;
  touch-action: none;
  width: 100%;
}

.complete-modal {
  align-items: center;
  background: rgba(4, 3, 13, 0.72);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: absolute;
}

.complete-modal[hidden] {
  display: none;
}

.modal-card {
  background:
    radial-gradient(circle at 50% 0%, rgba(140, 102, 255, 0.28), transparent 18rem),
    var(--panel-strong);
  border: 1px solid rgba(211, 197, 255, 0.28);
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  padding: 26px;
  text-align: center;
  width: min(420px, 100%);
}

.modal-card h2 {
  font-size: 1.7rem;
  margin-bottom: 10px;
}

.modal-card p {
  color: var(--muted);
  margin: 0;
}

.result-stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
  margin: 22px 0;
}

.result-stats span {
  background: rgba(7, 6, 21, 0.62);
  border: 1px solid rgba(177, 153, 255, 0.18);
  border-radius: 14px;
  color: var(--text);
  font-weight: 900;
  padding: 12px 8px;
}

.modal-actions,
.action-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-actions {
  flex-wrap: wrap;
}

.modal-actions button {
  flex: 1 1 108px;
}

.action-row {
  flex-wrap: wrap;
  margin: 14px 0;
}

.mobile-controls {
  display: none;
}

.map-panel {
  background:
    radial-gradient(circle at 24% 18%, rgba(121, 87, 255, 0.22), transparent 24rem),
    radial-gradient(circle at 78% 58%, rgba(255, 79, 159, 0.16), transparent 24rem),
    linear-gradient(rgba(126, 94, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 94, 255, 0.08) 1px, transparent 1px),
    #070615;
  background-size:
    auto,
    auto,
    26px 26px,
    26px 26px;
  inset: 0;
  overflow: auto;
  padding: min(6vw, 58px);
  position: fixed;
  z-index: 30;
}

.map-panel[hidden] {
  display: none;
}

.map-header {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin: 0 auto 34px;
  max-width: 1040px;
  width: 100%;
}

.map-header-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.map-header h2 {
  font-size: clamp(2rem, 4.8vw, 4.8rem);
  line-height: 0.95;
}

.map-header span {
  background: rgba(7, 6, 21, 0.66);
  border: 1px solid rgba(177, 153, 255, 0.18);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  padding: 8px 12px;
}

.level-map {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, minmax(250px, 1fr));
  margin: 0 auto;
  max-width: 1120px;
  width: 100%;
}

.map-chapter {
  background:
    linear-gradient(180deg, rgba(34, 28, 64, 0.78), rgba(12, 10, 25, 0.64)),
    rgba(12, 10, 25, 0.86);
  border: 1px solid rgba(177, 153, 255, 0.18);
  border-radius: 22px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  padding: 18px;
}

.chapter-title {
  align-items: flex-start;
  border-bottom: 1px solid rgba(177, 153, 255, 0.14);
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding-bottom: 14px;
}

.chapter-title span,
.chapter-title em,
.level-node em {
  color: var(--muted);
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-title strong {
  color: var(--text);
  font-size: 1.22rem;
  line-height: 1;
}

.chapter-levels {
  display: grid;
  gap: 12px 8px;
  grid-template-columns: repeat(5, minmax(46px, 1fr));
}

.level-node {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 132px;
  padding: 0;
  position: relative;
}

.level-node:hover {
  transform: translateY(-2px);
}

.level-orb {
  align-items: center;
  background: linear-gradient(145deg, #33245c, #1a1532);
  border: 1px solid rgba(177, 153, 255, 0.34);
  border-radius: 50%;
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  color: var(--text);
  display: flex;
  font-size: 0.96rem;
  font-weight: 950;
  height: 58px;
  justify-content: center;
  width: 58px;
}

.level-node.cleared .level-orb {
  background: linear-gradient(145deg, #ff8f3d, #8b5cff);
  border-color: rgba(255, 255, 255, 0.58);
  box-shadow:
    0 0 0 5px rgba(255, 203, 85, 0.12),
    0 16px 34px rgba(124, 87, 255, 0.32);
}

.level-node.active .level-orb {
  background: linear-gradient(145deg, #fff1a8, #ff7c35 52%, #7a5cff);
  border-color: rgba(255, 255, 255, 0.72);
  color: #fff;
  box-shadow:
    0 0 0 6px rgba(255, 203, 85, 0.16),
    0 0 30px rgba(255, 121, 75, 0.48);
}

.level-node.upcoming .level-orb {
  color: rgba(248, 247, 255, 0.42);
}

.level-stars {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 900;
  min-height: 16px;
}

.level-node small {
  color: var(--muted);
  display: block;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1.15;
  max-width: 92px;
  min-height: 32px;
}

.level-node em {
  color: rgba(168, 160, 199, 0.72);
  font-size: 0.56rem;
  letter-spacing: 0.03em;
  line-height: 1.15;
  max-width: 94px;
  text-transform: none;
}

.prototype-notes {
  background: rgba(12, 10, 25, 0.62);
  border: 1px solid rgba(177, 153, 255, 0.16);
  border-radius: 18px;
  color: var(--muted);
  line-height: 1.55;
  margin-top: 14px;
  padding: 14px 16px;
}

.prototype-notes strong {
  color: var(--text);
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 18px, 680px);
    padding-top: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .hud {
    grid-template-columns: repeat(3, 1fr);
  }

  .hud div {
    padding: 10px 8px;
  }

  .stage-panel {
    border-radius: 18px;
    min-height: 420px;
  }

  #gameCanvas {
    height: min(58vh, 540px);
    min-height: 420px;
  }

  .action-row button {
    flex: 1 1 calc(50% - 10px);
    padding: 0 10px;
  }

  .mobile-controls {
    align-items: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px auto;
    max-width: 360px;
  }

  .mobile-controls > div {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .mobile-controls button {
    min-height: 48px;
    padding: 0 10px;
  }

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

  .map-header-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .level-map {
    grid-template-columns: 1fr;
  }

  .chapter-levels {
    grid-template-columns: repeat(5, minmax(44px, 1fr));
  }

  .level-node {
    min-height: 124px;
  }

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