:root {
  --md-surface: hsla(134, 50%, 12%, 0.85);
  --md-surface-high: hsla(134, 50%, 17%, 0.9);
  --md-outline: hsla(67, 60%, 70%, 0.2);
  --md-outline-focus: hsla(67, 100%, 80%, 0.7);
  --md-primary: hsl(67, 100%, 89%);
  --md-on-surface: hsl(67, 100%, 89%);
  --md-elevation-1:
    0 1px 3px hsla(0, 0%, 0%, 0.35), 0 1px 2px hsla(0, 0%, 0%, 0.25);
  --md-elevation-2:
    0 3px 8px hsla(0, 0%, 0%, 0.4), 0 1px 4px hsla(0, 0%, 0%, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden; /* Prevent scrolling */
  position: fixed; /* Ensure no scrolling */
  touch-action: none; /* Disable touch scrolling behaviors */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  background-color: hsl(0, 0%, 0%);
  font-family: "Lato", sans-serif;
  font-size: 0.7rem;
  color: var(--md-on-surface);
  -webkit-overflow-scrolling: none; /* Disable momentum scrolling on iOS */
}

main {
  display: flex;
  width: 100%;
  height: 100%;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  overflow: hidden; /* Prevent scrolling within main */
  touch-action: none; /* Disable touch scrolling behaviors */
}

canvas {
  width: 100%;
  height: 100%;
  display: block; /* Remove any inline spacing */
  touch-action: none; /* Prevent touch scrolling */
}

#stats,
#inspect-organism {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  margin: 0.5rem;
  background-color: var(--md-surface);
  width: auto;
  max-width: calc(100vw - 5rem);
  /* 1.5rem = panel's own margin/spacing; 1.25rem = clearance for the
     fixed-height dev-beta badge (labels.bottom-left). Update if the
     badge's own sizing changes. */
  max-height: calc(100vh - var(--bottom-controls-height, 0px) - 1.5rem - 1.25rem);
  max-height: calc(100dvh - var(--bottom-controls-height, 0px) - 1.5rem - 1.25rem);
  padding: 1rem;
  border: 1px solid var(--md-outline);
  border-radius: 16px;
  overflow: auto;
  overscroll-behavior: contain; /* Prevent scroll chaining */
  scrollbar-width: none; /* Firefox */
  touch-action: pan-y; /* Allow vertical scrolling on touch devices */
  box-shadow: var(--md-elevation-1);
  backdrop-filter: blur(8px);
}
#stats::-webkit-scrollbar,
#inspect-organism::-webkit-scrollbar {
  display: none; /* Safari and Chrome */
}

