* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --page-bg: #030407;
  --page-bg-lift: #111f39;
  --root-panel: rgba(5, 8, 13, 0.56);
  --board-panel: rgba(8, 12, 18, 0.94);
  --footer-panel: rgba(8, 14, 22, 0.78);
  --tile: rgba(13, 20, 30, 0.98);
  --tile-fixed: rgba(8, 13, 20, 0.96);
  --tile-powered: rgba(10, 27, 40, 0.98);
  --tile-empty: rgba(4, 8, 12, 0.72);
  --primary: #f0f8ff;
  --secondary: #a6bedb;
  --solved: #8cffcc;
  --cyan: #5cf5ff;
  --cyan-strong: #74f8ff;
  --cyan-soft: #2fc6da;
  --source: #ffc254;
  --target: #ff59b8;
  --button: #132b40;
  --button-disabled: rgba(6, 8, 13, 0.78);
  --panel-border: rgba(92, 245, 255, 0.16);
  --board-border: rgba(92, 245, 255, 0.42);
  --button-border: rgba(163, 238, 255, 0.26);
  --shadow: rgba(0, 1, 4, 0.72);
  --shell-pad: clamp(12px, 2vw, 22px);
}

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

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(160deg, rgba(18, 35, 64, 0.94) 0%, rgba(7, 13, 24, 0.98) 46%, var(--page-bg) 100%),
    var(--page-bg);
  color: var(--primary);
  font-family: "Avenir Next", "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    linear-gradient(90deg, transparent 0 17%, rgba(54, 211, 235, 0.20) 17.1% 17.35%, transparent 17.45% 100%),
    linear-gradient(0deg, transparent 0 76%, rgba(54, 211, 235, 0.18) 76.1% 76.32%, transparent 76.42% 100%),
    linear-gradient(90deg, transparent 0 78%, rgba(54, 211, 235, 0.16) 78.1% 78.32%, transparent 78.42% 100%),
    linear-gradient(180deg, rgba(18, 33, 58, 0.64), rgba(2, 4, 8, 0.92));
  opacity: 0.66;
  pointer-events: none;
}

button,
a {
  font: inherit;
}

a {
  color: var(--cyan);
}

.play-shell {
  width: min(1180px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.play-header {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 12px;
  color: var(--primary);
  font-size: 22px;
  font-weight: 900;
  text-decoration: none;
  text-shadow: 0 2px 0 var(--shadow);
}

.brand-mark {
  position: relative;
  width: 30px;
  height: 30px;
  border: 2px solid rgba(92, 245, 255, 0.72);
  border-radius: 10px;
  background:
    linear-gradient(90deg, transparent 0 41%, var(--cyan) 41% 59%, transparent 59% 100%),
    linear-gradient(0deg, transparent 0 41%, var(--source) 41% 59%, transparent 59% 100%),
    #050b12;
  box-shadow:
    0 0 18px rgba(92, 245, 255, 0.46),
    inset 0 0 18px rgba(92, 245, 255, 0.14);
}

.brand-mark::before,
.brand-mark::after {
  position: absolute;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  content: "";
  transform: translateY(-50%);
}

.brand-mark::before {
  left: -5px;
  background: var(--source);
  box-shadow: 0 0 12px rgba(255, 194, 84, 0.62);
}

.brand-mark::after {
  right: -5px;
  background: var(--target);
  box-shadow: 0 0 12px rgba(255, 89, 184, 0.62);
}

.level-meta {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--secondary);
  font-size: 14px;
  font-weight: 900;
}

.meta-chip {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--button-border);
  border-radius: 999px;
  padding: 0 14px 0 12px;
  background: rgba(19, 43, 64, 0.68);
  box-shadow:
    0 12px 26px rgba(0, 0, 0, 0.22),
    inset 0 0 16px rgba(92, 245, 255, 0.07);
}

.meta-icon,
.button-icon {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  color: var(--primary);
}

.stage-icon::before {
  position: absolute;
  left: 5px;
  top: 3px;
  width: 3px;
  height: 16px;
  border-radius: 3px;
  background: currentColor;
  content: "";
}

.stage-icon::after {
  position: absolute;
  left: 8px;
  top: 4px;
  width: 11px;
  height: 9px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 25%, 0 100%);
  content: "";
}

.moves-icon::before,
.moves-icon::after {
  position: absolute;
  content: "";
}

.moves-icon::before {
  left: 4px;
  top: 10px;
  width: 15px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(22deg);
  transform-origin: center;
}

.moves-icon::after {
  left: 2px;
  top: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow:
    8px 5px 0 currentColor,
    15px 0 0 currentColor;
}

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 330px);
  align-items: stretch;
  gap: 18px;
}

.board-wrap {
  position: relative;
  isolation: isolate;
  min-height: min(74vh, 760px);
  border: 2px solid var(--board-border);
  border-radius: clamp(24px, 3vw, 38px);
  padding: var(--shell-pad);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(13, 25, 39, 0.92), rgba(3, 6, 11, 0.98)),
    var(--board-panel);
  box-shadow:
    0 26px 90px rgba(0, 0, 0, 0.46),
    0 0 34px rgba(92, 245, 255, 0.25),
    inset 0 0 0 1px rgba(116, 248, 255, 0.16),
    inset 0 0 46px rgba(92, 245, 255, 0.08);
}

.board-wrap::before,
.board-wrap::after {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  content: "";
}

