:root {
  --bg: #f4f2ee;
  --ink: #2a2925;
  --muted: #8a877f;
  --line: #d9d5cc;
  --accent: #2a2925;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}

/* ---- Start overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 20;
  transition: opacity 0.5s ease;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.overlay-card {
  text-align: center;
  max-width: 320px;
  padding: 0 24px;
}
.overlay-card h1 {
  font-weight: 300;
  font-size: 2.4rem;
  letter-spacing: 0.18em;
  margin: 0 0 0.6rem;
  text-transform: lowercase;
}
.overlay-card p {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0 0 1.6rem;
}
/* ---- Bubble level (splash calibration aid) ---- */
.level {
  width: 92px;
  height: 92px;
  margin: 0 auto 1.6rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  position: relative;
  transition: border-color 0.2s ease;
}
/* Crosshair to read the centre against. */
.level::before,
.level::after {
  content: "";
  position: absolute;
  background: var(--line);
}
.level::before { left: 50%; top: 14%; bottom: 14%; width: 1px; transform: translateX(-0.5px); }
.level::after { top: 50%; left: 14%; right: 14%; height: 1px; transform: translateY(-0.5px); }
.level-bubble {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s ease;
  will-change: transform;
}
.level.is-level { border-color: #7ad17a; }
.level.is-level .level-bubble { background: #7ad17a; }

.start-btn {
  appearance: none;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  padding: 0.7rem 1.8rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.start-btn:hover { background: var(--ink); color: var(--bg); }
.overlay-hint {
  margin-top: 1.4rem !important;
  font-size: 0.78rem !important;
  color: var(--muted);
}

/* ---- Debug toggle ---- */
.debug-toggle {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  z-index: 15;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}
.debug-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.debug-track {
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background 0.2s ease;
}
.debug-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 0.2s ease;
}
.debug-toggle input:checked + .debug-track { background: var(--accent); }
.debug-toggle input:checked + .debug-track .debug-thumb { transform: translateX(16px); }

/* ---- Debug legend ---- */
.legend {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: calc(16px + env(safe-area-inset-left));
  z-index: 15;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.74rem;
  color: var(--ink);
  line-height: 1.5;
}
.legend-row { display: flex; align-items: center; gap: 0.5rem; }
.swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}
.swatch-dash {
  background: repeating-linear-gradient(90deg, var(--ink) 0 3px, transparent 3px 6px);
}
.legend-hud {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: pre;
  font-size: 0.7rem;
}
