:root {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  --icon-size: min(60px, 15.4vw);
  --icon-radius: calc(var(--icon-size) * 0.225);
  --grid-columns: 4;
  --status-bar-height: 44px;
  --home-bar-space: 28px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  --wallpaper: url("/home/wallpaper.svg");
  --home-glass: rgba(255, 255, 255, 0.3);
  --home-glass-edge: rgba(255, 255, 255, 0.5);
  --widget-bg: #fff;
  --widget-text: #000;
  --widget-text-dim: rgba(60, 60, 67, 0.6);
  --widget-accent: #ff3b30;
  --label-shadow:
    0 1px 2px rgba(0, 0, 0, 0.45),
    0 0 8px rgba(0, 0, 0, 0.2);
  --page-bg: #090119;
  /* An iOS-style spring (response 0.45s, damping 0.9) sampled for linear(); it
     settles in about 420ms, which is the duration to pair it with. */
  --spring: cubic-bezier(0.2, 0.9, 0.3, 1);
}

@supports (transition-timing-function: linear(0, 1)) {
  :root {
    --spring: linear(0, 0.0252, 0.0874, 0.1706, 0.2635, 0.3583, 0.4499, 0.5351, 0.6121, 0.6803, 0.7394, 0.79,
      0.8326, 0.8681, 0.8973, 0.921, 0.9401, 0.9552, 0.9672, 0.9765, 0.9836, 0.9889, 0.9929, 0.9959, 1);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --home-glass: rgba(255, 255, 255, 0.14);
    --home-glass-edge: rgba(255, 255, 255, 0.2);
    --widget-bg: #1c1c1e;
    --widget-text: #fff;
    --widget-text-dim: rgba(235, 235, 245, 0.6);
    --widget-accent: #ff453a;
  }
}

body {
  margin: 0;
  overscroll-behavior: none;
  background: var(--page-bg);
}

.home [hidden] {
  display: none !important;
}

.home,
.home * {
  box-sizing: border-box;
}

.home {
  position: relative;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: calc(var(--safe-top) + var(--status-bar-height) + 10px);
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  /* No long-press link previews or callouts, and no double-tap zoom, as on a home screen. */
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overflow: hidden;
}

.wallpaper {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--wallpaper) center / cover no-repeat;
  /* `scale`, not `transform`, so search's zoom composes with the launch zoom. */
  transition: filter 220ms ease, scale 220ms ease;
}

/* Kept on their own compositor layers for good. Promoting them only while a
   launch runs means tearing the layers down as it ends, and the repaint that
   follows shows as a flash of the bare page behind the wallpaper. */
.wallpaper,
.home-surface {
  will-change: transform;
}

[data-launch-fade] {
  will-change: opacity;
}

/* Straight after signing in, the icons settle into place as an iPhone's do on unlock. */
.home[data-unlocked] .home-surface {
  animation: unlock-settle 480ms var(--spring) backwards;
}

.home[data-unlocked] [data-launch-fade] {
  animation: unlock-reveal 280ms ease-out backwards;
}

@keyframes unlock-settle {
  from {
    scale: 1.12;
  }
}

@keyframes unlock-reveal {
  from {
    opacity: 0;
  }
}

.squircle-defs {
  position: absolute;
  width: 0;
  height: 0;
}

/* Status bar */

.status-bar {
  position: absolute;
  top: var(--safe-top);
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--status-bar-height);
  padding: 0 max(28px, var(--safe-left)) 0 max(32px, var(--safe-right));
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.status-icons {
  display: flex;
  align-items: center;
  gap: 7px;
}

.status-icons svg {
  display: block;
  fill: currentColor;
  stroke: currentColor;
}

/* Installed to the home screen, the device draws its own status bar and home indicator. */
@media (display-mode: standalone) {
  :root {
    --status-bar-height: 0px;
    --home-bar-space: 0px;
  }

  .status-bar,
  .home-bar {
    display: none;
  }
}

/* Pages and icons */

.home-surface {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  transition: filter 220ms ease, opacity 220ms ease;
}

.home.is-searching .home-surface {
  filter: blur(20px);
  opacity: 0.55;
}

.home.is-searching .wallpaper {
  filter: blur(24px);
  scale: 1.1;
}

.home-pages {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior: none;
  scrollbar-width: none;
}

.home-pages::-webkit-scrollbar {
  display: none;
}