.board-wrap::before {
  inset: 10px;
  border: 1px solid rgba(92, 245, 255, 0.22);
  border-radius: calc(clamp(24px, 3vw, 38px) - 9px);
}

.board-wrap::after {
  left: 24%;
  right: 24%;
  bottom: 11px;
  height: 3px;
  border-radius: 999px;
  background: rgba(92, 245, 255, 0.34);
  box-shadow: 0 0 14px rgba(92, 245, 255, 0.24);
}

canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  min-height: min(74vh, 760px);
  border-radius: clamp(12px, 2vw, 22px);
  background: #03070b;
  box-shadow:
    inset 0 0 0 1px rgba(92, 245, 255, 0.08),
    inset 0 0 42px rgba(0, 0, 0, 0.62);
  touch-action: manipulation;
  cursor: pointer;
}

.complete-banner {
  position: absolute;
  left: 50%;
  bottom: calc(var(--shell-pad) + 18px);
  z-index: 3;
  width: min(420px, calc(100% - 48px));
  transform: translateX(-50%);
  border: 1px solid rgba(140, 255, 204, 0.48);
  border-radius: 18px;
  padding: 12px 16px;
  background: rgba(3, 12, 14, 0.92);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.38),
    0 0 26px rgba(92, 245, 255, 0.16);
}

.complete-banner strong,
.complete-banner span {
  display: block;
}

.complete-banner strong {
  color: var(--solved);
  font-size: 15px;
  text-transform: uppercase;
}

.complete-banner span {
  color: var(--secondary);
  font-size: 13px;
}

.hud {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(13, 25, 39, 0.84), rgba(5, 8, 13, 0.86)),
    var(--footer-panel);
  box-shadow:
    0 18px 52px rgba(0, 0, 0, 0.30),
    inset 0 0 0 1px rgba(92, 245, 255, 0.06);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(92, 245, 255, 0.34);
}

h1 {
  margin: 0;
  color: var(--primary);
  font-size: 32px;
  line-height: 1.05;
  text-shadow: 0 2px 0 var(--shadow);
}

.hint {
  margin: 14px 0 0;
  color: var(--secondary);
}

.progress-block {
  display: grid;
  gap: 10px;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 900;
}

.progress-track {
  height: 12px;
  border: 1px solid rgba(163, 238, 255, 0.28);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.36);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.42);
}

.progress-track i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--target));
  box-shadow: 0 0 18px rgba(92, 245, 255, 0.52);
  transition: width 180ms ease;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border: 1px solid rgba(92, 245, 255, 0.18);
  border-radius: 999px;
  padding: 8px;
  background: rgba(2, 5, 8, 0.72);
  box-shadow:
    0 0 22px rgba(92, 245, 255, 0.12),
    inset 0 0 18px rgba(92, 245, 255, 0.05);
}

.controls button:first-child {
  grid-column: 1 / -1;
}

button {
  min-height: 46px;
  border: 1px solid var(--button-border);
  border-radius: 999px;
  color: var(--primary);
  background:
    linear-gradient(180deg, rgba(20, 54, 78, 0.96), rgba(8, 18, 28, 0.98)),
    var(--button);
  font-weight: 900;
  cursor: pointer;
  text-shadow: 0 2px 0 var(--shadow);
}

.control-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
}

.reset-icon::before {
  position: absolute;
  inset: 4px;
  border: 3px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
  content: "";
}

.reset-icon::after {
  position: absolute;
  right: 3px;
  top: 4px;
  width: 8px;
  height: 8px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 45%, 18% 100%);
  content: "";
}

.prev-icon::before,
.next-icon::before {
  position: absolute;
  top: 3px;
  width: 4px;
  height: 16px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}

.prev-icon::after,
.next-icon::after {
  position: absolute;
  top: 4px;
  width: 15px;
  height: 14px;
  background: currentColor;
  content: "";
}

.prev-icon::before {
  left: 4px;
}

.prev-icon::after {
  left: 7px;
  clip-path: polygon(100% 0, 100% 100%, 0 50%);
}

.next-icon::before {
  right: 4px;
}

.next-icon::after {
  right: 7px;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

button:hover:not(:disabled),
button:focus-visible {
  border-color: rgba(116, 248, 255, 0.72);
  outline: none;
  box-shadow:
    0 0 0 3px rgba(92, 245, 255, 0.14),
    0 0 24px rgba(92, 245, 255, 0.20);
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
  background: var(--button-disabled);
}

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

@media (max-width: 860px) {
  .play-shell {
    width: calc(100% - 20px);
    max-width: 680px;
    padding-top: 14px;
  }

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

  .board-wrap {
    min-height: auto;
    aspect-ratio: 1 / 1;
  }

  canvas {
    min-height: auto;
    aspect-ratio: 1 / 1;
  }

  .hud {
    padding: 16px;
  }

  h1 {
    font-size: 26px;
  }
}

@media (max-width: 430px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .play-shell {
    width: 100%;
    max-width: 100%;
    padding: 12px 10px 18px;
  }

  .play-header {
    gap: 10px;
  }

  .brand {
    font-size: 20px;
  }

  .level-meta {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .meta-chip {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
    padding: 0 10px;
  }

  .stage,
  .board-wrap,
  .hud {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .controls {
    border-radius: 24px;
  }

  .control-button {
    padding: 0 10px;
  }
}
