:root {
  --bg-0: #04070d;
  --bg-1: #0b1320;
  --bg-2: #152235;
  --panel: rgba(7, 11, 19, 0.76);
  --panel-strong: rgba(6, 10, 18, 0.9);
  --border: rgba(255, 255, 255, 0.12);
  --text: #edf4ff;
  --muted: #bccbe4;
  --pink: #ff7fb5;
  --gold: #ffcf72;
  --green: #94f0be;
  --red: #ff8d96;
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, var(--bg-2) 0%, var(--bg-1) 55%, var(--bg-0) 100%);
  color: var(--text);
  font-family: Inter, Arial, Helvetica, sans-serif;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.game-shell {
  position: relative;
  width: min(100%, 1440px);
  aspect-ratio: 16 / 9;
  min-height: min(88vh, 520px);
  overflow: hidden;
  border-radius: 22px;
  background: linear-gradient(180deg, #0e1725, #08101a);
  border: 1px solid var(--border);
  box-shadow: 0 28px 56px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  outline: none;
  touch-action: none;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  image-rendering: auto;
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud-top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: grid;
  grid-template-columns: minmax(220px, auto) 1fr auto;
  gap: 12px;
  align-items: start;
}

.hud-box,
.story-card,
.message-box,
.controls-box,
.loading-bar-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(6px);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22);
}

.hud-box {
  min-height: 46px;
  padding: 10px 14px;
  font-weight: 700;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

.hud-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.hud-button {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 16, 26, 0.9);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

.hud-button:hover {
  border-color: rgba(255, 255, 255, 0.34);
}

.story-card {
  position: absolute;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 760px);
  padding: 20px 22px;
  text-align: center;
  pointer-events: auto;
  transition: opacity 0.24s ease, visibility 0.24s ease, transform 0.24s ease;
}

.story-card.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-8px);
  pointer-events: none;
}

.eyebrow {
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.84rem;
  margin-bottom: 8px;
}

.story-card h1 {
  margin: 0 0 10px;
  font-size: clamp(1.6rem, 3vw, 2.7rem);
  color: var(--pink);
}

.story-card p {
  margin: 8px 0;
  line-height: 1.55;
}

.overlay-actions {
  margin-top: 14px;
}

.primary-btn {
  pointer-events: auto;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #ff93c3, #f45b9a);
  color: white;
  font-weight: 800;
  font-size: 1rem;
  padding: 12px 16px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(255, 91, 154, 0.28);
}

.overlay-small {
  color: var(--muted);
  font-size: 0.95rem;
}

.bottom-panels {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: grid;
  grid-template-columns: 1fr minmax(270px, 340px);
  gap: 12px;
  align-items: end;
}

.message-box {
  min-height: 56px;
  padding: 14px 16px;
  font-size: 0.98rem;
}

.controls-box {
  padding: 12px 14px;
  line-height: 1.48;
  color: var(--muted);
  font-size: 0.94rem;
}

.touch-controls {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 108px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
  pointer-events: none;
}

.touch-cluster {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.touch-btn {
  min-width: 72px;
  min-height: 72px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(8, 14, 22, 0.78);
  color: var(--text);
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.touch-btn.primary {
  min-width: 84px;
  min-height: 84px;
  background: rgba(255, 127, 181, 0.22);
  border-color: rgba(255, 127, 181, 0.34);
}

.touch-btn:active,
.touch-btn.active {
  transform: scale(0.98);
}

.loading-bar-wrap {
  position: absolute;
  left: 50%;
  bottom: 152px;
  transform: translateX(-50%);
  width: min(92%, 440px);
  padding: 14px 16px;
  text-align: center;
}

.loading-bar {
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.loading-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff8fc1, #ffd67d);
  transition: width 0.18s ease;
}

.loading-text {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.94rem;
}

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

@media (max-width: 900px) {
  .hud-top {
    grid-template-columns: 1fr;
  }

  .bottom-panels {
    grid-template-columns: 1fr;
  }

  .controls-box {
    display: none;
  }
}

@media (max-width: 720px) {
  .page { padding: 0; }
  .game-shell {
    width: 100vw;
    min-height: 100dvh;
    aspect-ratio: auto;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .touch-controls {
    bottom: 120px;
    left: 10px;
    right: 10px;
  }

  .touch-btn {
    min-width: 68px;
    min-height: 68px;
  }

  .touch-btn.primary {
    min-width: 86px;
    min-height: 86px;
  }

  .story-card {
    top: 64px;
    width: min(94%, 560px);
    padding: 16px;
  }

  .bottom-panels {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .message-box {
    min-height: 48px;
    padding: 11px 12px;
    font-size: 0.9rem;
  }

  .loading-bar-wrap {
    bottom: 178px;
    width: min(92%, 360px);
  }
}
