:root {
  --page-bg: #20314d;
  --panel-bg: #2c405f;
  --screen-border: #f1e7c8;
  --button-bg: #f6ecd0;
  --button-fg: #182332;
  --button-shadow: #7e6b4b;
  --accent: #df6358;
  --accent-alt: #4b8fcb;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page-bg);
  color: #fff;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  line-height: 1.35;
  overscroll-behavior: none;
  -ms-touch-action: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 241, 186, 0.18), transparent 30%),
    linear-gradient(180deg, #35507a 0%, #20314d 48%, #162338 100%);
}

.app-shell {
  width: min(100vw, 520px);
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(18px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto auto;
  align-content: start;
  justify-items: center;
  gap: 24px;
  touch-action: none;
  contain: layout paint;
}

.game-panel {
  width: 100%;
  display: grid;
  place-items: center;
  padding: 8px 0 0;
}

#game {
  display: block;
  width: min(100%, 480px);
  aspect-ratio: 3 / 2;
  height: auto;
  background: #10161f;
  border: 6px solid var(--screen-border);
  border-radius: 10px;
  box-shadow:
    0 0 0 3px #846f47,
    0 18px 0 #0d1219,
    0 28px 40px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}

.controls {
  width: min(100%, 480px);
  display: grid;
  grid-template-columns: minmax(132px, 1fr) minmax(132px, 1fr);
  align-items: center;
  gap: 36px;
  padding: 0 2px;
  touch-action: none;
  margin-top: 0;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(42vw, 182px);
  min-width: 146px;
  max-width: 182px;
  height: min(42vw, 182px);
  justify-self: start;
  align-self: center;
  margin-left: 4px;
}

.pad,
.action {
  border: 0;
  color: var(--button-fg);
  background: linear-gradient(180deg, #fff6df 0%, var(--button-bg) 70%, #ddcda1 100%);
  box-shadow: 0 7px 0 var(--button-shadow);
  font-weight: 800;
  user-select: none;
  touch-action: none;
  -webkit-user-select: none;
}

.pad:active,
.pad.is-pressed,
.action:active,
.action.is-pressed {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--button-shadow);
}

.pad {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  font-size: clamp(20px, 6.4vw, 30px);
  line-height: 1;
}

.pad-up {
  grid-column: 2;
  grid-row: 1;
}

.pad-left {
  grid-column: 1;
  grid-row: 2;
}

.pad-right {
  grid-column: 3;
  grid-row: 2;
}

.pad-down {
  grid-column: 2;
  grid-row: 3;
}

.action-buttons {
  justify-self: end;
  align-self: center;
  width: min(31vw, 128px);
  min-width: 112px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  column-gap: 12px;
  row-gap: 12px;
  margin-right: max(24px, env(safe-area-inset-right));
}

.action {
  width: clamp(58px, 16vw, 70px);
  min-width: 58px;
  aspect-ratio: 1;
  border-radius: 999px;
  font-size: clamp(22px, 6vw, 32px);
  letter-spacing: 0;
}

.action-a {
  background: linear-gradient(180deg, #ff9a88 0%, var(--accent) 85%);
  color: #fff;
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  align-self: start;
}

.action-b {
  background: linear-gradient(180deg, #8dc4f0 0%, var(--accent-alt) 85%);
  color: #fff;
  grid-column: 2;
  grid-row: 2;
  justify-self: center;
  align-self: end;
}

@media (max-width: 380px) {
  .controls {
    gap: 18px;
  }

  .dpad {
    width: min(38vw, 156px);
    min-width: 138px;
    height: min(38vw, 156px);
  }

  .action-buttons {
    width: min(30vw, 120px);
    min-width: 104px;
  }

  .action {
    width: clamp(56px, 15vw, 66px);
    min-width: 56px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app-shell {
    width: min(100vw, 780px);
    min-height: 100vh;
    grid-template-columns: 1fr 260px;
    grid-template-rows: auto;
    align-content: center;
  }

  .controls {
    width: 260px;
    grid-template-columns: 1fr;
    align-self: center;
  }
}
