:root {
  --app-height: 100vh;
  --ink: #f7fbff;
  --muted: #a7bdd3;
  --panel: #0e1520;
  --line: rgba(255, 255, 255, 0.16);
  --gold: #f8d66d;
  --cyan: #60f1dc;
  --danger: #ff6f91;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(96, 241, 220, 0.18), transparent 26rem),
    radial-gradient(circle at 78% 16%, rgba(248, 214, 109, 0.16), transparent 25rem),
    linear-gradient(145deg, #07111d 0%, #17202b 46%, #2a1421 100%);
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button {
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 900;
  color: var(--ink);
  cursor: pointer;
}

.shell {
  min-height: var(--app-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.game-panel {
  position: relative;
  width: min(100%, 1180px);
  aspect-ratio: 16 / 9;
  max-height: calc(var(--app-height) - 170px);
  min-height: 280px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #08101a;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
  touch-action: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  position: absolute;
  inset: 14px 14px auto;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
  text-shadow: 0 2px 10px #000;
  font-size: 0.92rem;
}

.hud strong {
  display: block;
  font-size: 1rem;
}

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

.meters {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.meters span {
  min-width: 72px;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(5, 11, 18, 0.54);
  border-radius: 8px;
  color: var(--ink);
  text-align: center;
}

.meters b {
  color: var(--gold);
}

.start {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 26px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 36%, rgba(96, 241, 220, 0.16), transparent 18rem),
    rgba(4, 8, 14, 0.7);
}

.start.hidden {
  display: none;
}

.start h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 7vw, 4.8rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.start p {
  max-width: 560px;
  margin: 0 auto 22px;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.15rem);
}

.start button {
  padding: 13px 24px;
  background: linear-gradient(135deg, #f8d66d, #ff8b6f);
  color: #17110b;
  box-shadow: 0 10px 28px rgba(248, 214, 109, 0.24);
}

.touch {
  display: none;
  width: min(100%, 760px);
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(23, 32, 43, 0.94), rgba(10, 15, 23, 0.94)),
    #101923;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.04), 0 18px 50px rgba(0, 0, 0, 0.35);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.pad {
  display: flex;
  gap: 10px;
}

.touch button {
  min-width: 70px;
  min-height: 54px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(180deg, #263444, #141d28);
  color: var(--ink);
  box-shadow: 0 7px 0 #07101a;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch button:active,
.touch button.pressed {
  transform: translateY(5px);
  box-shadow: 0 2px 0 #07101a;
  background: linear-gradient(180deg, #34546a, #1b2b39);
}

.actions button:nth-child(2) {
  background: linear-gradient(180deg, #7b2741, #321522);
}

.actions button:nth-child(3) {
  background: linear-gradient(180deg, #24605b, #12312f);
}

@media (pointer: coarse), (max-width: 820px), (max-height: 560px) {
  html,
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .shell {
    display: grid;
    grid-template-rows: minmax(0, 1fr) clamp(132px, 24dvh, 190px);
    align-items: stretch;
    justify-content: stretch;
    width: 100vw;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    gap: 0;
    padding: 0;
    background:
      radial-gradient(circle at 18% 28%, rgba(96, 241, 220, 0.12), transparent 9rem),
      radial-gradient(circle at 84% 35%, rgba(255, 111, 145, 0.13), transparent 8rem),
      linear-gradient(180deg, #151b21 0%, #0f1216 100%);
  }

  .game-panel {
    width: 100vw;
    height: 100%;
    align-self: end;
    aspect-ratio: auto;
    max-height: none;
    min-height: 0;
    border: 0;
    border-radius: 0;
    border-bottom: 6px solid rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 -18px 40px rgba(0, 0, 0, 0.35);
  }

  canvas {
    width: auto;
    min-width: 100%;
    height: 100%;
    max-width: none;
  }

  .touch {
    display: flex;
    width: 100vw;
    min-height: 0;
    height: 100%;
    padding: 16px max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom))
      max(18px, env(safe-area-inset-left));
    border-width: 1px 0 0;
    border-radius: 0;
    background:
      linear-gradient(180deg, rgba(31, 39, 48, 0.98), rgba(12, 15, 19, 0.98)),
      #101923;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      inset 0 0 0 2px rgba(255, 255, 255, 0.03);
  }

  .pad {
    align-items: center;
    gap: 12px;
  }

  .actions {
    gap: 10px;
  }

  .touch button {
    min-width: 74px;
    min-height: 66px;
    padding: 0 12px;
    border-radius: 10px;
    font-size: 0.95rem;
    box-shadow: 0 8px 0 #070b10, 0 18px 34px rgba(0, 0, 0, 0.3);
  }

  .touch-left,
  .touch-right {
    min-width: 70px;
    border-radius: 12px;
  }

  .touch-jump {
    min-width: 86px;
    min-height: 78px;
    border-radius: 999px;
    background: linear-gradient(180deg, #6df5df, #2fbfaf);
    color: #062119;
  }

  .touch-strike {
    min-width: 82px;
    min-height: 72px;
    border-radius: 999px;
    background: linear-gradient(180deg, #ff8aaa, #8c2e4b);
    color: #260c16;
  }

  .touch-dash {
    min-width: 78px;
    min-height: 68px;
    border-radius: 999px;
    background: linear-gradient(180deg, #ffe180, #c69034);
    color: #201405;
  }

  .hud {
    inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) auto
      max(8px, env(safe-area-inset-left));
    font-size: 0.82rem;
  }

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

  .meters {
    gap: 6px;
  }

  .meters span {
    min-width: 58px;
    padding: 6px;
  }
}

@media (max-width: 560px) and (orientation: portrait) {
  .shell {
    grid-template-rows: minmax(0, 68dvh) minmax(148px, 32dvh);
    align-content: stretch;
  }

  .game-panel {
    grid-row: 1;
    width: 100vw;
    height: 100%;
    aspect-ratio: auto;
    align-self: start;
  }

  .touch {
    grid-row: 2;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 148px;
  }

  .pad,
  .actions {
    justify-content: center;
  }

  .touch button {
    flex: 0 0 auto;
    min-width: clamp(50px, 14.5vw, 62px);
    min-height: clamp(54px, 15vw, 66px);
    padding: 0 8px;
    font-size: clamp(0.68rem, 2.7vw, 0.78rem);
  }

  .pad {
    flex: 0 0 auto;
    gap: clamp(6px, 2vw, 9px);
  }

  .actions {
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: clamp(5px, 1.8vw, 8px);
  }

  .touch-left,
  .touch-right {
    min-width: clamp(50px, 14.5vw, 62px);
  }

  .touch-jump {
    min-width: clamp(62px, 18vw, 78px);
    min-height: clamp(62px, 18vw, 78px);
  }

  .touch-strike {
    min-width: clamp(62px, 18vw, 76px);
    min-height: clamp(60px, 17vw, 72px);
  }

  .touch-dash {
    min-width: clamp(56px, 16vw, 70px);
    min-height: clamp(56px, 16vw, 68px);
  }
}

@media (pointer: coarse) and (orientation: landscape), (max-width: 820px) and (orientation: landscape), (max-height: 560px) and (orientation: landscape) {
  .shell {
    grid-template-rows: minmax(0, 1fr) clamp(86px, 22dvh, 112px);
  }

  .game-panel {
    width: 100vw;
    height: 100%;
    max-width: 100vw;
    aspect-ratio: auto;
    justify-self: center;
  }

  .touch {
    min-height: 0;
    padding-top: 8px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

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

  .touch-jump {
    min-height: 62px;
  }

  .touch-strike,
  .touch-dash {
    min-height: 58px;
  }
}

.analogue-stick {
  position: relative;
  display: grid;
  place-items: center;
  width: 126px;
  height: 126px;
  border-radius: 50%;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.stick-base {
  position: relative;
  display: block;
  width: 116px;
  height: 116px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(96, 241, 220, 0.18), transparent 36%),
    linear-gradient(145deg, #263444, #101923);
  box-shadow: inset 0 0 0 10px rgba(255, 255, 255, 0.035), 0 14px 36px rgba(0, 0, 0, 0.38);
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(145deg, #f7fbff, #60f1dc);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.38), inset 0 -5px 0 rgba(0, 0, 0, 0.2);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

@media (pointer: coarse), (max-width: 820px), (max-height: 560px) {
  .shell {
    grid-template-rows: minmax(0, 1fr) clamp(164px, 30dvh, 220px);
  }

  .touch {
    overflow: hidden;
  }

  .actions {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(92px, 1fr));
    gap: 10px;
    width: min(214px, 56vw);
  }

  .touch-left,
  .touch-right {
    display: none;
  }

  .touch button {
    flex: 0 0 auto;
    min-width: 92px;
    min-height: 82px;
    font-size: 1rem;
  }

  .touch-jump {
    min-width: 106px;
    min-height: 98px;
  }

  .touch-strike {
    min-width: 102px;
    min-height: 92px;
  }

  .touch-dash {
    min-width: 96px;
    min-height: 86px;
  }
}

@media (max-width: 560px) and (orientation: portrait) {
  .shell {
    grid-template-rows: minmax(0, 63dvh) minmax(176px, 37dvh);
  }

  .touch button {
    width: 100%;
    min-width: 0;
    min-height: clamp(72px, 20vw, 88px);
    padding-inline: 8px;
  }

  .touch-jump {
    min-width: 0;
    min-height: clamp(80px, 22vw, 96px);
  }

  .touch-strike {
    min-width: 0;
    min-height: clamp(80px, 22vw, 96px);
  }

  .touch-dash {
    min-width: 0;
    min-height: clamp(76px, 21vw, 92px);
  }
}

@media (pointer: coarse) and (orientation: landscape), (max-width: 820px) and (orientation: landscape), (max-height: 560px) and (orientation: landscape) {
  .shell {
    grid-template-rows: minmax(0, 1fr) clamp(116px, 27dvh, 138px);
  }

  .analogue-stick {
    width: 92px;
    height: 92px;
  }

  .stick-base {
    width: 88px;
    height: 88px;
  }

  .stick-knob {
    width: 44px;
    height: 44px;
  }

  .touch button {
    flex: 0 0 auto;
    min-width: 104px;
    min-height: 70px;
  }

  .actions {
    display: flex;
    width: auto;
  }
}
