:root {
  color-scheme: dark;
  --ink: #fff7de;
  --muted: #d9c99e;
  --panel: #213526;
  --panel-2: #31513a;
  --line: rgba(255, 247, 222, 0.2);
  --accent: #ffe38a;
  --accent-2: #f7a7bd;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 18% 8%, rgba(247, 167, 189, 0.18), transparent 30%),
    radial-gradient(circle at 78% 0%, rgba(255, 227, 138, 0.13), transparent 28%),
    linear-gradient(180deg, #172419 0%, #0f1b14 100%);
  color: var(--ink);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body {
  display: grid;
  place-items: center;
  padding: 24px;
  min-height: 100svh;
}

.shell {
  width: min(1120px, 100%);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 54px);
  line-height: 0.95;
  letter-spacing: 0;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}

.game-logo {
  display: block;
  width: min(560px, 58vw);
  max-height: 112px;
  object-fit: contain;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.version-badge {
  border: 1px solid rgba(255, 247, 222, 0.18);
  border-radius: 8px;
  background: rgba(33, 53, 38, 0.62);
  color: var(--muted);
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #456b44, #29472e);
  color: var(--ink);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  padding: 0 14px;
  font: inherit;
  font-weight: 700;
}

button:hover {
  border-color: rgba(255, 209, 102, 0.65);
}

.game-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #172d25;
  box-shadow:
    0 22px 80px rgba(0, 0, 0, 0.36),
    inset 0 0 0 1px rgba(255, 247, 222, 0.06);
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
}

.hud {
  position: absolute;
  inset: 14px 14px auto;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.hud span {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(33, 53, 38, 0.78);
  color: var(--ink);
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 800;
  backdrop-filter: blur(8px);
}

.touch-controls {
  position: absolute;
  inset: auto max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: none;
  align-items: end;
  justify-content: space-between;
  pointer-events: none;
}

.joystick {
  --stick-x: 0px;
  --stick-y: 0px;
  width: 112px;
  height: 112px;
  border: 1px solid rgba(255, 247, 222, 0.22);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 247, 222, 0.18), transparent 22%),
    radial-gradient(circle at 50% 50%, rgba(49, 81, 58, 0.72), rgba(20, 38, 27, 0.62));
  box-shadow:
    inset 0 2px 10px rgba(255, 247, 222, 0.08),
    0 14px 34px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.joystick::before {
  content: "";
  position: absolute;
  inset: 24px;
  border: 1px dashed rgba(255, 247, 222, 0.24);
  border-radius: 50%;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 247, 222, 0.32);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.36), transparent 28%),
    linear-gradient(180deg, rgba(247, 167, 189, 0.9), rgba(110, 145, 79, 0.92));
  box-shadow:
    inset 0 1px 0 rgba(255, 247, 222, 0.28),
    0 10px 20px rgba(0, 0, 0, 0.32);
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
  transition: transform 90ms ease-out;
}

.joystick.active .joystick-knob {
  transition: none;
}

.touch-button {
  width: 64px;
  height: 64px;
  min-height: 64px;
  padding: 0;
  border-color: rgba(248, 243, 223, 0.28);
  background: rgba(49, 81, 58, 0.82);
  font-size: 25px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 247, 222, 0.18),
    0 10px 24px rgba(0, 0, 0, 0.24);
}

.touch-button:active {
  transform: translateY(2px);
  filter: brightness(1.12);
}

.touch-button.jump {
  margin-left: auto;
  background: rgba(247, 167, 189, 0.28);
}

@media (max-width: 720px) {
  body {
    align-items: start;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .topbar {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 10px;
  }

  h1 {
    line-height: 0;
  }

  .game-logo {
    width: min(420px, 82vw);
    max-height: 86px;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    width: 100%;
  }

  .hud {
    inset: 8px 8px auto;
  }

  .hud span {
    font-size: 12px;
    padding: 7px 8px;
  }

  .touch-controls {
    display: flex;
    gap: 14px;
  }

}

@media (max-width: 920px) and (orientation: landscape) {
  body {
    display: block;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overflow: hidden;
  }

  .shell {
    width: 100%;
  }

  .topbar {
    align-items: center;
    margin-bottom: 8px;
  }

  h1 {
    line-height: 0;
  }

  .game-logo {
    width: min(340px, 58vw);
    max-height: 54px;
  }

  .actions button {
    min-height: 36px;
    padding: 0 12px;
    font-size: 13px;
  }

  .game-wrap {
    height: calc(100svh - 58px);
  }

  canvas {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: contain;
  }

  .touch-controls {
    display: flex;
  }

  .joystick {
    width: 96px;
    height: 96px;
  }

  .joystick-knob {
    width: 42px;
    height: 42px;
  }

  .touch-button {
    width: 58px;
    height: 58px;
    min-height: 58px;
  }

}
