:root {
  --bg: #05060f;
  --accent: #36e0ff;
  --accent-2: #ff4d8d;
  --text: #eaf6ff;
}

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

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

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

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

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 18px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.hud-label {
  display: block;
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0.6;
}

#hud span:not(.hud-label),
#hud > div {
  font-size: 26px;
  font-weight: 700;
}

.hud-clock {
  text-align: center;
}

.hud-best {
  text-align: right;
  color: var(--accent);
}

#time {
  display: inline-block;
  color: #36ffa6;
  text-shadow: 0 0 16px rgba(54, 255, 166, 0.5);
}

#time.low {
  color: #ff4d4d;
  text-shadow: 0 0 18px rgba(255, 77, 77, 0.8);
  animation: lowPulse 0.8s ease-in-out infinite;
}

#time.time-bonus {
  animation: timeBonus 0.5s ease-out;
}

@keyframes lowPulse {
  50% { opacity: 0.45; }
}

@keyframes timeBonus {
  0% { transform: scale(1.5); color: #ffffff; }
  100% { transform: scale(1); }
}

/* ---------- Math HUD ---------- */
#mathbar {
  position: absolute;
  top: max(60px, calc(env(safe-area-inset-top) + 48px));
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  text-align: center;
}

#mathbar .hud-label {
  font-size: 11px;
  letter-spacing: 3px;
  opacity: 0.6;
}

#targets {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 96vw;
}

.target-chip {
  font-size: 26px;
  font-weight: 800;
  color: #ffd84d;
  font-variant-numeric: tabular-nums;
  padding: 4px 14px;
  border-radius: 12px;
  background: rgba(8, 14, 28, 0.55);
  border: 2px solid rgba(255, 216, 77, 0.5);
  text-shadow: 0 0 14px rgba(255, 216, 77, 0.5);
}

.target-chip.chip-solved {
  animation: chipSolved 0.55s ease-out;
}

@keyframes chipSolved {
  0% {
    color: #36ffa6;
    border-color: #36ffa6;
    transform: scale(1.4);
    box-shadow: 0 0 26px rgba(54, 255, 166, 0.9);
  }
  100% { transform: scale(1); }
}

#expr {
  margin-top: 4px;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  padding: 2px 18px;
  border-radius: 999px;
  background: rgba(8, 14, 28, 0.5);
  min-height: 1.2em;
}

#expr.flash-good {
  animation: flashGood 0.55s ease-out;
}

@keyframes flashGood {
  0% { color: #36ffa6; transform: scale(1.3); text-shadow: 0 0 24px rgba(54, 255, 166, 0.9); }
  100% { color: var(--text); transform: scale(1); }
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(54, 224, 255, 0.08), rgba(5, 6, 15, 0.85) 70%);
  backdrop-filter: blur(2px);
  z-index: 10;
}

h1 {
  font-size: clamp(44px, 16vw, 96px);
  letter-spacing: 4px;
  line-height: 1;
  text-shadow: 0 0 24px rgba(54, 224, 255, 0.6);
}

h1 span {
  color: var(--accent);
}

h2 {
  font-size: clamp(34px, 11vw, 64px);
  letter-spacing: 3px;
  color: var(--accent-2);
  text-shadow: 0 0 24px rgba(255, 77, 141, 0.5);
}

.tagline {
  margin-top: 10px;
  opacity: 0.7;
  letter-spacing: 3px;
  font-size: 14px;
  text-transform: uppercase;
}

.hint {
  margin-top: 22px;
  max-width: 280px;
  font-size: 13px;
  opacity: 0.55;
  line-height: 1.5;
}

.btn {
  margin-top: 30px;
  padding: 16px 34px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--bg);
  background: var(--accent);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 28px rgba(54, 224, 255, 0.55);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn:active {
  transform: scale(0.95);
  box-shadow: 0 0 14px rgba(54, 224, 255, 0.4);
}

.final {
  display: flex;
  gap: 48px;
  margin-top: 26px;
}

.final strong {
  display: block;
  font-size: 40px;
  font-variant-numeric: tabular-nums;
}

.new-best {
  margin-top: 18px;
  color: #ffd84d;
  letter-spacing: 2px;
  font-weight: 700;
  animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

.hidden {
  display: none !important;
}
