:root {
  --bg-top: #0c1116;
  --bg-bottom: #1e1410;
  --panel: #151d24;
  --panel-border: #2c3b47;
  --text-main: #f6f3ec;
  --text-muted: #a6b1bc;
  --accent: #f5a33e;
  --accent-soft: #f4c06d;
  --danger: #ec5f4f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text-main);
  font-family: "VT323", "Trebuchet MS", "Courier New", monospace;
  background:
    radial-gradient(circle at 20% 20%, rgba(245, 163, 62, 0.2), transparent 42%),
    radial-gradient(circle at 80% 5%, rgba(39, 99, 156, 0.22), transparent 35%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  display: grid;
  place-items: center;
  padding: 18px;
}

#app {
  width: min(100%, 760px);
  background: linear-gradient(160deg, rgba(17, 24, 31, 0.93), rgba(18, 13, 10, 0.9));
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.45);
  padding: 18px;
}

.top h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 3.2rem);
  letter-spacing: 1px;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 1.45rem;
}

.mode-switch {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

button.mode {
  background: linear-gradient(180deg, #334351, #212d37);
  color: #d7e2ec;
  border: 1px solid #3a4b57;
}

button.mode.active {
  background: linear-gradient(180deg, #f5be66, #d38c33);
  color: #1f160a;
  border-color: #da9b49;
}

.hud {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  background: rgba(8, 12, 16, 0.65);
  border: 1px solid #25313b;
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.35rem;
}

.label {
  color: var(--text-muted);
}

.board-wrap {
  margin-top: 12px;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #2d3a45;
}

#game {
  width: 100%;
  height: auto;
  display: block;
  background: #11161c;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 10, 13, 0.82);
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
}

.overlay h2 {
  margin: 0;
  color: var(--danger);
  font-size: 2.2rem;
}

.overlay p {
  margin-top: 8px;
  font-size: 1.5rem;
}

.hidden {
  display: none;
}

.controls {
  margin-top: 12px;
}

.controls p {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 1.3rem;
}

.touch {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

button {
  border: none;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
  font-size: 1.2rem;
  padding: 10px 8px;
  background: linear-gradient(180deg, var(--accent), #db8030);
  color: #1a140d;
  font-weight: 700;
}

button:hover {
  filter: brightness(1.04);
}

#restart {
  width: 100%;
  background: linear-gradient(180deg, var(--accent-soft), #d39a3f);
}

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

  #app {
    padding: 12px;
    border-radius: 14px;
  }

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

  .mode-switch {
    grid-template-columns: 1fr;
  }
}
