:root {
  --bg: #111413;
  --panel: #f5f0e6;
  --panel-2: #ebe2d0;
  --ink: #17201b;
  --muted: #6d736e;
  --line: rgba(23, 32, 27, 0.16);
  --green: #2f8f5b;
  --green-dark: #17613d;
  --red: #dd5341;
  --gold: #efb93f;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 22%, rgba(239, 185, 63, 0.18), transparent 28%),
    linear-gradient(135deg, #0f1513 0%, #17251f 48%, #2f342b 100%);
  display: grid;
  place-items: center;
  padding: 28px;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  color: var(--ink);
  background: #fff9ee;
  box-shadow: inset 0 0 0 1px var(--line);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: inset 0 0 0 1px rgba(23, 32, 27, 0.24), 0 8px 18px rgba(0, 0, 0, 0.12);
}

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

button:focus-visible {
  outline: 3px solid rgba(239, 185, 63, 0.72);
  outline-offset: 3px;
}

.shell {
  width: min(1120px, 100%);
  display: grid;
  gap: 18px;
}

.hud,
.game-layout {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 4.25rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 10px;
  min-width: min(440px, 100%);
}

.stat {
  min-height: 72px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fffaf0;
  box-shadow: inset 0 0 0 1px var(--line);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.35rem, 4vw, 2rem);
  line-height: 1;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 18px;
  padding: 18px;
}

.board-wrap {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  overflow: hidden;
  border-radius: 8px;
  background: #1b2b23;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08);
  touch-action: none;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(12, 17, 15, 0.52);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-panel {
  width: min(340px, 100%);
  padding: 22px;
  border-radius: 8px;
  color: #fffaf0;
  text-align: center;
  background: rgba(17, 20, 19, 0.82);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 20px 44px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(10px);
}

.overlay-panel p {
  margin-bottom: 8px;
  color: #efb93f;
  font-weight: 900;
}

.overlay-panel h2 {
  margin-bottom: 18px;
  font-size: clamp(1.5rem, 8vw, 2.8rem);
  line-height: 1;
  letter-spacing: 0;
}

.side {
  display: grid;
  align-content: start;
  gap: 14px;
}

.toolbar,
.mode-group {
  display: grid;
  gap: 10px;
}

.toolbar {
  grid-template-columns: 1fr 54px 54px;
}

.primary {
  color: white;
  background: var(--green);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
}

.primary:hover {
  background: #36a368;
}

.mode-group {
  grid-template-columns: repeat(4, 1fr);
  padding: 4px;
  border-radius: 8px;
  background: var(--panel-2);
}

.mode {
  min-height: 40px;
  background: transparent;
  box-shadow: none;
  font-size: 0.74rem;
}

.mode.is-active {
  color: white;
  background: var(--ink);
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(54px, 1fr));
  grid-template-rows: repeat(3, 54px);
  gap: 8px;
  margin-top: 4px;
}

.dpad button {
  min-height: 54px;
  font-size: 1.35rem;
}

.dpad [data-dir="up"] {
  grid-column: 2;
}

.dpad [data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad [data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.dpad [data-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}

@media (max-width: 820px) {
  body {
    padding: 14px;
    align-items: start;
  }

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

  .stats {
    min-width: 0;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 460px) {
  body {
    padding: 10px;
  }

  .hud,
  .game-layout {
    padding: 12px;
  }

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

  .stat {
    min-height: 62px;
    padding: 8px;
  }

  .stat span {
    font-size: 0.68rem;
  }

  .toolbar {
    grid-template-columns: 1fr 48px 48px;
  }
}
