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

* { box-sizing: border-box; }

/* `hidden` must win over element rules that set `display` (e.g. .level). */
[hidden] { display: none !important; }

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;
}
/* The `.overlay` display:flex above outranks the UA `[hidden]` rule, so the
   HTML `hidden` attribute alone wouldn't hide #gameover — restore it. */
.overlay[hidden] { display: 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 {
  display: block;
  appearance: none;
  width: 92px;
  height: 92px;
  margin: 0 auto 0.9rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  position: relative;
  cursor: pointer;
  transition: border-color 0.2s ease;
}
.level:active { transform: scale(0.96); }
/* 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; }

/* "Set level here" — recalibrate the bubble's neutral to the current tilt. */
.level-reset {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  padding: 0.35rem 0.9rem;
  margin: 0 auto 1.5rem;
  display: block;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.level-reset:hover { color: var(--ink); border-color: var(--ink); }
.level-reset.is-set { color: #7ad17a; border-color: #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); }

/* ---- Score + timer HUD ---- */
.status {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  z-index: 15;
  display: flex;
  gap: 0.75rem;
  font-variant-numeric: tabular-nums;
}
/* Same as .overlay: keep the `hidden` attribute working despite display:flex. */
.status[hidden] { display: none; }
.status-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px;
  min-width: 56px;
}
.status-label {
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.status-item span:last-child {
  font-size: 1.2rem;
  font-weight: 300;
  color: var(--ink);
}
.status.is-low #time { color: #e8546b; }

/* ---- Admin mode ---- */
.admin-toggle {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  right: calc(16px + env(safe-area-inset-right));
  z-index: 16;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.admin-toggle:hover { color: var(--ink); border-color: var(--ink); }

.admin-panel {
  position: fixed;
  bottom: calc(64px + env(safe-area-inset-bottom));
  right: calc(16px + env(safe-area-inset-right));
  z-index: 16;
  width: 248px;
  max-height: 70dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.admin-panel[hidden] { display: none; }
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.admin-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.admin-close:hover { color: var(--ink); }
.admin-fields { display: flex; flex-direction: column; gap: 0.55rem; }
.admin-row { display: flex; flex-direction: column; gap: 0.2rem; cursor: pointer; }
.admin-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.admin-val { color: var(--ink); }
.admin-row input[type="checkbox"] {
  align-self: flex-start;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.admin-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  outline: none;
  touch-action: pan-x;
  cursor: pointer;
}
.admin-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.admin-row input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.admin-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.2rem;
}
.admin-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.admin-btn:hover { color: var(--ink); border-color: var(--ink); }
.admin-publish {
  flex: 1;
  border-color: var(--ink);
  color: var(--ink);
}
.admin-publish:hover { background: var(--ink); color: var(--bg); }
.admin-status {
  margin: 0.1rem 0 0;
  min-height: 1em;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ---- 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;
}

/* ---- High scores (game-over overlay) ---- */
.overlay-card-wide { max-width: 360px; width: 100%; }

.hs-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.7rem;
  margin: 0 0 1.4rem;
}
.hs-form[hidden] { display: none; }
.hs-congrats {
  margin: 0 !important;
  color: var(--ink) !important;
  font-size: 0.9rem !important;
  letter-spacing: 0.02em;
}
.hs-name {
  appearance: none;
  text-align: center;
  font: inherit;
  font-size: 1.1rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
}
.hs-name:focus { outline: none; border-color: var(--ink); }
.hs-status {
  margin: 0 !important;
  min-height: 1em;
  font-size: 0.74rem !important;
  color: var(--muted);
}

.hs-board { margin: 0 0 1.4rem; }
.hs-board[hidden] { display: none; }
.hs-tabs {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.7rem;
}
.hs-tab {
  flex: 1;
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.4rem 0.3rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.hs-tab.is-active {
  color: var(--bg);
  background: var(--ink);
  border-color: var(--ink);
}
.hs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.hs-list li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.4rem 0.2rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.hs-list li:last-child { border-bottom: none; }
.hs-rank { width: 1.4rem; color: var(--muted); font-size: 0.78rem; }
.hs-entry-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hs-coins { font-weight: 400; }
.hs-list li.is-me { color: #2a7d46; font-weight: 500; }
.hs-list li.is-me .hs-rank,
.hs-list li.is-me .hs-coins { color: #2a7d46; }
.hs-empty { color: var(--muted); font-size: 0.84rem; padding: 0.6rem 0.2rem; }
