:root {
  --lime: #9cff2e;
  --lime-dim: rgba(156, 255, 46, 0.55);
  --ink: #000;
  --panel: rgba(6, 14, 6, 0.82);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--lime);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#trail-canvas { z-index: 0; }
#ui-canvas { z-index: 1; }

#appIcon {
  position: fixed;
  z-index: 6;
  display: block;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: max(16px, env(safe-area-inset-left, 0px));
  width: 44px;
  height: 44px;
  border-radius: 10px;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
#appIcon:hover { transform: scale(1.05); opacity: 0.9; }
#appIcon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: 10px;
}

.hud {
  position: absolute;
  z-index: 2;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: flex-end;
  gap: 16px;
  pointer-events: none;
}

.hud-stats {
  display: flex;
  gap: clamp(12px, 3.5vw, 22px);
  align-items: flex-end;
}

.stat { display: flex; flex-direction: column; gap: 3px; }

.stat-label {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: rgba(156, 255, 46, 0.45);
}

.stat-value {
  font-size: clamp(13px, 3.6vw, 17px);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-shadow: 0 0 12px rgba(156, 255, 46, 0.35);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.mode-stat { white-space: nowrap; }
.mode-stat .stat-label { color: rgba(77, 141, 255, 0.5); }
.mode-stat[data-mode="attract"] .stat-value {
  color: #7ba9ff;
  text-shadow: 0 0 12px rgba(77, 141, 255, 0.35);
}
.mode-stat[data-mode="repel"] .stat-label { color: rgba(255, 107, 107, 0.5); }
.mode-stat[data-mode="repel"] .stat-value {
  color: #ff8a8a;
  text-shadow: 0 0 12px rgba(255, 107, 107, 0.35);
}

#moreBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: var(--lime);
  color: #061006;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-decoration: none;
  white-space: nowrap;
  pointer-events: auto;
  box-shadow: 0 0 18px rgba(156, 255, 46, 0.18);
  transition: filter 140ms ease, transform 140ms ease;
}

#moreBtn:hover, #moreBtn:focus-visible {
  filter: brightness(1.12);
  transform: translateY(-1px);
  outline: none;
}

#coffeeBtn {
  display: block;
  width: 34px;
  height: 34px;
  padding: 5px;
  border-radius: 9px;
  background: var(--lime);
  box-shadow: 0 0 18px rgba(156, 255, 46, 0.18);
  pointer-events: auto;
  transition: filter 140ms ease, transform 140ms ease;
}

#coffeeBtn:hover, #coffeeBtn:focus-visible {
  filter: brightness(1.12);
  transform: translateY(-1px);
  outline: none;
}

#coffeeBtn img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.hint {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom, 0px)) + 38px);
  transform: translateX(-50%);
  margin: 0;
  width: max-content;
  max-width: min(88vw, 640px);
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: 0.06em;
  color: rgba(156, 255, 46, 0.8);
  pointer-events: none;
  transition: opacity 600ms ease;
}

.hint span {
  display: block;
}

.hint.faded { opacity: 0; }

.overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.overlay.hidden { display: none; }

.panel {
  width: min(100%, 440px);
  padding: 34px 30px 30px;
  border: 1px solid rgba(156, 255, 46, 0.34);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 0 70px rgba(156, 255, 46, 0.1), inset 0 0 44px rgba(156, 255, 46, 0.035);
  text-align: center;
}

.kicker {
  font-size: 13px;
  letter-spacing: 0.22em;
  color: rgba(156, 255, 46, 0.6);
}

.panel h1 {
  margin: 14px 0 28px;
  font-size: clamp(30px, 8vw, 44px);
  letter-spacing: -0.03em;
  color: var(--lime);
  text-shadow: 0 0 28px rgba(156, 255, 46, 0.4);
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr;
  margin-bottom: 28px;
}

.result-stats div {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-stats span {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: rgba(156, 255, 46, 0.5);
}

.result-stats b {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}

.primary {
  appearance: none;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 15px 18px;
  background: var(--lime);
  color: #061006;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: filter 140ms ease, transform 140ms ease;
}

.primary:hover, .primary:focus-visible { filter: brightness(1.12); outline: none; }
.primary:active { transform: translateY(1px); }

@media (max-width: 420px) {
  .hud { gap: 10px; right: max(12px, env(safe-area-inset-right, 0px)); bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
  .hud-stats { gap: 12px; }
  .hud-actions { gap: 8px; }
  .mode-stat .stat-label { font-size: 8px; }
  .mode-stat .stat-value { font-size: 13px; }
  #moreBtn { height: 30px; padding: 0 8px; font-size: 10px; }
  #coffeeBtn { width: 30px; height: 30px; padding: 4px; border-radius: 8px; }
  .hint { font-size: 16px; }
  .panel { padding: 28px 22px 24px; }
}
