:root {
  --bg: #0f0f1a;
  --panel: #1a1a2e;
  --light: #c4f0c2;
  --dark: #3d6b4f;
  --hi: #ffe66d;
  --hi2: #ff6b6b;
  --ok: #6dffb0;
  --ink: #e8ffe8;
  --muted: #7a9a7a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Press Start 2P", monospace;
  image-rendering: pixelated;
}

body {
  display: grid;
  place-items: center;
  padding: 1rem;
  background-image:
    linear-gradient(rgba(15, 15, 26, 0.92), rgba(15, 15, 26, 0.96)),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0, 255, 120, 0.03) 2px,
      rgba(0, 255, 120, 0.03) 4px
    );
}

.crt {
  width: min(100%, 460px);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: boot 0.45s steps(4) both;
}

@keyframes boot {
  from { opacity: 0; filter: brightness(3); }
  to { opacity: 1; filter: brightness(1); }
}

header h1 {
  font-size: clamp(0.85rem, 4vw, 1.15rem);
  letter-spacing: 0.06em;
  text-shadow: 3px 3px 0 #000, -1px 0 0 #2cff8a;
}

header h1 span {
  color: var(--hi);
  margin-left: 0.35rem;
}

.tag {
  margin-top: 0.55rem;
  font-size: 0.48rem;
  color: var(--muted);
  line-height: 1.6;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--panel);
  border: 4px solid #000;
  box-shadow: 4px 4px 0 #000;
  padding: 0.65rem 0.7rem;
}

.status {
  font-size: 0.5rem;
  line-height: 1.5;
  color: var(--hi);
  min-height: 1.6em;
}

.badge {
  font-size: 0.45rem;
  padding: 0.35rem 0.4rem;
  border: 3px solid #444;
  color: #888;
  background: #000;
}

.badge.on {
  color: #0f0;
  border-color: #0f0;
}

.coach {
  background: #121222;
  border: 4px solid #000;
  box-shadow: 4px 4px 0 #000;
  padding: 0.7rem;
  max-height: 180px;
  overflow: auto;
}

.coach.ok { border-color: #1a7a4a; }
.coach.bad { border-color: #a33; }
.coach.info { border-color: #456; }

.coach-title {
  font-size: 0.45rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.coach-body {
  font-size: 0.48rem;
  line-height: 1.75;
  color: var(--ink);
}

.coach-body p + p { margin-top: 0.55rem; }
.coach-body .muted { color: var(--muted); }
.coach-body .mv {
  color: var(--hi);
  white-space: nowrap;
}
.coach-body strong { color: #fff; }

.board-wrap {
  border: 4px solid #000;
  box-shadow: 6px 6px 0 #000;
  background: #000;
  touch-action: manipulation;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
}

.sq {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  border: none;
  padding: 0;
}

.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }

.sq.selected {
  outline: 3px solid var(--hi);
  outline-offset: -3px;
  z-index: 1;
}

.sq.move::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  background: rgba(255, 230, 109, 0.85);
  box-shadow: 0 0 0 2px #000;
  pointer-events: none;
}

.sq.capture::after {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 4px solid var(--hi2);
  box-shadow: none;
}

.sq.last {
  box-shadow: inset 0 0 0 3px rgba(255, 230, 109, 0.55);
}

.sq.best {
  box-shadow: inset 0 0 0 4px #6dffb0;
}

.piece {
  font-size: clamp(1.4rem, 8vw, 2.35rem);
  line-height: 1;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

.piece.white { color: #fffef0; text-shadow: 2px 2px 0 #222, -1px -1px 0 #888; }
.piece.black { color: #1a1a1a; text-shadow: 1px 1px 0 #fff, 2px 2px 0 #000; }

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

button {
  font-family: inherit;
  font-size: 0.48rem;
  padding: 0.8rem 0.4rem;
  background: var(--hi);
  color: #111;
  border: 4px solid #000;
  box-shadow: 4px 4px 0 #000;
  cursor: pointer;
}

button:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 #000;
}

#hint { background: #7ec8ff; }
#retry { background: #ffb347; }
#continueBad { background: #ff7e7e; }
#newGame { background: var(--ok); }

.hint {
  font-size: 0.4rem;
  color: var(--muted);
  line-height: 1.7;
  text-align: center;
}

.thinking .status {
  animation: blink 0.6s steps(2) infinite;
}

@keyframes blink {
  50% { opacity: 0.35; }
}

@media (max-width: 400px) {
  .controls { grid-template-columns: 1fr; }
}
