:root {
  --sky: #5cb6e3;
  --sky-wash: rgba(92, 182, 227, 0.55);
  --text: #ffffff;
  --stroke: #000000;
  --hud-yellow: #ffe14d;
  --hud-red: #ff2222;
  --hud-green: #4ade80;
  --hud-stroke-2:
    -2px -2px 0 var(--stroke), 0 -2px 0 var(--stroke), 2px -2px 0 var(--stroke),
    -2px 0 0 var(--stroke), 2px 0 0 var(--stroke),
    -2px 2px 0 var(--stroke), 0 2px 0 var(--stroke), 2px 2px 0 var(--stroke);
  --hud-stroke-1:
    -1px -1px 0 var(--stroke), 0 -1px 0 var(--stroke), 1px -1px 0 var(--stroke),
    -1px 0 0 var(--stroke), 1px 0 0 var(--stroke),
    -1px 1px 0 var(--stroke), 0 1px 0 var(--stroke), 1px 1px 0 var(--stroke);
  --font-hud: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--sky);
  color: var(--text);
  font-family: var(--font-hud);
  font-weight: 700;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app { position: relative; width: 100%; height: 100%; }

.view { display: none; width: 100%; height: 100%; position: relative; }
.view.active { display: block; }
#controller-view.active { display: flex; flex-direction: column; }

/* ============ HOST VIEW ============ */
#game-area { width: 100%; height: 100%; position: relative; overflow: hidden; }
#game-area canvas { display: block; }

/* ============ QR MODAL ============ */
.modal-overlay {
  position: absolute; inset: 0;
  background: var(--sky-wash);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal {
  position: relative;
  background: var(--sky);
  border: 4px solid var(--stroke);
  padding: 32px 28px 28px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  box-shadow: 8px 8px 0 var(--stroke);
  overflow: hidden;
}

.modal h1 {
  font: 700 36px/1 var(--font-hud);
  letter-spacing: 0.06em;
  color: var(--text);
  text-shadow: var(--hud-stroke-2);
  margin-bottom: 10px;
  position: relative;
  z-index: 3;
}
.modal-sub {
  font: 700 11px/1.4 var(--font-hud);
  letter-spacing: 0.28em;
  color: var(--text);
  text-shadow: var(--hud-stroke-1);
  margin-bottom: 22px;
  text-transform: uppercase;
  position: relative;
  z-index: 3;
}
#qr-wrap {
  display: inline-block;
  padding: 10px;
  background: var(--text);
  border: 4px solid var(--stroke);
  position: relative;
  z-index: 3;
}
#qr-wrap canvas, #qr-wrap img {
  display: block;
  image-rendering: pixelated;
}

.status {
  font: 700 11px/1 var(--font-hud);
  color: var(--text);
  text-shadow: var(--hud-stroke-1);
  margin-top: 18px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  position: relative;
  z-index: 3;
}
.pip {
  display: inline-block;
  width: 12px; height: 12px;
  background: var(--hud-yellow);
  border: 2px solid var(--stroke);
  margin-right: 10px;
  vertical-align: middle;
  animation: pip-blink 1.3s steps(1) infinite;
}
.status.connected .pip,
.ctrl-status.connected .pip {
  background: var(--hud-green);
  animation: none;
}
.status.error .pip,
.ctrl-status.error .pip {
  background: var(--hud-red);
  animation: none;
}
@keyframes pip-blink {
  0%, 49% { background: var(--hud-yellow); }
  50%, 100% { background: var(--text); }
}

.test-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 9px 14px;
  background: var(--hud-yellow);
  border: 3px solid var(--stroke);
  color: var(--stroke);
  font: 700 10px/1 var(--font-hud);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
}
.test-btn:active {
  transform: translate(2px, 2px);
}
.modal-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 2px dashed var(--stroke);
  position: relative;
  z-index: 3;
}
.modal-buttons .test-btn {
  flex: 1;
  min-width: 0;
}

/* ============ CREDITS PANEL ============ */
#credits-panel {
  position: relative;
  z-index: 3;
}
#credits-content {
  margin: 18px 0 8px;
  text-align: center;
}
.credits-section {
  margin-bottom: 16px;
}
.credits-section:last-child {
  margin-bottom: 0;
}
.credits-title {
  font: 700 10px/1 var(--font-hud);
  letter-spacing: 0.22em;
  color: var(--hud-yellow);
  text-shadow: var(--hud-stroke-1);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.credits-line {
  font: 700 12px/1.7 var(--font-hud);
  letter-spacing: 0.08em;
  color: var(--text);
  text-shadow: var(--hud-stroke-1);
}

/* ============ DIORAMA ============ */
.decor-dog {
  position: absolute;
  width: 160px;
  height: auto;
  image-rendering: pixelated;
  pointer-events: none;
  user-select: none;
}
.decor-duck {
  position: absolute;
  width: 128px;
  height: 128px;
  background-image: url('assets/duck/sprite_newduck_right.png');
  background-repeat: no-repeat;
  background-position: 0 0;
  image-rendering: pixelated;
  pointer-events: none;
}
@keyframes duck-flap {
  0%, 33%  { background-position: 0 0; }
  34%, 66% { background-position: -128px 0; }
  67%, 100%{ background-position: -256px 0; }
}
.modal-decor-duck {
  top: 4px;
  transform: scale(0.5);
  transform-origin: top left;
  z-index: 2;
  animation:
    duck-flap 0.33s steps(1) infinite,
    duck-glide 7s linear infinite;
}
@keyframes duck-glide {
  0%   { left: -80px; }
  100% { left: 100%; }
}

/* ============ CONTROLLER VIEW ============ */
#controller-view {
  background-color: var(--sky);
  background-image:
    url('assets/bg/sprite_bg_ground.png'),
    url('assets/bg/sprite_bg.png');
  background-repeat: no-repeat, no-repeat;
  background-position: bottom center, bottom center;
  background-size: auto 100%, auto 100%;
  image-rendering: pixelated;
  height: 100dvh;
}

