:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  background: #050816;
  color: #fff;
  touch-action: none;
}

* { box-sizing: border-box; }

html, body { width: 100%; min-height: 100%; margin: 0; overflow: hidden; }

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 45%, rgba(32, 57, 145, .26), transparent 43%),
    #050816;
  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));
}

button { font: inherit; -webkit-tap-highlight-color: transparent; }

.game-shell { width: min(100%, 570px); }
.game-panel { min-width: 0; }

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 14px;
  padding: 0 6px 7px;
  text-transform: uppercase;
}

.scoreboard div:last-child { text-align: right; }
.scoreboard span { display: block; color: #7f91c9; font-size: clamp(.62rem, 2vw, .78rem); letter-spacing: .14em; }
.scoreboard strong { font-variant-numeric: tabular-nums; font-size: clamp(1rem, 4vw, 1.35rem); }
.scoreboard h1 { margin: 0; color: #ffe600; font-size: clamp(1.15rem, 5vw, 1.75rem); letter-spacing: .08em; text-shadow: 0 0 14px rgba(255, 230, 0, .35); }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 19 / 23;
  border: 2px solid #1b3ff2;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 30px rgba(28, 64, 255, .2), inset 0 0 20px rgba(0, 0, 0, .8);
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 9px;
  padding: 28px;
  text-align: center;
  background: rgba(1, 4, 15, .78);
  backdrop-filter: blur(3px);
}

.overlay[hidden] { display: none; }
.overlay h2 { margin: 0; color: #ffe600; font-size: clamp(1.8rem, 8vw, 3rem); }
.overlay p { max-width: 350px; margin: 0 0 9px; color: #d6dcff; line-height: 1.45; }
.overlay button, #pauseButton {
  border: 0;
  border-radius: 999px;
  background: #ffe600;
  color: #090b16;
  font-weight: 900;
  cursor: pointer;
}
.overlay button { padding: 12px 28px; font-size: 1.05rem; }

.game-footer { display: flex; align-items: center; justify-content: space-between; min-height: 38px; padding: 6px 4px 0; }
#lives { min-height: 24px; color: #ffe600; font-size: 1.15rem; letter-spacing: .2em; }
#pauseButton { padding: 7px 16px; background: #17265d; color: #e7ebff; }

.landscape-controls { display: none; }

@media (orientation: landscape) {
  body { padding: max(5px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .game-shell {
    width: min(100%, 920px);
    height: calc(100dvh - max(10px, env(safe-area-inset-top)) - max(10px, env(safe-area-inset-bottom)));
    display: grid;
    grid-template-columns: minmax(260px, 570px) minmax(150px, 230px);
    justify-content: center;
    align-items: center;
    gap: clamp(18px, 5vw, 58px);
  }
  .game-panel { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
  .canvas-wrap { width: auto; height: 100%; max-width: 100%; margin: auto; }
  .landscape-controls { display: grid; justify-items: center; gap: 14px; user-select: none; }
  .landscape-controls p { margin: 0; color: #ffe600; font-size: 1.08rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
  .landscape-controls small { color: #8292c8; text-align: center; line-height: 1.4; }
  .joystick {
    display: grid;
    grid-template: repeat(3, 66px) / repeat(3, 66px);
    place-items: stretch;
    padding: 8px;
    border-radius: 50%;
    background: radial-gradient(circle, #16245b, #080e2b 70%);
    box-shadow: inset 0 0 0 2px #253b8d, 0 14px 30px rgba(0, 0, 0, .4);
  }
  .direction {
    border: 0;
    border-radius: 15px;
    background: linear-gradient(#344ba5, #1a2d73);
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    touch-action: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 4px 0 #0b143e;
  }
  .direction:active, .direction.active { transform: translateY(3px); box-shadow: inset 0 1px 0 rgba(255,255,255,.16), 0 1px 0 #0b143e; background: #ffe600; color: #071036; }
  .up { grid-area: 1 / 2; }
  .left { grid-area: 2 / 1; }
  .stick-centre { grid-area: 2 / 2; margin: 9px; border-radius: 50%; background: #0a1234; box-shadow: inset 0 0 0 2px #2c4194; }
  .right { grid-area: 2 / 3; }
  .down { grid-area: 3 / 2; }
}

@media (orientation: landscape) and (max-height: 460px) {
  .scoreboard { position: absolute; z-index: 2; width: min(55vw, 440px); padding: 5px 10px; pointer-events: none; text-shadow: 0 2px 4px #000; }
  .scoreboard span { display: none; }
  .scoreboard h1 { font-size: .95rem; }
  .game-footer { position: absolute; z-index: 2; left: 12px; bottom: 9px; width: min(52vw, 420px); pointer-events: none; }
  #pauseButton { pointer-events: auto; }
  .game-panel { position: relative; grid-template-rows: 1fr; }
  .canvas-wrap { height: 100%; }
  .joystick { grid-template: repeat(3, 52px) / repeat(3, 52px); }
  .landscape-controls small { display: none; }
}
