/* The glow behind the gallery takes the open wallpaper's color, and fades between them. */
@property --glow {
  syntax: "<color>";
  inherits: true;
  initial-value: #4f7bff;
}

:root {
  --glow: #4f7bff;
  transition: --glow 900ms ease;
  --bg: #0e1030;
  --fg: #ffffff;
  --ch: clamp(360px, calc(100svh - 320px), 1000px);
  --rw: 1290; /* screen width and height in pixels, set from the page's script */
  --rh: 2796;
  --cw: min(calc(var(--ch) * var(--rw) / var(--rh)), 78vw);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: #0b0d1c;
  color: #fff;
  font-family: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: -0.01em;
}

/* ---------- opening: color field, clock, three lines ---------- */

.field {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  animation: field-in 2200ms ease both;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: var(--grain);
  background-size: 160px 160px;
  mix-blend-mode: overlay;
  opacity: 0.16;
}

/* The grain blends with what is behind it, which is costly: only keep it where it can be seen. */
body[data-zone="gallery"]::before { display: none; }

@keyframes field-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes clock-in {
  from { opacity: 0; filter: blur(16px); transform: translateY(1.5vh); }
  to { opacity: 1; filter: blur(0); transform: none; }
}

.hero {
  position: relative;
  z-index: 2;
  min-height: 100svh;
  display: grid;
  place-items: center;
  text-align: center;
}

.clock {
  animation: clock-in 2000ms var(--ease) 900ms both;
}
.clock-date {
  margin: 0;
  font-size: clamp(16px, 2.2vw, 24px);
  font-weight: 500;
  opacity: 0.85;
}
.clock-time {
  margin: 0;
  --clock: min(40vw, 62svh);
  font-size: calc(var(--clock) * var(--fit, 1));
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
}
/* AM / PM sits small beside the numbers, like on a lock screen. */
.ampm {
  margin-left: 0.1em;
  font-size: 0.16em;
  font-weight: 500;
  letter-spacing: 0;
  opacity: 0.85;
}

.cue {
  position: absolute;
  bottom: calc(28px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  margin: 0;
  font-size: 14px;
  opacity: 0;
  animation: cue-in 1200ms ease 3200ms forwards;
}
@keyframes cue-in { to { opacity: 0.6; } }

.about {
  position: relative;
  z-index: 2;
  padding: 0 clamp(24px, 8vw, 120px);
  text-align: center;
}
.line {
  min-height: 55svh;
  display: grid;
  place-items: center;
  margin: 0 auto;
  max-width: 22ch;
  font-size: clamp(30px, 5vw, 60px);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.03em;
  text-wrap: balance;
  opacity: 0.15;
}

/* ---------- gallery ---------- */

.gallery {
  position: relative;
  z-index: 3;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-top: 72px;
  background: var(--bg);
  color: var(--fg);
  transition: background-color 900ms ease, color 900ms ease;
}
.gallery::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(70% 52% at 50% 50%, color-mix(in srgb, var(--glow) 30%, transparent), transparent 74%);
}
.tabs, .foot { position: relative; z-index: 1; }

/* Sections of the gallery (Essentials, Navy) */
.tabs {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding: 0 20px 26px; /* room below, so the tabs never touch the wallpapers */
}
.tabs button {
  font: inherit;
  font-size: 14px;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 300ms ease, background-color 300ms ease, color 300ms ease, border-color 900ms ease;
}
.tabs button:hover { opacity: 1; }
.tabs button[aria-pressed="true"] {
  opacity: 1;
  border-color: color-mix(in srgb, var(--fg) 40%, transparent);
}

/* ---------- top bar ---------- */

.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px clamp(20px, 4vw, 40px);
  color: #fff;
  pointer-events: none;
  transition: color 600ms ease;
}
.bar > * { pointer-events: auto; }
body[data-zone="gallery"] .bar { color: var(--fg); }
body[data-zone="intro"] .toggle { opacity: 0; pointer-events: none; }

.mark {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.03em;
  color: inherit;
  text-decoration: none;
}

