:root {
  color-scheme: dark;
  --ink: #f7f2df;
  --muted: #c9d2bc;
  --panel: rgba(16, 28, 22, 0.9);
  --line: rgba(255, 255, 255, 0.16);
  --accent: #f7c846;
  --accent-2: #57d3a3;
  --danger: #f05f4a;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 0%, rgba(87, 211, 163, 0.22), transparent 28rem),
    linear-gradient(135deg, #18291d 0%, #301f19 45%, #112c30 100%);
  color: var(--ink);
}

button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 0.78rem 1rem;
  background: #f7c846;
  color: #1f1a0b;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:active {
  transform: translateY(0);
}

.shell {
  width: min(1180px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(12px, 2vw, 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.hud {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(320px, 1.8fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

.brand h1 {
  margin: 2px 0 0;
  font-size: 1.4rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.home-link {
  display: inline-flex;
  width: fit-content;
  margin-top: 8px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
}

.home-link:hover,
.home-link:focus-visible {
  color: var(--ink);
  text-decoration: underline;
}

.kicker,
.overline {
  margin: 0;
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.meters {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 8px;
}

.meters span {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  font-size: 0.8rem;
}

.meters strong {
  display: block;
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1.05;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  gap: 8px;
}

#pauseButton {
  background: rgba(255, 255, 255, 0.09);
  color: var(--ink);
}

#musicButton {
  background: rgba(87, 211, 163, 0.14);
  color: var(--ink);
}

.game-wrap {
  position: relative;
  display: grid;
  place-items: center;
  justify-self: center;
  align-self: start;
  width: min(100%, calc(min(82svh, calc(100svh - 122px)) * 0.818));
  max-width: 100%;
  height: fit-content;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #112018;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 900 / 1100;
  background: #173322;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 22px;
  background: rgba(5, 12, 10, 0.58);
  backdrop-filter: blur(4px);
}

.overlay.visible {
  display: grid;
}

.overlay > div {
  width: min(470px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(19, 31, 23, 0.94);
  text-align: center;
}

.overlay h2 {
  margin: 6px 0 10px;
  font-size: clamp(2rem, 6vw, 3.7rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.overlay p:not(.overline) {
  margin: 0 auto 18px;
  color: var(--muted);
  line-height: 1.5;
}

.dpad {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  top: 50%;
  z-index: 10;
  display: none;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 6px;
  transform: translateY(-50%);
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(12, 24, 19, 0.35);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(2px);
}

.dpad--hidden {
  display: none !important;
}

.dpad-button,
.dpad-center {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
  user-select: none;
  touch-action: manipulation;
}

.dpad-button {
  background: rgba(247, 200, 70, 0.45);
  color: #fff;
}

.dpad-center {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.08);
  cursor: default;
}

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

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

.dpad-center {
  grid-column: 2;
  grid-row: 2;
}

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

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

@media (max-width: 920px), (pointer: coarse) {
  .shell {
    padding: 6px;
    gap: 6px;
  }

  .hud {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px;
  }

  .brand {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
    align-items: end;
  }

  .brand h1 {
    font-size: 1.05rem;
  }

  .kicker {
    font-size: 0.62rem;
  }

  .home-link {
    grid-row: 1 / span 2;
    grid-column: 2;
    align-self: center;
    margin-top: 0;
    font-size: 0.7rem;
    text-align: right;
  }

  .meters {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .meters span {
    padding: 6px;
    font-size: 0.66rem;
  }

  .meters strong {
    font-size: 0.95rem;
  }

  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .actions button {
    min-width: 0;
    padding: 0.58rem 0.35rem;
    font-size: 0.76rem;
  }

  .game-wrap {
    width: min(calc(100vw - 12px), calc((100dvh - 166px) * 0.818));
  }

  canvas {
    width: 100%;
    height: auto;
  }

  .dpad {
    display: grid;
  }
}

@media (max-width: 520px), (max-height: 520px) {
  .dpad {
    grid-template-columns: repeat(3, 32px);
    grid-template-rows: repeat(3, 32px);
    gap: 4px;
    padding: 6px;
    background: rgba(12, 24, 19, 0.35);
  }

  .dpad-button,
  .dpad-center {
    width: 32px;
    height: 32px;
    font-size: 0.78rem;
  }
}

/* Info button */
.info-btn {
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 900;
  flex-shrink: 0;
}

/* Help dialog */
#helpDialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(14, 26, 18, 0.98);
  color: var(--ink);
  padding: 0;
  max-width: min(560px, 94vw);
  max-height: 88dvh;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

#helpDialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.help-inner {
  overflow-y: auto;
  max-height: 88dvh;
  padding: 28px 28px 32px;
  position: relative;
}

.help-inner h2 {
  margin: 0 0 20px;
  font-size: 1.6rem;
  padding-right: 2rem;
}

.help-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.help-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.help-section h3 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.help-section p,
.help-section ul {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.93rem;
}

.help-section ul {
  padding-left: 1.2em;
}

.help-section li {
  margin-bottom: 4px;
}

.help-section strong {
  color: var(--ink);
}

.help-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.14);
}