labels {
  position: fixed;
  display: flex;
}
labels.top-right {
  top: 0.5rem;
  bottom: auto;
  left: auto;
  right: 0.5rem;
  flex-direction: column;
  gap: 0.5rem;
}
labels.bottom-center {
  top: auto;
  bottom: 0.5rem;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
labels.right {
  top: auto;
  bottom: 0.5rem;
  left: auto;
  right: 0.5rem;
  gap: 0;
}
labels.bottom-left {
  top: auto;
  bottom: 0.5rem;
  left: 0.5rem;
  right: auto;
}

/* `.label` lets non-`<label>` elements (e.g. the tutorial's `<button>`s)
   opt into the same pill styling as the `<label>` elements below. */
.label,
label {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  background-color: hsla(67, 60%, 40%, 0.25);
  color: var(--md-primary);
  border: 1px solid var(--md-outline);
  font-weight: 600;
  transition: background-color 0.2s;
}

/* Control labels whose toggled/cycled state is away from its default. */
label.active {
  background-color: hsla(67, 60%, 45%, 0.7);
}

@media (max-width: 768px) {
  .label,
  label {
    font-size: 1rem;
  }
}

labels.right label {
  transition:
    opacity 0.5s ease,
    background-color 0.5s ease,
    border-color 0.5s ease;
  opacity: 0;
  background-color: transparent;
  border-color: transparent;
  width: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
}
labels.right label.highlight {
  opacity: 1;
  background-color: hsla(67, 60%, 40%, 0.25);
  border-color: var(--md-outline);
  width: auto;
  padding: 0.4rem 0.8rem;
  margin-left: 0.5rem;
}

/* Shared sizing for small corner-pinned text (status labels, the dev-beta
   badge) — smaller and less padded than the pill buttons/labels above.
   Listed as a selector group (not a standalone utility class) so each
   side keeps the specificity it needs: `.status-text.highlight` must
   still outrank `labels.right label.highlight`'s padding below. */
labels.right label.status-text.highlight,
.dev-beta-badge {
  font-size: 0.6rem;
  padding: 0.4rem 0.2rem;
}

/* Status text labels (smaller, no background) */
labels.right label.status-text.highlight {
  background-color: transparent;
  border-color: transparent;
}

/* Action buttons row (bottom-center) */
.action-buttons {
  display: flex;
  gap: 0.5rem;
}

.label,
label {
  background-color: hsla(67, 60%, 40%, 0.5);
}

.label:not(.active):hover,
.label:not(.active):active,
label:not(.active):hover,
label:not(.active):active {
  background-color: hsla(67, 60%, 45%, 0.7);
}

.action-buttons label svg {
  fill: var(--md-primary);
}

/* Rising label naming a motile action, shown over its button on each
   press (click, tap or 1-4 key). Starts 0.2rem above the button and rises
   1.5x its own height over 0.8s, fading out over the last 0.4s; duration
   matches ACTION_FEEDBACK_DURATION_MS. Same text size as the dev-beta
   badge. The wrapper is a flex container so the label stays a blockified
   flex item (as it was directly inside .action-buttons) and the wrapper's
   box matches the button exactly. */
.action-button {
  position: relative;
  display: flex;
}
.action-feedback {
  position: absolute;
  bottom: calc(100% + 0.2rem);
  left: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  animation: action-feedback-rise 0.8s linear forwards;
}
@keyframes action-feedback-rise {
  0% {
    transform: translate(-50%, 0);
    opacity: 1;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -150%);
    opacity: 0;
  }
}

/* Permanent beta notice, sized to match the bottom-right status text
   (labels.right label.status-text.highlight, above); positioned via the
   labels.bottom-left container. */
.dev-beta-badge {
  color: var(--md-primary);
  white-space: nowrap;
}
.dev-beta-badge a {
  color: inherit;
  text-decoration: underline;
}

/* Stats panel "More data" link — same color as the surrounding stats
   text in every state (no visited/hover/active differentiation). */
#stats a.more-data {
  display: block;
  margin-top: 0.6rem;
  color: inherit;
  text-decoration: underline;
}

/* ── Tutorial coach marks ──────────────────────────────────────────── */
/* Non-blocking by design: at most one box is shown at a time, floating
   next to (or below) the control it explains, so the user can still
   interact with the rest of the UI — including the very button the box
   is pointing at — while it's visible. */

.tutorial-box {
  position: fixed;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
  background-color: var(--md-surface-high);
  border: 1px solid var(--md-outline);
  border-radius: 16px;
  box-shadow: var(--md-elevation-2);
  backdrop-filter: blur(12px);
  padding: 1rem 1.25rem;
  max-width: min(20rem, calc(100vw - 2rem));
  color: var(--md-on-surface);
  font-family: "Lato", sans-serif;
}

/* Step 1 has no button to anchor to: centered horizontally (matching
   the followed organism, which is always screen-centered) and placed
   below the viewport's vertical center. */
.tutorial-box-centered {
  left: 50%;
  top: calc(50% + 4rem);
  transform: translateX(-50%);
  width: max-content;
}

.tutorial-body {
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 0;
  opacity: 0.9;
}

/* `.tutorial-close` reuses the shared pill-button look from `label`
   (radius, cursor, padding, border, weight, transition) via
   `className="label tutorial-close"`; only the font reset (buttons
   don't inherit the page font like `label` elements elsewhere do) and
   the fill color are button-specific. */
.label.tutorial-close {
  font-family: "Lato", sans-serif;
  background: hsla(67, 60%, 40%, 0.4);
}
.label.tutorial-close:hover {
  background: hsla(67, 60%, 40%, 0.6);
}

@media (max-width: 768px) {
  .tutorial-box {
    max-width: calc(100vw - 1.5rem);
    padding: 0.85rem 1rem;
  }
  .tutorial-body {
    font-size: 0.95rem;
  }
  .label.tutorial-close {
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
  }
}
