/* Dusk: a light and dark switch where the sun sets. */

.dusk {
  box-sizing: border-box;
  width: min(620px, 100%);
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 34px;
  background: var(--dk-surface);
  border-radius: var(--dk-radius);
  box-shadow: var(--dk-shadow);
  color: var(--dk-ink);
  color-scheme: var(--dk-scheme);
  font-family: var(--dk-font);
  font-size: 14px;
  transition:
    background-color var(--dk-duration) var(--dk-ease),
    color var(--dk-duration) var(--dk-ease),
    box-shadow var(--dk-duration) var(--dk-ease);
}

.dusk__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; }

.dusk__intro { display: flex; flex-direction: column; gap: 4px; max-width: 300px; }

.dusk__title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }

.dusk__lead { margin: 0; color: var(--dk-muted); transition: color var(--dk-duration) var(--dk-ease); }

/* The switch: a little landscape. Day is a peach sky with the sun up; night is violet with stars. */
.dusk__switch {
  position: relative;
  flex: none;
  width: 220px;
  height: 104px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--dk-day-sky);
  cursor: pointer;
  isolation: isolate;
}

.dusk__switch:focus-visible { outline: 3px solid var(--dk-focus); outline-offset: 3px; }

.dusk__switch span { position: absolute; pointer-events: none; }

.dusk__sky { inset: 0; background: var(--dk-night-sky); opacity: 0; }

.dusk__star { width: 3px; height: 3px; border-radius: 50%; background: var(--dk-star); opacity: 0; }
.dusk__star:nth-child(2) { right: 40px; top: 20px; width: 4px; height: 4px; --dk-star-on: 1; }
.dusk__star:nth-child(3) { right: 70px; top: 34px; --dk-star-on: 0.7; }
.dusk__star:nth-child(4) { right: 30px; top: 46px; --dk-star-on: 0.5; }
.dusk__star:nth-child(5) { right: 104px; top: 16px; width: 2px; height: 2px; --dk-star-on: 0.6; }
.dusk__star:nth-child(6) { left: 46px; top: 26px; width: 2px; height: 2px; --dk-star-on: 0.5; }

.dusk__sun {
  left: 58px;
  top: 12px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--dk-sun);
}

.dusk__ground { left: 0; right: 0; top: 68px; bottom: 0; background: var(--dk-day-ground); }
.dusk__ground::after { content: ""; position: absolute; inset: 0; background: var(--dk-night-ground); opacity: 0; transition: inherit; }

.dusk__horizon { left: 0; right: 0; top: 66px; height: 2px; background: var(--dk-ink); }

.dusk__ring { inset: 0; border-radius: 999px; box-shadow: inset 0 0 0 2px var(--dk-ink); }

/* Night. */
.dusk__switch[aria-checked="true"] .dusk__sky { opacity: 1; }
.dusk__switch[aria-checked="true"] .dusk__sun { transform: translate(28px, 70px); }
.dusk__switch[aria-checked="true"] .dusk__ground::after { opacity: 1; }
.dusk__switch[aria-checked="true"] .dusk__star { opacity: var(--dk-star-on); }

/* Motion. The sun sinks, the sky darkens, then the stars come out. Going back runs the other way. */
.dusk--ready .dusk__sky,
.dusk--ready .dusk__ground,
.dusk--ready .dusk__sun {
  transition:
    opacity var(--dk-duration) var(--dk-ease),
    transform var(--dk-duration) var(--dk-ease);
}
.dusk--ready .dusk__horizon { transition: background-color var(--dk-duration) var(--dk-ease); }
.dusk--ready .dusk__ring { transition: box-shadow var(--dk-duration) var(--dk-ease); }
.dusk--ready .dusk__star { transition: opacity calc(var(--dk-duration) * 0.4) linear 0s; }
.dusk--ready .dusk__switch[aria-checked="true"] .dusk__star { transition: opacity calc(var(--dk-duration) * 0.5) linear calc(var(--dk-duration) * 0.5); }

/* The three-way choice. */
.dusk__choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.dusk__legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.dusk__choice { display: flex; flex-direction: column; gap: 10px; cursor: pointer; }

/* The previews always show the theme they stand for, so their colours are fixed. */
.dusk__preview {
  height: 96px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-radius: var(--dk-card-radius);
  box-shadow: 0 0 0 1px var(--dk-line);
}

.dusk__preview i { display: block; height: 6px; width: 80%; border-radius: 3px; }
.dusk__preview i:first-child { height: 8px; width: 50%; border-radius: 4px; }
.dusk__preview i:last-child { width: 70%; }

.dusk__preview--light { background: #ffffff; }
.dusk__preview--light i { background: #e4e4e7; }
.dusk__preview--light i:first-child { background: #18181b; }

.dusk__preview--dark { background: var(--dk-night-ground); }
.dusk__preview--dark i { background: #4a4470; }
.dusk__preview--dark i:first-child { background: #f4f4f5; }

.dusk__preview--system { flex-direction: row; gap: 0; padding: 0; overflow: hidden; }
.dusk__preview--system i,
.dusk__preview--system i:first-child,
.dusk__preview--system i:last-child { flex: 1; width: auto; height: auto; border-radius: 0; background: #ffffff; }
.dusk__preview--system i:last-child { background: var(--dk-night-ground); }

.dusk__choice:has(input:checked) .dusk__preview { box-shadow: 0 0 0 2px var(--dk-accent); }

.dusk__option { display: flex; align-items: center; gap: 8px; }
.dusk__choice:has(input:checked) .dusk__option { font-weight: 600; }

.dusk__option input { width: 16px; height: 16px; margin: 0; accent-color: var(--dk-accent); }
.dusk__option input:focus-visible { outline: 2px solid var(--dk-focus); outline-offset: 2px; }

/* Reduced motion: nothing moves. The sun fades out and the night fades in, over 160 ms. */
@media (prefers-reduced-motion: reduce) {
  .dusk,
  .dusk__lead { transition-duration: var(--dk-fade); transition-timing-function: linear; }
  .dusk__switch[aria-checked="true"] .dusk__sun { transform: none; opacity: 0; }
  .dusk--ready .dusk__sky,
  .dusk--ready .dusk__ground,
  .dusk--ready .dusk__sun,
  .dusk--ready .dusk__star,
  .dusk--ready .dusk__switch[aria-checked="true"] .dusk__star { transition: opacity var(--dk-fade) linear 0s; }
  .dusk--ready .dusk__horizon { transition: background-color var(--dk-fade) linear; }
  .dusk--ready .dusk__ring { transition: box-shadow var(--dk-fade) linear; }
}
