:root {
  --sage: #8fbc8f;
  --sage-deep: #5f8f6a;
  --sky: #a8d4ef;
  --wood: #c4a574;
  --cream: #f7f3e8;
  --ink: #2f3a34;
  --teal: #3aa6a0;
  --coral: #e07a6a;
  --good: #7dcb7a;
  --perfect: #4caf50;
  --panel: rgba(247, 243, 232, 0.94);
  --shadow: 0 10px 28px rgba(47, 58, 52, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: #7eb8d8;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  position: fixed;
  inset: 0;
}

#game-root {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden {
  display: none !important;
}

.panel {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border-radius: 18px;
  padding: 10px 18px;
  box-shadow: var(--shadow);
  min-width: min(320px, calc(100vw - 24px));
  text-align: center;
  z-index: 5;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  font-weight: 700;
  font-size: 1rem;
}

.hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
  opacity: 0.75;
  font-weight: 600;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(
    160deg,
    rgba(168, 212, 239, 0.88),
    rgba(143, 188, 143, 0.9)
  );
  z-index: 20;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right))
    calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.card {
  background: var(--panel);
  border-radius: 28px;
  padding: 28px 26px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
  text-align: center;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--sage-deep);
}

h1 {
  margin: 6px 0 4px;
  font-size: clamp(2.2rem, 8vw, 3rem);
  font-weight: 800;
  color: var(--teal);
  line-height: 1.05;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.7rem;
  font-weight: 800;
}

.tagline {
  margin: 0 0 14px;
  font-size: 1.15rem;
  font-weight: 700;
}

.blurb {
  margin: 0 0 20px;
  line-height: 1.45;
  font-weight: 600;
  opacity: 0.85;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  min-height: 48px;
  min-width: 140px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(47, 58, 52, 0.15);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 rgba(47, 58, 52, 0.15);
}

.btn.primary {
  background: var(--teal);
  color: white;
}

.btn.accent {
  background: var(--coral);
  color: white;
  width: 100%;
  margin-top: 8px;
}

.meter-panel {
  position: absolute;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 24px));
  background: var(--panel);
  border-radius: 22px;
  padding: 16px;
  box-shadow: var(--shadow);
  z-index: 15;
  text-align: center;
}

.speech {
  margin: 0 0 12px;
  font-weight: 800;
  font-size: 1.05rem;
}

.meter-track {
  position: relative;
  height: 36px;
  border-radius: 18px;
  background: linear-gradient(90deg, #efb0a4, #f3d9a4 35%, #b8e0b4 50%, #f3d9a4 65%, #efb0a4);
  overflow: hidden;
  border: 3px solid rgba(47, 58, 52, 0.12);
}

.meter-zone {
  position: absolute;
  top: 0;
  bottom: 0;
}

.meter-zone.good {
  left: 32%;
  width: 36%;
  background: rgba(125, 203, 122, 0.35);
}

.meter-zone.perfect {
  left: 44%;
  width: 12%;
  background: rgba(76, 175, 80, 0.55);
}

.meter-needle {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 6px;
  margin-left: -3px;
  border-radius: 4px;
  background: var(--ink);
  left: 0%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.55);
}

.meter-prompt {
  margin: 10px 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0.75;
}

.world-bubble {
  position: absolute;
  left: 50%;
  top: 28%;
  transform: translateX(-50%);
  background: white;
  border-radius: 18px;
  padding: 10px 16px;
  font-weight: 800;
  box-shadow: var(--shadow);
  z-index: 12;
  max-width: min(280px, 80vw);
  text-align: center;
  pointer-events: none;
}

.joystick {
  position: absolute;
  left: calc(18px + var(--safe-left));
  bottom: calc(18px + var(--safe-bottom));
  z-index: 10;
  opacity: 0.92;
}

.joystick-base {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(247, 243, 232, 0.55);
  border: 3px solid rgba(47, 58, 52, 0.18);
  position: relative;
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(58, 166, 160, 0.9);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 10px rgba(47, 58, 52, 0.25);
  touch-action: none;
}

.camera-controls {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  display: flex;
  gap: 8px;
  z-index: 11;
}

.cam-btn {
  appearance: none;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
}

.cam-btn:active {
  transform: translateY(2px);
}

.cam-btn[disabled] {
  opacity: 0.35;
  pointer-events: none;
}

.camera-controls.first-person #view-toggle-btn {
  background: var(--teal);
  color: white;
}

@media (pointer: fine) {
  .joystick {
    opacity: 0.35;
  }

  .joystick:hover,
  .joystick.active {
    opacity: 0.9;
  }
}

/* Narrow portrait — keep HUD clear of camera controls */
@media (max-width: 520px) {
  .panel {
    left: calc(12px + var(--safe-left));
    right: calc(160px + var(--safe-right));
    transform: none;
    min-width: 0;
    width: auto;
    max-width: none;
    padding: 8px 12px;
    border-radius: 14px;
  }

  .hud-row {
    gap: 12px;
    font-size: 0.9rem;
  }

  .hint {
    font-size: 0.68rem;
    line-height: 1.35;
  }

  .camera-controls {
    top: calc(12px + var(--safe-top));
    right: calc(8px + var(--safe-right));
    gap: 6px;
  }

  .cam-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 0.85rem;
  }

  .meter-panel {
    bottom: calc(140px + var(--safe-bottom));
  }
}

/* Very narrow portrait — stack cam buttons so HUD has more width */
@media (max-width: 400px) and (orientation: portrait) {
  .panel {
    right: calc(72px + var(--safe-right));
  }

  .camera-controls {
    flex-direction: column;
    gap: 6px;
  }
}

/* Landscape phones (e.g. iPhone 15) — fill usable viewport, compact chrome */
@media (orientation: landscape) and (max-height: 500px) {
  .panel {
    top: calc(6px + var(--safe-top));
    padding: 6px 14px;
    min-width: min(280px, calc(100vw - 160px));
    border-radius: 14px;
  }

  .hud-row {
    font-size: 0.9rem;
    gap: 16px;
  }

  .hint {
    display: none;
  }

  .camera-controls {
    top: calc(6px + var(--safe-top));
    right: calc(8px + var(--safe-right));
    gap: 6px;
  }

  .cam-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 0.85rem;
  }

  .joystick {
    left: calc(12px + var(--safe-left));
    bottom: calc(8px + var(--safe-bottom));
  }

  .joystick-base {
    width: 88px;
    height: 88px;
  }

  .joystick-knob {
    width: 40px;
    height: 40px;
  }

  .meter-panel {
    bottom: calc(8px + var(--safe-bottom));
    width: min(320px, calc(100vw - 140px));
    padding: 10px 12px;
    border-radius: 16px;
  }

  .speech {
    margin-bottom: 8px;
    font-size: 0.95rem;
  }

  .meter-track {
    height: 28px;
  }

  .meter-prompt {
    margin-top: 6px;
    font-size: 0.75rem;
  }

  .btn.accent {
    margin-top: 6px;
    min-height: 42px;
    padding: 10px 20px;
  }

  .overlay {
    padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right))
      calc(8px + var(--safe-bottom)) calc(12px + var(--safe-left));
  }

  .card {
    padding: 16px 18px;
    border-radius: 20px;
    max-width: min(420px, 92vw);
  }

  h1 {
    font-size: clamp(1.6rem, 6vh, 2.2rem);
  }

  .blurb {
    margin-bottom: 12px;
    font-size: 0.92rem;
  }

  .world-bubble {
    top: 18%;
    padding: 8px 12px;
  }
}
