:root {
  --bg-0: #0e1022;
  --bg-1: #1a1f3a;
  --panel: rgba(12, 16, 36, 0.9);
  --line: rgba(255, 255, 255, 0.14);
  --ink: #eef3ff;
  --muted: #9fb0da;
  --hot: #ff5f4d;
  --good: #6fe39b;
  --btn: #2b80ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 100%);
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px;
}

.app-shell {
  width: min(980px, 100%);
}

.panel {
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.38);
}

.hidden {
  display: none !important;
}

.menu-panel {
  text-align: center;
  padding: clamp(20px, 4vw, 30px);
}

.menu-panel h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.2rem);
  color: #ffd764;
}

.tag {
  margin: 9px 0;
  color: var(--muted);
  font-weight: 700;
  font-size: clamp(1rem, 2.8vw, 1.2rem);
}

.menu-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.main-btn,
.ghost-btn,
.touch-btn {
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, filter 140ms ease;
}

.main-btn {
  padding: 12px 22px;
  background: linear-gradient(140deg, #ff9a3a, #ff5241);
  color: #fff;
}

.ghost-btn {
  padding: 12px 18px;
  color: #ddebff;
  background: linear-gradient(140deg, #345fca, #2e47a3);
}

.ghost-btn.mini {
  padding: 8px 14px;
  font-size: 0.9rem;
}

.main-btn:hover,
.ghost-btn:hover,
.touch-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.main-btn:active,
.ghost-btn:active,
.touch-btn:active {
  transform: translateY(1px);
}

.game-panel {
  padding: 12px;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.hud-line {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-weight: 800;
}

#stateText {
  color: #ffd764;
}

.hud-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.canvas-wrap {
  border: 2px solid rgba(255, 255, 255, 0.17);
  border-radius: 12px;
  overflow: hidden;
  background: #161a34;
}

#gameCanvas {
  display: block;
  width: 100%;
  max-height: min(74vh, 760px);
  max-height: min(74dvh, 760px);
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.touch-controls {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.touch-btn {
  min-height: 56px;
  background: linear-gradient(140deg, #3b4f9d, #2d3f84);
  color: #fff;
}

.touch-btn.jump {
  background: linear-gradient(140deg, #2f9d7d, #247c62);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 22, 0.58);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 30;
}

.overlay-card {
  width: min(420px, 100%);
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.26);
  background: linear-gradient(180deg, #1a244a, #141e40);
  text-align: center;
  padding: 20px;
}

.overlay-card h2 {
  margin: 0;
  color: #ffd764;
  font-size: clamp(1.5rem, 5vw, 2rem);
}

.overlay-card p {
  margin: 10px 0 16px;
  color: #d0ddff;
  white-space: pre-line;
  font-weight: 700;
}

@media (min-width: 860px) {
  .touch-controls {
    display: none;
  }
}

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

  .hud-line {
    font-size: 0.92rem;
  }

  .touch-btn {
    min-height: 52px;
  }
}
