:root {
  --bg: #2f343b;
  --panel: #3d434b;
  --panel-soft: #4a515b;
  --text: #edf1f5;
  --text-soft: #b5bdc8;
  --accent: #9eacbc;
  --warn: #cbb58f;
  --danger: #d57d63;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #252a31 0%, #30363e 48%, #3a424c 100%);
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.hud {
  background: linear-gradient(145deg, #4d545e, #373d45);
  border: 1px solid #636c77;
  border-radius: 14px;
  padding: 0.85rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.hud h1 {
  margin: 0;
  letter-spacing: 0.05em;
  font-size: 1.22rem;
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--text-soft);
  font-size: 0.86rem;
}

.stats {
  display: flex;
  gap: 0.6rem;
}

.stats p {
  margin: 0;
  min-width: 4.1rem;
  background: var(--panel-soft);
  border: 1px solid #636c77;
  border-radius: 10px;
  padding: 0.35rem 0.55rem;
  display: flex;
  flex-direction: column;
}

.stats span {
  color: var(--text-soft);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats strong {
  font-size: 1.05rem;
}

.board-wrap {
  border-radius: 14px;
  border: 1px solid #606975;
  background: linear-gradient(180deg, #323841, #2a2f36);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(236, 243, 255, 0.1);
}

#board {
  width: 100%;
  height: clamp(360px, 68vh, 760px);
  position: relative;
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.controls {
  background: var(--panel);
  border: 1px solid #636c77;
  border-radius: 14px;
  padding: 0.75rem 1rem;
  display: grid;
  gap: 0.55rem;
}

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

.debug-row {
  padding-top: 0.1rem;
}

.debug-row[hidden] {
  display: none;
}

button {
  border: 1px solid #69727f;
  border-radius: 10px;
  background: #8b96a4;
  color: #13181f;
  padding: 0.5rem 0.8rem;
  font-size: 0.92rem;
  cursor: pointer;
}

button:hover {
  background: #9ca8b7;
}

#message {
  margin: 0;
  min-height: 1.25rem;
  color: var(--warn);
  font-weight: 600;
}

.help {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.86rem;
}

kbd {
  background: #4b525c;
  border: 1px solid #6e7682;
  border-radius: 4px;
  padding: 0 0.3rem;
}

.touch {
  display: none;
  justify-items: center;
  gap: 0.5rem;
}

.touch > button,
.touch div button {
  width: 3rem;
  height: 3rem;
  font-size: 1.1rem;
}

.touch div {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

@media (max-width: 900px) {
  .hud {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 760px), (hover: none) {
  .touch {
    display: grid;
  }
}
