:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Monaco, monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --z-canvas: 1;
  --z-preloader: 25;
  --z-panel: 30;
  --z-toggle: 35;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #02040a;
  color: #F2F4F8;
  font-family: var(--font-sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

#canvas-wrap {
  position: fixed;
  inset: 0;
  z-index: var(--z-canvas);
}

#canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Fullscreen Minimalist World Preloader */
.space-preloader {
  position: fixed;
  inset: 0;
  z-index: var(--z-preloader);
  background: #06080F;
  display: grid;
  place-items: center;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.65s var(--ease-out), visibility 0s linear 0s;
}

.space-preloader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.65s var(--ease-out), visibility 0s linear 0.65s;
}

.preloader-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preloader-track {
  width: 148px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
  border: none;
}

.preloader-fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  transform-origin: left center;
  transform: scaleX(0.06);
  transition: transform 0.22s var(--ease-out);
}

/* Circular Obsidian Menu Trigger */
.burger-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: var(--z-toggle);
  width: 42px;
  height: 42px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: none;
  background: rgba(12, 14, 20, 0.42);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  touch-action: manipulation;
  display: grid;
  place-items: center;
  transition: background 180ms var(--ease-out), color 180ms var(--ease-out), transform 160ms var(--ease-out);
}

.burger-btn svg,
.burger-btn * {
  pointer-events: none;
}

.burger-btn:hover,
.burger-btn.open {
  background: rgba(20, 23, 32, 0.76);
  color: #F2F4F8;
}

.burger-btn:focus-visible {
  outline: none;
  background: rgba(20, 23, 32, 0.82);
  color: #F2F4F8;
  box-shadow: 0 0 0 2px rgba(242, 244, 248, 0.32);
}

.burger-btn:active {
  transform: scale(0.95);
}

.burger-svg {
  overflow: visible;
}

.burger-line {
  transform-box: view-box;
  transform-origin: 9px 9px;
}

.burger-btn.open .line-1 {
  transform: translateY(3.5px) rotate(45deg);
}

.burger-btn.open .line-2 {
  opacity: 0;
}

.burger-btn.open .line-3 {
  transform: translateY(-3.5px) rotate(-45deg);
}

/* Quiet Obsidian Control Panel (Instant 0ms opacity=1 under heavy 4K WebGL load) */
.space-menu {
  position: fixed;
  top: max(66px, calc(env(safe-area-inset-top) + 58px));
  right: max(16px, env(safe-area-inset-right));
  z-index: var(--z-panel);
  width: 308px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - max(82px, calc(env(safe-area-inset-top) + 74px)) - env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: 16px;
  border: none;
  background: rgba(15, 17, 23, 0.84);
  backdrop-filter: blur(28px) saturate(140%);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.52);
  color: #F2F4F8;
  opacity: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  transform-origin: top right;
}

.menu-block {
  display: flex;
  flex-direction: column;
}

.menu-divider {
  height: 1px;
  width: 100%;
  flex-shrink: 0;
  border: none;
  background: rgba(255, 255, 255, 0.06);
}

/* 1. Scanner & Access */
.qr-authorized {
  display: flex;
  align-items: center;
  gap: 13px;
}

.qr-box {
  width: 76px;
  height: 76px;
  flex-shrink: 0;
  padding: 5px;
  border-radius: 10px;
  border: none;
  background: #FFFFFF;
  display: block;
  transition: opacity 160ms var(--ease-out);
}

.qr-box:hover {
  opacity: 0.92;
}

.qr-box:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(242, 244, 248, 0.45);
}

.qr-box svg {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.qr-title {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: #F2F4F8;
  text-decoration: none;
  transition: color 160ms var(--ease-out);
}

.qr-title:hover {
  color: #FFFFFF;
}

.qr-title:focus-visible {
  outline: none;
  text-decoration: underline;
}

.pin-line {
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.25;
  color: #949BA6;
}

.pin-code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: #C4CAD4;
}

.qr-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.07);
  color: #E5E8EE;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out), transform 140ms var(--ease-out);
}

.chip-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #F2F4F8;
}

.chip-btn.confirming {
  background: rgba(255, 255, 255, 0.16);
  color: #FFFFFF;
}

.chip-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(242, 244, 248, 0.32);
}

.chip-btn:active {
  transform: scale(0.97);
}

.chip-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Unauthorized Compact Access */
.qr-locked {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.pin-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pin-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 9px;
  color: #F2F4F8;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.06em;
  user-select: text;
  transition: background 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

.pin-input::placeholder {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: #8E95A2;
}

.pin-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 0 2px rgba(242, 244, 248, 0.24);
}

