:root {
  --bg: #161927;
  --panel: rgba(24, 31, 52, 0.9);
  --panel-soft: rgba(40, 49, 79, 0.88);
  --ink: #f7f3ff;
  --accent: #ff9ec4;
  --accent-2: #ffe07a;
  --accent-3: #82e0c8;
  --danger: #ff7d7d;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(120, 136, 255, 0.28), transparent 35%),
    linear-gradient(180deg, #101322 0%, #171b31 45%, #0d1020 100%);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  background: rgba(18, 22, 38, 0.78);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: clamp(1.3rem, 2vw, 1.6rem);
}

.brand p {
  color: #cfd4ff;
  font-size: 0.95rem;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 158, 196, 0.22), rgba(255, 224, 122, 0.22));
  font-size: 1.7rem;
  flex: 0 0 auto;
}

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

.hud-stats div {
  min-width: 122px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
}

.label {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #b8bde5;
}

.canvas-wrap {
  position: relative;
  border-radius: 28px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #0b0f1e;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  max-height: min(72vh, 860px);
  background: transparent;
  touch-action: manipulation;
}

.touch-controls {
  position: absolute;
  inset: auto 0 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding: 18px;
  pointer-events: none;
}

.touch-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.touch-button {
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  min-width: 58px;
  min-height: 58px;
  padding: 0 16px;
  font: inherit;
  font-weight: 800;
  color: #f7f3ff;
  background: rgba(15, 19, 34, 0.72);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  touch-action: manipulation;
  user-select: none;
}

.touch-button:active,
.touch-button.is-active {
  transform: scale(0.96);
  background: rgba(255, 158, 196, 0.28);
}

.touch-button-jump {
  min-width: 112px;
  min-height: 72px;
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.touch-button-secondary {
  font-size: 0.95rem;
  min-width: 88px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 13, 24, 0.58);
  backdrop-filter: blur(8px);
}

.overlay.visible {
  display: flex;
}

.panel {
  width: min(560px, 100%);
  max-height: min(100%, 92vh);
  overflow: auto;
  padding: 24px;
  border-radius: 28px;
  background: linear-gradient(180deg, var(--panel), var(--panel-soft));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.panel p {
  margin: 0 0 16px;
  line-height: 1.5;
  color: #dde0fb;
}

.panel-art {
  position: relative;
  height: 160px;
  margin-bottom: 18px;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, #334078 0%, #1d2751 55%, #1b3d2c 100%);
}

.moon {
  position: absolute;
  width: 72px;
  height: 72px;
  right: 42px;
  top: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8c5 0%, #ffe59d 60%, #ffd974 100%);
  box-shadow: 0 0 40px rgba(255, 236, 154, 0.5);
}

.tree {
  position: absolute;
  bottom: -8px;
  width: 90px;
  height: 120px;
  background: linear-gradient(180deg, #264b39, #153425);
  clip-path: polygon(50% 0%, 83% 29%, 68% 29%, 100% 64%, 72% 63%, 86% 100%, 14% 100%, 28% 63%, 0% 64%, 32% 29%, 17% 29%);
}

.tree::after {
  content: "";
  position: absolute;
  left: 40px;
  bottom: -22px;
  width: 12px;
  height: 40px;
  border-radius: 999px;
  background: #5f3c22;
}

.tree-left { left: 28px; }
.tree-right { right: 150px; transform: scale(1.1); }

.possum-face {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: 138px;
  height: 92px;
  border-radius: 60% 60% 52% 52%;
  background: #b6acb7;
  box-shadow: inset 0 -12px 0 rgba(0, 0, 0, 0.08);
}

.ear,
.eye,
.nose {
  position: absolute;
  display: block;
}

.ear {
  top: -18px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #f8b8ca;
  border: 8px solid #978c98;
}

.ear-left { left: 12px; }
.ear-right { right: 12px; }
.eye {
  top: 36px;
  width: 12px;
  height: 16px;
  border-radius: 50%;
  background: #151515;
}
.eye-left { left: 38px; }
.eye-right { right: 38px; }
.nose {
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: 24px;
  height: 18px;
  border-radius: 50% 50% 65% 65%;
  background: #ff9fbb;
}

.controls-list {
  margin: 0 0 18px;
  padding-left: 18px;
  color: #dee2ff;
}

.controls-list li + li {
  margin-top: 8px;
}

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

button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  color: #1a1630;
  background: linear-gradient(180deg, #ffe48e, #ffb95b);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 185, 91, 0.32);
}

button.ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

button:hover {
  transform: translateY(-1px);
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls {
    display: none;
  }
}

@media (max-width: 900px) {
  .game-shell {
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .hud-bar {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
  }

  .hud-stats {
    width: 100%;
    gap: 10px;
  }

  .hud-stats div {
    flex: 1 1 140px;
  }

  .touch-controls {
    padding: 14px;
  }
}

@media (max-width: 640px) {
  .game-shell {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .brand {
    align-items: flex-start;
  }

  .brand p {
    font-size: 0.85rem;
  }

  .canvas-wrap {
    border-radius: 22px;
  }

  canvas {
    max-height: 56vh;
  }

  .overlay {
    align-items: stretch;
    padding: 12px;
  }

  .panel {
    width: 100%;
    padding: 18px;
    border-radius: 22px;
  }

  .panel-art {
    height: 118px;
  }

  .moon {
    width: 54px;
    height: 54px;
    right: 24px;
    top: 18px;
  }

  .tree {
    width: 72px;
    height: 96px;
  }

  .tree-right {
    right: 98px;
  }

  .possum-face {
    width: 110px;
    height: 74px;
  }

  .touch-controls {
    gap: 10px;
    padding: 10px;
  }

  .touch-row {
    gap: 8px;
  }

  .touch-row-right {
    flex-direction: column;
    align-items: stretch;
  }

  .touch-button {
    min-width: 52px;
    min-height: 52px;
    border-radius: 16px;
    padding: 0 14px;
  }

  .touch-button-jump {
    min-width: 104px;
    min-height: 64px;
  }

  .touch-button-secondary {
    min-width: 78px;
    min-height: 48px;
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) and (orientation: portrait) {
  .hud-bar {
    margin-bottom: 10px;
  }

  canvas {
    aspect-ratio: 10 / 13;
    max-height: 60vh;
  }

  .touch-controls {
    inset: auto 0 0;
    align-items: flex-end;
  }

  .touch-row-left {
    align-items: flex-end;
  }

  .touch-button-jump {
    margin-bottom: 18px;
  }
}
