/* Perigee design tokens: one dark space theme, one accent, radius-12 lock, 4px spacing base. */
:root {
  --bg: #070b14;
  --surface: #101827;
  --surface-2: #1a2436;
  --ink: #e6ebf5;
  --muted: #8b94a8;
  --accent: #e8a33d;
  --good: #4ade80;
  --bad: #f87171;
  --radius: 12px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --pad: max(12px, env(safe-area-inset-left)) ;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
}

canvas#c {
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

#ui { pointer-events: none; }
#ui button, #ui a, .modal-card { pointer-events: auto; }

/* ---- HUD ---- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 8px calc(14px + env(safe-area-inset-left));
  font-size: 0.95rem;
}

#hud-left { display: flex; align-items: baseline; gap: 8px; }
#hud-title { font-weight: 800; letter-spacing: 0.14em; font-size: 1rem; }
#hud-day { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
#hud-right { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

@media (max-width: 379px) {
  #hud { font-size: 0.82rem; gap: 6px; }
  #hud-title { font-size: 0.85rem; letter-spacing: 0.1em; }
}

#hud-holes { display: flex; gap: 7px; }
.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1.5px solid var(--muted);
  opacity: 0.7;
}
.dot.cur { border-color: var(--accent); opacity: 1; }
.dot.done { background: var(--good); border-color: var(--good); opacity: 1; }

/* ---- corner buttons ---- */
#corner {
  position: fixed;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
}
#corner button {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  color: var(--ink);
  font-size: 1.05rem;
  cursor: pointer;
}
#corner button:active { transform: translateY(1px); }
#corner button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- banner / hint / toast ---- */
#banner {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) scale(0.96);
  padding: 10px 22px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--surface-2);
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 1.05rem;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  white-space: nowrap;
}
#banner.show { opacity: 1; transform: translateX(-50%) scale(1); }
#banner.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
#banner.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

#hint {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 0.85rem;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  padding: 6px 14px;
  border-radius: var(--radius);
}

#toast {
  position: fixed;
  bottom: calc(120px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}
#toast.show { opacity: 1; }

/* ---- onboarding ---- */
#onboard {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
}
.onboard-card {
  text-align: center;
  padding: 28px 30px;
  max-width: 340px;
}
.onboard-card p { margin: 6px 0; color: var(--ink); font-size: 1.02rem; }
.onboard-card p:nth-of-type(2), .onboard-card p:nth-of-type(3) { color: var(--muted); font-size: 0.92rem; }

.drag-demo {
  position: relative;
  height: 90px;
  margin-bottom: 10px;
}
.drag-dot {
  position: absolute;
  left: 50%; top: 10px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  animation: dragloop 2s ease-in-out infinite;
}
@keyframes dragloop {
  0% { transform: translate(-50%, 0); opacity: 0; }
  15% { opacity: 1; }
  55% { transform: translate(-50%, 58px); opacity: 1; }
  75% { transform: translate(-50%, 0); opacity: 0; }
  100% { opacity: 0; }
}

/* ---- modal ---- */
#modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  padding: 18px;
}
.modal-card {
  width: min(92vw, 420px);
  max-height: min(86dvh, 640px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: calc(var(--radius) + 4px);
  padding: 22px 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-card h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.1em;
  text-align: center;
}

.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.98rem;
}
.row-label { color: var(--muted); min-width: 58px; }
.row-trail { flex: 1; letter-spacing: 0.05em; }
.row-score { font-variant-numeric: tabular-nums; font-weight: 700; }
.row.total { background: transparent; border: 1px dashed var(--surface-2); justify-content: space-between; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}
.stats div { display: flex; flex-direction: column; gap: 2px; }
.stats strong { font-size: 1.15rem; }
.stats span { color: var(--muted); font-size: 0.72rem; }

.countdown {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

#modal-actions { display: flex; flex-direction: column; gap: 8px; }
.btn {
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.98rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1c1303; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn:active { transform: translateY(1px); }

#made-by {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-decoration: none;
}
#made-by:hover, #made-by:focus-visible { color: var(--accent); }

.help-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.help-list li { color: var(--ink); font-size: 0.95rem; line-height: 1.5; }
.kb-hint { color: var(--muted); font-size: 0.85rem; text-align: center; margin: 0; }

/* ---- loading / dev / noscript ---- */
#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--muted);
  letter-spacing: 0.12em;
  font-size: 0.95rem;
}
#loading span { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

#dev {
  position: fixed;
  top: 4px; left: 4px;
  color: #0f0;
  font: 12px monospace;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--ink);
  padding: 24px;
  text-align: center;
}

/* Larger screens: cap UI width, keep the game centered */
@media (min-width: 700px) {
  #hud { max-width: 720px; margin: 0 auto; }
  #banner { font-size: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  .drag-dot { animation: none; opacity: 1; transform: translate(-50%, 30px); }
  #loading span { animation: none; }
  #banner, #toast { transition: none; }
}
