:root {
  --bg-0: #7ec2e2;
  --bg-1: #c9edf7;
  --frame: #2f3f4e;
  --ui-bg: #f8f4df;
  --ui-border: #1f2f3d;
  --text-main: #1b2730;
  --text-soft: #4a5963;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "VT323", monospace;
  background: radial-gradient(circle at 20% 20%, var(--bg-1), transparent 45%),
    radial-gradient(circle at 80% 85%, #8acde8, transparent 45%),
    linear-gradient(160deg, var(--bg-0), #69afdf);
  color: var(--text-main);
  overflow: hidden;
}

.game-shell {
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(0.4rem, 1vw, 0.8rem);
  padding: clamp(0.5rem, 1vw, 0.8rem);
}

.hud {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.35rem 0.5rem;
  background: rgba(248, 244, 223, 0.85);
  border: 3px solid var(--frame);
}

.hud h1,
.hud p {
  margin: 0;
}

.hud-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.hud h1 {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.62rem, 1.2vw, 0.9rem);
  letter-spacing: 0.05em;
}

.hud p {
  font-size: clamp(1rem, 1.8vw, 1.4rem);
  color: var(--text-soft);
}

.music-toggle {
  border: 3px solid var(--frame);
  background: #f6f0d5;
  color: #2c3844;
  padding: 0.18rem 0.45rem;
  min-height: 1.8rem;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.45rem, 0.8vw, 0.58rem);
  cursor: pointer;
}

.music-toggle:hover {
  background: #eee6c8;
}

.viewport-wrap {
  position: relative;
  min-height: 0;
  border: 4px solid var(--frame);
  background: linear-gradient(180deg, #2b6f9f 0%, #8fcde8 34%, #87c870 35%, #6bb65f 100%);
  overflow: hidden;
  box-shadow: inset 0 0 0 2px rgba(234, 247, 255, 0.3), 0 14px 30px rgba(10, 16, 24, 0.25);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

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

.vignette {
  background: radial-gradient(circle at center, transparent 45%, rgba(10, 15, 25, 0.3) 100%);
}

.loading-screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #2a6b96 0%, #80b9dc 36%, #6ebf5f 37%, #529f4f 100%);
}

.loading-screen p {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border: 4px solid var(--frame);
  background: rgba(248, 244, 223, 0.95);
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.55rem, 1vw, 0.75rem);
  letter-spacing: 0.06em;
  color: #24303b;
}

.loading-screen.hidden {
  display: none;
}

.interaction-hint {
  position: absolute;
  left: 50%;
  top: 0.65rem;
  transform: translateX(-50%);
  padding: 0.22rem 0.52rem;
  border: 3px solid var(--frame);
  background: rgba(248, 244, 223, 0.92);
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.46rem, 0.8vw, 0.62rem);
  letter-spacing: 0.06em;
  color: #28333e;
  pointer-events: none;
}

.interaction-hint.hidden {
  display: none;
}

.dialogue {
  position: absolute;
  left: clamp(0.45rem, 1vw, 0.8rem);
  right: clamp(0.45rem, 1vw, 0.8rem);
  bottom: clamp(0.45rem, 1vw, 0.8rem);
  z-index: 6;
  background: var(--ui-bg);
  border: 4px solid var(--ui-border);
  padding: clamp(0.5rem, 1vw, 0.7rem);
  box-shadow: 0 8px 0 rgba(31, 47, 61, 0.2);
  pointer-events: auto;
}

.dialogue * {
  pointer-events: auto;
}

.dialogue.hidden {
  display: none;
}

.dialogue-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.dialogue-head h2,
.dialogue-head span,
.dialogue p {
  margin: 0;
}

.dialogue-head h2 {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.62rem, 1.1vw, 0.8rem);
}

.dialogue-head span {
  font-size: clamp(0.95rem, 1.4vw, 1.1rem);
  color: #4d5b66;
}

.dialogue p {
  margin-top: 0.4rem;
  min-height: 2.7rem;
  font-size: clamp(1.1rem, 2vw, 1.4rem);
  line-height: 1.2;
  white-space: pre-line;
}

.dialogue p a {
  color: #1f4f9d;
  text-decoration: underline;
  pointer-events: auto;
  cursor: pointer;
}

.touch-controls {
  display: none;
  justify-self: center;
  gap: 0.35rem;
}

.touch-controls button {
  width: 3rem;
  height: 2.6rem;
  border: 3px solid var(--frame);
  background: #f6f0d5;
  font: inherit;
  font-size: 1.2rem;
}

.touch-row {
  display: flex;
  gap: 0.35rem;
}

@media (max-width: 900px) {
  .hud {
    flex-direction: column;
    align-items: flex-start;
  }

  .hud-meta {
    width: 100%;
    justify-content: space-between;
  }

  .touch-controls {
    display: grid;
    place-items: center;
  }
}
