:root {
  --bg-1: #ffd166;
  --bg-2: #ef8a5d;
  --bg-3: #ff6b9b;
  --sky-1: #79c8ff;
  --sky-2: #b8e6ff;
  --road-1: #4a4a4a;
  --road-2: #2c2c2c;
  --accent: #1d6fbf;
  --accent-2: #ff4d6d;
  --good: #2ecc71;
  --bad: #e74c3c;
  --text: #1a1a1a;
  --text-dim: #4a4a4a;
  --card-bg: rgba(255, 255, 255, 0.92);
  --card-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    Roboto, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============ SCREENS ============ */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bot));
  overflow-y: auto;
  overflow-x: hidden;
}
.screen.visible { display: flex; }

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
}
.overlay.visible { display: flex; }

/* ============ START SCREEN ============ */
.logo {
  text-align: center;
  margin: 12px 0 16px;
  animation: bob 2.6s ease-in-out infinite;
}
.logo-emoji {
  font-size: 64px;
  display: inline-block;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.2));
}
.logo h1 {
  margin: 4px 0 2px;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: -1px;
  color: #fff;
  text-shadow: 0 4px 0 var(--accent), 0 8px 16px rgba(0, 0, 0, 0.25);
}
.tagline {
  margin: 0;
  color: #fff;
  font-weight: 600;
  opacity: 0.95;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border-radius: 18px;
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--card-shadow);
}
.card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}
.card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--text-dim);
  line-height: 1.5;
  font-size: 15px;
}
.card ul li + li { margin-top: 4px; }

.control-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.control {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: #f4f6fa;
  border-radius: 12px;
  padding: 10px 6px;
}
.control-icon { font-size: 26px; }
.control-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  font-weight: 600;
}

/* ============ BUTTONS ============ */
.primary-btn {
  width: 100%;
  max-width: 420px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  border: none;
  padding: 16px 20px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 0 #14559a, 0 10px 24px rgba(0, 0, 0, 0.2);
  transition: transform 0.08s, box-shadow 0.08s;
  margin-top: 6px;
}
.primary-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #14559a, 0 4px 12px rgba(0, 0, 0, 0.2);
}
.ghost-btn {
  width: 100%;
  max-width: 420px;
  background: transparent;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border: 2px solid rgba(255, 255, 255, 0.7);
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  margin-top: 10px;
}
.overlay .ghost-btn { color: var(--text); border-color: rgba(0, 0, 0, 0.2); }
.mini-btn {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border: none;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 6px;
}
.mini-btn:active { transform: translateY(1px); }

.hint {
  color: #fff;
  font-size: 12px;
  opacity: 0.9;
  margin-top: 14px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* ============ GAME SCREEN ============ */
#game-screen {
  padding: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-1), var(--sky-2) 60%, #f4d9a8 100%);
}

