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

html, body {
  margin: 0;
  height: 100%;
  background: #0b1020;
  color: #1a1a2e;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  touch-action: none;
}

.site-games {
  position: relative;
  z-index: 5;
  flex: none;
  align-self: flex-start;
  margin: 2px 0 6px;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  background: #fff6ea;
  color: #1c2340;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 3px 0 #1c2340;
  touch-action: manipulation;
}

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  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));
}

#play {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  place-items: center;
  container-type: size;
}

body.touch-ui:has(#touch:not([hidden])) #play {
  place-items: end center;
}

#stage {
  position: relative;
  width: min(100%, calc((100dvh - 150px) * 960 / 540));
  width: min(100cqw, calc(100cqh * 960 / 540));
  aspect-ratio: 960 / 540;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  background: #7ec8ff;
  container-type: size;
  container-name: stage;
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#hud {
  position: absolute;
  inset: 10px 12px auto 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  align-items: flex-start;
}

#hud button {
  pointer-events: auto;
}

.hud-left, .hud-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.hud-mid {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 2px 0 #1d3557, 0 0 8px rgba(0,0,0,.35);
  padding-top: 6px;
}

@container stage (max-height: 340px) {
  .hud-mid { display: none; }
  #hud { inset: 6px 8px auto 8px; }
  .chip, #mute-btn { font-size: 13px; padding: 3px 8px; }
  #hearts { font-size: 18px; }
}

.chip, #mute-btn {
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #1d3557;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 3px 0 #1d3557;
}

#mute-btn {
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

#hearts {
  display: flex;
  gap: 4px;
  font-size: 26px;
  color: #e74c3c;
  line-height: 1;
  filter: drop-shadow(0 2px 0 #1d3557);
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  touch-action: pan-y;
  background: linear-gradient(180deg, rgba(20, 30, 70, 0.28), rgba(20, 30, 70, 0.55));
  padding: 16px;
}

#hud[hidden], #touch[hidden], .screen[hidden] {
  display: none !important;
}

.card {
  flex: none;
  margin: auto;
  width: min(520px, 92%);
  background: #fff8e8;
  border: 5px solid #1d3557;
  border-radius: 24px;
  padding: 22px 24px 26px;
  box-shadow: 0 10px 0 #1d3557;
  text-align: center;
}

.card h1 {
  margin: 0 0 4px;
  color: #e63946;
  letter-spacing: 1px;
  font-size: clamp(28px, 6vw, 42px);
  text-shadow: 2px 2px 0 #1d3557;
}

.tag {
  margin: 0 0 12px;
  color: #1d3557;
  font-weight: 800;
}

.card p, .card li {
  color: #333;
  line-height: 1.4;
}

.card ul {
  text-align: left;
  margin: 0 0 18px;
  padding-left: 22px;
}

.help-touch,
.short-help { display: none; }

body.touch-ui .help-keys { display: none; }
body.touch-ui .help-touch { display: block; }

@container stage (max-height: 460px) {
  .screen { padding: 8px; }
  .card { padding: 10px 12px 12px; }
  .card h1 { font-size: 26px; }
  .tag { margin: 0 0 6px; font-size: 14px; }
  .card .blurb,
  .card ul { display: none !important; }
  .short-help { display: block; margin: 6px 0 10px; font-size: 15px; font-weight: 700; }
  .big { font-size: 18px; padding: 10px 18px; }
}

body.touch-ui .short-help.keys { display: none !important; }
body:not(.touch-ui) .short-help.touch { display: none !important; }

.big {
  appearance: none;
  border: 4px solid #1d3557;
  background: #2a9d8f;
  color: white;
  font-size: 22px;
  font-weight: 900;
  padding: 14px 28px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 0 #1d3557;
}

.big:hover {
  filter: brightness(1.06);
}

.big:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #1d3557;
}

#touch {
  flex: none;
  width: min(100%, 720px);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  padding-top: 8px;
  touch-action: none;
}

#touch .pad {
  display: flex;
  gap: 8px;
}

#touch .actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

#touch button {
  min-width: 72px;
  min-height: 64px;
  padding: 8px 10px;
  border-radius: 16px;
  border: 3px solid #1d3557;
  background: rgba(255, 255, 255, 0.92);
  font-weight: 900;
  color: #1d3557;
  font-size: 16px;
  touch-action: none;
}

#touch button:active, #touch button.held {
  background: #ffd166;
}

@media (max-height: 480px) {
  #touch { padding-top: 4px; }
  #touch .actions { display: flex; }
  #touch button {
    min-width: 58px;
    min-height: 48px;
    font-size: 14px;
    border-radius: 12px;
  }
}

@media (max-width: 380px) {
  #touch button {
    min-width: 64px;
    font-size: 15px;
  }
}
