:root,
body[data-sphere-chrome="light"] {
  --bg-color: #ffffff;
  --text-main: #000000;
  --text-sub: #5f5f5f;
  --nav-bg: #f0f0f0;
  --nav-ink: #000000;
}

body[data-sphere-chrome="dark"] {
  --bg-color: #000000;
  --text-main: #ffffff;
  --text-sub: #a0a0a0;
  --nav-bg: #111111;
  --nav-ink: #ffffff;
}

body[data-sphere-theme="earth"],
body[data-sphere-theme="moon"],
body[data-sphere-theme="glow"] {
  --bg-color: #05070c;
  --nav-bg: #0c1018;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg-color);
  color: var(--text-main);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

body.help-open {
  overflow: hidden;
}

.canvas-container {
  position: fixed;
  inset: 0;
  display: flex;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  outline: none;
  -webkit-user-drag: none;
}

#gameCanvas:active {
  cursor: grabbing;
}

#gameCanvas:focus-visible {
  outline: 3px solid #0067c5;
  outline-offset: -5px;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.glitch-status {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 46;
  max-width: min(34rem, calc(100vw - 8rem));
  margin: 0;
  padding: 0.48rem 0.78rem;
  transform: translateX(-50%);
  border: 1px solid color-mix(in srgb, var(--text-main) 16%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--nav-bg) 88%, transparent);
  color: var(--text-main);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.18s ease;
}

.sphere-banner {
  position: fixed;
  left: 50%;
  bottom: max(80px, calc(env(safe-area-inset-bottom) + 72px));
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 14px 18px;
  transform: translateX(-50%) translateY(12px);
  border: 1px solid color-mix(in srgb, var(--text-main) 20%, transparent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--nav-bg) 92%, transparent);
  color: var(--text-main);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.sphere-banner[hidden] {
  display: none;
}

.sphere-banner.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.banner-msg {
  line-height: 1.35;
}

.banner-meta {
  color: var(--text-sub);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.banner-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.banner-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--text-main) 22%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-main) 8%, transparent);
  color: var(--text-main);
  cursor: pointer;
}

.banner-btn.primary {
  border-color: transparent;
  background: var(--text-main);
  color: var(--bg-color);
}

.banner-btn svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.banner-btn:focus-visible,
.help-close:focus-visible,
.help-done:focus-visible,
.help-pack:focus-visible,
.help-more a:focus-visible,
.menu-links a:focus-visible {
  outline: 2px solid var(--text-main);
  outline-offset: 2px;
}

.hud-cluster {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.hud-cluster .hud-actions {
  position: static;
  pointer-events: auto;
}

.count-style-toast {
  position: fixed;
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 64px));
  left: 50%;
  z-index: 48;
  padding: 8px 14px;
  transform: translate(-50%, -6px);
  border-radius: 999px;
  background: color-mix(in srgb, var(--nav-bg) 72%, transparent);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.count-style-toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: color-mix(in srgb, var(--bg-color) 88%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.help-overlay[hidden] {
  display: none;
}

.help-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.help-panel {
  position: relative;
  width: min(320px, 100%);
  max-height: min(88vh, 760px);
  padding: 1.05rem 1rem 0.85rem;
  overflow: auto;
  border: 1px solid color-mix(in srgb, var(--text-main) 14%, transparent);
  border-radius: 12px;
  background: var(--bg-color);
  color: var(--text-main);
  text-align: left;
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
}

.help-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-sub);
  font-size: 1.3rem;
  cursor: pointer;
}

.help-panel h2 {
  margin: 0 3rem 0.35rem 0;
  font-size: 1rem;
  font-weight: 650;
}

.help-lede,
.help-body,
.help-keys,
.help-more {
  color: var(--text-sub);
  line-height: 1.45;
}

.help-lede {
  margin: 0 0 0.85rem;
  font-size: 0.8rem;
}

.help-controls {
  margin: 0 0 0.85rem;
  padding: 0;
  border-block: 1px solid color-mix(in srgb, var(--text-main) 10%, transparent);
  list-style: none;
}

.help-controls li {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.4rem 0;
  color: var(--text-main);
  font-size: 0.75rem;
  line-height: 1.35;
}

.help-controls li + li {
  border-top: 1px solid color-mix(in srgb, var(--text-main) 8%, transparent);
}

.help-controls .act {
  color: var(--text-sub);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.help-body {
  margin-bottom: 0.75rem;
  font-size: 0.75rem;
}

.help-body p {
  margin: 0 0 0.5rem;
}

.help-keys,
.help-more {
  margin: 0 0 0.8rem;
  font-size: 0.68rem;
}

.help-keys kbd {
  padding: 0.05em 0.28em;
  border: 1px solid color-mix(in srgb, var(--text-main) 18%, transparent);
  border-radius: 3px;
  color: var(--text-main);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.help-more a,
.menu-links a {
  color: var(--text-main);
  text-underline-offset: 0.12em;
}

.help-done {
  appearance: none;
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border: 1px solid color-mix(in srgb, var(--text-main) 16%, transparent);
  border-radius: 999px;
  background: transparent;
  color: var(--text-main);
  font: 600 0.78rem/1.2 "IBM Plex Sans", system-ui, sans-serif;
  cursor: pointer;
}

.menu-links {
  margin-top: 0.65rem;
  text-align: center;
  font-size: 0.64rem;
}

.menu-links-sep {
  margin-inline: 0.3rem;
  opacity: 0.45;
}

@media (max-width: 540px) {
  .glitch-status {
    top: max(10px, env(safe-area-inset-top));
    max-width: calc(100vw - 24px);
    font-size: 0.68rem;
  }

  .help-panel {
    max-height: calc(100dvh - 2rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .glitch-status,
  .sphere-banner,
  .count-style-toast,
  .help-overlay {
    animation: none !important;
    transition: none !important;
  }
}

@media (forced-colors: active) {
  #gameCanvas:focus-visible,
  .banner-btn:focus-visible,
  .help-close:focus-visible,
  .help-done:focus-visible,
  .help-pack:focus-visible {
    outline: 3px solid Highlight;
  }

  .glitch-status,
  .sphere-banner,
  .help-panel {
    border: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }
}
