:root {
  color-scheme: dark;
  --ratio: 9/16;
  --game-width: 360px;
  --game-height: 640px;
  --bg: #050505;
  --panel: rgba(12, 12, 12, 0.7);
  --accent: #d0b46d;
  --text: #f2e8c9;
  --danger: #e05f5f;
  --safe: #6ed1a1;
  font-family: "Noto Sans JP", "Yu Gothic", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #000;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  user-select: none;
  touch-action: manipulation;
  color: var(--text);
}

#safe-area {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  background: #000;
}

#letterbox {
  position: relative;
  aspect-ratio: var(--ratio);
  max-width: 100vw;
  max-height: 100dvh;
  background: #000;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

#hud {
  position: absolute;
  inset: 0;
  padding: clamp(10px, calc(var(--game-width) * 0.03), 18px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  font-size: clamp(12px, calc(var(--game-width) * 0.035), 20px);
}

#titleScreen {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: center;
  justify-items: center;
  gap: clamp(10px, calc(var(--game-height) * 0.02), 18px);
  background: radial-gradient(circle at 50% 20%, rgba(208,180,109,0.18), rgba(0,0,0,0.82));
  padding: clamp(16px, calc(var(--game-width) * 0.07), 32px);
  text-align: center;
  z-index: 10;
  pointer-events: auto;
}

#titleScreen.hidden {
  display: none;
}

#titleLogo {
  width: min(70%, 420px);
  max-height: 48vh;
  object-fit: contain;
  filter: drop-shadow(0 6px 20px rgba(0,0,0,0.6));
}

.title-copy {
  color: #f8f0d8;
  text-shadow: 0 2px 8px rgba(0,0,0,0.55);
  display: grid;
  gap: 4px;
}

.title-name {
  font-size: clamp(28px, calc(var(--game-width) * 0.12), 46px);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.title-sub {
  font-size: clamp(14px, calc(var(--game-width) * 0.045), 20px);
  opacity: 0.9;
}

.title-desc {
  font-size: clamp(13px, calc(var(--game-width) * 0.04), 18px);
  line-height: 1.5;
  margin-top: 4px;
}

.title-actions {
  display: grid;
  gap: 8px;
  justify-items: center;
}

#titleStartButton {
  background: linear-gradient(135deg, #f5d270 0%, #d0b46d 60%, #b1934f 100%);
  color: #2b220f;
  border: none;
  border-radius: 999px;
  padding: 1.15em 2.6em;
  font-size: clamp(16px, calc(var(--game-width) * 0.055), 22px);
  font-weight: 850;
  letter-spacing: 0.08em;
  box-shadow: 0 10px 28px rgba(0,0,0,0.4);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

#titleStartButton:disabled {
  opacity: 0.5;
  cursor: wait;
}

#titleStartButton:active {
  transform: translateY(2px) scale(0.98);
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
}

#titleStatus {
  color: #e3d8aa;
  font-size: clamp(12px, calc(var(--game-width) * 0.035), 16px);
}

.status-row {
  display: flex;
  gap: 0.8em;
  justify-content: space-between;
  background: var(--panel);
  padding: 0.6em 0.8em;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
}

.instructions {
  text-align: center;
  margin-top: 1vh;
  opacity: 0.8;
  white-space: pre-line;
}

#startButton {
  align-self: center;
  pointer-events: auto;
  background: var(--accent);
  color: #2b220f;
  border: none;
  border-radius: 999px;
  padding: 0.8em 1.6em;
  font-weight: 700;
  letter-spacing: 0.05em;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

#startButton:active {
  transform: translateY(1px) scale(0.99);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

#message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  padding: 1em 1.5em;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(4px);
  display: none;
  text-align: center;
  min-width: 40%;
  white-space: pre-line;
}

#message.show {
  display: block;
}

#damageLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.aim-hidden {
  display: none;
}

#aimCursor {
  position: absolute;
  width: clamp(28px, 7vw, 42px);
  height: clamp(28px, 7vw, 42px);
  border: 2px solid #ff5f5f;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1);
  box-shadow: 0 0 10px rgba(255, 95, 95, 0.85);
  animation: aimPulse 0.8s ease-in-out infinite alternate;
}

@keyframes aimPulse {
  from { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
  to   { transform: translate(-50%, -50%) scale(1.12); opacity: 0.45; }
}

.damage-text {
  position: absolute;
  left: 0;
  top: 0;
  color: #c93636;
  font-weight: 800;
  font-size: clamp(14px, 3.6vw, 22px);
  text-shadow: 0 2px 6px rgba(0,0,0,0.35);
  transform: translate(-50%, -50%);
  will-change: transform, opacity;
}

#upgradePanel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  padding: clamp(12px, calc(var(--game-width) * 0.05), 28px);
}

#upgradePanel.hidden {
  display: none;
}

.upgrade-title {
  font-weight: 800;
  letter-spacing: 0.06em;
  margin-bottom: 1rem;
  text-align: center;
}

.upgrade-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
  width: min(92%, calc(var(--game-width) * 0.9));
  max-width: calc(var(--game-width) * 0.95);
}

.upgrade-card {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
  pointer-events: auto;
}

.upgrade-card:active {
  transform: translateY(2px) scale(0.99);
}

.upgrade-card:hover,
.upgrade-card:focus-visible {
  border-color: var(--accent);
}

.upgrade-card .name {
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.upgrade-card .desc {
  opacity: 0.82;
  font-size: 0.95em;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