#hud {
  position: absolute;
  top: calc(8px + var(--safe-top));
  left: 8px;
  right: 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  z-index: 10;
  pointer-events: none;
}
.hud-left, .hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: auto;
}
.hud-center {
  display: flex;
  justify-content: center;
  flex: 1;
}
/* ====== chip-style HUD pills ====== */
.chip {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  line-height: 1;
}
.chip-level {
  background: linear-gradient(135deg, #ffb02e, #ff6b35);
  color: #fff;
  letter-spacing: 0.5px;
}
.chip-lives .heart { color: #e74c3c; font-size: 14px; }
.chip-score .star  { color: #f1c40f; font-size: 14px; filter: drop-shadow(0 0 2px rgba(255,200,0,0.45)); }

/* Combo banner — sits below HUD, fades in only when combo > 1 */
.combo-banner {
  position: absolute;
  top: calc(58px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  background: linear-gradient(135deg, #ff4d6d, #ff8b4d);
  color: #fff;
  padding: 6px 16px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.5px;
  box-shadow: 0 6px 16px rgba(255, 77, 109, 0.45);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 6px;
}
.combo-banner.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
.combo-banner.pulse {
  animation: comboPulse 0.4s ease-out;
}
@keyframes comboPulse {
  0%   { transform: translateX(-50%) scale(1);   }
  40%  { transform: translateX(-50%) scale(1.18); }
  100% { transform: translateX(-50%) scale(1);   }
}
.combo-label {
  font-size: 10px;
  text-transform: uppercase;
  opacity: 0.9;
}
#hud-combo-num { font-size: 16px; }
.theme-banner {
  background: rgba(29, 111, 191, 0.95);
  color: #fff;
  border-radius: 12px;
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
  text-align: center;
  min-width: 110px;
}
.theme-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.9;
}
#hud-theme-name {
  font-weight: 800;
  font-size: 15px;
  line-height: 1.1;
}

#pause-btn {
  align-self: flex-end;
  padding: 4px 10px;
  font-size: 16px;
  margin-top: 0;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#touch-controls {
  position: absolute;
  bottom: calc(20px + var(--safe-bot));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 10;
  pointer-events: none;
}
.touch-btn {
  pointer-events: auto;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
.touch-btn:active { transform: scale(0.94); background: #fff; }

@media (hover: hover) and (pointer: fine) {
  #touch-controls { display: none; }
}

.floating-msg {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s, transform 0.6s;
  z-index: 11;
  text-align: center;
}
.floating-msg.show {
  opacity: 1;
  transform: translate(-50%, -80%);
}

/* ============ OVERLAYS ============ */
.overlay .card {
  text-align: center;
  max-width: 360px;
}
.overlay h2 {
  margin: 4px 0 12px;
  font-size: 28px;
}
.overlay .reason {
  margin: 0 0 14px;
  color: var(--text-dim);
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0 14px;
}
.stat {
  background: #f4f6fa;
  border-radius: 10px;
  padding: 8px 4px;
}
.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 700;
  letter-spacing: 0.5px;
}
.stat-value {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent);
}

/* ============ BRIEFING MODAL ============ */
.briefing-card {
  background: linear-gradient(180deg, #ffffff 0%, #f3f7ff 100%);
  max-width: 380px;
  width: 100%;
  text-align: center;
  padding: 14px 18px 18px;
  border-radius: 22px;
}
.briefing-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.briefing-card h2 {
  font-size: 22px;
  margin: 4px 0 2px;
  color: var(--accent);
}
.briefing-sub {
  margin: 0 0 12px;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 700;
}
.briefing-samples {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 8px 0 4px;
}
.sample-tile {
  position: relative;
  background: #fff;
  border-radius: 14px;
  padding: 14px 6px 8px;
  box-shadow: inset 0 0 0 2px #e6e9f0;
}
.sample-tile.good { box-shadow: inset 0 0 0 3px #2ecc71; }
.sample-tile.bad  { box-shadow: inset 0 0 0 3px #e74c3c; }
.sample-emoji {
  font-size: 38px;
  display: block;
  line-height: 1;
}
.sample-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 900;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.sample-tile.good .sample-badge { background: #2ecc71; }
.sample-tile.bad  .sample-badge { background: #e74c3c; }
.sample-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  font-weight: 700;
}
.briefing-character {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 14px;
  min-height: 80px;
}
.briefing-character img {
  width: 64px;
  height: auto;
  image-rendering: -webkit-optimize-contrast;
}
.speech-bubble {
  position: relative;
  background: #1d6fbf;
  color: #fff;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  max-width: 180px;
  box-shadow: 0 4px 12px rgba(29, 111, 191, 0.4);
}
.speech-bubble::after {
  content: '';
  position: absolute;
  right: -8px;
  bottom: 12px;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  border-left-color: #1d6fbf;
  border-right: 0;
}

/* tablet+ */
@media (min-width: 700px) {
  .logo h1 { font-size: 56px; }
  .logo-emoji { font-size: 80px; }
  .card { max-width: 480px; }
  .primary-btn, .ghost-btn { max-width: 480px; }
}