.toggle {
  font: inherit;
  font-size: 14px;
  color: inherit;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--fg) 35%, transparent);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: opacity 400ms ease, background-color 300ms ease, color 300ms ease, border-color 900ms ease;
}
.toggle[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.stage {
  position: relative; /* so card positions are measured from the stage itself */
  display: flex;
  align-items: center;
  gap: clamp(16px, 3vw, 40px);
  padding-inline: calc(50% - var(--cw) / 2);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.stage::-webkit-scrollbar { display: none; }

.card {
  position: relative;
  flex: none;
  width: var(--cw);
  aspect-ratio: var(--rw) / var(--rh);
  padding: 0;
  border: 0;
  border-radius: calc(var(--cw) * 0.14);
  font: inherit;
  overflow: hidden;
  background: transparent;
  scroll-snap-align: center;
  container-type: inline-size;
  cursor: pointer;
  /* --d is how many places away from the open wallpaper this one is: the farther, the smaller and fainter */
  --d: 1;
  opacity: max(0.14, calc(1 - var(--d) * 0.3));
  transform: scale(max(0.74, calc(1 - var(--d) * 0.07)));
  transition: transform 600ms var(--ease), opacity 600ms var(--ease);
}
.card[aria-current="true"] {
  opacity: 1;
  transform: scale(1);
  cursor: zoom-in;
  box-shadow: 0 40px 90px -40px rgba(0, 0, 0, 0.55);
}

/* Once the full-size picture is ready, the open wallpaper is a real image on top of the preview:
   that is what lets the phone offer "Save to Photos" when you press and hold it. */
.card .card-img {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card .card-img.on { display: block; }

/* Wallpapers drift in when a section opens */
@keyframes card-enter {
  from { opacity: 0; transform: translateY(18px) scale(0.9); }
}
.card.enter { animation: card-enter 800ms var(--ease) backwards; }

.card canvas {
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 500ms ease; /* a wallpaper fades in when it is ready */
}
.card canvas.ready { opacity: 1; }

/* lock screen preview */
.lock {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 7cqw;
  opacity: 0;
  pointer-events: none;
  transition: opacity 350ms ease;
}
body[data-lock="on"] .lock { opacity: 1; }

.island {
  width: 28cqw;
  height: 8cqw;
  border-radius: 8cqw;
  background: #000;
}
body[data-device="android"] .island {
  width: 5cqw;
  height: 5cqw;
  margin-top: 1cqw;
  border-radius: 50%;
}
.date {
  margin-top: 13cqw;
  font-size: 5.4cqw;
  font-weight: 500;
  opacity: 0.85;
}
.time {
  margin-top: 1cqw;
  font-size: 27cqw;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.04em;
}
.lock[data-ink="light"] { color: #fff; }
.lock[data-ink="dark"] { color: #111; }

.foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 0 20px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
}

.name {
  margin: 0;
  font-size: clamp(22px, 3vw, 28px);
  font-weight: 500;
  letter-spacing: -0.025em;
}

.download {
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--bg);
  background: var(--fg);
  border: 0;
  border-radius: 999px;
  padding: 13px 28px;
  cursor: pointer;
  transition: opacity 200ms ease, color 900ms ease, background-color 900ms ease;
}
.download:hover { opacity: 0.85; }
.download:disabled { opacity: 0.6; cursor: progress; }

/* The size picker is hidden for now: phones and foldables are sized automatically, computers get iPhone size.
   The picker and its code are kept, so it can come back (for example as a small "other devices" link). */
.spec {
  display: none;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 13px;
}
.spec label { opacity: 0.55; }
.spec select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--fg) 30%, transparent);
  border-radius: 999px;
  padding: 6px 12px;
  max-width: 62vw;
  cursor: pointer;
  transition: border-color 900ms ease;
}
.spec select option { color: #15151a; background: #fff; }

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}
.card:focus-visible { outline-offset: -4px; }

@media (max-width: 600px) {
  :root { --ch: clamp(340px, calc(100svh - 345px), 700px); }
  .bar { padding-block: 18px; }
  .clock-time { --clock: min(46vw, 62svh); }
}

/* ---------- full-screen viewer ---------- */

body.viewing { overflow: hidden; }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--bg);
  opacity: 0;
  transition: opacity 600ms ease;
}
.viewer[hidden] { display: none; }
.viewer.open { opacity: 1; }

