:root {
  --ink: #112033;
  --paper: #fff3d0;
  --panel: #fff7df;
  --accent: #e83f35;
  --blue: #2775d1;
  --green: #1b9b6c;
  --shadow: rgba(17, 32, 51, 0.25);
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #20354f;
  font-family: Arial, Helvetica, sans-serif;
  touch-action: none;
  user-select: none;
  overscroll-behavior: none;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.app-shell, .screen { width: 100vw; height: 100vh; }
.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.hidden { display: none !important; }
.rotate-warning {
  display: none;
  position: fixed;
  z-index: 50;
  inset: 0;
  align-items: center;
  justify-content: center;
  padding: 28px;
  color: #fff;
  background: #142436;
  font-size: clamp(28px, 8vw, 52px);
  font-weight: 900;
  text-align: center;
}
.menu-screen, .end-screen {
  background: linear-gradient(rgba(20, 33, 46, 0.48), rgba(20, 33, 46, 0.58)), repeating-linear-gradient(90deg, #3e8bc0 0 76px, #42b883 76px 152px, #f0b34c 152px 228px, #e85b5b 228px 304px);
}
.menu-panel {
  width: min(720px, 94vw);
  max-height: 96vh;
  overflow: auto;
  padding: 24px;
  border: 5px solid #17293a;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 0 rgba(0, 0, 0, 0.18), 0 18px 42px var(--shadow);
  text-align: center;
}
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: 15px; font-weight: 900; text-transform: uppercase; }
h1, h2 { margin: 0; line-height: 1.04; }
h1 { font-size: clamp(32px, 6vw, 64px); }
h2 { font-size: clamp(32px, 5vw, 54px); }
.subtitle { margin: 8px 0 0; color: #db3f36; font-size: clamp(20px, 3vw, 28px); font-weight: 900; }
.intro, #endText { margin: 14px auto 18px; max-width: 590px; font-size: clamp(17px, 2.2vw, 22px); line-height: 1.35; }
.difficulty-box, .map-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 12px;
  border: 3px solid #d5b772;
  border-radius: 8px;
  background: #fffdf4;
}
.map-box { margin-bottom: 20px; }
.difficulty-box legend, .map-box legend { padding: 0 8px; font-weight: 900; }
.difficulty-box label, .map-box label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 46px;
  padding: 8px 12px;
  border: 3px solid #eadfc9;
  border-radius: 8px;
  background: #ffffff;
  font-weight: 900;
}
.primary-button, .secondary-button, .shoot-button, .mini-button, .pad-button {
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
}
.primary-button { min-width: 190px; min-height: 56px; padding: 12px 26px; background: var(--accent); font-size: 22px; }
.secondary-button, .mini-button { min-height: 48px; padding: 10px 16px; background: #526476; }
.primary-button:active, .secondary-button:active, .shoot-button:active, .mini-button:active, .pad-button.active, .pad-button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.game-screen { position: relative; flex-direction: column; justify-content: space-between; gap: 8px; background: #142436; }
.hud {
  display: grid;
  grid-template-columns: repeat(6, minmax(78px, 1fr));
  gap: 8px;
  width: min(100%, 1040px);
  min-height: 58px;
}
.hud div { display: flex; flex-direction: column; justify-content: center; min-width: 0; padding: 7px 9px; border: 3px solid #243f58; border-radius: 8px; background: #fff7df; }
.hud span { color: #50616c; font-size: 12px; font-weight: 900; text-transform: uppercase; }
.hud strong { overflow: hidden; color: #101a24; font-size: clamp(14px, 2.1vw, 20px); line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.canvas-wrap { display: flex; align-items: center; justify-content: center; width: min(100%, 1040px); min-height: 0; flex: 1; }
#gameCanvas { display: block; width: min(100%, calc((100vh - 200px) * 1.777)); max-height: calc(100vh - 200px); aspect-ratio: 16 / 9; border: 5px solid #0a1722; border-radius: 8px; background: var(--paper); box-shadow: 0 14px 32px rgba(0, 0, 0, 0.32); }
.touch-controls { display: flex; align-items: center; justify-content: space-between; gap: 18px; width: min(100%, 1040px); min-height: 122px; }
.dpad { position: relative; width: 174px; height: 124px; }
.pad-button { position: absolute; width: 58px; height: 58px; background: var(--blue); font-size: 26px; }
.pad-button.up { top: 0; left: 58px; }
.pad-button.left { top: 62px; left: 0; }
.pad-button.right { top: 62px; right: 0; }
.pad-button.down { top: 62px; left: 58px; }
.action-pad { display: flex; align-items: center; gap: 12px; }
.mini-actions { display: flex; flex-direction: column; gap: 10px; }
.mini-button { min-width: 98px; font-size: 15px; }
.shoot-button { width: min(34vw, 210px); min-width: 150px; height: 92px; background: var(--accent); font-size: clamp(20px, 3vw, 28px); }
.pause-overlay { position: absolute; z-index: 20; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(10, 20, 32, 0.64); }
.pause-panel { display: flex; flex-direction: column; gap: 12px; width: min(360px, 88vw); padding: 24px; border: 5px solid #17293a; border-radius: 8px; background: #fff7df; text-align: center; }
.end-panel.win { background: #fff7d7; border-color: #1c9b62; }
.end-panel.lose { background: #fbe5e2; border-color: #d63c34; }
.end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
@media (max-height: 580px) {
  .hud { min-height: 48px; }
  .touch-controls { min-height: 100px; }
  .dpad { transform: scale(0.88); transform-origin: left center; }
  .shoot-button { height: 72px; }
  #gameCanvas { max-height: calc(100vh - 166px); }
}
@media (max-width: 840px) {
  .hud { grid-template-columns: repeat(3, minmax(74px, 1fr)); }
  .touch-controls { min-height: 108px; }
}
@media (orientation: portrait) and (max-width: 900px) {
  .rotate-warning { display: flex; }
}
