:root {
  --bg-a: #0e1a2b;
  --bg-b: #162b44;
  --bg-c: #1f3b57;
  --panel: rgba(255, 255, 255, 0.88);
  --text: #0f1723;
  --muted: #5a6777;
  --line: rgba(15, 23, 35, 0.16);
  --accent: #ff7b00;
  --accent-2: #00a6fb;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 15%, rgba(255, 123, 0, 0.3), transparent 28%),
    radial-gradient(circle at 85% 80%, rgba(0, 166, 251, 0.28), transparent 30%),
    linear-gradient(135deg, var(--bg-a), var(--bg-b) 42%, var(--bg-c));
  display: grid;
  place-items: center;
  padding: 1rem;
  min-height: 100dvh;
}

.game-shell {
  width: min(960px, 100%);
  padding: clamp(0.9rem, 1.8vw, 1.4rem);
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 22px 56px rgba(8, 15, 28, 0.35);
  backdrop-filter: blur(7px);
  overflow: hidden;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.73rem;
}

h1 {
  margin: 0.1rem 0 0;
  font-size: clamp(1.45rem, 2.8vw, 2rem);
  line-height: 1.1;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.75rem;
}

.stats article {
  padding: 0.65rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
}

.stats p {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats strong {
  display: inline-block;
  margin-top: 0.16rem;
  font-size: 1.05rem;
}

.board-wrap {
  position: relative;
  border-radius: 16px;
  padding: 0.6rem;
  border: 1px solid var(--line);
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.92), rgba(241, 246, 252, 0.93));
}

#board {
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1;
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 35, 0.14);
  touch-action: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.overlay {
  position: absolute;
  inset: 0.6rem;
  border-radius: 12px;
  display: grid;
  place-items: center;
  text-align: center;
  background: rgba(12, 23, 39, 0.58);
  color: #eef5ff;
  padding: 1rem;
}

.overlay h2 {
  margin: 0;
  font-size: clamp(1.3rem, 3vw, 1.7rem);
}

.overlay p {
  margin: 0.45rem 0 0;
  color: rgba(238, 245, 255, 0.85);
}

.actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.55rem;
}

button {
  border: 1px solid rgba(15, 23, 35, 0.2);
  border-radius: 10px;
  padding: 0.56rem 0.85rem;
  background: linear-gradient(150deg, #fff, #eef4fb);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  border-color: rgba(15, 23, 35, 0.32);
}

button:active {
  transform: translateY(1px);
}

button.ghost {
  background: rgba(255, 255, 255, 0.48);
}

.status {
  min-height: 1.5rem;
  margin: 0.65rem 0 0.2rem;
  font-weight: 600;
  color: #20304a;
}

.controls {
  margin-top: 0.65rem;
  display: grid;
  gap: 0.5rem;
  justify-items: center;
}

.dir {
  min-width: 80px;
}

.dpad-row {
  display: flex;
  gap: 0.45rem;
}

@media (min-width: 900px) {
  .controls {
    display: none;
  }
}

@media (max-width: 760px) {
  body {
    padding: 0;
    align-items: stretch;
  }

  .game-shell {
    width: 100vw;
    min-height: 100dvh;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    padding-top: calc(0.9rem + env(safe-area-inset-top));
    padding-bottom: calc(0.9rem + env(safe-area-inset-bottom));
    padding-left: max(0.9rem, env(safe-area-inset-left));
    padding-right: max(0.9rem, env(safe-area-inset-right));
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
    gap: 0.35rem;
  }

  .board-wrap {
    height: 100%;
    display: grid;
    align-items: center;
  }

  #board {
    max-width: 100%;
    max-height: 56vh;
  }

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

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

  button,
  .dir {
    padding: 0.66rem 0.8rem;
  }
}
