:root {
  color-scheme: dark;
  --ink: #f7f4eb;
  --muted: #a8b4ad;
  --page: #111416;
  --panel: #1c201d;
  --panel-strong: #202a29;
  --line: rgba(247, 244, 235, 0.14);
  --lime: #d2f25c;
  --coral: #ff6b57;
  --cyan: #42d3df;
  --shadow: rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
  background:
    linear-gradient(135deg, rgba(255, 107, 87, 0.11), transparent 28%),
    linear-gradient(315deg, rgba(66, 211, 223, 0.1), transparent 32%),
    repeating-linear-gradient(
      90deg,
      rgba(247, 244, 235, 0.035) 0 1px,
      transparent 1px 72px
    ),
    var(--page);
}

button {
  font: inherit;
}

.game-shell {
  width: min(100%, 1024px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(18px, 4vh, 42px) clamp(16px, 4vw, 52px);
  display: grid;
  align-content: center;
  gap: 20px;
}

.brand-bar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  width: min(100%, 704px);
  margin: 0 auto;
}

.eyebrow,
.hud p,
.result-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vh, 4.1rem);
  line-height: 0.92;
  font-weight: 950;
}

.play-layout {
  width: min(100%, 704px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(236px, 50vh) minmax(190px, 248px);
  justify-content: center;
  align-items: stretch;
  gap: clamp(14px, 2.4vw, 24px);
}

.board-frame {
  position: relative;
  width: min(100%, calc((100vh - 148px) / 2));
  min-width: 236px;
  aspect-ratio: 1 / 2;
  overflow: hidden;
  justify-self: end;
  border: 1px solid rgba(247, 244, 235, 0.24);
  background: #080b0d;
  box-shadow:
    0 22px 64px var(--shadow),
    inset 0 0 0 7px rgba(247, 244, 235, 0.045);
}

.board-frame::before {
  position: absolute;
  z-index: 1;
  inset: 0;
  border: 1px solid rgba(210, 242, 92, 0.16);
  pointer-events: none;
  content: "";
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
}

.score-block,
.metric-grid,
.next-block {
  border: 1px solid var(--line);
  background:
    linear-gradient(145deg, rgba(210, 242, 92, 0.08), transparent 38%),
    var(--panel);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.22);
}

.score-block {
  min-height: 136px;
  padding: clamp(16px, 2vw, 24px);
  display: grid;
  align-content: space-between;
}

.score-block strong {
  overflow-wrap: anywhere;
  color: var(--lime);
  font-size: clamp(2.4rem, 7vh, 5.15rem);
  line-height: 0.9;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background:
    linear-gradient(145deg, rgba(255, 107, 87, 0.09), transparent 42%),
    var(--panel-strong);
}

.metric-grid div {
  min-height: 82px;
  padding: 15px;
  display: grid;
  align-content: space-between;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric-grid div:nth-child(2n) {
  border-right: 0;
}

.metric-grid div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.metric-grid strong {
  overflow-wrap: anywhere;
  font-size: clamp(1.35rem, 3vh, 2rem);
  line-height: 1;
}

.next-block {
  min-height: 184px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  background:
    linear-gradient(145deg, rgba(66, 211, 223, 0.11), transparent 44%),
    var(--panel);
}

#next {
  width: min(100%, 184px);
  height: auto;
  aspect-ratio: 1;
  margin: auto;
}

.game-over {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 13px;
  padding: 22px;
  text-align: center;
  background: rgba(8, 11, 13, 0.86);
  backdrop-filter: blur(6px);
}

.game-over[hidden] {
  display: none;
}

.game-over strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--cyan);
  font-size: clamp(2.6rem, 9vh, 5.5rem);
  line-height: 0.92;
}

#restartButton {
  min-width: 174px;
  min-height: 50px;
  border: 0;
  padding: 0 20px;
  color: #101314;
  font-weight: 950;
  background: var(--lime);
  cursor: pointer;
  box-shadow: 6px 6px 0 var(--coral);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease;
}

#restartButton:hover,
#restartButton:focus-visible {
  filter: brightness(1.06);
  transform: translate(-2px, -2px);
  box-shadow: 8px 8px 0 var(--coral);
}

#restartButton:active {
  transform: translate(3px, 3px);
  box-shadow: 3px 3px 0 var(--coral);
}

@media (max-width: 660px) {
  .game-shell {
    min-height: auto;
    align-content: start;
  }

  .brand-bar {
    width: min(100%, 360px);
    align-items: start;
    flex-direction: column;
    gap: 7px;
  }

  .play-layout {
    width: min(100%, 360px);
    grid-template-columns: minmax(0, 1fr);
  }

  .board-frame {
    width: min(100%, max(236px, calc((100svh - 360px) / 2)));
    min-width: min(100%, 236px);
    justify-self: center;
  }

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

  .score-block {
    min-height: 112px;
  }

  .metric-grid {
    grid-column: 1 / -1;
    order: 2;
  }

  .next-block {
    min-height: 112px;
    padding-bottom: 8px;
  }

  #next {
    width: min(100%, 92px);
  }
}

@media (max-height: 760px) and (min-width: 661px) {
  .game-shell {
    padding-top: 18px;
    padding-bottom: 18px;
    gap: 12px;
  }

  .play-layout {
    grid-template-columns: minmax(236px, 44vh) minmax(190px, 226px);
  }

  .board-frame {
    width: min(100%, calc((100vh - 116px) / 2));
  }

  .score-block {
    min-height: 104px;
  }

  .metric-grid div {
    min-height: 64px;
  }

  .next-block {
    min-height: 150px;
  }
}