/* The picture keeps the exact shape of the chosen screen, as large as the window allows. */
.viewer-frame {
  position: relative;
  width: min(100vw, calc(100svh * var(--rw) / var(--rh)));
  aspect-ratio: var(--rw) / var(--rh);
  container-type: inline-size;
  /* No touch-action override and no drag blocking here: the phone's own press-and-hold menu must stay available. */
  overflow: hidden;
  transform: scale(0.94);
  /* The script starts it on top of the wallpaper you tapped, so it unfolds from there. */
  transition: transform 700ms var(--ease), border-radius 700ms var(--ease);
}
.viewer.open .viewer-frame { transform: none; }

/* Two pictures sit on top of each other: the next one fades in slowly over the one before. */
.vimg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.035);
  transition: opacity 900ms ease, transform 1400ms var(--ease);
}
.vimg.shown { opacity: 1; transform: none; }

.viewer-close {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--fg);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  border: 1px solid color-mix(in srgb, var(--fg) 35%, transparent);
  border-radius: 50%;
  cursor: pointer;
  transition: opacity 300ms ease;
}

.viewer-lock {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  color: var(--fg);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  transition: opacity 300ms ease, background-color 300ms ease, color 300ms ease;
}
.viewer.chrome-hidden .viewer-lock { opacity: 0; pointer-events: none; }
/* On a computer the picture sits in the middle of the window: give it an edge so you can see its shape. */
@media (pointer: fine) {
  .viewer-frame { border-radius: 44px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--fg) 16%, transparent); }
}

.viewer-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  text-shadow: 0 1px 12px color-mix(in srgb, var(--bg) 80%, transparent);
  transition: opacity 300ms ease;
}
.viewer-name { margin: 0; font-size: 22px; font-weight: 500; letter-spacing: -0.025em; }
.viewer-hint { margin: 0; font-size: 13px; opacity: 0.75; }
.viewer.chrome-hidden .viewer-bar,
.viewer.chrome-hidden .viewer-close { opacity: 0; pointer-events: none; }
@media (pointer: fine) { .viewer-hint { display: none; } }

/* Short screens (a phone held sideways): smaller phone, name and button on one row. */
@media (max-height: 520px) {
  :root { --ch: calc(100svh - 184px); }
  .tabs { gap: 14px; padding-bottom: 8px; }
  .tabs button { padding: 4px 14px; font-size: 13px; }
  .bar { padding-block: 14px; }
  .gallery { padding-top: 56px; }
  .foot {
    flex-direction: row;
    justify-content: center;
    gap: 20px;
    padding-bottom: 12px;
  }
  .name { font-size: 20px; }
  .download { padding: 10px 22px; }
  .clock-time { --clock: min(30vw, 52svh); }
  .line { min-height: 80svh; font-size: clamp(24px, 4vw, 40px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; }
  .stage { scroll-behavior: auto; }
}

/* ---------- Liquid Glass ----------
   Every button is translucent glass: it blurs and tints whatever is behind it, has a bright edge
   along the top where light catches it, and a soft shadow. It adapts to light and dark wallpapers. */

:root {
  --glass-tint: rgba(255, 255, 255, 0.07);
  --glass-tint-strong: rgba(255, 255, 255, 0.17);
  --glass-edge: rgba(255, 255, 255, 0.2);
  --glass-hi: rgba(255, 255, 255, 0.5);
  --glass-shine: rgba(255, 255, 255, 0.3);
  --glass-shadow: rgba(0, 0, 0, 0.3);
}
:root[data-tone="light"] {
  --glass-tint: rgba(255, 255, 255, 0.34);
  --glass-tint-strong: rgba(255, 255, 255, 0.6);
  --glass-edge: rgba(255, 255, 255, 0.75);
  --glass-hi: rgba(255, 255, 255, 0.95);
  --glass-shine: rgba(255, 255, 255, 0.7);
  --glass-shadow: rgba(30, 45, 80, 0.2);
}

.toggle:not(.viewer-lock),
.glass-group,
.download { position: relative; }
/* (the close and lock buttons in the full-screen view keep their own absolute position) */

.toggle,
.glass-group,
.download,
.viewer-close {
  isolation: isolate;
  color: var(--fg);
  background: linear-gradient(180deg, var(--glass-tint-strong), var(--glass-tint));
  border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(18px) saturate(1.7);
  backdrop-filter: blur(18px) saturate(1.7);
  box-shadow:
    inset 0 1px 0 var(--glass-hi),
    inset 0 -1px 0 rgba(255, 255, 255, 0.07),
    inset 0 0 16px rgba(255, 255, 255, 0.05),
    0 10px 30px var(--glass-shadow);
  transition: transform 250ms var(--ease), background 300ms ease, box-shadow 300ms ease, border-color 600ms ease, color 600ms ease, opacity 400ms ease;
}
/* the shine: a soft highlight across the top left, as if a window were reflected in it */
.toggle::before,
.glass-group::before,
.download::before,
.viewer-close::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(130% 170% at 16% -25%, var(--glass-shine), transparent 56%);
}
.toggle:hover,
.download:hover,
.viewer-close:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0.1));
}
:root[data-tone="light"] .toggle:hover,
:root[data-tone="light"] .download:hover,
:root[data-tone="light"] .viewer-close:hover {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.46));
}
.toggle:active,
.download:active,
.viewer-close:active { transform: scale(0.96); }

