:root {
  --bg: #050812;
  --phone: rgba(4, 7, 13, 0.98);
  --panel: rgba(9, 12, 21, 0.88);
  --panel-strong: rgba(3, 6, 12, 0.96);
  --footer: rgba(7, 12, 22, 0.86);
  --line: rgba(143, 241, 255, 0.28);
  --line-strong: rgba(148, 251, 255, 0.74);
  --ink: #effbff;
  --muted: #91b9cc;
  --cyan: #7df4ff;
  --cyan-soft: #c9fbff;
  --violet: #b15cff;
  --magenta: #f47aff;
  --amber: #ffc179;
  --danger: #ff744f;
  --cell: rgba(6, 9, 15, 0.96);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, transparent 0 8%, rgba(92, 231, 255, 0.11) 8.1% 8.4%, transparent 8.5% 74%, rgba(244, 122, 255, 0.08) 74.2% 74.5%, transparent 74.6%),
    linear-gradient(180deg, #101832 0%, #071022 42%, #050812 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.play-shell {
  width: min(1120px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding:
    max(clamp(42px, 6svh, 76px), env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.topbar {
  position: relative;
  z-index: 1;
  grid-area: topbar;
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #ffffff;
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 900;
  letter-spacing: 0;
  text-decoration: none;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(148, 251, 255, 0.28);
}

.brand::before {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(164, 247, 255, 0.9);
  border-radius: 5px;
  background:
    linear-gradient(135deg, transparent 0 38%, rgba(244, 122, 255, 0.98) 38% 62%, transparent 62% 100%),
    linear-gradient(45deg, transparent 0 43%, rgba(125, 244, 255, 0.95) 43% 57%, transparent 57% 100%),
    rgba(177, 92, 255, 0.18);
  box-shadow: 0 0 24px rgba(125, 244, 255, 0.28), 0 0 18px rgba(244, 122, 255, 0.18);
  content: "";
  transform: rotate(45deg);
}

.progress-chip {
  display: inline-flex;
  max-width: 100%;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--cyan-soft);
  background: rgba(1, 4, 9, 0.76);
  box-shadow: inset 0 0 18px rgba(125, 244, 255, 0.06);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.progress-chip span + span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.progress-chip span + span::before {
  width: 1px;
  height: 13px;
  background: rgba(148, 251, 255, 0.28);
  content: "";
}

.stage {
  position: relative;
  display: grid;
  min-width: 0;
  width: 100%;
  grid-template-columns: minmax(250px, 0.72fr) minmax(0, 1.28fr);
  grid-template-areas:
    "topbar topbar"
    "info board"
    "controls board"
    "levels board";
  gap: 14px;
  align-items: start;
  overflow: hidden;
  border: 1px solid rgba(125, 244, 255, 0.64);
  border-radius: 24px;
  padding: clamp(20px, 3vw, 34px);
  background:
    linear-gradient(160deg, rgba(17, 25, 44, 0.82), rgba(5, 7, 14, 0.97) 42%, rgba(8, 6, 15, 0.98)),
    var(--phone);
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.42),
    0 0 0 5px rgba(125, 244, 255, 0.07),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 0 46px rgba(125, 244, 255, 0.06);
}

.stage::before,
.stage::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
}

.stage::before {
  background:
    linear-gradient(90deg, transparent 0 8%, rgba(125, 244, 255, 0.25) 8.1% 26%, transparent 26.2% 69%, rgba(125, 244, 255, 0.16) 69.2% 91%, transparent 91.2%),
    linear-gradient(180deg, transparent 0 8%, rgba(125, 244, 255, 0.18) 8.1% 8.5%, transparent 8.6% 92%, rgba(244, 122, 255, 0.14) 92.1% 92.5%, transparent 92.6%);
  opacity: 0.72;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.9), transparent 26%, transparent 73%, rgba(0, 0, 0, 0.8));
}

.stage::after {
  inset: 16px;
  border: 1px solid rgba(125, 244, 255, 0.12);
  border-radius: 18px;
}

.stage > * {
  position: relative;
  min-width: 0;
  z-index: 1;
}

