{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "city-time",
  "type": "registry:block",
  "title": "City Time",
  "description": "A local-time page for any city: a live clock whose digits roll, the sun on today's arc, your working hours against theirs with the best time to meet, and the year's clock changes, all re-computed as you switch cities.",
  "categories": [
    "block",
    "Apps"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/combobox.json",
    "https://coss.com/ui/r/segmented-control.json"
  ],
  "files": [
    {
      "path": "registry/devl/city-time.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  BanknoteIcon,\n  FlagIcon,\n  LanguagesIcon,\n  MapIcon,\n  MountainIcon,\n  NavigationIcon,\n  PhoneIcon,\n  RotateCcwIcon,\n  RotateCwIcon,\n  SearchIcon,\n  UsersIcon,\n} from \"lucide-react\";\nimport {\n  AnimatePresence,\n  animate,\n  MotionConfig,\n  type MotionValue,\n  motion,\n  useMotionValue,\n  useReducedMotion,\n  useTransform,\n} from \"motion/react\";\nimport { type KeyboardEvent, type ReactNode, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport {\n  Combobox,\n  ComboboxEmpty,\n  ComboboxInput,\n  ComboboxItem,\n  ComboboxList,\n  ComboboxPopup,\n} from \"@/components/ui/combobox\";\nimport { SegmentedControl, SegmentedControlItem } from \"@/components/ui/segmented-control\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface City {\n  id: string;\n  name: string;\n  region: string;\n  country: string;\n  timeZone: string;\n  latitude: number;\n  longitude: number;\n  elevation: number;\n  population: number;\n  currency: string;\n  languages: string[];\n  dialCode: string;\n}\n\nexport type HourCycle = \"12h\" | \"24h\";\n\nexport interface CityTimeProps {\n  cities?: City[];\n  defaultCity?: string;\n  workingHours?: { start: number; end: number };\n  defaultHourCycle?: HourCycle;\n  locale?: string;\n  className?: string;\n}\n\nexport const defaultCities: City[] = [\n  {\n    id: \"flensburg\",\n    name: \"Flensburg\",\n    region: \"Schleswig-Holstein\",\n    country: \"Germany\",\n    timeZone: \"Europe/Berlin\",\n    latitude: 54.7937,\n    longitude: 9.4469,\n    elevation: 12,\n    population: 92_550,\n    currency: \"Euro (EUR)\",\n    languages: [\"German\", \"Danish\", \"Low German\"],\n    dialCode: \"+49 461\",\n  },\n  {\n    id: \"new-york\",\n    name: \"New York\",\n    region: \"New York\",\n    country: \"United States\",\n    timeZone: \"America/New_York\",\n    latitude: 40.7128,\n    longitude: -74.006,\n    elevation: 10,\n    population: 8_258_035,\n    currency: \"US dollar (USD)\",\n    languages: [\"English\", \"Spanish\"],\n    dialCode: \"+1 212\",\n  },\n  {\n    id: \"los-angeles\",\n    name: \"Los Angeles\",\n    region: \"California\",\n    country: \"United States\",\n    timeZone: \"America/Los_Angeles\",\n    latitude: 34.0522,\n    longitude: -118.2437,\n    elevation: 93,\n    population: 3_820_914,\n    currency: \"US dollar (USD)\",\n    languages: [\"English\", \"Spanish\"],\n    dialCode: \"+1 213\",\n  },\n  {\n    id: \"sao-paulo\",\n    name: \"São Paulo\",\n    region: \"São Paulo\",\n    country: \"Brazil\",\n    timeZone: \"America/Sao_Paulo\",\n    latitude: -23.5505,\n    longitude: -46.6333,\n    elevation: 760,\n    population: 11_451_999,\n    currency: \"Brazilian real (BRL)\",\n    languages: [\"Portuguese\"],\n    dialCode: \"+55 11\",\n  },\n  {\n    id: \"reykjavik\",\n    name: \"Reykjavík\",\n    region: \"Capital Region\",\n    country: \"Iceland\",\n    timeZone: \"Atlantic/Reykjavik\",\n    latitude: 64.1466,\n    longitude: -21.9426,\n    elevation: 15,\n    population: 139_875,\n    currency: \"Icelandic króna (ISK)\",\n    languages: [\"Icelandic\"],\n    dialCode: \"+354\",\n  },\n  {\n    id: \"longyearbyen\",\n    name: \"Longyearbyen\",\n    region: \"Svalbard\",\n    country: \"Norway\",\n    timeZone: \"Arctic/Longyearbyen\",\n    latitude: 78.2232,\n    longitude: 15.6267,\n    elevation: 20,\n    population: 2_583,\n    currency: \"Norwegian krone (NOK)\",\n    languages: [\"Norwegian\"],\n    dialCode: \"+47 79\",\n  },\n  {\n    id: \"mumbai\",\n    name: \"Mumbai\",\n    region: \"Maharashtra\",\n    country: \"India\",\n    timeZone: \"Asia/Kolkata\",\n    latitude: 19.076,\n    longitude: 72.8777,\n    elevation: 14,\n    population: 12_442_373,\n    currency: \"Indian rupee (INR)\",\n    languages: [\"Marathi\", \"Hindi\", \"English\"],\n    dialCode: \"+91 22\",\n  },\n  {\n    id: \"kathmandu\",\n    name: \"Kathmandu\",\n    region: \"Bagmati\",\n    country: \"Nepal\",\n    timeZone: \"Asia/Kathmandu\",\n    latitude: 27.7172,\n    longitude: 85.324,\n    elevation: 1_400,\n    population: 845_767,\n    currency: \"Nepalese rupee (NPR)\",\n    languages: [\"Nepali\", \"Newar\"],\n    dialCode: \"+977 1\",\n  },\n  {\n    id: \"tokyo\",\n    name: \"Tokyo\",\n    region: \"Kantō\",\n    country: \"Japan\",\n    timeZone: \"Asia/Tokyo\",\n    latitude: 35.6762,\n    longitude: 139.6503,\n    elevation: 40,\n    population: 14_094_034,\n    currency: \"Japanese yen (JPY)\",\n    languages: [\"Japanese\"],\n    dialCode: \"+81 3\",\n  },\n  {\n    id: \"sydney\",\n    name: \"Sydney\",\n    region: \"New South Wales\",\n    country: \"Australia\",\n    timeZone: \"Australia/Sydney\",\n    latitude: -33.8688,\n    longitude: 151.2093,\n    elevation: 39,\n    population: 5_450_496,\n    currency: \"Australian dollar (AUD)\",\n    languages: [\"English\"],\n    dialCode: \"+61 2\",\n  },\n  {\n    id: \"auckland\",\n    name: \"Auckland\",\n    region: \"Auckland\",\n    country: \"New Zealand\",\n    timeZone: \"Pacific/Auckland\",\n    latitude: -36.8509,\n    longitude: 174.7645,\n    elevation: 26,\n    population: 1_798_300,\n    currency: \"New Zealand dollar (NZD)\",\n    languages: [\"English\", \"Māori\"],\n    dialCode: \"+64 9\",\n  },\n];\n\nconst SECOND = 1_000;\nconst MINUTE = 60_000;\nconst HOUR = 3_600_000;\nconst DAY = 86_400_000;\nconst RAD = Math.PI / 180;\nconst ease = [0.23, 1, 0.32, 1] as const;\nconst glide = { type: \"spring\", duration: 0.5, bounce: 0 } as const;\nconst strip = Array.from({ length: 11 }, (_, slot) => slot % 10);\nconst ticks = [0, 3, 6, 9, 12, 15, 18, 21];\nconst shortZoneLocales = [\"en-US\", \"en-GB\", \"en-AU\", \"en-IN\", \"en-NZ\", \"en-CA\"];\n\ntype ZoneParts = { year: number; month: number; day: number; hour: number; minute: number; second: number };\ntype Shift = { at: number; from: number; to: number };\ntype Season = { start: number; end: number; offset: number };\ntype ClockYear = {\n  start: number;\n  end: number;\n  seasons: Season[];\n  standard: number;\n  previous: Shift | null;\n  next: Shift | null;\n};\ntype Sun = { kind: \"normal\"; rise: number; set: number; noon: number } | { kind: \"day\"; noon: number } | { kind: \"night\"; noon: number };\ntype Daylight = { sun: Sun; yesterday: Sun; phase: number; next: { kind: \"sunrise\" | \"sunset\"; at: number } | null };\n\nconst formatters = new Map<string, Intl.DateTimeFormat>();\n\nfunction formatter(locale: string, options: Intl.DateTimeFormatOptions) {\n  const key = `${locale}|${JSON.stringify(options)}`;\n  let cached = formatters.get(key);\n  if (!cached) {\n    cached = new Intl.DateTimeFormat(locale, options);\n    formatters.set(key, cached);\n  }\n  return cached;\n}\n\nfunction zoneParts(timeZone: string, at: number): ZoneParts {\n  const parts: Record<string, number> = {};\n  const wall = formatter(\"en-US\", {\n    timeZone,\n    hourCycle: \"h23\",\n    year: \"numeric\",\n    month: \"numeric\",\n    day: \"numeric\",\n    hour: \"numeric\",\n    minute: \"numeric\",\n    second: \"numeric\",\n  });\n  for (const part of wall.formatToParts(at)) if (part.type !== \"literal\") parts[part.type] = Number(part.value);\n  return { year: parts.year, month: parts.month, day: parts.day, hour: parts.hour % 24, minute: parts.minute, second: parts.second };\n}\n\nfunction offsetAt(timeZone: string, at: number) {\n  const p = zoneParts(timeZone, at);\n  const wall = Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second);\n  return Math.round((wall - (at - (at % SECOND))) / MINUTE);\n}\n\nfunction dayOf(timeZone: string, at: number) {\n  const p = zoneParts(timeZone, at);\n  return Date.UTC(p.year, p.month - 1, p.day) / DAY;\n}\n\nfunction hoursOf(timeZone: string, at: number) {\n  const p = zoneParts(timeZone, at);\n  return p.hour + p.minute / 60;\n}\n\nfunction findShift(timeZone: string, from: number, direction: 1 | -1, days: number): Shift | null {\n  let a = from;\n  let offsetA = offsetAt(timeZone, a);\n  for (let walked = 0; walked < days; walked += 7) {\n    const b = a + direction * 7 * DAY;\n    const offsetB = offsetAt(timeZone, b);\n    if (offsetB !== offsetA) {\n      let lo = Math.floor(Math.min(a, b) / MINUTE);\n      let hi = Math.ceil(Math.max(a, b) / MINUTE);\n      const before = offsetAt(timeZone, lo * MINUTE);\n      while (hi - lo > 1) {\n        const mid = Math.floor((lo + hi) / 2);\n        if (offsetAt(timeZone, mid * MINUTE) === before) lo = mid;\n        else hi = mid;\n      }\n      return { at: hi * MINUTE, from: before, to: offsetAt(timeZone, hi * MINUTE) };\n    }\n    a = b;\n    offsetA = offsetB;\n  }\n  return null;\n}\n\nfunction monthStart(at: number, plus = 0) {\n  const date = new Date(at);\n  return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + plus, 1);\n}\n\nfunction clockYear(timeZone: string, now: number): ClockYear {\n  const previous = findShift(timeZone, now, -1, 3_650);\n  const next = findShift(timeZone, now, 1, 400);\n  let start = monthStart(previous && now - previous.at < 300 * DAY ? previous.at : now - 150 * DAY);\n  let end = monthStart(start, 12);\n  if (next && next.at >= end) {\n    end = monthStart(next.at, 1);\n    start = monthStart(end, -12);\n  }\n  const seasons: Season[] = [];\n  let cursor = start;\n  let offset = offsetAt(timeZone, start);\n  while (cursor < end) {\n    const shift = findShift(timeZone, cursor, 1, Math.ceil((end - cursor) / DAY) + 7);\n    const stop = shift && shift.at < end ? shift.at : end;\n    seasons.push({ start: cursor, end: stop, offset });\n    if (!shift || shift.at >= end) break;\n    cursor = shift.at;\n    offset = shift.to;\n  }\n  const standard = Math.min(...seasons.map((season) => season.offset));\n  return { start, end, seasons, standard, previous, next };\n}\n\nfunction sunOn(day: number, latitude: number, longitude: number): Sun {\n  const meanNoon = day + 2_440_588 - 2_451_545 - longitude / 360;\n  const anomaly = (357.5291 + 0.98560028 * meanNoon) % 360;\n  const m = anomaly * RAD;\n  const centre = 1.9148 * Math.sin(m) + 0.02 * Math.sin(2 * m) + 0.0003 * Math.sin(3 * m);\n  const ecliptic = ((anomaly + centre + 180 + 102.9372) % 360) * RAD;\n  const transit = 2_451_545 + meanNoon + 0.0053 * Math.sin(m) - 0.0069 * Math.sin(2 * ecliptic);\n  const sinDeclination = Math.sin(ecliptic) * Math.sin(23.4397 * RAD);\n  const cosDeclination = Math.cos(Math.asin(sinDeclination));\n  const lat = latitude * RAD;\n  const cosHour = (Math.sin(-0.833 * RAD) - Math.sin(lat) * sinDeclination) / (Math.cos(lat) * cosDeclination);\n  const toTime = (julian: number) => (julian - 2_440_587.5) * DAY;\n  const noon = toTime(transit);\n  if (cosHour < -1) return { kind: \"day\", noon };\n  if (cosHour > 1) return { kind: \"night\", noon };\n  const half = Math.acos(cosHour) / (2 * Math.PI);\n  return { kind: \"normal\", rise: toTime(transit - half), set: toTime(transit + half), noon };\n}\n\nfunction daylightAt(city: City, now: number): Daylight {\n  const today = dayOf(city.timeZone, now);\n  const sun = sunOn(today, city.latitude, city.longitude);\n  const yesterday = sunOn(today - 1, city.latitude, city.longitude);\n  const midnight = today * DAY - offsetAt(city.timeZone, now) * MINUTE;\n  const clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n  if (sun.kind === \"day\") return { sun, yesterday, phase: clamp(0.5 + (now - sun.noon) / DAY, 0.03, 0.97), next: null };\n  if (sun.kind === \"night\") {\n    const fromMidnight = (now - midnight) / DAY;\n    return { sun, yesterday, phase: 1 + clamp((fromMidnight + 0.5) % 1, 0.03, 0.97), next: null };\n  }\n  if (now < sun.rise) {\n    const start = yesterday.kind === \"normal\" ? yesterday.set : midnight;\n    return { sun, yesterday, phase: 1 + clamp((now - start) / (sun.rise - start), 0, 1), next: { kind: \"sunrise\", at: sun.rise } };\n  }\n  if (now <= sun.set) {\n    return { sun, yesterday, phase: (now - sun.rise) / (sun.set - sun.rise), next: { kind: \"sunset\", at: sun.set } };\n  }\n  const tomorrow = sunOn(today + 1, city.latitude, city.longitude);\n  const end = tomorrow.kind === \"normal\" ? tomorrow.rise : midnight + DAY;\n  return {\n    sun,\n    yesterday,\n    phase: 1 + clamp((now - sun.set) / (end - sun.set), 0, 1),\n    next: tomorrow.kind === \"normal\" ? { kind: \"sunrise\", at: tomorrow.rise } : null,\n  };\n}\n\nfunction zoneNames(timeZone: string, at: number) {\n  const nameOf = (locale: string, style: \"short\" | \"long\") =>\n    formatter(locale, { timeZone, timeZoneName: style })\n      .formatToParts(at)\n      .find((part) => part.type === \"timeZoneName\")?.value ?? \"\";\n  const short = shortZoneLocales\n    .map((locale) => nameOf(locale, \"short\").replace(/^(GMT|UTC)([+\\-−]0)?$/, \"GMT\"))\n    .find((name) => !/^(GMT|UTC)[+\\-−]/.test(name));\n  return { short: short ?? null, long: nameOf(\"en-GB\", \"long\") || timeZone };\n}\n\nfunction formatOffset(minutes: number) {\n  const abs = Math.abs(minutes);\n  const rest = abs % 60;\n  return `UTC${minutes < 0 ? \"−\" : \"+\"}${Math.floor(abs / 60)}${rest ? `:${String(rest).padStart(2, \"0\")}` : \"\"}`;\n}\n\nfunction formatSpan(minutes: number) {\n  const abs = Math.round(Math.abs(minutes));\n  const hours = Math.floor(abs / 60);\n  const rest = abs % 60;\n  if (!hours) return `${rest} min`;\n  return rest ? `${hours} h ${rest} min` : `${hours} h`;\n}\n\nfunction formatClock(hours: number, twelve: boolean) {\n  const total = Math.round((((hours % 24) + 24) % 24) * 60) % 1_440;\n  const hour = Math.floor(total / 60);\n  const minute = String(total % 60).padStart(2, \"0\");\n  if (!twelve) return `${String(hour).padStart(2, \"0\")}:${minute}`;\n  return `${hour % 12 || 12}:${minute} ${hour < 12 ? \"AM\" : \"PM\"}`;\n}\n\nfunction formatTick(hours: number, twelve: boolean) {\n  const total = Math.round((((hours % 24) + 24) % 24) * 60) % 1_440;\n  const hour = Math.floor(total / 60);\n  const minute = total % 60;\n  const tail = minute ? `:${String(minute).padStart(2, \"0\")}` : \"\";\n  if (!twelve) return `${String(hour).padStart(2, \"0\")}${tail}`;\n  return `${hour % 12 || 12}${tail}${hour < 12 ? \"a\" : \"p\"}`;\n}\n\nfunction clockAt(timeZone: string, at: number, twelve: boolean) {\n  return formatClock(hoursOf(timeZone, at), twelve);\n}\n\nfunction placeOf(timeZone: string) {\n  return (timeZone.split(\"/\").pop() ?? timeZone).replaceAll(\"_\", \" \");\n}\n\nfunction searchable(text: string) {\n  return text\n    .normalize(\"NFD\")\n    .replace(/\\p{Diacritic}/gu, \"\")\n    .toLowerCase();\n}\n\nfunction useReducedMotionSafe() {\n  const prefers = useReducedMotion();\n  const [mounted, setMounted] = useState(false);\n  useEffect(() => setMounted(true), []);\n  return mounted && Boolean(prefers);\n}\n\nfunction useNow() {\n  const [now, setNow] = useState<number | null>(null);\n  useEffect(() => {\n    let timer = 0;\n    const tick = () => {\n      const at = Date.now();\n      setNow(at);\n      timer = window.setTimeout(tick, SECOND - (at % SECOND) + 4);\n    };\n    tick();\n    return () => window.clearTimeout(timer);\n  }, []);\n  return now;\n}\n\nfunction useVisitorZone() {\n  const [zone, setZone] = useState<string | null>(null);\n  useEffect(() => setZone(Intl.DateTimeFormat().resolvedOptions().timeZone || \"UTC\"), []);\n  return zone;\n}\n\nfunction Digit({ value, forward, reduce }: { value: number; forward: boolean; reduce: boolean }) {\n  const turn = useMotionValue(value);\n  const goal = useRef(value);\n  const forwardRef = useRef(forward);\n  forwardRef.current = forward;\n  const y = useTransform(turn, (t) => `${-(((t % 10) + 10) % 10)}em`);\n\n  useEffect(() => {\n    const at = ((goal.current % 10) + 10) % 10;\n    let step = (value - at + 10) % 10;\n    if (!forwardRef.current && step > 5) step -= 10;\n    goal.current += step;\n    if (reduce) {\n      turn.jump(goal.current);\n      return;\n    }\n    if (turn.get() === goal.current) return;\n    const controls = animate(turn, goal.current, { type: \"spring\", stiffness: 320, damping: 2 * Math.sqrt(320) });\n    return () => controls.stop();\n  }, [value, reduce, turn]);\n\n  return (\n    <span className=\"relative inline-block h-[1em] overflow-hidden [mask-image:linear-gradient(to_bottom,transparent,black_12%,black_88%,transparent)]\">\n      <span className=\"invisible block h-[1em]\">0</span>\n      <motion.span className=\"absolute inset-x-0 top-0 flex flex-col\" style={{ y }}>\n        {strip.map((digit, slot) => (\n          <span className=\"block h-[1em] text-center\" key={slot}>\n            {digit}\n          </span>\n        ))}\n      </motion.span>\n    </span>\n  );\n}\n\nfunction Slot({ children }: { children: ReactNode }) {\n  return (\n    <span className=\"relative inline-block h-[1em]\">\n      <span className=\"invisible\">0</span>\n      <span className=\"absolute inset-0 flex items-center justify-center\">{children}</span>\n    </span>\n  );\n}\n\nfunction Colon() {\n  return (\n    <span className=\"mx-[0.05em] flex h-[1em] flex-col items-center justify-center gap-[0.19em] pt-[0.02em] text-foreground/30\">\n      <span className=\"size-[0.1em] rounded-full bg-current\" />\n      <span className=\"size-[0.1em] rounded-full bg-current\" />\n    </span>\n  );\n}\n\nfunction BigTime({\n  timeZone,\n  now,\n  twelve,\n  forward,\n  reduce,\n}: {\n  timeZone: string;\n  now: number | null;\n  twelve: boolean;\n  forward: boolean;\n  reduce: boolean;\n}) {\n  const p = now === null ? null : zoneParts(timeZone, now);\n  const hour = p ? (twelve ? p.hour % 12 || 12 : p.hour) : 0;\n  const hours = twelve ? String(hour) : String(hour).padStart(2, \"0\");\n  const minutes = p ? String(p.minute).padStart(2, \"0\") : \"00\";\n\n  return (\n    <div className=\"flex items-end font-heading font-semibold text-[clamp(3.75rem,24cqi,8.25rem)] tabular-nums leading-none tracking-[-0.03em]\">\n      <span aria-hidden className=\"flex\">\n        {p ? (\n          <>\n            {hours.length > 1 && <Digit forward={forward} reduce={reduce} value={Number(hours[0])} />}\n            <Digit forward={forward} reduce={reduce} value={Number(hours[hours.length - 1])} />\n            <Colon />\n            <Digit forward={forward} reduce={reduce} value={Number(minutes[0])} />\n            <Digit forward={forward} reduce={reduce} value={Number(minutes[1])} />\n          </>\n        ) : (\n          <span className=\"flex text-muted-foreground/30\">\n            <Slot>–</Slot>\n            <Slot>–</Slot>\n            <Colon />\n            <Slot>–</Slot>\n            <Slot>–</Slot>\n          </span>\n        )}\n      </span>\n      <span\n        aria-hidden\n        className=\"ms-[0.14em] mb-[0.225em] flex flex-col gap-[0.25em] font-medium font-sans text-[0.2em] text-muted-foreground leading-none tracking-normal\"\n      >\n        <span className={cn(!twelve && \"invisible\")}>{p && p.hour >= 12 ? \"PM\" : \"AM\"}</span>\n        <span className=\"tabular-nums\">{p ? `:${String(p.second).padStart(2, \"0\")}` : \":––\"}</span>\n      </span>\n    </div>\n  );\n}\n\nfunction HourCycleSwitch({ value, onChange }: { value: HourCycle; onChange: (value: HourCycle) => void }) {\n  const options: HourCycle[] = [\"12h\", \"24h\"];\n  const refs = useRef<(HTMLButtonElement | null)[]>([]);\n  const index = options.indexOf(value);\n\n  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n    if (![\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\", \"Home\", \"End\"].includes(event.key)) return;\n    event.preventDefault();\n    const next = event.key === \"Home\" ? 0 : event.key === \"End\" ? 1 : 1 - index;\n    onChange(options[next]);\n    refs.current[next]?.focus();\n  };\n\n  return (\n    <SegmentedControl aria-label=\"Clock format\" onKeyDown={onKeyDown} role=\"radiogroup\" size=\"sm\">\n      {options.map((option, i) => {\n        const checked = option === value;\n        return (\n          <SegmentedControlItem\n            aria-checked={checked}\n            className=\"min-w-11 px-2.5 font-mono text-muted-foreground text-xs outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n            data-checked={checked ? \"\" : undefined}\n            key={option}\n            onClick={() => onChange(option)}\n            ref={(el: HTMLButtonElement | null) => {\n              refs.current[i] = el;\n            }}\n            role=\"radio\"\n            tabIndex={checked ? 0 : -1}\n          >\n            {option}\n          </SegmentedControlItem>\n        );\n      })}\n    </SegmentedControl>\n  );\n}\n\nfunction Swap({ id, children, className }: { id: string; children: ReactNode; className?: string }) {\n  return (\n    <AnimatePresence initial={false} mode=\"popLayout\">\n      <motion.span\n        animate={{ opacity: 1 }}\n        className={cn(\"inline-block\", className)}\n        exit={{ opacity: 0 }}\n        initial={{ opacity: 0 }}\n        key={id}\n        transition={{ duration: 0.16, ease }}\n      >\n        {children}\n      </motion.span>\n    </AnimatePresence>\n  );\n}\n\nfunction CityPicker({\n  cities,\n  city,\n  now,\n  twelve,\n  onChange,\n}: {\n  cities: City[];\n  city: City;\n  now: number | null;\n  twelve: boolean;\n  onChange: (id: string) => void;\n}) {\n  return (\n    <Combobox<City>\n      autoHighlight\n      filter={(item, query) => {\n        const needle = searchable(query.trim());\n        if (!needle || needle === searchable(city.name)) return true;\n        return searchable(`${item.name} ${item.region} ${item.country} ${item.timeZone}`).includes(needle);\n      }}\n      isItemEqualToValue={(a, b) => a.id === b.id}\n      itemToStringLabel={(item) => item.name}\n      items={cities}\n      onValueChange={(next) => next && onChange(next.id)}\n      value={city}\n    >\n      <ComboboxInput aria-label=\"Choose a city\" placeholder=\"Search a city\" startAddon={<SearchIcon />} triggerProps={{ \"aria-label\": \"Show cities\" }} />\n      <ComboboxPopup className=\"w-(--anchor-width) min-w-64\">\n        <ComboboxEmpty>No city by that name.</ComboboxEmpty>\n        <ComboboxList>\n          {(item: City) => (\n            <ComboboxItem className=\"py-1.5\" key={item.id} value={item}>\n              <span className=\"flex items-center justify-between gap-3\">\n                <span className=\"min-w-0\">\n                  <span className=\"block truncate font-medium\">{item.name}</span>\n                  <span className=\"block truncate text-muted-foreground text-xs\">{item.country}</span>\n                </span>\n                <span className=\"shrink-0 text-end text-muted-foreground text-xs tabular-nums\">\n                  <span className=\"block text-foreground\">{now === null ? \"––:––\" : clockAt(item.timeZone, now, twelve)}</span>\n                  <span className=\"block\">{now === null ? \"UTC\" : formatOffset(offsetAt(item.timeZone, now))}</span>\n                </span>\n              </span>\n            </ComboboxItem>\n          )}\n        </ComboboxList>\n      </ComboboxPopup>\n    </Combobox>\n  );\n}\n\nfunction ClockPanel({\n  city,\n  now,\n  visitorZone,\n  twelve,\n  cycle,\n  onCycle,\n  forward,\n  reduce,\n  locale,\n}: {\n  city: City;\n  now: number | null;\n  visitorZone: string | null;\n  twelve: boolean;\n  cycle: HourCycle;\n  onCycle: (value: HourCycle) => void;\n  forward: boolean;\n  reduce: boolean;\n  locale: string;\n}) {\n  const minute = now === null ? null : Math.floor(now / MINUTE) * MINUTE;\n  const offset = minute === null ? null : offsetAt(city.timeZone, minute);\n  const names = useMemo(() => (offset === null ? null : zoneNames(city.timeZone, Date.now())), [city.timeZone, offset]);\n  const date =\n    minute === null\n      ? null\n      : formatter(locale, { timeZone: city.timeZone, weekday: \"long\", day: \"numeric\", month: \"long\", year: \"numeric\" }).format(minute);\n  const ready = minute !== null && visitorZone !== null && offset !== null;\n  const gap = ready ? offset - offsetAt(visitorZone, minute) : 0;\n  const dayGap = ready ? dayOf(city.timeZone, minute) - dayOf(visitorZone, minute) : 0;\n  const relative = new Intl.RelativeTimeFormat(locale, { numeric: \"auto\" });\n  const spoken =\n    minute === null ? \"\" : `${clockAt(city.timeZone, minute, twelve)}, ${date}, ${names?.long ?? \"\"}`;\n\n  return (\n    <div className=\"@container flex min-w-0 flex-col gap-5 p-5 sm:p-6\">\n      <div className=\"flex items-center justify-between gap-3\">\n        <p className=\"flex min-w-0 items-center gap-2 text-muted-foreground text-xs\">\n          {names?.short && (\n            <span className=\"shrink-0 rounded-md bg-muted px-1.5 py-0.5 font-medium font-mono text-foreground\">{names.short}</span>\n          )}\n          <span className=\"truncate\">\n            {names ? `${names.long} · ${formatOffset(offset ?? 0)}` : <span className=\"text-muted-foreground/50\">Finding the time zone…</span>}\n          </span>\n        </p>\n        <HourCycleSwitch onChange={onCycle} value={cycle} />\n      </div>\n\n      <div>\n        <time className=\"sr-only\" dateTime={minute === null ? undefined : new Date(minute).toISOString()}>\n          {spoken}\n        </time>\n        <BigTime forward={forward} now={now} reduce={reduce} timeZone={city.timeZone} twelve={twelve} />\n        <p className=\"mt-3 flex min-h-6 flex-wrap items-center gap-x-2 gap-y-1 text-base text-foreground\">\n          {date ?? <span className=\"text-muted-foreground/50\">Today</span>}\n          {dayGap !== 0 && (\n            <span className=\"rounded-full bg-info/10 px-2 py-0.5 font-medium text-info-foreground text-xs\">\n              {relative.format(dayGap, \"day\").replace(/^./, (c) => c.toUpperCase())} for you\n            </span>\n          )}\n        </p>\n      </div>\n\n      <div className=\"mt-auto flex flex-wrap items-baseline gap-x-2 gap-y-1 border-t pt-4 text-sm\">\n        <span className=\"font-medium\">\n          {!ready ? \"Comparing with your time…\" : gap === 0 ? \"Same time as you\" : `${formatSpan(gap)} ${gap > 0 ? \"ahead of\" : \"behind\"} you`}\n        </span>\n        {ready && (\n          <span className=\"text-muted-foreground\">\n            You’re in {placeOf(visitorZone)}, <span className=\"tabular-nums\">{clockAt(visitorZone, minute, twelve)}</span>\n          </span>\n        )}\n      </div>\n    </div>\n  );\n}\n\nconst arc = { cx: 160, horizon: 104, rx: 136, top: 84, bottom: 26 };\n\nfunction pointAt(phase: number) {\n  if (phase <= 1) {\n    const angle = Math.PI * (1 - phase);\n    return { x: arc.cx + arc.rx * Math.cos(angle), y: arc.horizon - arc.top * Math.sin(angle) };\n  }\n  const angle = Math.PI * Math.min(1, phase - 1);\n  return { x: arc.cx + arc.rx * Math.cos(angle), y: arc.horizon + arc.bottom * Math.sin(angle) };\n}\n\nfunction SunMark({ phase, visible }: { phase: MotionValue<number>; visible: boolean }) {\n  const x = useTransform(phase, (p) => pointAt(p).x);\n  const y = useTransform(phase, (p) => pointAt(p).y);\n  const sun = useTransform(phase, (p) => (p <= 1 ? 1 : 0));\n  const moon = useTransform(phase, (p) => (p <= 1 ? 0 : 1));\n  const trail = useTransform(phase, (p) => {\n    const point = pointAt(Math.min(1, Math.max(0, p)));\n    return `M ${arc.cx - arc.rx} ${arc.horizon} A ${arc.rx} ${arc.top} 0 0 1 ${point.x.toFixed(2)} ${point.y.toFixed(2)}`;\n  });\n\n  return (\n    <motion.g animate={{ opacity: visible ? 1 : 0 }} initial={false} transition={{ duration: 0.3 }}>\n      <motion.path\n        className=\"stroke-amber-500 dark:stroke-amber-300\"\n        d={trail}\n        fill=\"none\"\n        strokeLinecap=\"round\"\n        strokeWidth={2}\n        style={{ opacity: sun }}\n      />\n      <motion.g style={{ x, y }}>\n        <motion.circle className=\"fill-amber-400 stroke-card dark:fill-amber-300\" r={9} strokeWidth={3} style={{ opacity: sun }} />\n        <motion.path\n          className=\"fill-indigo-400 stroke-card dark:fill-indigo-300\"\n          d=\"M 2.5 -8.6 A 9 9 0 1 0 8.9 1.6 A 7 7 0 0 1 2.5 -8.6 Z\"\n          strokeLinejoin=\"round\"\n          strokeWidth={2.5}\n          style={{ opacity: moon }}\n        />\n      </motion.g>\n    </motion.g>\n  );\n}\n\nfunction DayArc({ city, now, twelve, reduce }: { city: City; now: number | null; twelve: boolean; reduce: boolean }) {\n  const minute = now === null ? null : Math.floor(now / MINUTE) * MINUTE;\n  const light = useMemo(() => (minute === null ? null : daylightAt(city, minute)), [city, minute]);\n  const phase = useMotionValue(light?.phase ?? 0.5);\n  const placed = useRef(false);\n\n  useEffect(() => {\n    if (!light) return;\n    if (!placed.current || reduce) {\n      phase.jump(light.phase);\n      placed.current = true;\n      return;\n    }\n    const controls = animate(phase, light.phase, glide);\n    return () => controls.stop();\n  }, [light, reduce, phase]);\n\n  const sun = light?.sun;\n  const at = (time: number) => clockAt(city.timeZone, time, twelve);\n  const length = sun?.kind === \"normal\" ? (sun.set - sun.rise) / MINUTE : null;\n  const before = light?.yesterday.kind === \"normal\" ? (light.yesterday.set - light.yesterday.rise) / MINUTE : null;\n  const change = length !== null && before !== null ? Math.round(length - before) : null;\n  const status = !light\n    ? \"\"\n    : light.next\n      ? `${light.next.kind === \"sunrise\" ? \"Sunrise\" : \"Sunset\"} in ${formatSpan(Math.max(1, (light.next.at - (minute ?? 0)) / MINUTE))}`\n      : sun?.kind === \"day\"\n        ? \"Midnight sun today\"\n        : sun?.kind === \"normal\"\n          ? \"No sunrise tomorrow\"\n          : \"Polar night today\";\n\n  return (\n    <div className=\"flex min-w-0 flex-col gap-3 p-5 sm:p-6\">\n      <div className=\"flex items-baseline justify-between gap-3 text-xs\">\n        <span className=\"font-medium text-foreground text-sm\">Daylight</span>\n        <Swap className=\"text-muted-foreground tabular-nums\" id={status ? `${city.id}-${status}` : \"pending\"}>\n          {status || \" \"}\n        </Swap>\n      </div>\n      <svg aria-hidden className=\"mx-auto block h-auto w-full max-w-[360px] overflow-visible\" viewBox=\"0 0 320 136\">\n        <line className=\"stroke-border\" strokeWidth={1} x1={8} x2={312} y1={arc.horizon} y2={arc.horizon} />\n        <path\n          className=\"stroke-foreground/15\"\n          d={`M ${arc.cx - arc.rx} ${arc.horizon} A ${arc.rx} ${arc.top} 0 0 1 ${arc.cx + arc.rx} ${arc.horizon}`}\n          fill=\"none\"\n          strokeWidth={2}\n        />\n        <path\n          className=\"stroke-foreground/20\"\n          d={`M ${arc.cx + arc.rx} ${arc.horizon} A ${arc.rx} ${arc.bottom} 0 0 1 ${arc.cx - arc.rx} ${arc.horizon}`}\n          fill=\"none\"\n          strokeDasharray=\"0.5 5\"\n          strokeLinecap=\"round\"\n          strokeWidth={2}\n        />\n        <circle className=\"fill-card stroke-foreground/30\" cx={arc.cx - arc.rx} cy={arc.horizon} r={3.5} strokeWidth={1.5} />\n        <circle className=\"fill-card stroke-foreground/30\" cx={arc.cx + arc.rx} cy={arc.horizon} r={3.5} strokeWidth={1.5} />\n        <SunMark phase={phase} visible={light !== null} />\n      </svg>\n      <dl className=\"grid grid-cols-3 gap-2 text-xs\">\n        <div>\n          <dt className=\"text-muted-foreground\">Sunrise</dt>\n          <dd className=\"mt-0.5 font-medium text-foreground text-sm tabular-nums\">\n            {sun?.kind === \"normal\" ? at(sun.rise) : sun ? \"None\" : \"––:––\"}\n          </dd>\n        </div>\n        <div className=\"text-center\">\n          <dt className=\"text-muted-foreground\">Day length</dt>\n          <dd className=\"mt-0.5 font-medium text-foreground text-sm tabular-nums\">\n            {length !== null ? formatSpan(length) : sun?.kind === \"day\" ? \"24 h\" : sun ? \"0 min\" : \"–\"}\n          </dd>\n        </div>\n        <div className=\"text-end\">\n          <dt className=\"text-muted-foreground\">Sunset</dt>\n          <dd className=\"mt-0.5 font-medium text-foreground text-sm tabular-nums\">\n            {sun?.kind === \"normal\" ? at(sun.set) : sun ? \"None\" : \"––:––\"}\n          </dd>\n        </div>\n      </dl>\n      <p className=\"min-h-4 text-center text-muted-foreground text-xs tabular-nums\">\n        {change === null || change === 0\n          ? sun && sun.kind !== \"normal\"\n            ? sun.kind === \"day\"\n              ? \"The sun stays above the horizon all day.\"\n              : \"The sun stays below the horizon all day.\"\n            : \" \"\n          : `${formatSpan(change)} ${change > 0 ? \"longer\" : \"shorter\"} than yesterday`}\n      </p>\n    </div>\n  );\n}\n\nfunction overlapOf(hours: { start: number; end: number }, shift: number) {\n  for (const day of [-48, -24, 0, 24, 48]) {\n    const start = Math.max(hours.start, hours.start - shift + day);\n    const end = Math.min(hours.end, hours.end - shift + day);\n    if (end > start) return { start, end };\n  }\n  return null;\n}\n\nfunction DayTrack({\n  name,\n  detail,\n  local,\n  shift,\n  hours,\n  overlap,\n  nowAt,\n  twelve,\n  tone,\n  ready,\n}: {\n  name: ReactNode;\n  detail: ReactNode;\n  local: string;\n  shift: number;\n  hours: { start: number; end: number };\n  overlap: { start: number; end: number } | null;\n  nowAt: number | null;\n  twelve: boolean;\n  tone: \"you\" | \"city\";\n  ready: boolean;\n}) {\n  const span = hours.end - hours.start;\n  const band =\n    tone === \"you\"\n      ? \"bg-sky-500/15 ring-sky-500/35 dark:bg-sky-400/15 dark:ring-sky-400/35\"\n      : \"bg-violet-500/15 ring-violet-500/35 dark:bg-violet-400/15 dark:ring-violet-400/35\";\n\n  return (\n    <div className=\"grid gap-x-4 gap-y-1.5 @2xl:grid-cols-[9.5rem_minmax(0,1fr)] @2xl:items-start\">\n      <div className=\"flex min-w-0 items-baseline justify-between gap-3 @2xl:flex-col @2xl:items-start @2xl:gap-0.5 @2xl:pt-0.5\">\n        <span className=\"flex min-w-0 items-center gap-2 font-medium text-sm\">\n          <span\n            aria-hidden\n            className={cn(\n              \"size-2 shrink-0 rounded-full\",\n              tone === \"you\" ? \"bg-sky-500 dark:bg-sky-400\" : \"bg-violet-500 dark:bg-violet-400\",\n            )}\n          />\n          <span className=\"truncate\">{name}</span>\n        </span>\n        <span className=\"shrink-0 truncate text-muted-foreground text-xs tabular-nums @2xl:ps-4\">\n          {detail} · {local}\n        </span>\n      </div>\n      <div className=\"min-w-0\">\n        <div className=\"relative h-7 overflow-hidden rounded-lg bg-muted/70 dark:bg-muted/50\">\n          {ticks.slice(1).map((tick) => (\n            <span aria-hidden className=\"absolute inset-y-0 w-px bg-border/70\" key={tick} style={{ left: `${(tick / 24) * 100}%` }} />\n          ))}\n          <motion.div\n            animate={{ x: `${(-shift / 72) * 100}%` }}\n            className=\"absolute inset-y-0 -left-full w-[300%]\"\n            initial={false}\n            transition={glide}\n          >\n            {[0, 24, 48].map((day) => (\n              <span\n                className={cn(\"absolute inset-y-1 rounded-md ring-1 ring-inset transition-opacity\", band, !ready && \"opacity-40\")}\n                key={day}\n                style={{ left: `${((day + hours.start) / 72) * 100}%`, width: `${(span / 72) * 100}%` }}\n              />\n            ))}\n          </motion.div>\n          <motion.span\n            animate={{\n              left: `${((overlap?.start ?? 12) / 24) * 100}%`,\n              width: `${(((overlap?.end ?? 12) - (overlap?.start ?? 12)) / 24) * 100}%`,\n              opacity: overlap ? 1 : 0,\n            }}\n            className=\"absolute inset-y-1 rounded-md bg-emerald-500 dark:bg-emerald-400\"\n            initial={false}\n            transition={glide}\n          />\n          {nowAt !== null && (\n            <span\n              aria-hidden\n              className=\"absolute inset-y-0 w-0.5 -translate-x-1/2 bg-foreground\"\n              style={{ left: `${(nowAt / 24) * 100}%` }}\n            />\n          )}\n        </div>\n        <div aria-hidden className=\"mt-1 grid grid-cols-8 text-[10px] text-muted-foreground tabular-nums\">\n          {ticks.map((tick) => (\n            <span className=\"truncate ps-1\" key={tick}>\n              {ready ? formatTick(tick + shift, twelve) : formatTick(tick, twelve)}\n            </span>\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n\nfunction MeetPlanner({\n  city,\n  now,\n  visitorZone,\n  twelve,\n  hours,\n}: {\n  city: City;\n  now: number | null;\n  visitorZone: string | null;\n  twelve: boolean;\n  hours: { start: number; end: number };\n}) {\n  const minute = now === null ? null : Math.floor(now / MINUTE) * MINUTE;\n  const ready = minute !== null && visitorZone !== null;\n  const yourOffset = ready ? offsetAt(visitorZone, minute) : 0;\n  const cityOffset = ready ? offsetAt(city.timeZone, minute) : 0;\n  const shift = (cityOffset - yourOffset) / 60;\n  const overlap = ready ? overlapOf(hours, shift) : null;\n  const nowAt = ready ? hoursOf(visitorZone, minute) : null;\n  const yourNames = ready ? zoneNames(visitorZone, minute) : null;\n  const cityNames = ready ? zoneNames(city.timeZone, minute) : null;\n  const range = (start: number, end: number) => `${formatClock(start, twelve)}–${formatClock(end, twelve)}`.replaceAll(\" \", \"\\u00a0\").replace(\"–\", \"\\u2060–\\u2060\");\n  const shared = overlap ? (overlap.end - overlap.start) * 60 : 0;\n  const headline = !ready ? \"––:––\" : overlap ? range(overlap.start, overlap.end) : \"No overlap\";\n\n  return (\n    <section aria-label={`Best time to meet with ${city.name}`} className=\"rounded-2xl border bg-card shadow-xs/5\">\n      <div className=\"grid gap-6 p-5 sm:p-6 @3xl:grid-cols-[minmax(0,15rem)_minmax(0,1fr)] @3xl:gap-10\">\n        <div className=\"flex flex-col gap-3\">\n          <h3 className=\"font-medium text-muted-foreground text-sm\">Best time to meet</h3>\n          <div>\n            <Swap\n              className=\"font-heading font-semibold text-3xl tabular-nums tracking-tight\"\n              id={`${city.id}-${headline}`}\n            >\n              {headline}\n            </Swap>\n            <p className=\"mt-1 min-h-10 text-pretty text-muted-foreground text-sm\">\n              {!ready\n                ? \" \"\n                : overlap\n                  ? shift === 0\n                    ? \"Your working hours line up exactly.\"\n                    : `your time, which is ${range(overlap.start + shift, overlap.end + shift)} in ${city.name}`\n                  : `Their working day runs ${range(hours.start - shift, hours.end - shift)} your time.`}\n            </p>\n          </div>\n          <p className=\"mt-auto flex flex-wrap items-center gap-2 text-xs\">\n            <span\n              className={cn(\n                \"inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 font-medium\",\n                !ready\n                  ? \"bg-muted text-muted-foreground\"\n                  : overlap\n                    ? \"bg-emerald-500/12 text-emerald-700 dark:bg-emerald-400/12 dark:text-emerald-300\"\n                    : \"bg-warning/12 text-warning-foreground\",\n              )}\n            >\n              <span aria-hidden className={cn(\"size-1.5 rounded-full\", overlap ? \"bg-emerald-500 dark:bg-emerald-400\" : \"bg-current\")} />\n              {!ready ? \"Working hours\" : overlap ? `${formatSpan(shared)} shared` : \"No shared hours\"}\n            </span>\n            <span className=\"text-muted-foreground\">\n              {formatClock(hours.start, twelve)}–{formatClock(hours.end, twelve)} each side\n            </span>\n          </p>\n        </div>\n\n        <div className=\"@container flex min-w-0 flex-col gap-4\">\n          <DayTrack\n            detail={yourNames?.short ?? (ready ? formatOffset(yourOffset) : \"Your zone\")}\n            hours={hours}\n            local={ready ? clockAt(visitorZone, minute, twelve) : \"––:––\"}\n            name={ready ? `You · ${placeOf(visitorZone)}` : \"You\"}\n            nowAt={nowAt}\n            overlap={overlap}\n            ready={ready}\n            shift={0}\n            tone=\"you\"\n            twelve={twelve}\n          />\n          <DayTrack\n            detail={cityNames?.short ?? (ready ? formatOffset(cityOffset) : \"–\")}\n            hours={hours}\n            local={ready ? clockAt(city.timeZone, minute, twelve) : \"––:––\"}\n            name={city.name}\n            nowAt={nowAt}\n            overlap={overlap}\n            ready={ready}\n            shift={shift}\n            tone=\"city\"\n            twelve={twelve}\n          />\n          <p className=\"flex items-center gap-2 text-muted-foreground text-xs @2xl:ps-[calc(9.5rem+1rem)]\">\n            <span aria-hidden className=\"h-3 w-0.5 rounded-full bg-foreground\" />\n            Now, on your clock\n          </p>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nfunction ClockChanges({ city, now, locale }: { city: City; now: number | null; locale: string }) {\n  const hourKey = now === null ? null : Math.floor(now / HOUR);\n  const year = useMemo(\n    () => (hourKey === null ? null : clockYear(city.timeZone, hourKey * HOUR + 1)),\n    [city.timeZone, hourKey],\n  );\n  const minute = now === null ? null : Math.floor(now / MINUTE) * MINUTE;\n  const relative = new Intl.RelativeTimeFormat(locale, { numeric: \"auto\" });\n  const longDate = (at: number) =>\n    formatter(locale, { timeZone: city.timeZone, weekday: \"short\", day: \"numeric\", month: \"short\", year: \"numeric\" }).format(at);\n  const monthYear = (at: number) => formatter(locale, { timeZone: city.timeZone, month: \"short\", year: \"numeric\" }).format(at);\n  const daysFrom = (at: number) => (minute === null ? 0 : dayOf(city.timeZone, at) - dayOf(city.timeZone, minute));\n  const position = (at: number) => (year ? ((at - year.start) / (year.end - year.start)) * 100 : 0);\n  const offset = minute === null ? 0 : offsetAt(city.timeZone, minute);\n  const changes = year !== null && (year.seasons.length > 1 || year.next !== null);\n  const recent = year?.previous && minute !== null && minute - year.previous.at < 370 * DAY ? year.previous : null;\n  const months = year ? Array.from({ length: 12 }, (_, i) => monthStart(year.start, i)) : [];\n  const monthName = (at: number) => formatter(locale, { timeZone: \"UTC\", month: \"short\" }).format(at);\n  const zones = useMemo(() => {\n    if (!year) return null;\n    const standard = year.seasons.find((season) => season.offset === year.standard);\n    const summer = year.seasons.find((season) => season.offset > year.standard);\n    const nameAt = (season: Season | undefined) =>\n      season ? { offset: season.offset, short: zoneNames(city.timeZone, (season.start + season.end) / 2).short } : null;\n    return { standard: nameAt(standard), summer: nameAt(summer) };\n  }, [year, city.timeZone]);\n\n  const rows = [\n    recent && {\n      key: \"previous\",\n      icon: recent.to > recent.from ? RotateCwIcon : RotateCcwIcon,\n      label: `Clocks went ${recent.to > recent.from ? \"forward\" : \"back\"} ${formatSpan(recent.to - recent.from)}`,\n      when: relative.format(daysFrom(recent.at), \"day\"),\n      date: longDate(recent.at),\n      past: true,\n    },\n    year?.next && {\n      key: \"next\",\n      icon: year.next.to > year.next.from ? RotateCwIcon : RotateCcwIcon,\n      label: `Clocks go ${year.next.to > year.next.from ? \"forward\" : \"back\"} ${formatSpan(year.next.to - year.next.from)}`,\n      when: relative.format(daysFrom(year.next.at), \"day\"),\n      date: longDate(year.next.at),\n      past: false,\n    },\n  ].filter((row) => Boolean(row)) as {\n    key: string;\n    icon: typeof RotateCwIcon;\n    label: string;\n    when: string;\n    date: string;\n    past: boolean;\n  }[];\n\n  const summary = !year\n    ? \" \"\n    : changes\n      ? `On ${offset > year.standard ? \"daylight saving time\" : \"standard time\"}, ${formatOffset(offset)}.`\n      : `${formatOffset(offset)} all year${year.previous ? `, unchanged since ${monthYear(year.previous.at)}` : \"\"}.`;\n\n  return (\n    <section aria-label=\"Clock changes\" className=\"@container flex min-w-0 flex-col gap-4 rounded-2xl border bg-card p-5 shadow-xs/5 sm:p-6\">\n      <div className=\"flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1\">\n        <h3 className=\"font-medium text-sm\">{year && !changes ? \"No clock changes\" : \"Clock changes\"}</h3>\n        <div aria-hidden className=\"flex items-center gap-3 text-muted-foreground text-xs\">\n          <span className=\"inline-flex items-center gap-1.5\">\n            <span className=\"size-2 rounded-full bg-amber-400 dark:bg-amber-300\" />\n            Daylight saving\n          </span>\n          <span className=\"inline-flex items-center gap-1.5\">\n            <span className=\"size-2 rounded-full bg-foreground/15\" />\n            Standard\n          </span>\n        </div>\n      </div>\n      <Swap className=\"text-muted-foreground text-sm\" id={year ? `${city.id}-${summary}` : \"pending\"}>\n        {summary}\n      </Swap>\n\n      <div aria-hidden>\n        <div className=\"relative py-1.5\">\n          <div className=\"relative h-2.5 overflow-hidden rounded-full bg-foreground/10\">\n            <AnimatePresence initial={false}>\n              <motion.div\n                animate={{ opacity: 1 }}\n                className=\"absolute inset-0\"\n                exit={{ opacity: 0 }}\n                initial={{ opacity: 0 }}\n                key={city.id}\n                transition={{ duration: 0.2, ease }}\n              >\n                {year?.seasons\n                  .filter((season) => season.offset > year.standard)\n                  .map((season) => (\n                    <span\n                      className=\"absolute inset-y-0 bg-amber-400 dark:bg-amber-300\"\n                      key={season.start}\n                      style={{ left: `${position(season.start)}%`, width: `${position(season.end) - position(season.start)}%` }}\n                    />\n                  ))}\n              </motion.div>\n            </AnimatePresence>\n          </div>\n          {rows.map((row) => {\n            const at = row.past ? recent?.at : year?.next?.at;\n            if (at === undefined) return null;\n            return (\n              <span\n                className=\"absolute inset-y-0 w-0.5 -translate-x-1/2 rounded-full bg-foreground/45\"\n                key={row.key}\n                style={{ left: `${position(at)}%` }}\n              />\n            );\n          })}\n          {minute !== null && year && (\n            <span\n              className=\"absolute top-1/2 size-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-foreground ring-2 ring-card\"\n              style={{ left: `${position(minute)}%` }}\n            />\n          )}\n        </div>\n        <div className=\"mt-1 grid grid-cols-12 text-[10px] text-muted-foreground tabular-nums\">\n          {(months.length ? months : Array.from({ length: 12 }, () => null)).map((month, i) => (\n            <span className=\"truncate text-center\" key={month ?? i}>\n              {month === null ? \" \" : monthName(month)}\n            </span>\n          ))}\n        </div>\n      </div>\n\n      <ul className=\"grid gap-2 text-sm\">\n        {rows.length ? (\n          rows.map((row) => (\n            <li className=\"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5\" key={row.key}>\n              <span className={cn(\"inline-flex items-center gap-2\", row.past ? \"text-muted-foreground\" : \"font-medium\")}>\n                <row.icon aria-hidden className=\"size-3.5 shrink-0 translate-y-px opacity-70\" />\n                {row.label}\n              </span>\n              <span className=\"text-muted-foreground text-xs tabular-nums\">\n                {row.when} · {row.date}\n              </span>\n            </li>\n          ))\n        ) : (\n          <li className=\"text-muted-foreground text-xs\">\n            {year ? `${city.name} doesn’t observe daylight saving time.` : \" \"}\n          </li>\n        )}\n      </ul>\n\n      <dl className=\"mt-auto grid grid-cols-2 gap-3 border-t border-dashed pt-4 text-xs @md:grid-cols-3\">\n        {[\n          { label: \"Time zone\", value: city.timeZone.replaceAll(\"_\", \" \"), mono: true },\n          {\n            label: \"Standard\",\n            value: zones?.standard ? `${formatOffset(zones.standard.offset)}${zones.standard.short ? ` · ${zones.standard.short}` : \"\"}` : \"–\",\n          },\n          {\n            label: \"Daylight saving\",\n            value: zones?.summer ? `${formatOffset(zones.summer.offset)}${zones.summer.short ? ` · ${zones.summer.short}` : \"\"}` : zones ? \"Not observed\" : \"–\",\n          },\n        ].map((item) => (\n          <div className={cn(\"min-w-0\", item.mono && \"col-span-2 @md:col-span-1\")} key={item.label}>\n            <dt className=\"text-muted-foreground\">{item.label}</dt>\n            <dd className={cn(\"mt-0.5 truncate text-foreground text-sm tabular-nums\", item.mono && \"font-mono text-xs leading-5\")}>\n              <Swap id={`${city.id}-${item.label}-${item.value}`}>{item.value}</Swap>\n            </dd>\n          </div>\n        ))}\n      </dl>\n    </section>\n  );\n}\n\nfunction Facts({ city }: { city: City }) {\n  const coordinates = `${Math.abs(city.latitude).toFixed(2)}° ${city.latitude >= 0 ? \"N\" : \"S\"}, ${Math.abs(city.longitude).toFixed(2)}° ${city.longitude >= 0 ? \"E\" : \"W\"}`;\n  const facts = [\n    { label: \"Country\", value: city.country, icon: FlagIcon },\n    { label: \"Region\", value: city.region, icon: MapIcon },\n    { label: \"Coordinates\", value: coordinates, icon: NavigationIcon, numeric: true },\n    { label: \"Elevation\", value: `${city.elevation.toLocaleString(\"en-US\")} m`, icon: MountainIcon, numeric: true },\n    { label: \"Population\", value: city.population.toLocaleString(\"en-US\"), icon: UsersIcon, numeric: true },\n    { label: \"Currency\", value: city.currency, icon: BanknoteIcon },\n    { label: \"Languages\", value: city.languages.join(\", \"), icon: LanguagesIcon },\n    { label: \"Dialling code\", value: city.dialCode, icon: PhoneIcon, numeric: true },\n  ];\n\n  return (\n    <section aria-label={`About ${city.name}`} className=\"@container rounded-2xl border bg-card px-5 pt-4 pb-2 shadow-xs/5 sm:px-6\">\n      <h3 className=\"font-medium text-sm\">About {city.name}</h3>\n      <dl className=\"mt-2 grid grid-cols-2 gap-x-5\">\n        {facts.map((fact) => (\n          <div className=\"relative min-w-0 border-t border-dashed py-2.5 ps-6 first:border-t-0 [&:nth-child(2)]:border-t-0\" key={fact.label}>\n            <dt className=\"text-muted-foreground text-xs\">\n              <fact.icon aria-hidden className=\"absolute start-0 top-3 size-3.5 text-muted-foreground\" />\n              {fact.label}\n            </dt>\n            <dd className={cn(\"mt-0.5 text-sm\", \"numeric\" in fact && \"tabular-nums\")}>\n              <Swap id={`${city.id}-${fact.label}`}>{fact.value}</Swap>\n            </dd>\n          </div>\n        ))}\n      </dl>\n    </section>\n  );\n}\n\nexport function CityTime({\n  cities = defaultCities,\n  defaultCity,\n  workingHours = { start: 9, end: 17 },\n  defaultHourCycle = \"24h\",\n  locale = \"en-GB\",\n  className,\n}: CityTimeProps) {\n  const headingId = useId();\n  const reduce = useReducedMotionSafe();\n  const now = useNow();\n  const visitorZone = useVisitorZone();\n  const [cityId, setCityId] = useState(defaultCity ?? cities[0]?.id);\n  const [cycle, setCycle] = useState<HourCycle>(defaultHourCycle);\n  const city = cities.find((item) => item.id === cityId) ?? cities[0];\n  const twelve = cycle === \"12h\";\n\n  const shownCity = useRef(city?.id);\n  const forward = shownCity.current === city?.id;\n  useEffect(() => {\n    shownCity.current = city?.id;\n  });\n\n  if (!city) return null;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <section\n        aria-labelledby={headingId}\n        className={cn(\"@container mx-auto w-full max-w-[1100px] px-4 py-8 sm:px-8 sm:py-10\", className)}\n      >\n        <div className=\"flex flex-col gap-4 @3xl:flex-row @3xl:items-end @3xl:justify-between\">\n          <div className=\"min-w-0\">\n            <h2 className=\"text-balance font-heading font-semibold text-2xl tracking-tight @3xl:text-3xl\" id={headingId}>\n              Local time in <Swap id={city.id}>{city.name}</Swap>\n            </h2>\n            <p className=\"mt-1 text-muted-foreground text-sm\">\n              <Swap id={city.id}>\n                {city.region === city.name ? city.country : `${city.region}, ${city.country}`}\n              </Swap>\n            </p>\n          </div>\n          <div className=\"w-full @3xl:w-72\">\n            <CityPicker cities={cities} city={city} now={now} onChange={setCityId} twelve={twelve} />\n          </div>\n        </div>\n\n        <div className=\"mt-6 grid gap-4\">\n          <div className=\"grid overflow-hidden rounded-2xl border bg-card shadow-xs/5 @3xl:grid-cols-[minmax(0,1.45fr)_minmax(0,1fr)]\">\n            <ClockPanel\n              city={city}\n              cycle={cycle}\n              forward={forward}\n              locale={locale}\n              now={now}\n              onCycle={setCycle}\n              reduce={reduce}\n              twelve={twelve}\n              visitorZone={visitorZone}\n            />\n            <div className=\"border-t @3xl:border-t-0 @3xl:border-l\">\n              <DayArc city={city} now={now} reduce={reduce} twelve={twelve} />\n            </div>\n          </div>\n\n          <MeetPlanner city={city} hours={workingHours} now={now} twelve={twelve} visitorZone={visitorZone} />\n\n          <div className=\"grid gap-4 @3xl:grid-cols-[minmax(0,1.45fr)_minmax(0,1fr)]\">\n            <ClockChanges city={city} locale={locale} now={now} />\n            <Facts city={city} />\n          </div>\n        </div>\n      </section>\n    </MotionConfig>\n  );\n}\n"
    }
  ]
}