:root {
  --bg: #07111f;
  --panel: rgba(6, 18, 34, 0.76);
  --panel-border: rgba(159, 229, 255, 0.2);
  --panel-strong: rgba(8, 24, 44, 0.84);
  --text: #ecf7ff;
  --muted: #93b2c7;
  --gold: #ffd166;
  --shadow: 0 28px 60px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at top, rgba(39, 114, 181, 0.38), transparent 30%),
    radial-gradient(circle at bottom left, rgba(255, 111, 174, 0.18), transparent 26%),
    linear-gradient(135deg, var(--bg), #02060d 68%);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  overflow: hidden;
  overscroll-behavior: contain;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at center, black, transparent 88%);
}

body.modal-open {
  overflow: hidden;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  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-shell {
  min-height: calc(100vh - 24px);
  min-height: calc(100dvh - 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 30px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, auto) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.brand h1,
.overlay h2,
.help-modal h2 {
  margin: 0;
  font-family: "Syne", sans-serif;
  line-height: 0.96;
}

.brand h1 {
  font-size: clamp(1.9rem, 3.7vw, 3rem);
}

.eyebrow,
.label {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
  color: var(--muted);
}

.hud {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) repeat(3, minmax(96px, 108px)) minmax(92px, 110px);
  gap: 10px;
  align-items: stretch;
  justify-content: end;
}

.stat-card {
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-card strong {
  display: block;
}

.stat-card strong {
  font-size: 1.45rem;
}

.effects-panel {
  background: var(--panel-strong);
  min-width: 0;
}

.effects-panel p:last-child {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

#effects-detail:empty {
  display: none;
}

.help-button,
.modal-close,
.touch-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.help-button:hover,
.modal-close:hover,
.touch-button:hover,
.help-button:focus-visible,
.modal-close:focus-visible,
.touch-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
}

.help-button {
  padding: 12px 18px;
  border-radius: 18px;
  min-width: 92px;
  height: 100%;
}

.canvas-stage {
  min-height: 0;
  display: grid;
  place-items: center;
}

.canvas-frame {
  position: relative;
  width: min(100%, calc((100dvh - 220px) * 1.6667));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 5 / 3;
  padding: 12px;
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: linear-gradient(180deg, #102036, #09111f 65%);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  padding: 24px;
  border-radius: 18px;
  background: rgba(4, 10, 20, 0.56);
  text-align: center;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.overlay.hidden,
.modal-backdrop.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-content {
  max-width: min(520px, 100%);
}

.overlay-kicker {
  margin: 0 0 12px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.74rem;
}

.overlay p:last-child {
  color: var(--muted);
}

.touch-controls {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
  pointer-events: auto;
}

.touch-button {
  min-width: 132px;
  min-height: 56px;
  border-radius: 20px;
  pointer-events: auto;
  backdrop-filter: blur(8px);
  touch-action: manipulation;
}

.touch-button.is-active {
  background: rgba(115, 240, 255, 0.22);
  border-color: rgba(115, 240, 255, 0.5);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 8, 16, 0.66);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.help-modal {
  width: min(760px, 100%);
  border-radius: 28px;
  padding: 22px;
  background: rgba(9, 21, 38, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow);
}

.help-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.modal-close {
  padding: 10px 14px;
  border-radius: 14px;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.help-section {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.help-section h3 {
  margin: 0 0 12px;
  font-family: "Syne", sans-serif;
}

.help-section p {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.45;
}

.help-section strong,
.help-section code {
  color: var(--text);
}

body:not(.touch-device) .touch-controls {
  display: none;
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .hud {
    grid-template-columns: repeat(5, minmax(88px, 1fr));
    justify-content: stretch;
  }
}

@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .game-shell {
    min-height: auto;
  }

  .canvas-frame {
    width: 100%;
  }

  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
  }

  .effects-panel {
    grid-column: span 2;
  }

  .help-button {
    min-height: 52px;
    height: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    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));
  }

  .game-shell {
    padding: 10px;
    border-radius: 22px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .effects-panel {
    grid-column: 1 / -1;
  }

  .stat-card strong {
    font-size: 1.16rem;
  }

  .canvas-frame {
    padding: 8px;
    border-radius: 20px;
  }

  .overlay {
    inset: 8px;
    padding: 18px;
  }

  .touch-button {
    min-width: 112px;
    min-height: 52px;
    border-radius: 18px;
  }

  .help-grid {
    grid-template-columns: 1fr;
  }
}
