:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --ink: #f8faff;
  --muted: #aeb8dd;
  --glass: rgba(17, 23, 60, .76);
  --line: rgba(255, 255, 255, .14);
  --pink: #ff4da6;
  --cyan: #49e7ff;
  --yellow: #ffd84d;
  --radius: 18px;
}

* { box-sizing: border-box; }
html { height: 100%; background: #090b22; }
body {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: flex;
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 8%, #392f8d 0, transparent 32%),
    radial-gradient(circle at 92% 92%, #771353 0, transparent 35%),
    #090b22;
}
button { font: inherit; }
button:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
#root { flex: 1 1 auto; width: 100%; min-height: 0; }

.game-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  padding:
    calc(var(--safe-top) + 10px)
    calc(var(--safe-right) + 10px)
    calc(var(--safe-bottom) + 10px)
    calc(var(--safe-left) + 10px);
}

.topbar {
  z-index: 5;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 8px 8px;
  background: var(--glass);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .22);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 11px;
  color: #17132e;
  font-size: 19px;
  background: linear-gradient(145deg, var(--yellow), #ff7c4d);
  box-shadow: 0 0 20px rgba(255, 216, 77, .35);
}
.brand h1 { margin: 0; font-size: clamp(.95rem, 3.8vw, 1.25rem); letter-spacing: -.04em; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: .65rem; }

.stats { display: flex; gap: 5px; }
.stat {
  min-width: 48px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
  background: rgba(255,255,255,.06);
}
.stat span { display: block; color: var(--muted); font-size: .55rem; text-transform: uppercase; letter-spacing: .1em; }
.stat strong { color: var(--yellow); font-size: .82rem; }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px 9px 18px 18px;
  background: #11183f;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .35);
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.level-name {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 3;
  transform: translateX(-50%);
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #fff;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  background: rgba(8, 10, 33, .66);
  backdrop-filter: blur(10px);
}

.sound-btn {
  position: absolute;
  z-index: 4;
  top: 9px;
  right: 9px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: white;
  background: rgba(8, 10, 33, .66);
  cursor: pointer;
}

.controls {
  position: absolute;
  z-index: 5;
  right: calc(var(--safe-right) + 20px);
  bottom: calc(var(--safe-bottom) + 20px);
  left: calc(var(--safe-left) + 20px);
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.control-group { display: flex; gap: 10px; pointer-events: auto; }
.control {
  width: clamp(54px, 16vw, 70px);
  height: clamp(54px, 16vw, 70px);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 22px;
  color: white;
  font-size: 1.35rem;
  font-weight: 900;
  background: rgba(19, 25, 64, .72);
  box-shadow: 0 8px 22px rgba(0,0,0,.28), inset 0 1px rgba(255,255,255,.15);
  backdrop-filter: blur(12px);
  touch-action: none;
  user-select: none;
  transition: transform .12s ease, background .2s ease;
}
.control.jump { color: #1a1730; background: linear-gradient(145deg, var(--yellow), #ff8b4d); }
.control:active, .control.active { transform: scale(.91); background: rgba(73,231,255,.45); }

.overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at 50% 30%, rgba(71,61,167,.72), rgba(7,9,31,.94));
  backdrop-filter: blur(8px);
}
.card {
  width: min(100%, 440px);
  padding: clamp(22px, 6vw, 38px);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 28px;
  text-align: center;
  background: linear-gradient(150deg, rgba(36,43,103,.92), rgba(20,15,55,.94));
  box-shadow: 0 28px 80px rgba(0,0,0,.45);
}
.card .mascot { font-size: clamp(3rem, 14vw, 5.5rem); filter: drop-shadow(0 8px 16px rgba(0,0,0,.3)); }
.card h2 { margin: 8px 0; font-size: clamp(1.8rem, 8vw, 3.1rem); line-height: .95; letter-spacing: -.06em; }
.card p { margin: 13px auto 20px; max-width: 32ch; color: var(--muted); line-height: 1.5; }
.play {
  min-height: 50px;
  padding: 10px 24px;
  border: 0;
  border-radius: 14px;
  color: #15142d;
  font-weight: 900;
  background: linear-gradient(135deg, var(--yellow), #ff7f55);
  box-shadow: 0 12px 30px rgba(255,128,82,.28);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease;
}
.play:hover { transform: translateY(-2px); box-shadow: 0 16px 35px rgba(255,128,82,.38); }
.tips { margin-top: 14px; color: #8692be; font-size: .7rem; }

footer {
  position: absolute;
  z-index: 2;
  bottom: calc(var(--safe-bottom) + 3px);
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.45);
  font-size: .58rem;
  pointer-events: none;
}

@media (min-width: 760px) {
  .game-shell { padding: 18px; }
  .topbar { padding: 10px 16px; }
  .brand p { font-size: .72rem; }
  .controls { right: 32px; bottom: 32px; left: 32px; }
  .control { opacity: .8; }
}
@media (hover: hover) and (pointer: fine) {
  .controls { opacity: .55; }
  .controls:hover { opacity: 1; }
}
@media (max-height: 500px) {
  .brand p, footer { display: none; }
  .topbar { padding-block: 5px; }
  .logo { width: 30px; height: 30px; }
  .control { width: 50px; height: 50px; border-radius: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition-duration: .01ms !important; }
}