:root {
  color-scheme: dark;
  --bg: #0c0f16;
  --panel: #151b27;
  --card: #1b2333;
  --line: #293349;
  --text: #edf2ff;
  --muted: #aab6d2;
  --accent: #ffd54f;
  --accent-2: #80d8ff;
  --good: #86efac;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(128,216,255,0.08), transparent 30%),
    linear-gradient(180deg, #0e1420 0%, #090c12 100%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
}

.app-shell {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat {
  padding: 10px 14px;
  background: rgba(21, 27, 39, 0.85);
  border: 1px solid var(--line);
  border-radius: 16px;
  min-width: 100px;
  box-shadow: var(--shadow);
}
.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.game-layout {
  display: grid;
  grid-template-columns: 1.75fr 0.85fr;
  gap: 16px;
}

.viewport-wrap {
  position: relative;
  background: rgba(14, 20, 32, 0.65);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 12px;
  box-shadow: var(--shadow);
}

#gameCanvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 18px;
  background: #000;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: rgba(21, 27, 39, 0.92);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

button {
  appearance: none;
  border: 0;
  border-radius: 14px;
  background: #2a3650;
  color: var(--text);
  padding: 12px 14px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, background 120ms ease;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px) scale(0.995); }
button.active, .primary-btn {
  background: linear-gradient(135deg, #ffd54f 0%, #ffb300 100%);
  color: #1a1400;
}
.full-width { width: 100%; }

.controls-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}
.controls-list li + li { margin-top: 8px; }

.hint, #statusText {
  margin: 0;
  color: var(--muted);
}
.hint { margin-top: 8px; }

.overlay {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  background: rgba(5, 8, 14, 0.66);
  border-radius: 18px;
  backdrop-filter: blur(4px);
}
.hidden { display: none; }

.overlay-card {
  width: min(420px, 92%);
  background: rgba(24, 32, 47, 0.96);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.overlay-card h2 {
  margin-top: 0;
  margin-bottom: 10px;
}
.overlay-card p {
  color: var(--muted);
  margin-bottom: 18px;
}

.touch-controls {
  position: sticky;
  bottom: 10px;
  z-index: 20;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 16px;
}
.touch-controls button {
  min-height: 56px;
  font-size: 1.25rem;
}

@media (max-width: 980px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .touch-controls { display: grid; }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
