:root {
  --stage-w: 420px;
  --stage-h: 720px;
  --accent: #ffcf3f;
  --accent-deep: #f5a623;
  --panel-bg: rgba(18, 28, 46, 0.72);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #f4f8ff;
  --text-dim: #b9c6dd;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a1526;
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* 3D background canvas fills the whole viewport */
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* Center the play stage */
#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

#game-canvas {
  position: relative;
  width: var(--stage-w);
  height: var(--stage-h);
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 22px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  cursor: pointer;
  background: transparent;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: var(--stage-w);
  max-width: 100vw;
  height: var(--stage-h);
  max-height: 100vh;
  pointer-events: none;
  display: flex;
  justify-content: center;
}

.score {
  margin-top: 34px;
  font-size: 64px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 18px rgba(0, 0, 0, 0.25);
  letter-spacing: 1px;
  transition: transform 0.08s ease-out;
}

.score.pop {
  transform: scale(1.28);
}

/* Overlays */
.overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: var(--stage-w);
  max-width: 100vw;
  height: var(--stage-h);
  max-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22px;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 34px 30px;
  text-align: center;
  box-shadow: var(--shadow);
  width: 86%;
  max-width: 340px;
  animation: floatIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.title {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.5px;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

.title .accent {
  color: var(--accent);
}

.logo-duck {
  display: block;
  width: 118px;
  height: 118px;
  margin: 0 auto 6px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.35));
  animation: bob 2.4s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-8px) rotate(3deg); }
}

.subtitle {
  margin-top: 10px;
  color: var(--text-dim);
  font-size: 15px;
}

.how-to {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 22px 0 14px;
  flex-wrap: wrap;
}

.powerup-hint {
  margin: 0 auto 22px;
  max-width: 300px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  opacity: 0.9;
}

.key-hint {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 7px;
}

.tap-icon {
  font-size: 16px;
}

.kbd {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 700;
  color: #fff;
  font-size: 12px;
}

.btn {
  border: none;
  border-radius: 16px;
  padding: 15px 40px;
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  letter-spacing: 0.4px;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #43331a;
  box-shadow: 0 8px 0 #c07d0f, 0 12px 24px rgba(0, 0, 0, 0.3);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-primary:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #c07d0f, 0 6px 12px rgba(0, 0, 0, 0.3);
}

.best-line {
  margin-top: 18px;
  color: var(--text-dim);
  font-size: 14px;
}

.best-line span {
  color: var(--accent);
  font-weight: 700;
}

.over-title {
  font-size: 34px;
  font-weight: 800;
  color: #ff6b6b;
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
}

.score-card {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 24px 0;
}

.score-item {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 16px 22px;
  min-width: 110px;
}

.score-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.score-value {
  display: block;
  font-size: 40px;
  font-weight: 800;
  color: #fff;
}

.new-best {
  margin-bottom: 18px;
  color: var(--accent);
  font-weight: 800;
  font-size: 17px;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.hidden {
  display: none !important;
}

.ready-flash {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 30px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  pointer-events: none;
  animation: readyPop 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes readyPop {
  from { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.sound-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(18, 28, 46, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  z-index: 3;
  transition: transform 0.12s ease, background 0.12s ease;
}

.sound-btn:hover {
  background: rgba(18, 28, 46, 0.8);
  transform: scale(1.06);
}

.sound-btn:active {
  transform: scale(0.94);
}

@media (max-height: 740px) {
  :root {
    --stage-h: 100vh;
  }
  #game-canvas {
    border-radius: 0;
  }
  .overlay,
  .score {
    border-radius: 0;
  }
}