.ctrl-header {
  padding: 20px 20px 16px;
  text-align: center;
  border-bottom: 4px solid var(--stroke);
  background: var(--sky);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}
.ctrl-header h1 {
  font: 700 24px/1 var(--font-hud);
  letter-spacing: 0.08em;
  color: var(--text);
  text-shadow: var(--hud-stroke-2);
}
.ctrl-status {
  font: 700 10px/1 var(--font-hud);
  letter-spacing: 0.22em;
  color: var(--text);
  text-shadow: var(--hud-stroke-1);
  text-transform: uppercase;
  margin-top: 8px;
}
.ctrl-status .pip { width: 10px; height: 10px; margin-right: 8px; }

/* The whole area beneath the header. Tap anywhere to pop. */
#aim-zone {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-decor-dog {
  bottom: 0;
  right: 8px;
  width: 180px;
  z-index: 1;
}
.ctrl-decor-duck {
  top: 18px;
  transform: scale(0.7);
  transform-origin: top left;
  z-index: 1;
  animation:
    duck-flap 0.33s steps(1) infinite,
    duck-glide 9s linear infinite;
}

.tap-flash-overlay {
  position: absolute; inset: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.55), transparent 65%);
  pointer-events: none;
  opacity: 0;
  animation: tapPulse 0.3s ease-out;
  z-index: 10;
}
@keyframes tapPulse {
  0% { opacity: 1; transform: scale(0.9); }
  100% { opacity: 0; transform: scale(1.05); }
}

/* === Arm screen === */
#start-prompt {
  text-align: center;
  padding: 0 24px;
  position: relative;
  z-index: 4;
  animation: armFade 0.4s ease-out;
}
@keyframes armFade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
#start-btn {
  background: var(--hud-yellow);
  border: 4px solid var(--stroke);
  color: var(--stroke);
  font: 700 22px/1 var(--font-hud);
  letter-spacing: 0.1em;
  padding: 22px 34px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 6px 6px 0 var(--stroke);
}
#start-btn:active {
  transform: translate(4px, 4px);
  box-shadow: 2px 2px 0 var(--stroke);
}
.start-sub {
  margin: 28px auto 0;
  font: 700 10px/1.7 var(--font-hud);
  letter-spacing: 0.22em;
  color: var(--text);
  text-shadow: var(--hud-stroke-1);
  text-transform: uppercase;
  max-width: 260px;
}

/* === Active aiming display === */
#aim-display {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  position: relative;
  z-index: 4;
  animation: armFade 0.4s ease-out;
}
#aim-display[hidden] { display: none; }

.aim-frame {
  width: 184px;
  height: 184px;
  position: relative;
  background: var(--text);
  border: 4px solid var(--stroke);
  box-shadow: 6px 6px 0 var(--stroke);
}
.aim-frame::before, .aim-frame::after {
  content: '';
  position: absolute;
  background: var(--stroke);
}
.aim-frame::before {
  left: 50%; top: 8px; bottom: 8px; width: 2px;
  transform: translateX(-50%);
}
.aim-frame::after {
  top: 50%; left: 8px; right: 8px; height: 2px;
  transform: translateY(-50%);
}

#aim-dot {
  position: absolute;
  width: 28px; height: 28px;
  background-image: url('assets/ui/sprite_aim.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  image-rendering: pixelated;
  transform: translate(-50%, -50%);
  left: 50%; top: 50%;
  will-change: left, top;
  pointer-events: none;
}

.aim-instructions {
  text-align: center;
  line-height: 2;
}
.instr-line {
  font: 700 12px/2 var(--font-hud);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: var(--hud-stroke-1);
}
.instr-line .key {
  display: inline-block;
  background: var(--hud-yellow);
  color: var(--stroke);
  text-shadow: none;
  border: 2px solid var(--stroke);
  padding: 2px 8px;
  margin-right: 10px;
  letter-spacing: 0.08em;
}

#recenter-btn {
  background: var(--hud-yellow);
  border: 3px solid var(--stroke);
  color: var(--stroke);
  font: 700 11px/1 var(--font-hud);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 12px 22px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 4px 4px 0 var(--stroke);
}
#recenter-btn:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--stroke);
}

/* ============ BOOT SCREEN ============ */
#boot-screen {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-bottom: 24vmin;
  transition: opacity 0.45s ease-out;
}
#boot-screen.hidden {
  opacity: 0;
  pointer-events: none;
}
#boot-logo {
  width: min(45vmin, 420px);
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
#boot-wordmark {
  margin-top: -2vmin;
  font-family: 'Helvetica Neue', Arial, system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #fff;
  font-size: clamp(32px, 4.0vmin, 48px);
  text-transform: uppercase;
}
#boot-progress {
  /* position: absolute;
  bottom: 12vmin; */
  margin-top: 5vmin;
  width: 180px;
  height: 14px;
  padding: 2px;
  border: 1px solid #fff;
  border-radius: 5px;
  overflow: hidden;
}
#boot-progress-fill {
  height: 100%;
  width: 0%;
  background: #fff;
  transition: width 0.15s linear;
  animation: boot-progress-idle 1.6s ease-out forwards;
}
@keyframes boot-progress-idle {
  from { width: 0%; }
  to { width: 100%; }
}
