:root {
  --bg-deep: #02030a;
  --bg-mid: #060914;
  --panel: rgba(10, 14, 28, 0.88);
  --panel-border: rgba(255, 255, 255, 0.07);
  --text: #e8ecf5;
  --text-dim: rgba(232, 236, 245, 0.55);
  --accent: #ffd570;
  --accent-hot: #ff6b3d;
  --good: #7af0a8;
  --warn: #ffd570;
  --bad: #ff8b6b;
  --hud-blur: blur(10px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(ellipse at center, var(--bg-mid) 0%, var(--bg-deep) 70%);
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: clamp(12px, 2.5vw, 28px);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hud-block {
  background: var(--panel);
  backdrop-filter: var(--hud-blur);
  -webkit-backdrop-filter: var(--hud-blur);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.hud-block-left { align-items: flex-start; }

.hud-label {
  font-size: 10px;
  color: var(--text-dim);
}

.hud-percent {
  font-size: clamp(28px, 4.5vw, 44px);
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(255, 213, 112, 0.35);
}

.hud-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 99px;
  overflow: hidden;
}

.hud-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--good) 0%, var(--warn) 70%, var(--bad) 100%);
  border-radius: 99px;
  transition: width 0.05s linear;
  box-shadow: 0 0 8px rgba(255, 213, 112, 0.4);
}

.hud-phase {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.hud-phase.phase-beads { color: var(--warn); }
.hud-phase.phase-diamond {
  color: #fff;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.9);
  animation: pulse 0.45s ease-in-out infinite alternate;
}
.hud-phase.phase-totality {
  color: var(--accent-hot);
  text-shadow: 0 0 12px rgba(255, 107, 61, 0.7);
}
.hud-phase.phase-post { color: var(--text-dim); }

@keyframes pulse {
  from { opacity: 0.65; }
  to { opacity: 1; }
}

.hud-title {
  font-size: clamp(16px, 2.2vw, 22px);
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--text);
}
.hud-title-accent { color: var(--accent); }

.hud-hint {
  font-size: 11px;
  color: var(--text-dim);
}

/* ---------- Flash overlay ---------- */

#flash {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  transition: opacity 0.18s ease-out;
}

#flash.active { opacity: 0.55; }

/* ---------- Modal ---------- */

.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 3, 10, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
  animation: fadeIn 0.18s ease-out;
}

.modal.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-panel {
  width: min(92vw, 520px);
  background: linear-gradient(180deg, rgba(15, 19, 36, 0.95), rgba(8, 11, 22, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

#modal-image {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #000;
}

.modal-body {
  padding: 22px 24px 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.modal-emoji { font-size: 38px; line-height: 1; }

.modal-percent {
  font-size: clamp(40px, 6vw, 56px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff, #d3d8e6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal-phase {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
}

.modal-quote {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
  max-width: 38ch;
  line-height: 1.5;
}

.modal-hint {
  margin: 14px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-family: inherit;
  color: var(--text);
}

/* ---------- Best Banner ---------- */

#best-banner {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 99px;
  padding: 8px 18px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  pointer-events: none;
  backdrop-filter: var(--hud-blur);
  -webkit-backdrop-filter: var(--hud-blur);
}

#best-banner.hidden { display: none; }

#best-banner strong {
  color: var(--accent);
  margin-left: 4px;
  font-weight: 700;
}

/* ---------- Capture button (mobile / touch) ---------- */

.capture-btn {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  transform: translateX(-50%);
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.1s ease-out, box-shadow 0.18s ease-out;
  pointer-events: auto;
  animation: captureBtnReady 1.6s ease-in-out infinite;
}

.capture-btn.hidden { display: none; }

.capture-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

@keyframes captureBtnReady {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 213, 112, 0.0), 0 8px 24px rgba(0, 0, 0, 0.4); }
  50%      { box-shadow: 0 0 0 10px rgba(255, 213, 112, 0.18), 0 8px 24px rgba(0, 0, 0, 0.4); }
}

.capture-btn:active {
  transform: translateX(-50%) scale(0.92);
}

.capture-btn-ring {
  position: absolute;
  inset: 6px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  pointer-events: none;
}

.capture-btn-icon {
  position: relative;
  width: 28px;
  height: 22px;
  background: var(--accent);
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 0 18px rgba(255, 213, 112, 0.4);
}

.capture-btn-icon::before {
  content: '';
  position: absolute;
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 8px;
  border: 2px solid var(--accent);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  box-shadow: 0 0 18px rgba(255, 213, 112, 0.4);
}

@media (max-width: 520px) {
  .capture-btn { width: 88px; height: 88px; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); }
  .capture-btn-icon { width: 32px; height: 24px; }
}

/* Hide the button on devices with a real keyboard (heuristic: hover-capable).
   This way desktop users see only the SPACE hint, while touch users see a button. */
@media (hover: hover) and (pointer: fine) {
  .capture-btn { display: none; }
  .capture-btn.always-show { display: flex; }
}

/* ---------- Install button (PWA) ---------- */

.install-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 8px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent);
  color: #1a1300;
  border: none;
  border-radius: 99px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 213, 112, 0.35);
  transition: transform 0.1s ease-out;
  z-index: 6;
  -webkit-tap-highlight-color: transparent;
  animation: installPulse 2.4s ease-in-out infinite;
}

.install-btn.hidden { display: none; }

.install-btn:active { transform: scale(0.94); }
.install-btn:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

.install-btn span[aria-hidden] {
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}

@keyframes installPulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(255, 213, 112, 0.35); }
  50%      { box-shadow: 0 6px 28px rgba(255, 213, 112, 0.6); }
}

@media (max-width: 520px) {
  .install-btn-text { display: none; }
  .install-btn { padding: 10px 12px; }
}

/* ---------- Small screens ---------- */

@media (max-width: 520px) {
  .hud-block { min-width: 0; padding: 10px 12px; }
  .hud-percent { font-size: 28px; }
}
