:root {
  --bg: #08080f;
  --panel: #10101d;
  --panel-2: #171727;
  --cyan: #00f5ff;
  --magenta: #ff006e;
  --yellow: #ffe600;
  --green: #00ff88;
  --ink: #f6fbff;
  --muted: #9ea4bd;
  --line: rgba(255, 255, 255, 0.12);
  --danger: #ff3158;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 12%, rgba(0, 245, 255, 0.14), transparent 30%),
    radial-gradient(circle at 86% 18%, rgba(255, 0, 110, 0.13), transparent 28%),
    linear-gradient(135deg, #08080f 0%, #10101b 54%, #070710 100%);
}

button {
  font: inherit;
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.035) 50%, transparent 50%);
  background-size: 100% 4px;
  mix-blend-mode: overlay;
  opacity: 0.3;
}

.back-link {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 70;
  color: var(--cyan);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 10px 12px;
  border: 1px solid rgba(0, 245, 255, 0.35);
  background: rgba(8, 8, 15, 0.82);
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.18);
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 72px 0 28px;
}

.hud,
.arena,
.achievements {
  border: 1px solid var(--line);
  background: rgba(15, 15, 26, 0.86);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
}

.eyebrow,
.stat span,
.scoreline span,
.result-stats span {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2 {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  letter-spacing: 0;
}

h1 {
  margin-top: 8px;
  color: var(--cyan);
  font-size: clamp(1.35rem, 4vw, 2.35rem);
  text-shadow: 0 0 20px rgba(0, 245, 255, 0.45);
}

.stats,
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 10px;
}

.stat,
.result-stats div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.stat strong,
.scoreline strong,
.result-stats strong {
  display: block;
  margin-top: 6px;
  color: var(--yellow);
  font-family: "Press Start 2P", monospace;
  font-size: 1rem;
}

.arena {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 300px;
  gap: 18px;
  margin-top: 18px;
  padding: 18px;
}

.board-wrap {
  display: grid;
  gap: 12px;
  align-content: center;
}

.turnbar {
  width: 100%;
  height: 10px;
  border: 1px solid rgba(0, 245, 255, 0.45);
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

#timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--green), var(--cyan), var(--yellow));
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.65);
  transform-origin: left center;
}

.board {
  width: min(68vh, 100%);
  max-width: 650px;
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: clamp(5px, 1vw, 9px);
  padding: clamp(8px, 1.6vw, 14px);
  border: 1px solid rgba(0, 245, 255, 0.35);
  background:
    linear-gradient(rgba(0, 245, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 245, 255, 0.08) 1px, transparent 1px),
    rgba(4, 6, 14, 0.78);
  background-size: 28px 28px;
  box-shadow: inset 0 0 30px rgba(0, 245, 255, 0.12), 0 0 44px rgba(0, 245, 255, 0.12);
}

.cell {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.045);
  color: transparent;
  cursor: default;
  transition: transform 120ms ease, border-color 120ms ease, background 160ms ease, box-shadow 160ms ease;
}

.cell::after {
  content: "";
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  opacity: 0;
}

.cell.player {
  border-color: rgba(0, 245, 255, 0.7);
  background: linear-gradient(135deg, rgba(0, 245, 255, 0.88), rgba(0, 255, 136, 0.55));
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.34);
}

.cell.rival {
  border-color: rgba(255, 0, 110, 0.78);
  background: linear-gradient(135deg, rgba(255, 0, 110, 0.86), rgba(255, 230, 0, 0.3));
  box-shadow: 0 0 18px rgba(255, 0, 110, 0.26);
}

.cell.blocker {
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0 5px, rgba(255, 255, 255, 0.02) 5px 10px);
  border-color: rgba(255, 255, 255, 0.18);
}

.cell.bonus {
  border-color: rgba(255, 230, 0, 0.64);
}

.cell.bonus::after {
  opacity: 1;
  background: var(--yellow);
  box-shadow: 0 0 16px var(--yellow);
}

.cell.legal {
  cursor: pointer;
  border-color: var(--yellow);
  box-shadow: inset 0 0 0 2px rgba(255, 230, 0, 0.24), 0 0 16px rgba(255, 230, 0, 0.22);
}

.cell.legal:hover,
.cell.focused {
  transform: translateY(-2px) scale(1.03);
  border-color: #fff;
}

.cell.pulse {
  animation: pulse 260ms ease;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
}

.scoreline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.scoreline.rival strong {
  color: var(--magenta);
}

.meter {
  height: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(90deg, rgba(0, 245, 255, 0.15) 50%, rgba(255, 0, 110, 0.15) 50%);
  overflow: hidden;
}

#control-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.5);
}

.message {
  min-height: 58px;
  margin: 0;
  color: #dce7ff;
  line-height: 1.45;
  font-weight: 700;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: auto;
}

.actions button {
  min-height: 44px;
  border: 1px solid rgba(0, 245, 255, 0.44);
  background: rgba(0, 245, 255, 0.12);
  color: var(--ink);
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
}

.actions button:hover,
.actions button:focus-visible {
  outline: none;
  background: rgba(0, 245, 255, 0.24);
}

.achievements {
  margin-top: 18px;
  padding: 16px;
}

.achievements h2 {
  font-size: 0.9rem;
  color: var(--green);
}

.achievement-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.badge {
  min-height: 48px;
  padding: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.unlocked {
  color: var(--ink);
  border-color: rgba(0, 255, 136, 0.46);
  background: rgba(0, 255, 136, 0.1);
  box-shadow: 0 0 18px rgba(0, 255, 136, 0.12);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 60;
  transform: translate(-50%, 80px);
  padding: 11px 16px;
  background: var(--cyan);
  color: #001015;
  font-weight: 900;
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 4, 10, 0.78);
  backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.result-card {
  width: min(520px, 100%);
  padding: 22px;
  border: 1px solid rgba(0, 245, 255, 0.38);
  background: #10101d;
  box-shadow: 0 0 50px rgba(0, 245, 255, 0.18);
}

.result-card h2 {
  margin-top: 10px;
  color: var(--cyan);
  font-size: 1.2rem;
}

.result-card p:not(.eyebrow) {
  color: #dce7ff;
  line-height: 1.5;
}

.result-stats {
  margin: 16px 0;
}

@keyframes pulse {
  0% {
    transform: scale(0.92);
  }

  55% {
    transform: scale(1.08);
  }

  100% {
    transform: scale(1);
  }
}

@media (max-width: 820px) {
  .shell {
    width: min(100vw - 18px, 680px);
    padding-top: 66px;
  }

  .hud {
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .arena {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .board {
    width: min(100%, 74vh);
  }

  .panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .meter,
  .message,
  .actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .back-link {
    top: 8px;
    left: 8px;
    padding: 8px 10px;
    font-size: 0.74rem;
  }

  .shell {
    width: calc(100vw - 12px);
    padding-top: 56px;
  }

  h1 {
    font-size: 1.22rem;
  }

  .hud,
  .arena,
  .achievements {
    padding: 10px;
  }

  .stat {
    padding: 9px;
  }

  .stat span,
  .scoreline span,
  .result-stats span {
    font-size: 0.62rem;
  }

  .stat strong,
  .scoreline strong,
  .result-stats strong {
    font-size: 0.8rem;
  }

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

  .scoreline {
    padding-bottom: 8px;
  }

  .achievement-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
