/* App subpages (privacy policy, terms of service, help centre, release notes of My School, My Kitchen and
   Vane): the portfolio's toolbar (back button, navigation title, scroll edge, the help centre's search item) and
   its page transitions. Load it after the page's own stylesheets; it undoes their old floating back button.
   Wired up by js/subpage-toolbar.js. */

/* The old floating back button's arrival, size and colours, undone for the toolbar item */
.legal-toolbar .back-link,
.legal-toolbar .back-link.is-visible {
  transition-delay: 0s;
}

.legal-toolbar .back-link {
  gap: 0;
  padding: 0;
  border: 0;
  font-size: 0;
  opacity: 1;
  filter: none;
  transform: none;
}

/* ==========================================================================
   Toolbar, as on the case studies: a glass back button on the left (the toolbar's 44px single item), with a
   navigation title beside it once the page title has scrolled up under the toolbar. Same width, side padding
   and top offset as the portfolio's toolbars. Glass tokens from css/style.css.
   ========================================================================== */

: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-icon: brightness(0) opacity(.91);
  --tb-ease: cubic-bezier(.32, .72, 0, 1);
  /* The toolbar morph's spring with its overshoot (css/style.css ::view-transition-group) */
  --tb-morph: 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);
}

@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-icon: brightness(0) invert(1) opacity(.96);
  }
}

.legal-toolbar {
  position: fixed;
  top: 12px;
  left: 0;
  right: 0;
  z-index: 70;
  width: min(100%, 1160px);
  margin-inline: auto;
  padding-inline: clamp(20px, 6vw, 48px);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.legal-toolbar .back-link {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  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%);
  pointer-events: auto;
  -webkit-user-drag: none;
  transition: background .2s, transform 420ms cubic-bezier(.22, 1, .36, 1);
  view-transition-name: tb-left;
}

.legal-toolbar .back-link img {
  width: 11px;
  height: 16px;
  object-fit: contain;
  pointer-events: none;
  filter: var(--tb-icon);
  view-transition-name: tb-left-content;
}

/* A single item: hover tints the whole glass; pressed, the whole glass squeezes, as on the case studies */
.legal-toolbar .back-link:hover {
  background: linear-gradient(var(--tb-hover), var(--tb-hover)), var(--tb-glass);
}

.legal-toolbar .back-link.is-pressed,
.legal-toolbar .back-link:hover.is-pressed {
  transform: scale(.94);
}

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

html.is-safari .legal-toolbar .back-link img {
  view-transition-name: none;
}

/* Navigation title: the page's title beside the back button, as in an iOS navigation bar once its large title
   has scrolled away; it rises into place out of a blur, and sinks back the same way */
.nav-title {
  min-width: 0;
  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 var(--tb-ease),
    filter .45s var(--tb-ease),
    transform .55s var(--tb-ease);
}

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

/* Scroll edge, as on the product page: the top frosts once the page scrolls */
.toolbar-edge {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 69;
  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;
}

/* ==========================================================================
   Help centre search toolbar item. The page's own search field no longer sticks; once it has scrolled up under
   the toolbar, a search item arrives at the trailing end (growing out of a blur, as toolbar items arrive):
   - .search-wide: a 260px glass search field, when it fits beside the back button and title;
   - otherwise a 44px glass search button. Tapping it (.is-searching) springs it out to the full width while
     the back button and title step aside, and a close button arrives at the trailing end.
   ========================================================================== */

body:has(.legal-toolbar) .search-bar {
  position: static;
}

.legal-toolbar {
  --pad: clamp(20px, 6vw, 48px);
}

.legal-toolbar.has-search .nav-title {
  margin-right: 54px;
}

/* The row the search item and close button sit in: the toolbar's content box */
.toolbar-search-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pad);
  right: var(--pad);
  pointer-events: none;
}

.toolbar-search,
.toolbar-search-close {
  position: absolute;
  top: 0;
  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%);
  transform-origin: right center;
}

/* The search item: hidden, it has shrunk away into a blur */
.toolbar-search {
  right: 0;
  width: 44px;
  overflow: hidden;
  opacity: 0;
  filter: blur(8px);
  transform: scale(.6);
  transition:
    width .7s var(--tb-morph),
    right .7s var(--tb-morph),
    opacity .3s ease,
    filter .4s ease,
    transform .6s var(--tb-ease),
    background .2s;
}

.legal-toolbar.search-shown .toolbar-search {
  opacity: 1;
  filter: none;
  transform: none;
  pointer-events: auto;
}

.legal-toolbar.search-wide .toolbar-search {
  width: 260px;
}

.legal-toolbar.is-searching .toolbar-search {
  right: 54px;
  width: calc(100% - 54px);
}

/* As a button: hover tints the whole glass, and a press squeezes it, like the back button */
.legal-toolbar:not(.search-wide, .is-searching) .toolbar-search:hover {
  background: linear-gradient(var(--tb-hover), var(--tb-hover)), var(--tb-glass);
}

.legal-toolbar.search-shown .toolbar-search.is-pressed {
  transform: scale(.94);
  transition:
    width .7s var(--tb-morph),
    right .7s var(--tb-morph),
    opacity .3s ease,
    filter .4s ease,
    transform 420ms cubic-bezier(.22, 1, .36, 1),
    background .2s;
}

.toolbar-search-button {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text-main);
  cursor: pointer;
}

.toolbar-search-button svg {
  width: 17px;
  height: 17px;
}

