:root {
  --bg: #101816;
  --surface: rgba(18, 30, 28, 0.88);
  --surface-2: rgba(31, 44, 39, 0.94);
  --line: rgba(221, 235, 224, 0.18);
  --text: #f6fbf4;
  --muted: #b5c8b8;
  --green: #4ade80;
  --sky: #38bdf8;
  --gold: #f59e0b;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(56, 189, 248, 0.14), transparent 38%),
    linear-gradient(225deg, rgba(245, 158, 11, 0.12), transparent 32%),
    linear-gradient(180deg, #14221f 0%, #101816 58%, #0d1514 100%);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

body { display: flex; justify-content: center; }

.wrap {
  width: min(1040px, 100vw);
  padding: 14px;
}

.topbar,
.controls,
.panel,
.stat {
  backdrop-filter: blur(14px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(20, 34, 31, 0.94), rgba(14, 25, 23, 0.94));
}

.topbar h1,
.panel h2 { margin: 0; }

.topbar h1 {
  font-size: clamp(1.35rem, 3.2vw, 2.15rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 62ch;
  font-size: 0.95rem;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  color: #f8fffb;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, opacity 120ms ease;
}

button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.48; cursor: not-allowed; transform: none; }

#restartBtn {
  padding: 10px 14px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
}

#soundBtn {
  padding: 10px 14px;
  background: linear-gradient(135deg, #16a34a, #0f766e);
}

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

.stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat span { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.stat strong { font-size: 1.03rem; }

.stage-shell {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(221, 235, 224, 0.22);
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(180deg, #8cd9ff 0 28%, #4f8f43 28% 100%);
  touch-action: none;
  box-shadow: 0 24px 60px rgba(2, 8, 23, 0.34);
}

#game-stage,
#game-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
}

#message { margin: 0; font-weight: 700; }

.control-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.save-state {
  margin: 0;
  color: #bbf7d0;
  font-size: 0.82rem;
  font-weight: 700;
}

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

.panel {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.panel h2 { font-size: 1rem; letter-spacing: 0; }

.actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.actions button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.28), rgba(14, 165, 233, 0.2));
  border: 1px solid rgba(134, 239, 172, 0.2);
}

.actions button span { color: #fef3c7; font-weight: 900; white-space: nowrap; }

@media (max-width: 860px) {
  .panel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { width: 100%; }
  #restartBtn, #soundBtn { width: 100%; }
}

@media (max-width: 560px) {
  .hud,
  .panel-grid { grid-template-columns: 1fr; }
  .wrap { padding: 10px; }
  .control-meta { align-items: flex-start; }
}