/* the Lock screen preview toggle: when on, the glass glows a little brighter instead of turning solid */
.toggle[aria-pressed="true"] {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.16));
  color: var(--fg);
  border-color: var(--glass-hi);
}
:root[data-tone="light"] .toggle[aria-pressed="true"] {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.62));
}

.toggle { padding: 9px 18px; }

.download {
  padding: 13px 32px;
  font-weight: 500;
}
.download:hover { opacity: 1; }
.download:disabled { opacity: 0.7; transform: none; }

.viewer-close,
.viewer-lock { background-color: transparent; }

/* the three sections sit in one glass capsule; the open one is a brighter glass pill inside it */
.glass-group {
  display: inline-flex;
  gap: 10px;
  padding: 5px;
  border-radius: 999px;
}
.tabs button {
  position: relative;
  color: var(--fg);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 9px 20px;
  opacity: 0.72;
  transition: opacity 300ms ease, background 300ms ease, box-shadow 300ms ease, border-color 400ms ease, color 600ms ease;
}
.tabs button:hover { opacity: 1; }
.tabs button[aria-pressed="true"],
.tabs button.under-thumb { opacity: 1; }

/* The moving glass pill: it sits under the labels, follows a finger dragged along the bar,
   and settles on the nearest tab with a small overshoot. */
.glass-group { touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.glass-thumb {
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 0;
  width: 0;
  border-radius: 999px;
  pointer-events: none;
  z-index: 0;
  transform: translateX(var(--tx, 0px)) scale(var(--sc, 1));
  transition: transform 520ms cubic-bezier(0.3, 1.35, 0.4, 1), width 520ms cubic-bezier(0.3, 1.35, 0.4, 1), box-shadow 300ms ease, background 300ms ease;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.27), rgba(255, 255, 255, 0.11));
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-hi), 0 4px 14px var(--glass-shadow);
}
:root[data-tone="light"] .glass-thumb { background: linear-gradient(180deg, var(--glass-tint-strong), var(--glass-tint)); }
.glass-thumb::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(130% 170% at 16% -25%, var(--glass-shine), transparent 56%);
}
/* pressed: brighter and a little bigger, like a drop of glass under a finger */
.glass-thumb.dragging {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.16));
  box-shadow: inset 0 1px 0 var(--glass-hi), 0 8px 24px var(--glass-shadow);
}
:root[data-tone="light"] .glass-thumb.dragging { background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.7)); }
.tabs button { z-index: 1; }

/* where the screen cannot blur what is behind (older browsers), or the person asked for less transparency */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .toggle, .glass-group, .download, .viewer-close { background: rgba(40, 48, 80, 0.72); }
  :root[data-tone="light"] .toggle, :root[data-tone="light"] .glass-group, :root[data-tone="light"] .download, :root[data-tone="light"] .viewer-close { background: rgba(255, 255, 255, 0.85); }
}
@media (prefers-reduced-transparency: reduce) {
  .toggle, .glass-group, .download, .viewer-close {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgba(40, 48, 80, 0.85);
  }
  :root[data-tone="light"] .toggle, :root[data-tone="light"] .glass-group, :root[data-tone="light"] .download, :root[data-tone="light"] .viewer-close { background: rgba(255, 255, 255, 0.92); }
}

/* the glass buttons in the short, sideways phone layout stay compact */
@media (max-height: 520px) {
  .download { padding: 10px 24px; }
  .glass-group { gap: 6px; padding: 4px; }
  .tabs button { padding: 5px 14px; }
}
