:root {
  color-scheme: dark;
  --bg: #0f1422;
  --surface: rgba(20, 28, 48, 0.9);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f0f3fb;
  --muted: #aab3c8;
  --accent: #ffd166;
  --danger: #ff5c5c;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.4);
  font-family: "Bahnschrift", "Yu Gothic", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.04), transparent 40%),
    var(--bg);
  color: var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  min-height: 40px;
  padding: 0 12px;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

button:active {
  transform: translateY(1px);
}

.game-shell {
  width: min(960px, calc(100% - 24px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.hero-copy {
  margin: 0;
  color: var(--muted);
}

.ghost-button {
  background: transparent;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.difficulty-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
}

.difficulty-button {
  border: 0;
  border-radius: 0;
  min-height: 36px;
  padding: 0 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: transparent;
}

.difficulty-button + .difficulty-button {
  border-left: 1px solid var(--line);
}

.difficulty-button.is-active[data-difficulty="normal"] {
  background: rgba(58, 175, 90, 0.22);
  color: #b8f0c4;
}

.difficulty-button.is-active[data-difficulty="hard"] {
  background: rgba(229, 92, 92, 0.22);
  color: #ffc0c0;
}

.hud-cell.hud-difficulty {
  font-weight: 700;
  letter-spacing: 0.08em;
}

.stage-frame {
  display: grid;
  gap: 10px;
  justify-items: center;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.92rem;
  color: var(--muted);
}

.hud-cell strong {
  color: var(--text);
  font-size: 1.02rem;
  margin-left: 6px;
}

.hud-cell.hud-stage {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
}

canvas#game {
  display: block;
  width: min(512px, 100%);
  height: auto;
  aspect-ratio: 512 / 448;
  border: 2px solid #000;
  border-radius: 4px;
  background: #6cb0f0;
  image-rendering: pixelated;
  outline: none;
  box-shadow: var(--shadow);
  touch-action: none;
}

canvas#game:focus-visible {
  border-color: var(--accent);
}

.controls-hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.touch-controls {
  display: none;
}

.touch-pad {
  display: flex;
  gap: 12px;
  pointer-events: none;
}

.touch-pad button {
  pointer-events: auto;
}

.touch-controls button {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(20, 24, 38, 0.55);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.35);
  font-size: 1.4rem;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  min-width: 72px;
  min-height: 72px;
}

.touch-controls button.is-pressed,
.touch-controls button:active {
  background: rgba(255, 220, 110, 0.55);
  color: #1a1a1a;
  transform: scale(0.96);
}

.touch-controls button.touch-jump {
  min-width: 96px;
  min-height: 96px;
  pointer-events: auto;
}

.controls-hint-mobile {
  display: none;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

@media (hover: none) and (pointer: coarse) {
  .controls-hint {
    display: none;
  }
  .controls-hint-mobile {
    display: block;
  }
  .touch-controls {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    padding: 0 16px;
    justify-content: space-between;
    gap: 12px;
    pointer-events: none;
    z-index: 50;
  }
  /* Keep enough space under the canvas so the fixed dpad doesn't cover gameplay */
  .game-shell {
    padding-bottom: 140px;
  }
  /* Compact HUD on narrow screens */
  .hud {
    font-size: 0.82rem;
    gap: 8px;
    padding: 6px 10px;
  }
  .hud-cell strong {
    font-size: 0.92rem;
    margin-left: 4px;
  }
}

.info {
  display: grid;
  margin-top: 16px;
}

.surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 16px;
}

.surface ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.surface li {
  margin: 2px 0;
}

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

@media (max-width: 720px) {
  .hero {
    display: grid;
  }
  .hero-actions {
    align-items: stretch;
    flex-direction: row;
    flex-wrap: wrap;
  }
}
