:root {
  color-scheme: dark;
  --void: #05040a;
  --glass-bg: rgba(18, 16, 28, 0.55);
  --glass-border: rgba(255, 255, 255, 0.09);
  --text: #ece9f5;
  --text-dim: #9d97b8;
  --accent: #7fe8d0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--void);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

canvas#bg, canvas#fg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

canvas#bg {
  filter: blur(18px) saturate(1.3) brightness(1.35);
  opacity: 0.75;
  transform: scale(1.04);
}

canvas#fg {
  cursor: crosshair;
  touch-action: none;
}

.panel {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  margin: 16px;
  max-width: min(78vw, 300px);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  padding: 16px 18px;
  transition: transform 0.35s ease, opacity 0.35s ease;
}

.panel.collapsed .panel-inner {
  display: none;
}

.panel.collapsed {
  padding: 8px 12px;
  border-radius: 999px;
}

.panel-collapse {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.panel.collapsed .panel-collapse {
  position: static;
  color: var(--text);
}

.panel h1 {
  margin: 0 0 2px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-dim);
}

.stats {
  display: flex;
  gap: 16px;
  margin: 0 0 12px;
}

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

.stats dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.stats dd {
  margin: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#sparkline {
  display: block;
  width: 100%;
  height: 40px;
  opacity: 0.9;
}

.info-btn {
  position: fixed;
  bottom: env(safe-area-inset-bottom, 0px);
  right: 0;
  margin: 16px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.hint {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  animation: hint-fade 6s ease forwards;
}

@keyframes hint-fade {
  0% { opacity: 0; transform: translateX(-50%) translateY(6px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 2, 6, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  position: relative;
  max-width: 480px;
  background: #0d0b16;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 28px 26px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-height: 80vh;
  overflow-y: auto;
}

.modal h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.modal p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-dim);
  margin: 0 0 12px;
}

.modal p:last-child { margin-bottom: 0; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
}

@media (max-width: 560px) {
  .panel { max-width: 68vw; padding: 14px 16px; }
  .stats { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .hint { animation: hint-fade-simple 6s ease forwards; }
  @keyframes hint-fade-simple {
    0% { opacity: 0; }
    15% { opacity: 1; }
    80% { opacity: 1; }
    100% { opacity: 0; }
  }
}
