:root {
  --fg: #f3efe9;
  --muted: rgba(243, 239, 233, 0.6);
  --panel: rgba(18, 14, 18, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --accent: #f0b8c6;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  display: block;
  touch-action: none;
}

#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }

.hidden { display: none !important; }

/* Start overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 60%, rgba(40, 20, 30, 0.75), rgba(0, 0, 0, 0.92));
  transition: opacity 0.5s ease;
  cursor: pointer;
}
.overlay.fade { opacity: 0; pointer-events: none; }
.ov-inner { text-align: center; padding: 24px; }
.ov-title { font-size: 30px; font-weight: 300; letter-spacing: 0.18em; text-transform: uppercase; }
.ov-sub { margin-top: 18px; font-size: 16px; color: var(--fg); animation: breathe 2.4s ease-in-out infinite; }
.ov-note { margin-top: 10px; font-size: 13px; color: var(--muted); }
@keyframes breathe { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

/* Gear */
.gear {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.25);
  color: var(--fg);
  opacity: 0.7;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}
.gear.clear { right: calc(env(safe-area-inset-right, 0px) + 64px); }
.gear:active { opacity: 1; transform: scale(0.94); }
.gear svg { width: 24px; height: 24px; }

/* Перемещение источника */
.movebar {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 14px;
  white-space: nowrap;
}
.movebar button, .row button.small {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}
.movebar button.primary { background: var(--accent); color: #2a1018; }

/* Hint */
.hint {
  position: absolute;
  left: 0;
  right: 0;
  top: 42%;
  text-align: center;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--muted);
  pointer-events: none !important;
  transition: opacity 0.8s ease;
}
.hint.off { opacity: 0; }

/* FPS */
.fps {
  position: absolute;
  left: calc(env(safe-area-inset-left, 0px) + 10px);
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace;
  color: #9f9;
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 6px;
  border-radius: 6px;
  white-space: pre;
  pointer-events: none !important;
}

/* Settings panel */
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); }
.panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 460px);
  max-height: 80dvh;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 18px 16px calc(env(safe-area-inset-bottom, 0px) + 18px);
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  touch-action: pan-y;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; font-weight: 500; letter-spacing: 0.05em; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}
.row:last-of-type { border-bottom: 0; }
.row label { font-size: 14px; color: var(--fg); min-width: 0; }
.row.off { opacity: 0.45; }
.row label em.why { display: block; font-style: normal; font-size: 11.5px; color: var(--accent); margin-top: 2px; }
.row label em.why:empty { display: none; }
.row label small { display: block; margin-top: 2px; font-size: 11.5px; line-height: 1.3; color: var(--fg); opacity: 0.55; }
.panel h3 {
  margin: 18px 0 2px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.panel h3 .note { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.6; color: var(--fg); }
.row select { flex: 0 0 52%; max-width: 52%; }
.row input[type="range"] { flex: 0 0 42%; max-width: 42%; }
.row label b { white-space: nowrap; }
.row select {
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
}
.row select option { background: #1a1418; color: var(--fg); }
.row input[type="range"] { accent-color: var(--accent); touch-action: none; }
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.close {
  margin-top: 14px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--fg);
  font: inherit;
  font-size: 15px;
}