.level-panel {
  grid-area: info;
  display: flex;
  min-height: 224px;
  flex-direction: column;
  border: 1px solid rgba(148, 251, 255, 0.18);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  box-shadow: 0 18px 56px rgba(0, 0, 0, 0.26), inset 0 0 30px rgba(125, 244, 255, 0.04);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan-soft);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.level-panel h1 {
  margin: 0;
  min-height: 104px;
  color: #ffffff;
  font-size: clamp(32px, 4vw, 48px);
  line-height: 1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  text-shadow: 0 0 20px rgba(148, 251, 255, 0.2);
}

.level-panel p:last-child {
  min-height: 52px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.board-wrap {
  position: relative;
  grid-area: board;
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(125, 244, 255, 0.42);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(125, 244, 255, 0.08), transparent 32%),
    linear-gradient(180deg, rgba(2, 6, 11, 0.98), rgba(5, 5, 13, 0.98));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4), inset 0 0 48px rgba(125, 244, 255, 0.06);
  touch-action: manipulation;
}

canvas {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: auto;
  max-height: calc(100svh - 144px);
  aspect-ratio: 1;
}

.completion {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 10px;
  min-width: 170px;
  border: 1px solid rgba(244, 122, 255, 0.52);
  border-radius: 8px;
  padding: 12px;
  background: rgba(4, 6, 13, 0.9);
  box-shadow: 0 0 32px rgba(244, 122, 255, 0.2), inset 0 0 18px rgba(125, 244, 255, 0.06);
}

.completion[hidden] {
  display: none;
}

.completion p {
  margin: 0;
  color: var(--magenta);
  font-size: 13px;
  font-weight: 900;
}

.controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  border-radius: 8px;
  padding: 8px;
  background: var(--footer);
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(1, 4, 9, 0.9);
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, color 140ms ease, background 140ms ease;
}

button:hover:not(:disabled),
button:focus-visible {
  border-color: var(--line-strong);
  color: var(--cyan-soft);
  background: rgba(9, 24, 36, 0.98);
  box-shadow: 0 0 22px rgba(125, 244, 255, 0.12);
  outline: none;
  transform: translateY(-1px);
}

button:disabled {
  cursor: default;
  opacity: 0.42;
}

.primary-action {
  border-color: rgba(148, 251, 255, 0.58);
  color: #050812;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
}

.primary-action:hover:not(:disabled),
.primary-action:focus-visible {
  color: #050812;
  background: linear-gradient(90deg, var(--cyan-soft), #ffc4ff);
}

.level-select {
  grid-area: levels;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(34px, 1fr));
  gap: 6px;
  border: 1px solid rgba(148, 251, 255, 0.1);
  border-radius: 8px;
  padding: 8px;
  background: rgba(2, 5, 11, 0.64);
}

.level-select button {
  min-width: 0;
  min-height: 32px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.level-select button[aria-current="true"] {
  border-color: rgba(148, 251, 255, 0.82);
  color: var(--cyan-soft);
  background: rgba(11, 47, 63, 0.96);
  box-shadow: inset 0 0 18px rgba(125, 244, 255, 0.14);
}

.controls button {
  min-height: 44px;
  color: var(--cyan-soft);
  font-size: 23px;
  line-height: 1;
}

@media (max-width: 780px) {
  .play-shell {
    width: 100%;
    max-width: 100%;
    padding:
      max(34px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(18px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .stage {
    width: 100%;
    max-width: 358px;
    margin: 0 auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "info"
      "board"
      "controls"
      "levels";
    border-radius: 18px;
    padding: 16px;
  }

  .board-wrap {
    width: min(100%, calc(100vw - 64px), 300px);
    justify-self: center;
  }

  .level-panel {
    min-height: 176px;
    padding: 14px;
  }

  .level-panel h1 {
    min-height: 72px;
    font-size: 34px;
  }

  .level-panel p:last-child {
    min-height: 48px;
    font-size: 14px;
  }

  canvas {
    max-height: none;
  }

  .completion {
    right: 10px;
    bottom: 10px;
    min-width: 156px;
  }

  .progress-chip {
    width: 100%;
    flex-wrap: wrap;
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
