{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "meridian",
  "type": "registry:ui",
  "title": "Meridian",
  "description": "A day/night theme switch built as a miniature diorama: the sun sets and the moon rises along a shallow arc, the sky crossfades through dusk, clouds drift out, and stars ignite staggered once the moon seats. A real role=switch with keyboard toggle; controlled or uncontrolled.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/themes/meridian/meridian.tsx",
      "type": "registry:ui",
      "target": "components/crucible/meridian.tsx",
      "content": "\"use client\";\n\nimport { animate, motion, useMotionValue, useTransform } from \"motion/react\";\nimport * as React from \"react\";\n\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface MeridianPalette {\n  /** Top sky gradient stop. */\n  skyTop: string;\n  /** Bottom sky gradient stop. */\n  skyBottom: string;\n  /** Celestial body core color (sun in day, moon in night). */\n  body: string;\n}\n\nexport interface MeridianProps\n  extends Omit<React.ComponentPropsWithoutRef<\"button\">, \"onChange\"> {\n  /** Controlled night state — `true` is night/dark. */\n  checked?: boolean;\n  /** Initial night state when uncontrolled. @default false */\n  defaultChecked?: boolean;\n  /** Fires on every toggle with the next night state. */\n  onChange?: (checked: boolean) => void;\n  /** Size multiplier applied to the whole diorama. @default 1 */\n  scale?: number;\n  /**\n   * Seconds the arc + scene transition takes (spring visual duration).\n   * @default 0.6\n   */\n  duration?: number;\n  /** Stars that ignite, staggered, once the moon seats. @default 7 */\n  starCount?: number;\n  /** Clouds that drift in the day sky. @default 3 */\n  cloudCount?: number;\n  /** Day palette overrides — warm sun on blue sky. */\n  dayColors?: Partial<MeridianPalette>;\n  /** Night palette overrides — cool moon on indigo sky. */\n  nightColors?: Partial<MeridianPalette>;\n  /** Accessible label for the switch. @default \"Toggle dark mode\" */\n  label?: string;\n}\n\nconst DAY_DEFAULT: MeridianPalette = {\n  skyTop: \"#3aa0e8\",\n  skyBottom: \"#a6d9f6\",\n  body: \"#ffd24d\",\n};\nconst NIGHT_DEFAULT: MeridianPalette = {\n  skyTop: \"#111033\",\n  skyBottom: \"#2b2a5e\",\n  body: \"#e7ecfb\",\n};\n/** Warm sunset band that peaks at mid-track as the two palettes cross. */\nconst DUSK_TOP = \"#f0955a\";\nconst DUSK_BOTTOM = \"#6d5a9c\";\n\n/** Deterministic PRNG so scatter is identical on server and client. */\nfunction mulberry32(seed: number): () => number {\n  let a = seed >>> 0;\n  return () => {\n    a |= 0;\n    a = (a + 0x6d2b79f5) | 0;\n    let t = Math.imul(a ^ (a >>> 15), 1 | a);\n    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n  };\n}\n\ninterface Star {\n  left: number;\n  top: number;\n  size: number;\n  cross: boolean;\n  twinkleDur: number;\n  twinkleDelay: number;\n}\ninterface Cloud {\n  top: number;\n  left: number;\n  w: number;\n  driftDur: number;\n  driftDelay: number;\n}\n\n/**\n * Meridian — a day/night theme switch built as a miniature diorama. The track\n * is a sky and the thumb is the celestial body: toggling sends the sun setting\n * and the moon rising along a shallow meridian arc that dips at mid-track while\n * the sky crossfades day-blue → dusk → night-indigo. Clouds drift out ahead of\n * the moon; stars ignite in a staggered scatter once it seats. A real\n * `role=\"switch\"` with keyboard toggle; the arc runs on transform only.\n * Reduced motion collapses to an instant scene swap — no arc, no twinkle.\n */\nexport function Meridian({\n  checked,\n  defaultChecked = false,\n  onChange,\n  scale = 1,\n  duration = 0.6,\n  starCount = 7,\n  cloudCount = 3,\n  dayColors,\n  nightColors,\n  label = \"Toggle dark mode\",\n  className,\n  style,\n  disabled,\n  ...rest\n}: MeridianProps) {\n  const reducedMotion = useReducedMotion();\n\n  const isControlled = checked !== undefined;\n  const [internal, setInternal] = React.useState(defaultChecked);\n  const on = isControlled ? checked : internal;\n\n  const day = { ...DAY_DEFAULT, ...dayColors };\n  const night = { ...NIGHT_DEFAULT, ...nightColors };\n\n  // Geometry (px), all driven off the size multiplier.\n  const S = scale;\n  const W = 92 * S;\n  const H = 40 * S;\n  const PAD = 4 * S;\n  const THUMB = H - PAD * 2;\n  const TRAVEL = W - THUMB - PAD * 2;\n  const DIP = reducedMotion ? 0 : H * 0.16;\n\n  // Single spring drives the whole scene; every layer derives from it, so the\n  // arc, crossfade, and body swap stay locked in phase.\n  const progress = useMotionValue(on ? 1 : 0);\n  React.useEffect(() => {\n    // Reduced motion: snap instantly to the target (visualDuration:0 on a spring\n    // still resolves over several frames — it must be an immediate set, so the\n    // scene swaps with no arc/dusk/star-ignition, per the a11y contract).\n    if (reducedMotion) {\n      progress.set(on ? 1 : 0);\n      return;\n    }\n    const controls = animate(progress, on ? 1 : 0, {\n      type: \"spring\",\n      visualDuration: duration,\n      bounce: 0.28,\n    });\n    return controls.stop;\n  }, [on, reducedMotion, duration, progress]);\n\n  const x = useTransform(progress, [0, 1], [0, TRAVEL]);\n  const yArc = useTransform(progress, [0, 0.5, 1], [0, DIP, 0]);\n  const dayOpacity = useTransform(progress, [0, 1], [1, 0]);\n  const nightOpacity = useTransform(progress, [0, 1], [0, 1]);\n  const duskOpacity = useTransform(progress, [0, 0.5, 1], [0, 0.85, 0]);\n  const sunOpacity = useTransform(progress, [0, 0.55], [1, 0]);\n  const moonOpacity = useTransform(progress, [0.45, 1], [0, 1]);\n  const glowDay = useTransform(progress, [0, 1], [0.55, 0]);\n  const glowNight = useTransform(progress, [0, 1], [0, 0.5]);\n\n  const stars = React.useMemo<Star[]>(() => {\n    const rnd = mulberry32(0x51a2 + starCount);\n    return Array.from({ length: Math.max(0, starCount) }, () => {\n      const rx = rnd();\n      const ry = rnd();\n      return {\n        left: 8 + rx * 82,\n        top: 12 + ry * 52,\n        size: (1.4 + rnd() * 1.8) * S,\n        cross: rnd() > 0.62,\n        twinkleDur: 1.8 + rnd() * 2.2,\n        twinkleDelay: rnd() * 1.5,\n      };\n    });\n  }, [starCount, S]);\n\n  const clouds = React.useMemo<Cloud[]>(() => {\n    const rnd = mulberry32(0xc10d + cloudCount);\n    return Array.from({ length: Math.max(0, cloudCount) }, () => ({\n      top: 22 + rnd() * 34,\n      left: 30 + rnd() * 42,\n      w: (14 + rnd() * 12) * S,\n      driftDur: 7 + rnd() * 5,\n      driftDelay: rnd() * 3,\n    }));\n  }, [cloudCount, S]);\n\n  const seatDelay = reducedMotion ? 0 : duration * 0.62;\n  const starStagger = reducedMotion ? 0 : duration * 0.14;\n\n  const toggle = React.useCallback(() => {\n    if (disabled) return;\n    const next = !on;\n    if (!isControlled) setInternal(next);\n    onChange?.(next);\n  }, [disabled, on, isControlled, onChange]);\n\n  return (\n    <button\n      type=\"button\"\n      role=\"switch\"\n      aria-checked={on}\n      aria-label={label}\n      disabled={disabled}\n      onClick={toggle}\n      data-crucible=\"meridian\"\n      data-state={on ? \"night\" : \"day\"}\n      className={cn(\n        \"relative isolate inline-flex shrink-0 overflow-hidden rounded-full\",\n        \"cursor-pointer select-none outline-none\",\n        \"focus-visible:ring-2 focus-visible:ring-white/70 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-950\",\n        \"disabled:cursor-not-allowed disabled:opacity-50\",\n        className\n      )}\n      style={{ width: W, height: H, ...style }}\n      {...rest}\n    >\n      {/* Sky — day, dusk, and night crossfaded by the same progress. */}\n      <motion.span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-full\"\n        style={{\n          opacity: dayOpacity,\n          background: `linear-gradient(to bottom, ${day.skyTop}, ${day.skyBottom})`,\n        }}\n      />\n      <motion.span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-full\"\n        style={{\n          opacity: nightOpacity,\n          background: `linear-gradient(to bottom, ${night.skyTop}, ${night.skyBottom})`,\n        }}\n      />\n      <motion.span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-full\"\n        style={{\n          opacity: duskOpacity,\n          background: `linear-gradient(to bottom, ${DUSK_TOP}, ${DUSK_BOTTOM})`,\n        }}\n      />\n\n      {/* Clouds drift out ahead of the rising moon. */}\n      {clouds.map((c, i) => (\n        <motion.span\n          key={`cloud-${i}`}\n          aria-hidden\n          className=\"pointer-events-none absolute\"\n          style={{\n            top: `${c.top}%`,\n            left: `${c.left}%`,\n            width: c.w,\n            height: c.w * 0.42,\n          }}\n          // Mount at the current state's pose — without an explicit initial,\n          // motion would fade clouds out from full opacity on a night mount.\n          initial={on ? { opacity: 0, x: -14 * S, y: 3 * S } : { opacity: 0.92, x: 0, y: 0 }}\n          animate={\n            on\n              ? { opacity: 0, x: -14 * S, y: 3 * S }\n              : { opacity: 0.92, x: reducedMotion ? 0 : [0, 5 * S, 0], y: 0 }\n          }\n          transition={\n            on\n              ? { duration: reducedMotion ? 0 : 0.4, ease: \"easeIn\" }\n              : reducedMotion\n                ? { duration: 0 }\n                : {\n                    opacity: { duration: 0.5, ease: \"easeOut\" },\n                    x: {\n                      duration: c.driftDur,\n                      delay: c.driftDelay,\n                      repeat: Infinity,\n                      ease: \"easeInOut\",\n                    },\n                  }\n          }\n        >\n          <span\n            className=\"absolute bottom-0 left-0 rounded-full bg-white/90\"\n            style={{ width: \"100%\", height: \"62%\", filter: \"blur(0.4px)\" }}\n          />\n          <span\n            className=\"absolute rounded-full bg-white\"\n            style={{\n              width: \"48%\",\n              height: \"100%\",\n              left: \"22%\",\n              bottom: \"18%\",\n              filter: \"blur(0.4px)\",\n            }}\n          />\n        </motion.span>\n      ))}\n\n      {/* Stars ignite, staggered, after the moon seats. */}\n      {stars.map((s, i) => (\n        <motion.span\n          key={`star-${i}`}\n          aria-hidden\n          className=\"pointer-events-none absolute rounded-full\"\n          style={{\n            left: `${s.left}%`,\n            top: `${s.top}%`,\n            width: s.size,\n            height: s.size,\n            background: \"#fdfdff\",\n            boxShadow: s.cross\n              ? `0 0 ${3 * S}px ${1 * S}px rgba(255,255,255,0.9)`\n              : `0 0 ${2 * S}px 0 rgba(255,255,255,0.7)`,\n          }}\n          // Mount at the resting pose so a day mount never flashes stars that\n          // then fade out (motion would otherwise start them at opacity 1).\n          initial={{ opacity: on ? 1 : 0, scale: on ? 1 : 0.3 }}\n          animate={{ opacity: on ? 1 : 0, scale: on ? 1 : 0.3 }}\n          transition={\n            on && !reducedMotion\n              ? { delay: seatDelay + i * starStagger, duration: 0.5, ease: \"easeOut\" }\n              : { duration: reducedMotion ? 0 : 0.22 }\n          }\n        >\n          <motion.span\n            aria-hidden\n            className=\"absolute inset-0 rounded-full bg-[#fdfdff]\"\n            style={{\n              boxShadow: s.cross\n                ? `0 0 ${3 * S}px ${1 * S}px rgba(255,255,255,0.9)`\n                : undefined,\n            }}\n            animate={\n              on && !reducedMotion ? { opacity: [1, 0.4, 1] } : { opacity: 1 }\n            }\n            transition={\n              on && !reducedMotion\n                ? {\n                    duration: s.twinkleDur,\n                    delay: s.twinkleDelay,\n                    repeat: Infinity,\n                    ease: \"easeInOut\",\n                  }\n                : { duration: 0 }\n            }\n          />\n        </motion.span>\n      ))}\n\n      {/* Thumb — the celestial body, arcing on transform only. */}\n      <motion.span\n        aria-hidden\n        className=\"absolute rounded-full\"\n        style={{\n          left: PAD,\n          top: PAD,\n          width: THUMB,\n          height: THUMB,\n          x,\n          y: yArc,\n        }}\n      >\n        {/* Warm ambient glow (day) fades to cool (night). */}\n        <motion.span\n          className=\"absolute inset-0 rounded-full\"\n          style={{\n            opacity: glowDay,\n            boxShadow: `0 0 ${10 * S}px ${2 * S}px ${day.body}, 0 0 ${20 * S}px ${4 * S}px rgba(255,190,90,0.55)`,\n          }}\n        />\n        <motion.span\n          className=\"absolute inset-0 rounded-full\"\n          style={{\n            opacity: glowNight,\n            boxShadow: `0 0 ${9 * S}px ${1 * S}px rgba(210,220,255,0.65)`,\n          }}\n        />\n\n        {/* Sun */}\n        <motion.span\n          className=\"absolute inset-0 rounded-full\"\n          style={{\n            opacity: sunOpacity,\n            background: `radial-gradient(circle at 38% 34%, #fff6d0 0%, ${day.body} 46%, #ff9a3d 100%)`,\n            boxShadow: `inset 0 0 ${4 * S}px 0 rgba(255,180,80,0.6)`,\n          }}\n        />\n\n        {/* Moon — pale disc, seeded craters, a crescent inner shadow for form. */}\n        <motion.span\n          className=\"absolute inset-0 overflow-hidden rounded-full\"\n          style={{\n            opacity: moonOpacity,\n            background: `radial-gradient(circle at 40% 36%, #ffffff 0%, ${night.body} 55%, #c4cbe6 100%)`,\n            boxShadow: `inset ${-3.5 * S}px ${-2.5 * S}px ${4 * S}px 0 rgba(70,80,120,0.45)`,\n          }}\n        >\n          <span\n            className=\"absolute rounded-full\"\n            style={{\n              width: THUMB * 0.24,\n              height: THUMB * 0.24,\n              left: \"22%\",\n              top: \"48%\",\n              background: \"#c8cee4\",\n              boxShadow: \"inset 0.5px 0.5px 1px rgba(90,98,130,0.5)\",\n            }}\n          />\n          <span\n            className=\"absolute rounded-full\"\n            style={{\n              width: THUMB * 0.16,\n              height: THUMB * 0.16,\n              left: \"56%\",\n              top: \"24%\",\n              background: \"#ccd2e6\",\n              boxShadow: \"inset 0.5px 0.5px 1px rgba(90,98,130,0.5)\",\n            }}\n          />\n          <span\n            className=\"absolute rounded-full\"\n            style={{\n              width: THUMB * 0.13,\n              height: THUMB * 0.13,\n              left: \"58%\",\n              top: \"62%\",\n              background: \"#c8cee4\",\n              boxShadow: \"inset 0.5px 0.5px 1px rgba(90,98,130,0.5)\",\n            }}\n          />\n        </motion.span>\n      </motion.span>\n\n      {/* Rim light + inner shadow so the pill reads as a glassy porthole. */}\n      <span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-full\"\n        style={{\n          boxShadow:\n            \"inset 0 1px 1px rgba(255,255,255,0.35), inset 0 -2px 6px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(0,0,0,0.14)\",\n        }}\n      />\n    </button>\n  );\n}\n"
    }
  ]
}