:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0e1525;
  color: #eef4ff;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
  background: #0e1525;
}

body {
  margin: 0;
  position: absolute;
  inset: 0;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 82% 12%, rgba(52, 208, 194, 0.13), transparent 35%),
    radial-gradient(circle at 12% 86%, rgba(117, 92, 255, 0.2), transparent 38%),
    linear-gradient(145deg, #111a2c 0%, #0d1423 100%);
}

button {
  font: inherit;
}

.maze {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;
  min-height: 100%;
  height: 100%;
  padding: 12px 16px 16px;
}

.maze__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.maze h1 {
  margin: 0;
  color: #f7f9ff;
  font-size: clamp(20px, 4vw, 28px);
  line-height: 1.12;
}

.maze__restart,
.maze__overlay button {
  border: 1px solid rgba(150, 168, 207, 0.28);
  border-radius: 9px;
  padding: 9px 12px;
  color: #e7efff;
  background: rgba(39, 54, 84, 0.76);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease;
}

.maze__restart:hover,
.maze__overlay button:hover {
  border-color: rgba(142, 124, 255, 0.68);
  background: rgba(61, 68, 119, 0.9);
}

.maze__restart:active,
.maze__overlay button:active {
  transform: translateY(1px);
}

.maze__restart:focus-visible,
.maze__overlay button:focus-visible,
.maze__control:focus-visible {
  outline: 3px solid rgba(129, 109, 255, 0.34);
  outline-offset: 2px;
}

.maze__panel {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 14px;
  margin-bottom: 9px;
  color: #afbdd7;
  font-size: 12px;
}

.maze__panel strong {
  color: #eef4ff;
}

.maze__key-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #a8b6d0;
}

.maze__key-state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7f8da8;
  box-shadow: 0 0 0 3px rgba(127, 141, 168, 0.12);
}

.maze__key-state.is-found {
  color: #6fe1bc;
}

.maze__key-state.is-found::before {
  background: #3dd5a5;
  box-shadow: 0 0 0 3px rgba(61, 213, 165, 0.16);
}

.maze__message {
  min-width: 0;
  overflow: hidden;
  color: #95a8ca;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.maze__stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 14px;
  box-shadow:
    0 18px 38px rgba(3, 7, 16, 0.36),
    0 0 0 1px rgba(144, 163, 203, 0.19);
}

.maze__header,
.maze__panel {
  flex: 0 0 auto;
}

.maze canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  border: 0;
  outline: none;
  background: #101a2c;
  cursor: crosshair;
  touch-action: manipulation;
}

.maze canvas:focus-visible {
  box-shadow: inset 0 0 0 3px rgba(133, 113, 255, 0.8);
}

.maze__overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(circle, rgba(110, 94, 234, 0.27), transparent 52%),
    rgba(8, 13, 25, 0.83);
  backdrop-filter: blur(4px);
}

.maze__overlay[hidden] {
  display: none;
}

.maze__overlay p {
  margin: 0 0 5px;
  color: #80e3c7;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.maze__overlay strong {
  margin-bottom: 18px;
  color: #fff;
  font-size: clamp(20px, 4vw, 30px);
}

.maze__overlay button {
  border-color: rgba(153, 135, 255, 0.58);
  padding: 10px 16px;
  background: linear-gradient(135deg, #735ff2 0%, #467dcf 100%);
  box-shadow: 0 10px 24px rgba(70, 73, 180, 0.34);
}

.maze__controls {
  display: none;
  flex: 0 0 auto;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 48px);
  justify-content: center;
  gap: 7px;
  margin-top: 13px;
}

.maze__control {
  display: grid;
  place-items: center;
  border: 1px solid rgba(146, 164, 203, 0.3);
  border-radius: 12px;
  color: #eaf1ff;
  background: rgba(35, 48, 76, 0.88);
  font-size: 21px;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.maze__control.is-pressed {
  border-color: rgba(141, 123, 255, 0.82);
  background: linear-gradient(135deg, #6858d9, #3e739f);
  transform: translateY(1px);
}

.maze__control--up {
  grid-column: 2;
  grid-row: 1;
}

.maze__control--left {
  grid-column: 1;
  grid-row: 2;
}

.maze__control--down {
  grid-column: 2;
  grid-row: 2;
}

.maze__control--right {
  grid-column: 3;
  grid-row: 2;
}

.maze__hint {
  flex: 0 0 auto;
  margin: 9px 0 0;
  color: #8397bb;
  font-size: 11px;
  text-align: center;
}

@media (max-width: 720px), (pointer: coarse) {
  .maze__controls {
    display: grid;
  }

  .maze__hint {
    display: none;
  }
}

@media (max-width: 520px) {
  .maze {
    padding: 11px;
  }

  .maze__header {
    align-items: flex-start;
    flex-direction: column;
    gap: 9px;
  }

  .maze__restart {
    padding: 7px 10px;
  }

  .maze__panel {
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
  }

  .maze__message {
    grid-column: 1 / -1;
    text-align: left;
  }
}

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