/* As a field, the symbol is only a label: clicks fall through to the field */
.legal-toolbar:is(.search-wide, .is-searching) .toolbar-search-button {
  pointer-events: none;
  cursor: default;
}

.toolbar-search input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0 16px 0 40px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text-main);
  font: inherit;
  font-size: 15px;
  outline: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

.toolbar-search input::placeholder {
  color: var(--text-soft);
}

.legal-toolbar:is(.search-wide, .is-searching) .toolbar-search input {
  opacity: 1;
  pointer-events: auto;
  transition: opacity .3s ease .12s;
}

.toolbar-search:focus-within {
  box-shadow:
    inset 0 0 0 1.5px var(--accent),
    inset 0 1px 1px var(--tb-hi),
    -1px 0 1px -.5px var(--tb-side-shadow),
    1px 0 1px -.5px var(--tb-side-shadow),
    var(--tb-drop);
}

.legal-toolbar:not(.search-wide, .is-searching) .toolbar-search:focus-within {
  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);
}

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

/* Close button: arrives at the trailing end once the field has sprung out */
.toolbar-search-close {
  right: 0;
  display: grid;
  place-items: center;
  width: 44px;
  padding: 0;
  border: 0;
  cursor: pointer;
  opacity: 0;
  filter: blur(8px);
  transform: scale(.6);
  transition:
    opacity .3s ease,
    filter .4s ease,
    transform .6s var(--tb-ease),
    background .2s;
}

.legal-toolbar.is-searching .toolbar-search-close {
  opacity: 1;
  filter: none;
  transform: none;
  pointer-events: auto;
  transition:
    opacity .3s ease .1s,
    filter .4s ease .1s,
    transform .6s var(--tb-ease) .1s,
    background .2s;
}

.toolbar-search-close:hover {
  background: linear-gradient(var(--tb-hover), var(--tb-hover)), var(--tb-glass);
}

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

.toolbar-search-close img {
  width: 13px;
  height: 13px;
  filter: var(--tb-icon);
}

/* Page transitions: while shown, the search item is the trailing toolbar item, so it morphs into its
   counterpart (the product page's Download Now) with its symbol blurring across, instead of zooming away
   with the page. Hidden, it takes no part. While searching, the back button has stepped aside, so it takes
   no part either and the next page's leading item simply arrives. */
.legal-toolbar.search-shown .toolbar-search {
  view-transition-name: tb-right;
}

.legal-toolbar.search-shown .toolbar-search-button {
  view-transition-name: tb-right-content;
}

html.is-safari .legal-toolbar .toolbar-search-button,
.legal-toolbar.is-searching :is(.back-link, .back-link img) {
  view-transition-name: none;
}

/* While searching, the back button and title step aside: shrinking and blurring out, as toolbar items leave */
.legal-toolbar .back-link {
  transition:
    background .2s,
    transform .6s var(--tb-ease),
    opacity .3s ease,
    filter .4s ease;
}

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

.legal-toolbar.is-searching .back-link {
  opacity: 0;
  filter: blur(8px);
  transform: scale(.6);
  pointer-events: none;
}

.legal-toolbar.is-searching .nav-title.is-visible {
  opacity: 0;
  filter: blur(6px);
  transform: translateY(10px);
}

/* ==========================================================================
   Help centre page controls in toolbar glass, at their own sizes: the search field above the topics, and the
   topic buttons. The field takes the toolbar search field's focus ring; the topic buttons tint the whole glass
   on hover and squeeze as one when pressed, like single toolbar items.
   ========================================================================== */

body:has(.legal-toolbar) .search-bar input,
body:has(.legal-toolbar) .quick-nav a {
  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%);
}

body:has(.legal-toolbar) .search-bar input {
  transition: box-shadow .2s ease;
}

body:has(.legal-toolbar) .search-bar input:focus {
  border: 0;
  background: var(--tb-glass);
  box-shadow:
    inset 0 0 0 1.5px var(--accent),
    inset 0 1px 1px var(--tb-hi),
    -1px 0 1px -.5px var(--tb-side-shadow),
    1px 0 1px -.5px var(--tb-side-shadow),
    var(--tb-drop);
}

body:has(.legal-toolbar) .quick-nav a {
  padding: 9px 18px;
  color: var(--text-main);
  -webkit-user-drag: none;
  transition: background .2s, transform .3s var(--tb-ease);
}

body:has(.legal-toolbar) .quick-nav a:hover {
  color: var(--text-main);
  background: linear-gradient(var(--tb-hover), var(--tb-hover)), var(--tb-glass);
}

body:has(.legal-toolbar) .quick-nav a:active {
  transform: scale(.94);
  transition: background .2s, transform 420ms cubic-bezier(.22, 1, .36, 1);
}

body:has(.legal-toolbar) .quick-nav a:focus-visible {
  outline: 2px solid var(--text-main);
  outline-offset: 2px;
}

/* Topics land just below the toolbar (12px + 44px + a 20px breath), not under it */
body:has(.legal-toolbar) :is(.help-category, .release-card) {
  scroll-margin-top: 76px;
}

@media (prefers-reduced-motion: reduce) {
  .nav-title { filter: none; transform: none; transition: opacity .2s; }
  .legal-toolbar :is(.back-link, .toolbar-search, .toolbar-search-close) { filter: none !important; transition: opacity .2s !important; }
}

/* ==========================================================================
   Page transitions: the toolbar morph from css/style.css (also in product-page.css), so the back button
   arrives and leaves like the portfolio's toolbar items 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;
  }
}
