/* ==========================================================================
   Product pages' toolbar (My School, My Kitchen, Vane), as on the portfolio's homepage and case studies:
   the app icon on the left with the app's name as a navigation title once the hero has scrolled away, the
   download item on the right, the frosted scroll edge, glass page controls, and the page transitions in
   which toolbar items morph into their counterparts. Wired up by js/product-toolbar.js.
   ========================================================================== */

/* Toolbar glass (from css/style.css), shared by the download item and the carousel controls */
:root {
  --tb-glass: rgb(255 255 255 / 0.52);
  --tb-hi: rgb(255 255 255 / 0.95);
  --tb-bottom-light: rgb(255 255 255 / .76);
  --tb-side-shadow: rgb(0 0 0 / .18);
  --tb-drop: 0 3px 12px rgb(0 0 0 / 0.07), 0 0 1px rgb(0 0 0 / 0.08);
  --tb-hover: rgb(0 0 0 / 0.05);
  --tb-menu: rgb(255 255 255 / 0.58);
  --tb-thumb: rgb(0 0 0 / 0.055);
  --tb-ease: cubic-bezier(.32, .72, 0, 1);
  --tb-rim: rgb(0 0 0 / 0.13);
  --tb-menu-drop: 0 16px 44px rgb(0 0 0 / 0.16), 0 2px 6px rgb(0 0 0 / 0.06);
  --tb-spring: linear(0, .06 2.5%, .22 6%, .46 11%, .69 17%, .85 23%, .95 30%, 1.01 38%, 1.02 46%, 1.01 58%, 1);
  --tb-line: rgb(0 0 0 / 0.1);
  --tb-icon: brightness(0) opacity(.91);
}

@media (prefers-color-scheme: dark) {
  :root {
    --tb-glass: rgb(40 40 42 / 0.5);
    --tb-hi: rgb(255 255 255 / 0.13);
    --tb-bottom-light: rgb(255 255 255 / .14);
    --tb-side-shadow: rgb(0 0 0 / .52);
    --tb-drop: 0 3px 12px rgb(0 0 0 / 0.45), 0 0 1px rgb(0 0 0 / 0.6);
    --tb-hover: rgb(255 255 255 / 0.07);
    --tb-menu: rgb(44 44 46 / 0.56);
    --tb-thumb: rgb(255 255 255 / 0.07);
    --tb-rim: rgb(255 255 255 / 0.15);
    --tb-menu-drop: 0 16px 44px rgb(0 0 0 / 0.55), 0 2px 6px rgb(0 0 0 / 0.4);
    --tb-line: rgb(255 255 255 / 0.12);
    --tb-icon: brightness(0) invert(1) opacity(.96);
  }
}

/* Scroll edge, as on the homepage and case studies (css/style.css): the top frosts once the page scrolls,
   so the toolbar item stays legible over content, and morphs with theirs between pages */
