:root {
  --bg: #090d08;
  --panel: #141d10;
  --green: #9bbc0f;
  --mid: #8bac0f;
  --dark: #306230;
  --ink: #0f380f;
  --muted: #6f8a4f;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background:
    radial-gradient(circle at 50% 12%, rgba(139, 172, 15, 0.13), transparent 42%),
    var(--bg);
  color: var(--green);
  font-family: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  width: min(720px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.brand {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--mid);
  opacity: 0.85;
}

.brand-links {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.brand a {
  color: var(--green);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-decoration: none;
  border-bottom: 1px solid #3f5a2a;
  padding-bottom: 1px;
}

.brand a:hover,
.brand a:focus-visible {
  color: #c7e83a;
}

.brand small {
  letter-spacing: 0.08em;
  font-size: 9px;
  color: var(--muted);
}

.screen-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

canvas {
  display: block;
  width: min(92vw, 64vh, 640px);
  height: auto;
  aspect-ratio: 160 / 144;
  background: var(--green);
  border-radius: 10px;
  border: 1px solid #2d441c;
  box-shadow:
    0 0 0 6px #0d140a,
    0 18px 50px rgba(0, 0, 0, 0.55),
    0 0 60px rgba(139, 172, 15, 0.07);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: pointer;
}

.controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 8vw, 54px);
  margin-top: 2px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
}

.dpad button {
  font-size: 15px;
}

.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }

.right-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.ab {
  display: flex;
  align-items: center;
  gap: 12px;
}

button {
  appearance: none;
  border: 1px solid #3f5a2a;
  background: linear-gradient(#1d2a16, #131c0e);
  color: var(--green);
  font: inherit;
  font-weight: 700;
  border-radius: 10px;
  height: 46px;
  min-width: 46px;
  padding: 0 10px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 3px 0 #080c06;
}

button.round {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 50%;
  font-size: 17px;
}

button.start {
  width: 106px;
  height: 34px;
  border-radius: 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
}

button:active,
button.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #080c06;
  background: linear-gradient(#2a3d1e, #1a2712);
}

button:focus-visible {
  outline: 1px solid var(--green);
  outline-offset: 3px;
}

.help {
  margin: 0;
  text-align: center;
  font-size: 10px;
  line-height: 1.7;
  color: var(--muted);
  letter-spacing: 0.02em;
}

#install-hint {
  opacity: 0.75;
}

button.sound {
  height: auto;
  min-width: 0;
  padding: 1px 6px;
  border-radius: 4px;
  box-shadow: none;
  background: transparent;
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--muted);
  vertical-align: baseline;
}

button.sound:active {
  transform: none;
  box-shadow: none;
  background: #1d2a16;
}

@media (orientation: landscape) and (max-height: 560px) {
  body {
    padding: 8px;
  }

  .shell {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 18px;
    width: 100%;
  }

  .brand,
  .help {
    display: none;
  }

  .screen-wrap {
    width: auto;
  }

  canvas {
    width: min(58vw, 88vh);
  }

  .controls {
    width: auto;
    flex-direction: column;
    gap: 16px;
    margin: 0;
  }

  .dpad {
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
  }

  .dpad button {
    height: 42px;
    min-width: 42px;
  }

  button.round {
    width: 52px;
    height: 52px;
    min-width: 52px;
  }

  button.start {
    width: 98px;
  }
}

@media (prefers-reduced-motion: reduce) {
  button:active,
  button.pressed {
    transform: none;
  }
}
