:root {
  --bg1: #a8e6cf;
  --bg2: #dcedc1;
  --accent: #2ecc71;
  --accent-dark: #27ae60;
  --glass: rgba(255,255,255,0.75);
  --text: #2c3e50;
  --glow: #ffeaa7;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #88d8b0;
  color: var(--text);
  touch-action: none;
  position: fixed;
  inset: 0;
  margin: 0;
}
#app {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}
canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #a8e6cf 0%, #88d8b0 40%, #6ab04c 100%);
  touch-action: none;
}

/* HUD */
#hud {
  position: absolute;
  top: var(--safe-top);
  left: var(--safe-left);
  right: var(--safe-right);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}
.equation-banner {
  background: var(--glass);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 10px 28px;
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  font-weight: 700;
  color: #1a5276;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1), inset 0 0 0 2px rgba(255,255,255,0.5);
  text-shadow: 0 1px 2px rgba(255,255,255,0.8);
  min-width: 180px;
  text-align: center;
}
.stats {
  display: flex;
  gap: 16px;
  align-items: center;
  background: var(--glass);
  backdrop-filter: blur(6px);
  border-radius: 16px;
  padding: 6px 16px;
  font-weight: 600;
  font-size: 0.95rem;
}
.lives { letter-spacing: 2px; font-size: 1.1rem; }
.combo { color: #e67e22; font-weight: 800; animation: pulse 0.6s ease; }
.controls-top {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  pointer-events: auto;
  touch-action: manipulation;
}
.controls-top button {
  width: 44px; height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(6px);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  touch-action: manipulation;
}
.controls-top button:active { transform: scale(0.95); }

/* D-pad */
.dpad {
  position: absolute;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 20;
  pointer-events: auto;
  touch-action: manipulation;
}
.dpad button {
  width: 56px; height: 56px;
  border: none;
  border-radius: 16px;
  background: rgba(255,255,255,0.85);
  font-size: 1.6rem;
  font-weight: bold;
  color: #2c3e50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  cursor: pointer;
  touch-action: manipulation;
}
.dpad-row { display: flex; gap: 4px; }
@media (pointer: coarse), (max-width: 800px) {
  .dpad { display: none; }
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
  touch-action: manipulation;
  pointer-events: auto;
}
.overlay[hidden] { display: none !important; }
.panel {
  background: var(--glass);
  backdrop-filter: blur(12px);
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.6);
  touch-action: manipulation;
}
.logo { font-size: 4rem; margin-bottom: 8px; }
h1, h2 { margin: 8px 0 12px; color: #1a5276; }
p { margin: 8px 0; line-height: 1.4; }
.stats-row { display: flex; justify-content: space-around; margin: 16px 0; font-weight: 600; }
.primary, .secondary {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 14px;
  border: none;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.primary { background: linear-gradient(135deg, #2ecc71, #27ae60); color: white; box-shadow: 0 6px 0 #1e8449; }
.primary:active { transform: translateY(2px); box-shadow: 0 4px 0 #1e8449; }
.secondary { background: white; color: #2c3e50; box-shadow: 0 4px 0 #bdc3c7; }
.big { font-size: 1.2rem; padding: 16px; }
.toggle { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; font-size: 0.9rem; }
.stars { font-size: 2rem; margin: 12px 0; letter-spacing: 4px; }

body.high-contrast {
  --glass: rgba(255,255,255,0.95);
  --text: #000;
}
body.high-contrast .equation-banner { background: #fff; color: #000; border: 3px solid #000; }
body.high-contrast canvas { filter: contrast(1.15); }

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

@media (min-width: 900px) {
  .equation-banner {
    font-size: 3.4rem;
    padding: 16px 48px;
    min-width: 280px;
  }
  .stats { font-size: 1.15rem; padding: 8px 20px; }
  .lives { font-size: 1.3rem; }
}