.toolbar-edge {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 99;
  height: 96px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s;
  background: linear-gradient(color-mix(in srgb, var(--page-bg) 72%, transparent) 0%, color-mix(in srgb, var(--page-bg) 45%, transparent) 45%, transparent 100%);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  -webkit-mask-image: linear-gradient(#000 40%, transparent);
  mask-image: linear-gradient(#000 40%, transparent);
  view-transition-name: tb-edge;
}

body.scrolled .toolbar-edge {
  opacity: 1;
}

/* The toolbar row: the same width, side padding and top offset as the homepage's .page header and the case
   studies' .detail-actions, so the item sits exactly where the right-hand toolbar item sits on those pages */
.product-toolbar {
  position: fixed;
  top: 12px;
  left: 0;
  right: 0;
  z-index: 100;
  width: min(100%, 1160px);
  margin-inline: auto;
  padding-inline: clamp(20px, 6vw, 48px);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

/* Leading item: the app icon, as the homepage's brand icon (css/style.css .toolbar-brand) */
.toolbar-brand {
  display: flex;
  align-items: center;
  pointer-events: auto;
  /* The shadow belongs to the link, not the picture, so the picture has nothing hanging off one side
     in Safari's page transitions */
  filter: drop-shadow(0 2px 6px rgb(0 0 0 / .1)) drop-shadow(0 0 1px rgb(0 0 0 / .14));
  transition: transform .3s var(--tb-spring);
  -webkit-user-drag: none;
  view-transition-name: tb-left;
}

.toolbar-brand:active {
  transform: scale(.94);
}

.toolbar-brand img {
  display: block;
  width: 44px;
  height: 44px;
  view-transition-name: tb-left-content;
}

html.is-safari .toolbar-brand img {
  view-transition-name: none;
}

/* Navigation title: the app's name beside the icon, as on the case studies once the hero has scrolled away;
   it rises into place out of a blur, and sinks back the same way */
.product-toolbar .nav-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 10px;
  overflow: hidden;
  color: var(--text-main);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 44px;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0;
  filter: blur(6px);
  transform: translateY(10px);
  transition:
    opacity .35s cubic-bezier(.32, .72, 0, 1),
    filter .45s cubic-bezier(.32, .72, 0, 1),
    transform .55s cubic-bezier(.32, .72, 0, 1);
}

.product-toolbar .nav-title.is-visible {
  opacity: 1;
  filter: blur(0);
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .product-toolbar .nav-title { filter: none; transform: none; transition: opacity .2s; }
}

.toolbar-download {
  pointer-events: auto;

  height: 44px;

  border-radius: 999px;
  background: var(--tb-glass);
  box-shadow:
    inset 0 1px 1px var(--tb-hi),
    inset 0 -1px 1px var(--tb-bottom-light),
    -1px 0 1px -.5px var(--tb-side-shadow),
    1px 0 1px -.5px var(--tb-side-shadow),
    var(--tb-drop);
  -webkit-backdrop-filter: blur(8px) saturate(170%);
  backdrop-filter: blur(8px) saturate(170%);

  transition: background .2s;
  view-transition-name: tb-right;
}

/* A single item: the link fills the glass, so hover tints the whole pill */
.toolbar-download:hover {
  background: linear-gradient(var(--tb-hover), var(--tb-hover)), var(--tb-glass);
}

/* Pressed: the whole glass squeezes, like the case studies' back button and menus */
.toolbar-download.is-pressed {
  transform: scale(.94);
  transition: transform 420ms cubic-bezier(.22, 1, .36, 1), background .2s;
}

.toolbar-download:not(.is-pressed) {
  transition: transform 420ms cubic-bezier(.22, 1, .36, 1), background .2s;
}

.toolbar-download-link {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 18px;

  border-radius: 999px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  -webkit-user-drag: none;
  view-transition-name: tb-right-content;
}

.toolbar-download-link:focus-visible {
  outline: 2px solid var(--text-main);
  outline-offset: 2px;
}

html.is-safari .toolbar-download-link {
  view-transition-name: none;
}

/* ==========================================================================
   Page transitions: the toolbar morph from css/style.css, so the download item morphs into its counterpart
   (the homepage's LinkedIn/CV, a case study's projects menu) and the page zooms, blurs and fades.
   Keep in step with css/style.css.
   ========================================================================== */

/* Fade the page behind the toolbar without zooming its snapshot. */
html.is-safari::view-transition-old(root) {
  animation-name: page-out-flat;
}

html.is-safari::view-transition-new(root) {
  animation-name: page-in-flat;
}

@keyframes page-out-flat {
  to { opacity: 0; filter: blur(10px); }
}

@keyframes page-in-flat {
  from { opacity: 0; filter: blur(10px); }
}

@view-transition {
  navigation: auto;
}

/* Glass and content: both move and resize on a spring with a clear overshoot (the bounce) */
::view-transition-group(tb-left),
::view-transition-group(tb-centre),
::view-transition-group(tb-right),
::view-transition-group(tb-left-content),
::view-transition-group(tb-centre-content),
::view-transition-group(tb-right-content) {
  animation-duration: .7s;
  animation-timing-function: linear(0, .06 2%, .22 5%, .5 10%, .78 16%, .96 22%, 1.06 28%, 1.09 33%, 1.08 38%, 1.04 46%, 1 56%, .99 64%, 1 78%, 1);
}

/* The glass stretches to fill its morphing box (no squashed corners), crossfading as it goes, and swells
   partway through */
::view-transition-old(tb-left),
::view-transition-new(tb-left),
::view-transition-old(tb-centre),
::view-transition-new(tb-centre),
::view-transition-old(tb-right),
::view-transition-new(tb-right) {
  width: 100%;
  height: 100%;
  object-fit: fill;
  animation-duration: .3s;
}

::view-transition-old(tb-left):not(:only-child),
::view-transition-old(tb-centre):not(:only-child),
::view-transition-old(tb-right):not(:only-child) {
  animation: tb-swell .7s cubic-bezier(.32, .72, 0, 1) both, tb-glass-out .3s ease both;
}
::view-transition-new(tb-left):not(:only-child),
::view-transition-new(tb-centre):not(:only-child),
::view-transition-new(tb-right):not(:only-child) {
  animation: tb-swell .7s cubic-bezier(.32, .72, 0, 1) both, tb-glass-in .3s ease both;
}
@keyframes tb-glass-out { to { opacity: 0; } }
@keyframes tb-glass-in { from { opacity: 0; } }

@keyframes tb-swell {
  0% { transform: scale(1); }
  36% { transform: scale(1.09); }
  68% { transform: scale(.98); }
  100% { transform: scale(1); }
}

/* Content: the old symbol or label blurs and shrinks away while the new one blurs in from slightly large, each
   drawn centred at its natural size (never stretched) */
::view-transition-old(tb-left-content),
::view-transition-old(tb-centre-content),
::view-transition-old(tb-right-content),
::view-transition-new(tb-left-content),
::view-transition-new(tb-centre-content),
::view-transition-new(tb-right-content) {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: none;
  object-position: 50% 50%;
}

::view-transition-old(tb-left-content),
::view-transition-old(tb-centre-content),
::view-transition-old(tb-right-content) {
  animation: tb-blur-out .3s cubic-bezier(.4, 0, 1, 1) both;
}

::view-transition-new(tb-left-content),
::view-transition-new(tb-centre-content),
::view-transition-new(tb-right-content) {
  animation: tb-blur-in .45s cubic-bezier(0, 0, .2, 1) .14s both;
}

@keyframes tb-blur-out {
  to { opacity: 0; filter: blur(8px); transform: scale(.7); }
}

@keyframes tb-blur-in {
  from { opacity: 0; filter: blur(8px); transform: scale(1.25); }
}

/* An item with no counterpart on the other page (the browser gives it only an old or only a new picture) leaves
   or arrives in place, its glass and content together: expanding and blurring out, or settling down to size and sharpening */
::view-transition-old(tb-left):only-child,
::view-transition-old(tb-centre):only-child,
::view-transition-old(tb-right):only-child,
::view-transition-old(tb-left-content):only-child,
::view-transition-old(tb-centre-content):only-child,
::view-transition-old(tb-right-content):only-child {
  animation: tb-solo-out .4s cubic-bezier(.4, 0, .7, .2) both;
}

::view-transition-new(tb-left):only-child,
::view-transition-new(tb-centre):only-child,
::view-transition-new(tb-right):only-child,
::view-transition-new(tb-left-content):only-child,
::view-transition-new(tb-centre-content):only-child,
::view-transition-new(tb-right-content):only-child {
  animation: tb-solo-in .6s cubic-bezier(.32, .72, 0, 1) .1s both;
}

@keyframes tb-solo-out {
  to { opacity: 0; filter: blur(8px); transform: scale(1.25); }
}

@keyframes tb-solo-in {
  from { opacity: 0; filter: blur(8px); transform: scale(1.25); }
}

::view-transition-group(root) {
  animation-duration: .5s;
}

::view-transition-old(root) {
  animation: page-out .4s cubic-bezier(.4, 0, .6, 1) both;
}

::view-transition-new(root) {
  animation: page-in .75s cubic-bezier(.32, .72, 0, 1) .1s both;
}

@keyframes page-out {
  to { opacity: 0; transform: scale(.965); filter: blur(10px); }
}

@keyframes page-in {
  from { opacity: 0; transform: scale(1.035); filter: blur(10px); }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-image-pair(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

/* ==========================================================================
   Page controls as toolbar items (Get to know, Design, Intelligence): the toolbar's glass at its size, 44px.
   Single items (the play/pause button) tint the whole glass on hover and squeeze as one, like the toolbar's
   single items; grouped items (prev/next) are 38px, 3px in from one glass pill with a divider between them,
   and tint and squeeze one at a time, like the toolbar's LinkedIn/CV group.
   ========================================================================== */

.carousel-toggle,
.carousel-dots,
.design-nav-group {
  border: 0;
  background: var(--tb-glass);
  box-shadow:
    inset 0 1px 1px var(--tb-hi),
    inset 0 -1px 1px var(--tb-bottom-light),
    -1px 0 1px -.5px var(--tb-side-shadow),
    1px 0 1px -.5px var(--tb-side-shadow),
    var(--tb-drop);
  -webkit-backdrop-filter: blur(8px) saturate(170%);
  backdrop-filter: blur(8px) saturate(170%);
}

.carousel-controls {
  gap: 10px;
}

.carousel-toggle {
  width: 44px;
  height: 44px;
}

.carousel-dots {
  height: 44px;
  gap: 14px;
  padding: 0 18px;
}

.carousel-toggle .icon {
  width: 17px;
  height: 17px;
}

.carousel-toggle:hover {
  background: linear-gradient(var(--tb-hover), var(--tb-hover)), var(--tb-glass);
}

.carousel-toggle .icon,
.carousel-toggle:hover .icon,
.design-nav-btn img,
.design-nav-btn:hover img {
  filter: var(--tb-icon);
}

.carousel-controls.is-visible .carousel-toggle.is-pressed,
.carousel-controls.is-visible .carousel-toggle:hover.is-pressed {
  transform: scale(.94);
}

/* Prev/next: one glass pill that arrives as the buttons used to */
.design-nav-group {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 0 3px;
  border-radius: 999px;

  opacity: 0;
  filter: blur(20px);
  transform: translateY(120px) scale(0);
  transition:
    opacity 520ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 900ms cubic-bezier(0.34, 1.56, 0.64, 1),
    filter 900ms cubic-bezier(0.16, 1, 0.3, 1);
}

.design-nav.is-visible .design-nav-group {
  opacity: 1;
  filter: blur(0);
  transform: translateY(0) scale(1);
}

.design-nav:not(.is-visible) .design-nav-group {
  pointer-events: none;
}

/* The toolbar's divider */
.design-nav-group::before {
  content: "";
  order: 1;
  width: 1px;
  height: 20px;
  margin: 0 3px;
  background: var(--tb-line);
}

.design-nav-group .design-nav-btn:last-child {
  order: 2;
}

/* Reset the old separate-circle styles (as specific as they were) */
.design-nav .design-nav-group .design-nav-btn,
.design-nav.is-visible .design-nav-group .design-nav-btn,
.design-nav:not(.is-visible) .design-nav-group .design-nav-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: none;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  opacity: 1;
  filter: none;
  transform: none;
  transition: background .2s, transform .3s var(--tb-spring);
}

.design-nav-btn img {
  width: 11px;
  height: 16px;
}

.design-nav .design-nav-group .design-nav-btn:hover:not(:disabled) {
  background: var(--tb-hover);
}

/* Pressed: the toolbar items' squeeze, .9 on its spring */
.design-nav .design-nav-group .design-nav-btn.is-pressed,
.design-nav .design-nav-group .design-nav-btn:hover.is-pressed {
  transform: scale(.9);
}
