:root {
  --bg-1: #dff3ff;
  --bg-2: #b9e2ff;
  --panel: #ffffff;
  --ink: #102136;
  --muted: #486078;
  --accent: #2f8bff;
  --accent-strong: #1f66c5;
  --danger: #cc3f42;
  --border: #c7d9ea;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
  color: var(--ink);
}

body {
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
}

.app {
  width: min(560px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 1.4rem;
}

.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: inherit;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(16, 33, 54, 0.12);
}

.hud {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  flex-shrink: 0;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.label {
  color: var(--muted);
  font-size: 0.84rem;
}

.stat strong {
  font-size: 1.18rem;
}

.board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f6fbff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
}

#game-canvas {
  display: block;
  width: auto;
  height: 100%;
  max-width: 100%;
  border-radius: 10px;
  background: #9ed8ff;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 8px;
  border-radius: 10px;
  background: rgba(14, 26, 39, 0.55);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 18px;
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  margin: 0;
  font-size: 1.5rem;
}

.overlay p {
  margin: 0;
  max-width: 280px;
}

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

.btn {
  border: none;
  border-radius: 12px;
  min-height: 44px;
  padding: 10px;
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  background: var(--accent);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  min-width: 130px;
  background: var(--accent-strong);
}

.btn.danger {
  background: var(--danger);
}
