:root {
  --bg-dark: #08100e;
  --panel: rgba(9, 22, 18, 0.8);
  --edge: #96ff7a;
  --text: #f6ffe8;
  --text-dim: #cbf8cf;
  --hot: #ffd86c;
  --cool: #78f4ff;
  --grid-cell: clamp(48px, 6.9vw, 81px);
  --bank-cell: clamp(39px, 4.65vw, 60px);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "VT323", monospace;
  color: var(--text);
  background: var(--bg-dark);
  overflow: hidden;
  min-height: 100vh;
  display: grid;
  place-content: center;
  place-items: center;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(3, 11, 9, 0.48), rgba(3, 11, 9, 0.48)),
    url("images/vfd.png") center/cover no-repeat;
  filter: saturate(1.08) contrast(1.12);
  z-index: -3;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(194, 255, 213, 0.07) 0,
    rgba(194, 255, 213, 0.07) 1px,
    transparent 2px,
    transparent 4px
  );
  opacity: 0.34;
  z-index: -1;
}

.crt-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.08) 0.4px, transparent 0.4px);
  background-size: 3px 3px;
  opacity: 0.06;
  animation: noiseShift 0.35s steps(2) infinite;
  z-index: -2;
}

@keyframes noiseShift {
  0% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(1px, 1px);
  }
  100% {
    transform: translate(0, 0);
  }
}

.hangman-shell {
  width: min(1220px, 96vw);
  height: 48vh;
  margin: 0;
  display: grid;
  gap: 0;
  align-self: center;
  transition: opacity 260ms ease, transform 260ms ease, filter 260ms ease;
}

body.ui-hidden .hangman-shell {
  opacity: 0;
  transform: scale(0.97);
  filter: blur(1px);
  pointer-events: none;
}

.playfield {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
}

.upper-panel {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
}

.hangman-pane,
.answer-pane,
.lower-panel {
  border: 2px solid var(--edge);
  background: var(--panel);
  min-height: 0;
  box-shadow: 0 0 18px rgba(150, 255, 122, 0.16);
}

.hangman-pane,
.answer-pane {
  padding: 7px;
}

.hangman-pane {
  display: flex;
  align-items: center;
  justify-content: center;
}

#hangmanCanvas {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 6 / 5;
  border: 0;
  background: rgba(0, 0, 0, 0.25);
}

.answer-pane {
  display: block;
}

.answer-grid {
  border: 2px solid rgba(157, 245, 255, 0.45);
  background: rgba(4, 14, 11, 0.68);
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(9, var(--grid-cell));
  grid-auto-rows: var(--grid-cell);
  gap: 6px;
  justify-content: center;
  align-content: center;
  height: 100%;
}

.cell {
  width: var(--grid-cell);
  height: var(--grid-cell);
  display: grid;
  place-items: center;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(2.02rem, 4.2vw, 3.22rem);
  border: 2px solid rgba(141, 223, 155, 0.36);
  border-bottom-color: rgba(255, 210, 122, 0.75);
  color: rgba(236, 255, 233, 0.55);
  background: rgba(7, 21, 16, 0.66);
}

.cell.revealed {
  color: var(--text);
  border-color: rgba(120, 244, 255, 0.9);
  text-shadow: 0 0 10px rgba(120, 244, 255, 0.65);
}

.cell.given {
  color: #7ef6ff;
  text-shadow: 0 0 11px rgba(126, 246, 255, 0.8);
}

.lower-panel {
  padding: 8px;
}

.letter-bank {
  display: grid;
  grid-template-columns: repeat(13, var(--bank-cell));
  gap: 6px;
  justify-content: center;
}

.letter-btn {
  font-family: "Press Start 2P", monospace;
  width: var(--bank-cell);
  height: var(--bank-cell);
  font-size: clamp(0.87rem, 1.8vw, 1.57rem);
  border: 2px solid rgba(141, 223, 155, 0.62);
  background: rgba(11, 34, 24, 0.95);
  color: #e2ffdc;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease, opacity 120ms ease;
  box-shadow: 0 0 10px rgba(150, 255, 122, 0.16);
}

.letter-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(120, 244, 255, 0.9);
  background: rgba(21, 53, 39, 0.98);
}

.letter-btn.is-correct {
  border-color: rgba(120, 244, 255, 0.96);
  background: rgba(30, 98, 94, 0.94);
  color: #d8ffff;
  opacity: 0.9;
  box-shadow: 0 0 14px rgba(120, 244, 255, 0.3);
}

.letter-btn.is-wrong {
  border-color: rgba(255, 118, 118, 0.95);
  background: rgba(118, 34, 34, 0.94);
  color: #ffe2e2;
  opacity: 0.86;
  box-shadow: 0 0 12px rgba(255, 118, 118, 0.22);
}

.letter-btn.is-used {
  cursor: default;
}

.letter-btn.is-used:hover {
  transform: none;
}

.map-wipe {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 20;
  background-color: #000;
  background-image: url("map.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: auto 100%;
  clip-path: inset(0 50% 0 50%);
  filter: saturate(1.06) contrast(1.08) brightness(1.05);
}

body.exiting .map-wipe {
  opacity: 1;
  animation: mapPortalOpen 5000ms cubic-bezier(0.2, 0.75, 0.2, 1) forwards;
}

body.exiting:not(.ui-hidden) .hangman-shell {
  animation: boardSink 360ms ease forwards;
}

@keyframes mapPortalOpen {
  from {
    clip-path: inset(0 50% 0 50%);
    opacity: 0.85;
  }
  to {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
}

@keyframes boardSink {
  from {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
  to {
    opacity: 0;
    transform: scale(0.94);
    filter: blur(1px);
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
    display: block;
  }

  .hangman-shell {
    height: auto;
    margin: 10px auto;
    padding-bottom: 12px;
  }

  body.ui-hidden .hangman-shell {
    display: none;
  }

  .upper-panel {
    grid-template-columns: 1fr;
  }

  .letter-bank {
    grid-template-columns: repeat(9, var(--bank-cell));
  }
}

@media (max-width: 640px) {
  .hangman-shell {
    width: 98vw;
  }

  .answer-grid {
    gap: 5px;
    padding: 7px;
  }

  .letter-bank {
    grid-template-columns: repeat(7, var(--bank-cell));
  }
}