.home-page {
  flex: 0 0 100%;
  scroll-snap-align: start;
  overflow-y: auto;
  overscroll-behavior: none;
  scrollbar-width: none;
  padding: 8px max(24px, var(--safe-left)) 24px max(24px, var(--safe-right));
}

.home-page > * {
  max-width: 400px;
  margin-inline: auto;
}

.home-empty {
  margin-top: 24px;
  text-align: center;
  font-size: 15px;
  text-shadow: var(--label-shadow);
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
  row-gap: 26px;
  justify-items: center;
}

.app-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: #fff;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.icon-tile {
  display: block;
  flex-shrink: 0;
  width: var(--icon-size);
  height: var(--icon-size);
  border-radius: var(--icon-radius);
  clip-path: url(#squircle);
  overflow: hidden;
  transition: filter 160ms ease;
}

.icon-tile svg {
  display: block;
}

.icon-tile.monogram {
  display: grid;
  place-items: center;
  color: #fff;
  font-size: calc(var(--icon-size) * 0.4);
  font-weight: 600;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.icon-tile.glyph {
  display: grid;
  place-items: center;
}

/* Lit from above, as iOS draws its icons: a soft brightening at the top and a
   touch of shade at the foot, scaled with the tile. */
.icon-tile.glyph,
.icon-tile.monogram {
  box-shadow:
    inset 0 calc(var(--icon-size) * 0.12) calc(var(--icon-size) * 0.2) rgba(255, 255, 255, 0.16),
    inset 0 calc(var(--icon-size) * -0.1) calc(var(--icon-size) * 0.2) rgba(0, 0, 0, 0.1);
}

.icon-tile.glyph svg {
  width: 62%;
  height: 62%;
  filter: drop-shadow(0 calc(var(--icon-size) * 0.012) calc(var(--icon-size) * 0.02) rgba(0, 0, 0, 0.22));
}

/* A tool's symbol: solid white, with the few line parts stroked heavily. */
.glyph-art {
  fill: #fff;
}

.glyph-art .line {
  fill: none;
  stroke: #fff;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-icon:active .icon-tile,
.app-icon.is-launching .icon-tile {
  filter: brightness(0.7);
}

.app-icon .icon-tile {
  position: relative;
}

.app-icon.is-launching .icon-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 38%;
  height: 38%;
  border: 3px solid rgb(255 255 255 / 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: icon-launch-spin 700ms linear infinite;
}

@keyframes icon-launch-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-icon.is-launching .icon-tile::after {
    animation-duration: 2s;
  }
}

@media (hover: hover) {
  .app-icon:hover .icon-tile {
    filter: brightness(1.06);
  }

  .app-icon:hover:active .icon-tile {
    filter: brightness(0.7);
  }
}

/* White over whatever the wallpaper is. The sun behind the icons is a pale
   yellow that white alone barely shows on, so each letter gets a near-black
   edge, close to an outline, and a wider halo darkens the yellow around it. */
.icon-label {
  max-width: min(100%, calc(var(--icon-size) + 24px));
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-font-smoothing: antialiased;
  text-shadow:
    0 0 1px rgba(0, 0, 0, 0.95),
    0 0 2px rgba(0, 0, 0, 0.85),
    0 1px 3px rgba(0, 0, 0, 0.7),
    0 0 8px rgba(0, 0, 0, 0.55),
    0 0 16px rgba(0, 0, 0, 0.35);
}

/* Widgets use the same two-column footprint as four app icons. */

/* Every widget on the first page, stacked with the same gap between them. */
.widget-stack {
  display: grid;
  gap: 18px;
  margin-bottom: 30px;
}

.widget-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

/* Refreshed as one piece, but laid out as the stack's own items. */
.tool-widgets {
  display: contents;
}

.widget {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 158px;
  padding: 16px;
  border-radius: 24px;
  background: var(--widget-bg);
  color: var(--widget-text);
  box-shadow: 0 2px 8px rgb(0 0 0 / 10%);
}

.widget-weekday {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--widget-accent);
}

.widget-day {
  font-size: 64px;
  font-weight: 300;
  letter-spacing: -3px;
  line-height: 1.05;
}

.widget-month {
  margin-top: auto;
  font-size: 15px;
  font-weight: 500;
}