.pin-submit-btn {
  height: 36px;
  padding: 0 14px;
  background: #F2F4F8;
  color: #0F1117;
  border: none;
  border-radius: 9px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 160ms var(--ease-out), transform 140ms var(--ease-out);
}

.pin-submit-btn:hover {
  background: #FFFFFF;
}

.pin-submit-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(242, 244, 248, 0.45);
}

.pin-submit-btn:active {
  transform: scale(0.97);
}

.locked-subrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 18px;
}

.quiet-link {
  font-size: 12.5px;
  font-weight: 400;
  color: #949BA6;
  text-decoration: none;
  white-space: nowrap;
  transition: color 160ms var(--ease-out);
}

.quiet-link:hover {
  color: #E5E8EE;
}

.quiet-link:focus-visible {
  outline: none;
  color: #F2F4F8;
  text-decoration: underline;
}

.pin-feedback {
  font-size: 12px;
  font-weight: 400;
  color: #F87171;
  text-align: right;
  line-height: 1.25;
}

/* 2. Sound & Language */
.sound-lang-block {
  gap: 10px;
}

.sound-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 24px;
}

.row-label {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: #E5E8EE;
}

.ios-switch {
  position: relative;
  width: 38px;
  height: 22px;
  padding: 2px;
  margin: 0;
  flex-shrink: 0;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  transition: background 180ms var(--ease-out);
}

.ios-switch[aria-checked="true"] {
  background: rgba(255, 255, 255, 0.90);
}

.ios-switch:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(242, 244, 248, 0.35);
}

.ios-switch-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.32);
  transform: translateX(0);
  transition: transform 180ms var(--ease-out), background 180ms var(--ease-out);
}

.ios-switch[aria-checked="true"] .ios-switch-thumb {
  transform: translateX(16px);
  background: #0F1117;
}

.lang-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 26px;
}

.menu-lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
}

.menu-lang-btn {
  appearance: none;
  border: none;
  border-radius: 6px;
  padding: 4px 9px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.01em;
  background: transparent;
  color: #8E95A2;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out);
}

.menu-lang-btn:hover {
  color: #E5E8EE;
}

.menu-lang-btn.is-active {
  background: rgba(255, 255, 255, 0.90);
  color: #0F1117;
}

.menu-lang-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(242, 244, 248, 0.35);
}

/* 3. Astronauts Flat List */
.heroes-block {
  gap: 8px;
}

.heroes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
}

.heroes-heading {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
}

.heroes-heading .row-label {
  color: #F2F4F8;
}

.heroes-count {
  font-size: 13px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: #8E95A2;
}

.clear-all-btn {
  background: transparent;
  border: none;
  border-radius: 7px;
  color: #F87171;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  padding: 4px 6px;
  margin-right: -6px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out);
}

.clear-all-btn:hover {
  background: rgba(248, 113, 113, 0.10);
  color: #FCA5A5;
}

.clear-all-btn.confirming {
  background: rgba(248, 113, 113, 0.14);
  color: #FCA5A5;
  margin-right: 0;
  padding: 4px 8px;
}

.clear-all-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.35);
}

.heroes-list {
  display: flex;
  flex-direction: column;
  max-height: 236px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.heroes-empty {
  font-size: 13px;
  font-weight: 400;
  color: #7D8592;
  padding: 4px 0;
  border: none;
}

.hero-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border: none;
}

.hero-row-thumb {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 8px;
  background: #F5F6F8;
  object-fit: cover;
  object-position: center 24%;
  border: none;
  display: block;
}

.hero-row-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.hero-row-title {
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: #F2F4F8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-row-sub {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.25;
  color: #8E95A2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-delete-btn {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.07);
  color: #E5E8EE;
  border: none;
  border-radius: 8px;
  padding: 6px 11px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.15;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out), transform 140ms var(--ease-out);
}

.hero-delete-btn:hover,
.hero-delete-btn:active {
  background: rgba(239, 68, 68, 0.22);
  color: #FCA5A5;
}

.hero-delete-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .space-preloader,
  .space-preloader.is-hidden,
  .preloader-fill,
  .burger-btn,
  .burger-line,
  .space-menu,
  .qr-box,
  .qr-title,
  .chip-btn,
  .pin-input,
  .pin-submit-btn,
  .quiet-link,
  .ios-switch,
  .ios-switch-thumb,
  .menu-lang-btn,
  .clear-all-btn,
  .hero-delete-btn {
    animation: none !important;
    transition: none !important;
  }
}