.widget-clock-label {
  color: var(--widget-text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.widget-time {
  margin-block: auto;
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -1.5px;
  font-variant-numeric: tabular-nums;
}

.widget-greeting {
  font-size: 12px;
  font-weight: 500;
  color: var(--widget-text-dim);
}

/* A wide widget spans both columns, under the pair. */

.widget-wide {
  min-width: 0;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: filter 160ms ease;
}

.widget-wide:active {
  filter: brightness(0.85);
}

.todo-widget {
  display: grid;
  grid-template-columns: minmax(64px, auto) minmax(0, 1fr);
  gap: 16px;
}

.todo-widget-summary {
  display: flex;
  flex-direction: column;
}

.todo-widget-icon svg {
  display: block;
  fill: #007aff;
}

.todo-widget-count {
  margin-top: auto;
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

.todo-widget-name {
  margin-top: 4px;
  color: #007aff;
  font-size: 13px;
  font-weight: 600;
}

.todo-widget-list {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.todo-widget-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 0;
  font-size: 14px;
  line-height: 18px;
}

.todo-widget-list li + li {
  border-top: 0.5px solid var(--widget-separator, rgba(60, 60, 67, 0.2));
}

.todo-widget-list li::before {
  content: "";
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  border: 1.5px solid var(--widget-text-dim);
  border-radius: 50%;
  box-sizing: border-box;
}

.todo-widget-list li.is-overdue span {
  color: #ff453a;
}

.todo-widget-list span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Widgets a tool publishes: the panel draws each type, the tool only fills it. */

.tool-widget {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tool-widget-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tool-widget-tile {
  --icon-size: 22px;
  --icon-radius: 5px;
  flex-shrink: 0;
}

.tool-widget-names {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.tool-widget-app {
  color: var(--widget-text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tool-widget-title,
.tool-widget-app {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tool-widget-title {
  font-size: 14px;
  font-weight: 600;
}

.tool-widget-summary {
  flex-shrink: 0;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tool-widget-stat {
  display: flex;
  flex-direction: column;
  margin-top: auto;
}

.tool-widget-value {
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

.tool-widget-label {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
}

.tool-widget-detail {
  color: var(--widget-text-dim);
  font-size: 12px;
}

.tool-widget-bars {
  display: flex;
  flex: 1;
  align-items: stretch;
  gap: 6px;
  min-height: 92px;
}

.tool-widget-bar {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.tool-widget-bar-value {
  color: var(--widget-text-dim);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tool-widget-bar-fill {
  width: 100%;
  max-width: 22px;
  /* A zero still shows, so the day reads as empty rather than missing. */
  height: max(3px, calc(var(--fill) * 56px));
  border-radius: 4px;
  background: linear-gradient(#5ac8fa, #007aff);
}

.tool-widget-bar-label {
  overflow: hidden;
  max-width: 100%;
  color: var(--widget-text-dim);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: clip;
}

.tool-widget-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tool-widget-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: 5px 0;
  font-size: 14px;
}

.tool-widget-list li + li {
  border-top: 0.5px solid rgba(60, 60, 67, 0.2);
}

.tool-widget-item {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tool-widget-item-detail {
  flex-shrink: 0;
  color: var(--widget-text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.tool-widget-empty {
  margin: auto 0;
  color: var(--widget-text-dim);
  font-size: 14px;
}

.todo-widget-empty {
  align-self: center;
  margin: 0;
  color: var(--widget-text-dim);
  font-size: 15px;
  font-weight: 500;
}

/* Footer and dock */

.home-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 4px 0 14px;
}

.page-dots {
  display: flex;
  gap: 8px;
}

.page-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  transition: background 200ms;
}

.page-dots span.active {
  background: #fff;
}

.search-pill {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 44px;
  flex-shrink: 0;
  padding: 0 12px;
  border: 0;
  border-radius: 14px;
  background: none;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.search-pill-glass {
  position: absolute;
  z-index: -1;
  inset: 8px 0;
  border-radius: 14px;
  background: var(--home-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.search-pill-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.search-pill:active {
  filter: brightness(0.85);
}

.dock {
  display: flex;
  justify-content: center;
  gap: clamp(18px, 7vw, 28px);
  /* Clear of the bottom edge, and of the home bar where one is drawn. */
  margin: 0 max(12px, var(--safe-left)) max(14px, calc(var(--safe-bottom) + var(--home-bar-space)));
  padding: 16px 20px;
  border-radius: 36px;
  background: var(--home-glass);
  backdrop-filter: blur(40px) saturate(1.8);
  -webkit-backdrop-filter: blur(40px) saturate(1.8);
  box-shadow: inset 0 0.5px 0 var(--home-glass-edge), 0 8px 32px rgb(0 0 0 / 8%);
}

.dock form {
  margin: 0;
}

.dock .app-icon {
  width: auto;
}

.home-bar {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 134px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.9);
  transform: translateX(-50%);
}

.app-icon:focus-visible,
.search-pill:focus-visible,
.spotlight-cancel:focus-visible,
.spotlight-result:focus-visible {
  outline: 2px solid white;
  outline-offset: 4px;
  border-radius: 12px;
}

/* Spotlight */

.spotlight {
  position: absolute;
  inset: var(--visual-viewport-top, 0px) 0 auto;
  height: var(--visual-viewport-height, 100dvh);
  z-index: 5;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + var(--status-bar-height) + 8px) max(16px, var(--safe-left)) 0
    max(16px, var(--safe-right));
  animation: spotlight-in 220ms ease-out;
}

@keyframes spotlight-in {
  from {
    opacity: 0;
  }
}

.spotlight-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 40, 0.35);
  backdrop-filter: blur(40px) saturate(1.4);
  -webkit-backdrop-filter: blur(40px) saturate(1.4);
}

.spotlight-bar,
.spotlight-results,
.spotlight-empty {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin-inline: auto;
}

/* The field sits at the bottom, in thumb reach, as on the device. */
.spotlight-bar {
  order: 2;
  flex-shrink: 0;
  padding: 12px 0 max(12px, var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
}

.spotlight-field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--home-glass);
  box-shadow: inset 0 0 0 0.5px var(--home-glass-edge);
  color: rgba(255, 255, 255, 0.7);
}

.spotlight-field:focus-within {
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.4);
}

.spotlight-field svg {
  flex-shrink: 0;
}

.spotlight-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: #fff;
  font: inherit;
  font-size: 17px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.spotlight-field input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.spotlight-field input::-webkit-search-cancel-button {
  display: none;
}

.spotlight-clear {
  display: grid;
  place-items: center;
  width: 36px;
  height: 44px;
  margin-right: -10px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.spotlight-cancel {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: #fff;
  font: inherit;
  font-size: 17px;
  cursor: pointer;
}

/* Safari doesn't reliably blur a sibling backdrop through nested glass layers. */
.spotlight-content {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 16px;
}

.spotlight-heading {
  max-width: 400px;
  margin: 12px auto 8px;
  font-size: 22px;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.spotlight-results {
  --icon-size: 36px;

  margin-top: 8px;
  padding: 0;
  list-style: none;
  border-radius: 16px;
  background: var(--home-glass);
  box-shadow: inset 0 0 0 0.5px var(--home-glass-edge);
  overflow: hidden;
}

.spotlight-result {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 6px 12px;
  color: #fff;
  font-size: 17px;
  text-decoration: none;
}

.spotlight-results li:not([hidden]) ~ li .spotlight-result {
  box-shadow: inset 0 0.5px 0 rgba(255, 255, 255, 0.25);
}

.spotlight-result:active {
  background: rgba(255, 255, 255, 0.15);
}

.spotlight-empty {
  margin-top: 40px;
  text-align: center;
  font-size: 17px;
  color: rgba(255, 255, 255, 0.7);
}

/* Wider screens: a desktop launcher rather than a phone. */

@media (min-width: 768px) {
  :root {
    --icon-size: 76px;
    --grid-columns: 6;
    --status-bar-height: 0px;
    --home-bar-space: 0px;
  }

  .icon-label {
    font-size: 13px;
  }

  .status-bar,
  .home-bar {
    display: none;
  }

  .home {
    padding-top: 28px;
  }

  .home-page > * {
    max-width: 760px;
  }

  .icon-grid {
    row-gap: 30px;
  }

  .widget-stack {
    max-width: 360px;
    margin-bottom: 36px;
  }

  .dock {
    align-self: center;
    gap: 24px;
    margin-bottom: 24px;
    padding: 16px 24px;
  }
}

/* Keep both icon rows visible on compact phones without scrolling the launcher. */
@media (max-width: 767px) and (max-height: 600px) {
  .widget { min-height: 128px; padding: 12px; }
  .widget-stack { margin-bottom: 20px; }
  .widget-day { font-size: 56px; }
  .icon-grid { row-gap: 20px; }
  .home-footer { padding-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .spotlight { animation: none; }
  .home-surface, .wallpaper, .icon-tile, .page-dots span, .app-launch { transition: none; }
  .home[data-unlocked] .home-surface, .home[data-unlocked] [data-launch-fade] { animation: none; }
}

/* App window */

:root {
  --window-bg: #fff;
  --window-text: #000;
  --window-bar-bg: #f9f9f9;
  --window-bar-text: #000;
  --window-bar-edge: rgba(60, 60, 67, 0.29);
  --window-close: rgba(60, 60, 67, 0.3);
  --window-close-hover: rgba(60, 60, 67, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root {
    --window-bar-bg: #1c1c1e;
    --window-bar-text: #fff;
    --window-bar-edge: rgba(84, 84, 88, 0.65);
    --window-close: rgba(235, 235, 245, 0.3);
    --window-close-hover: rgba(235, 235, 245, 0.45);
  }
}

.app-layer,
.app-layer * {
  box-sizing: border-box;
}

.app-layer {
  position: fixed;
  inset: var(--visual-viewport-top, 0px) 0 auto;
  height: var(--visual-viewport-height, 100dvh);
  z-index: 10;
}

.app-window {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: 0 0;
  background: var(--window-bg);
  color: var(--window-text);
  outline: none;
}

.app-content {
  position: relative;
  flex: 1;
  min-height: 0;
}

.app-frame {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--window-bg);
}

/* The title bar is how a tool is closed by pointer, and on a phone it takes
   the place of the status bar, below the device's own when installed. */
.window-bar {
  position: relative;
  z-index: 1;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  height: calc(var(--safe-top) + 44px);
  padding: var(--safe-top) calc(var(--safe-right) + 52px) 0 calc(var(--safe-left) + 52px);
  border-bottom: 0.5px solid var(--window-bar-edge);
  background: var(--window-bar-bg);
  color: var(--window-bar-text);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.window-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.window-close {
  position: absolute;
  top: var(--safe-top);
  right: calc(var(--safe-right) + 4px);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--window-close);
  cursor: pointer;
}

.window-close:hover {
  color: var(--window-close-hover);
}

.window-close:focus-visible {
  outline: 2px solid #007aff;
  outline-offset: -4px;
  border-radius: 50%;
}

.app-window .window-close-mark {
  stroke: var(--window-bar-bg);
}

.app-launch {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--window-bg);
  transition: opacity 250ms ease, visibility 0s linear 250ms;
}

.app-launch.is-done {
  opacity: 0;
  visibility: hidden;
}

/* The launch icon's artwork, centred in the window and scaled to cover the
   visible rect, so the zoom starts from the icon itself. */
.app-splash {
  position: absolute;
  z-index: 6002;
  opacity: 0;
  pointer-events: none;
}

.app-splash .icon-tile {
  width: 100%;
  height: 100%;
  border-radius: 0;
  clip-path: none;
}

.home-indicator {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6000;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: calc(var(--safe-bottom) + 26px);
  padding-bottom: max(8px, var(--safe-bottom));
  touch-action: none;
  cursor: grab;
}

.home-indicator span {
  width: 134px;
  height: 5px;
  border-radius: 3px;
  background: var(--window-text);
}

@media (max-width: 767px) {
  .home[inert] > .status-bar {
    visibility: hidden;
  }
}

/* Wider screens have no home indicator to swipe. The tool's frame can't see
   the safe areas, so the window keeps it clear of a landscape phone's notch
   and of the device's own bars when installed. */
@media (min-width: 768px) {
  .app-content {
    margin: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  }

  .home-indicator {
    display: none;
  }
}

/* Settings' open and close

   Settings is a page of its own rather than a framed tool, so it opens
   out of its dock icon, and closes back into it, with a cross-document view
   transition: the browser captures the real screens and morphs one into the
   other. The motion copies a tool's launch (launch-transition.js): the same
   springs, sampled for linear(), the icon's artwork fading over the window,
   and the home screen zooming about the icon as its icons fade.
   admin-transition.js decides when it runs, and admin.css has the opening
   half. */

@view-transition {
  navigation: auto;
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}

:root {
  /* Settles in 700ms. */
  --open-spring: linear(0, 0.0217, 0.0759, 0.1499, 0.2339, 0.3214, 0.4075, 0.4893, 0.5649, 0.6332,
    0.6938, 0.7469, 0.7928, 0.8319, 0.865, 0.8926, 0.9155, 0.9342, 0.9495, 0.9617,
    0.9715, 0.9792, 0.9852, 0.9898, 0.9933, 0.996, 0.9979, 0.9993, 1.0002, 1.0008,
    1.0012, 1.0014, 1.0015, 1.0015, 1.0014, 1.0013, 1.0012, 1.0011, 1.001, 1.0008,
    1);
  /* Settles in 650ms, landing with a slight overshoot. */
  --close-spring: linear(0, 0.0224, 0.0789, 0.1564, 0.245, 0.3375, 0.4287, 0.5153, 0.5949, 0.6666,
    0.7296, 0.7842, 0.8307, 0.8696, 0.9018, 0.928, 0.9489, 0.9654, 0.9782, 0.9878,
    0.9949, 1, 1.0035, 1.0057, 1.007, 1.0076, 1.0077, 1.0074, 1.0069, 1.0063,
    1.0056, 1.0049, 1.0042, 1.0035, 1.0029, 1.0024, 1.0019, 1.0015, 1.0012, 1.0009,
    1);
}

.home > .status-bar {
  view-transition-name: status-bar;
}

.admin-launcher .icon-tile {
  view-transition-name: admin;
}

/* The icons and widgets are captured apart from the wallpaper so they can fade
   while it stays. Only during a transition, and never the dock: a captured
   element's glass can no longer blur anything outside it. */
html[data-transition] .home-pages {
  view-transition-name: home-pages;
}

/* Captured groups stack in the order their elements were found, which could
   put the arriving home screen over the departing window. */
html[data-transition]::view-transition-group(root) {
  z-index: 0;
}

html[data-transition]::view-transition-group(home-pages) {
  z-index: 1;
}

html[data-transition]::view-transition-group(admin) {
  z-index: 2;
}

html[data-transition]::view-transition-group(status-bar) {
  z-index: 3;
}

html[data-transition="close"]::view-transition-group(admin),
html[data-transition="close"]::view-transition-image-pair(admin),
html[data-transition="close"]::view-transition-old(root),
html[data-transition="close"]::view-transition-new(root),
html[data-transition="close"]::view-transition-new(home-pages) {
  animation-duration: 650ms;
  animation-fill-mode: both;
  animation-timing-function: var(--close-spring);
}

/* The window stays solid until the icon has faded in over it. */
html[data-transition="close"]::view-transition-old(admin) {
  mix-blend-mode: normal;
  animation: 650ms linear both close-window-out;
}

html[data-transition="close"]::view-transition-new(admin) {
  z-index: 1;
  mix-blend-mode: normal;
  animation: 650ms linear both close-icon-in;
}

html[data-transition="close"]::view-transition-old(root),
html[data-transition="close"]::view-transition-new(root) {
  mix-blend-mode: plus-lighter;
}

html[data-transition="close"]::view-transition-old(root) {
  animation-name: close-backdrop-out;
}

html[data-transition="close"]::view-transition-new(root) {
  transform-origin: var(--launch-x, 50%) var(--launch-y, 100%);
  animation-name: close-wallpaper-in;
}

html[data-transition="close"]::view-transition-new(home-pages) {
  transform-origin: var(--pages-x, 50%) var(--pages-y, 100%);
  animation-name: close-icons-in;
}

html[data-transition="close"]::view-transition-old(status-bar),
html[data-transition="close"]::view-transition-new(status-bar) {
  mix-blend-mode: plus-lighter;
  animation-duration: 650ms;
  animation-timing-function: linear;
  animation-fill-mode: both;
}

html[data-transition="close"]::view-transition-old(status-bar) {
  animation-name: close-status-out;
}

html[data-transition="close"]::view-transition-new(status-bar) {
  animation-name: close-status-in;
}

@keyframes close-window-out {
  42% {
    opacity: 1;
  }

  50%,
  to {
    opacity: 0;
  }
}

@keyframes close-icon-in {
  from,
  23% {
    opacity: 0;
  }

  42%,
  to {
    opacity: 1;
  }
}

@keyframes close-backdrop-out {
  to {
    opacity: 0;
  }
}

@keyframes close-wallpaper-in {
  from {
    opacity: 0;
    transform: scale(1.05);
  }
}

@keyframes close-icons-in {
  from {
    opacity: 0;
    transform: scale(1.1);
  }
}

/* The window leaves the top of the screen early in a close, so the status bar
   takes the home screen's colours early too. */
@keyframes close-status-out {
  6% {
    opacity: 1;
  }

  20%,
  to {
    opacity: 0;
  }
}

@keyframes close-status-in {
  from,
  6% {
    opacity: 0;
  }

  20%,
  to {
    opacity: 1;
  }
}

/* On a phone the window is the whole screen: its corners round off into the
   icon's as it shrinks, and the screen fills that shape however tall it is.
   The wallpaper is only ever uncovered, so it settles without fading, and the
   icons come back as the window clears them, as they do after a tool. */
@media (max-width: 767px) {
  html[data-transition="close"]::view-transition-image-pair(admin) {
    overflow: clip;
    animation-name: close-corners;
  }

  html[data-transition="close"]::view-transition-old(admin),
  html[data-transition="close"]::view-transition-new(admin) {
    height: 100%;
    object-fit: cover;
  }

  html[data-transition="close"]::view-transition-new(root) {
    animation-name: close-wallpaper-settle;
  }

  html[data-transition="close"]::view-transition-new(home-pages) {
    animation:
      650ms var(--close-spring) both close-icons-settle,
      650ms linear both close-icons-fade-in;
  }
}

@keyframes close-corners {
  from {
    border-radius: 0;
  }

  to {
    border-radius: var(--icon-radius);
  }
}

@keyframes close-wallpaper-settle {
  from {
    transform: scale(1.05);
  }
}

@keyframes close-icons-settle {
  from {
    transform: scale(1.2);
  }
}

@keyframes close-icons-fade-in {
  from,
  12% {
    opacity: 0;
  }

  45%,
  to {
    opacity: 1;
  }
}

/* Arranging the home screen */

.app-icon[data-slug] {
  -webkit-touch-callout: none;
}

/* Dock icons go unlabelled, as on iOS, unless an administrator turns labels on. */
.home:not([data-dock-labels]) .dock .icon-label {
  display: none;
}

.home[data-dock-labels] .dock {
  padding-bottom: 10px;
}

.home[data-dock-labels] .dock .icon-label {
  font-size: 11px;
}

.home.is-arranging .icon-grid .app-icon,
.home.is-arranging .dock .app-icon[data-slug] {
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.home.is-arranging .icon-grid .app-icon .icon-tile,
.home.is-arranging .dock .app-icon[data-slug] .icon-tile {
  animation: jiggle 0.26s ease-in-out infinite alternate;
}

/* Out of step with its neighbours, as iOS icons are. */
.home.is-arranging .icon-grid .app-icon:nth-child(even) .icon-tile,
.home.is-arranging .dock .app-icon[data-slug]:nth-child(even) .icon-tile {
  animation-delay: -0.13s;
  animation-direction: alternate-reverse;
}

@keyframes jiggle {
  from { rotate: -1.8deg; }
  to { rotate: 1.8deg; }
}

.app-icon.is-dragging {
  opacity: 0.2;
}

.arrange-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  pointer-events: none;
  scale: 1.1;
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, 0.35));
}

/* As on iOS: a round plus at the top left to add widgets, Done at the top
   right, both frosted glass over the jiggling home screen. */
.arrange-bar {
  position: fixed;
  top: calc(var(--safe-top) + var(--status-bar-height) + 8px);
  left: max(16px, var(--safe-left));
  right: max(16px, var(--safe-right));
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.arrange-bar[hidden] {
  display: none;
}

.arrange-bar > * {
  pointer-events: auto;
}

.arrange-add,
.arrange-done {
  border: 0;
  background: var(--home-glass);
  backdrop-filter: blur(30px) saturate(1.8);
  -webkit-backdrop-filter: blur(30px) saturate(1.8);
  box-shadow: inset 0 0.5px 0 var(--home-glass-edge), 0 6px 18px rgb(0 0 0 / 18%);
  color: #fff;
  cursor: pointer;
}

.arrange-add {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

.arrange-add svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.arrange-done {
  padding: 8px 18px;
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
}

.arrange-done:disabled {
  opacity: 0.6;
}

.arrange-hint {
  overflow: hidden;
  color: #fff;
  font-size: 13px;
  text-align: center;
  text-overflow: ellipsis;
  text-shadow: var(--label-shadow);
  white-space: nowrap;
}

/* Widgets while arranging */

.widget-item {
  position: relative;
  min-width: 0;
}

.widget-remove {
  position: absolute;
  top: -8px;
  left: -8px;
  z-index: 2;
  display: none;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(120, 120, 128, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 6px rgb(0 0 0 / 25%);
  color: #fff;
  cursor: pointer;
}

.widget-remove svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.home.is-arranging .widget-stack > .widget-item .widget-remove {
  display: grid;
}

.home.is-arranging .widget-stack > .widget-item {
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  animation: jiggle-widget 0.3s ease-in-out infinite alternate;
}

.home.is-arranging .widget-stack > .widget-item:nth-child(even) {
  animation-delay: -0.15s;
  animation-direction: alternate-reverse;
}

@keyframes jiggle-widget {
  from { rotate: -0.6deg; }
  to { rotate: 0.6deg; }
}

.widget-item.is-dragging {
  opacity: 0.25;
}

/* Specific enough to take over from the jiggle, which runs on the same element. */
.home.is-arranging .widget-stack > .widget-item.is-leaving {
  animation: widget-leave 220ms ease-in forwards;
}

.home.is-arranging .widget-stack > .widget-item.is-arriving {
  animation: widget-arrive 320ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes widget-leave {
  to { opacity: 0; scale: 0.6; }
}

@keyframes widget-arrive {
  from { opacity: 0; scale: 0.7; }
}

/* Dragging a widget lifts a copy of the whole card. */
.arrange-ghost.widget-item {
  scale: 1.03;
}

.arrange-ghost .widget-remove {
  display: none;
}

/* The widget gallery: a sheet that rises from the bottom, as on iOS. */

.widget-gallery {
  position: fixed;
  inset: 0;
  z-index: 70;
}

.widget-gallery[hidden] {
  display: none;
}

.widget-gallery-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 35%);
  animation: gallery-fade 200ms ease-out;
}

.widget-gallery-sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(100%, 520px);
  max-height: 82dvh;
  overflow-y: auto;
  padding: 10px max(20px, var(--safe-left)) calc(24px + var(--safe-bottom)) max(20px, var(--safe-right));
  border-radius: 28px 28px 0 0;
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(40px) saturate(1.8);
  -webkit-backdrop-filter: blur(40px) saturate(1.8);
  box-shadow: 0 -8px 40px rgb(0 0 0 / 35%);
  color: #fff;
  translate: -50% 0;
  animation: gallery-rise 320ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

.widget-gallery-header {
  position: sticky;
  top: -10px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -10px calc(-1 * max(20px, var(--safe-left))) 8px;
  padding: 16px max(20px, var(--safe-left)) 8px;
  background: inherit;
}

.widget-gallery-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.widget-gallery-close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(120, 120, 128, 0.32);
  color: rgba(235, 235, 245, 0.6);
  cursor: pointer;
}

.widget-gallery-close svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.widget-gallery-empty {
  margin: 24px 0;
  color: rgba(235, 235, 245, 0.6);
  font-size: 15px;
  text-align: center;
}

.widget-gallery-list {
  display: grid;
  gap: 22px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.widget-gallery-preview .widget-remove {
  display: none;
}

.widget-gallery-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.widget-gallery-name {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.widget-gallery-add {
  flex-shrink: 0;
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: #0a84ff;
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

@keyframes gallery-rise {
  from { translate: -50% 100%; }
}

@keyframes gallery-fade {
  from { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .home.is-arranging .icon-grid .app-icon .icon-tile,
  .home.is-arranging .dock .app-icon[data-slug] .icon-tile {
    animation: none;
    outline: 2px dashed rgba(255, 255, 255, 0.7);
    outline-offset: 3px;
  }

  .home.is-arranging .widget-stack > .widget-item,
  .home.is-arranging .widget-stack > .widget-item.is-leaving,
  .home.is-arranging .widget-stack > .widget-item.is-arriving,
  .widget-gallery-sheet,
  .widget-gallery-backdrop {
    animation: none;
  }
}
