/* Save island (save-island.js): a slim pill in reverse colours floating at the bottom centre of
   the page area, with an amber dot and the keyboard shortcuts shown on its buttons. */
.save-island {
  position: fixed;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 5px 5px 5px 16px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--surface);
  box-shadow: 0 14px 36px #0f172a52, 0 2px 6px #0f172a2e;
  opacity: 0;
  visibility: hidden;
  /* Scale and tilt around the bar's visual centre: the left edge before the -50% shift. */
  transform-origin: 0 50%;
  transform: translate(-50%, 18px) scale(0.94);
  transition:
    opacity 0.18s ease-in,
    transform 0.2s ease-in,
    visibility 0s linear 0.2s,
    background 0.3s ease;
}
.save-island.is-shown {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%);
  transition:
    opacity 0.2s ease-out,
    transform 0.42s cubic-bezier(0.2, 1.4, 0.4, 1),
    visibility 0s,
    background 0.3s ease;
}
.save-island-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-right: 10px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 25%, transparent);
}
.save-island-text {
  display: grid;
  min-width: 0;
  margin-right: 14px;
}
.save-island-status {
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
}
.save-island kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 5px;
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
}
/* The font sits its letters a pixel low in their line box. Trimming the box to the capitals
   centres them exactly in the buttons and key hints; older browsers get a 1px lift instead. */
@supports (text-box: trim-both cap alphabetic) {
  .save-island-label,
  .save-island-status,
  .save-island kbd {
    text-box: trim-both cap alphabetic;
  }
  .save-island kbd {
    padding: 4px 5px;
  }
}
@supports not (text-box: trim-both cap alphabetic) {
  .save-island-label,
  .save-island-status,
  .save-island kbd {
    position: relative;
    top: -1px;
  }
}
/* Shortcuts mean nothing on touch screens. */
@media (hover: none) {
  .save-island kbd {
    display: none;
  }
}
/* A field the last save rejected: the line under it, and a brief red pulse when it's scrolled to. */
.island-field-error {
  display: block;
  margin-top: 6px;
  animation: island-error-in 0.2s ease-out;
}
.island-flash {
  animation: island-flash 1.4s ease-out;
}
@keyframes island-error-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
}
/* An outline, so the field's own focus ring doesn't hide it. */
@keyframes island-flash {
  0%,
  40% {
    outline: 4px solid color-mix(in srgb, var(--danger) 30%, transparent);
    outline-offset: 1px;
  }
  100% {
    outline: 4px solid transparent;
    outline-offset: 1px;
  }
}
/* Out-specifies the theme's .button rules: the island inverts the page colours. */
html body .save-island.save-island .button.save-island-discard,
html body .save-island.save-island .button.save-island-save {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 99px;
  box-shadow: none;
  font-size: var(--text-sm);
}
html body .save-island.save-island .button.save-island-discard {
  background: none;
  color: color-mix(in srgb, var(--surface) 70%, transparent);
  font-weight: 500;
}
html body .save-island.save-island .button.save-island-discard:hover,
html body .save-island.save-island .button.save-island-discard:focus-visible {
  background: color-mix(in srgb, var(--surface) 10%, transparent);
  color: var(--surface);
}
.save-island-discard kbd {
  background: color-mix(in srgb, var(--surface) 14%, transparent);
}
html body .save-island.save-island .button.save-island-save {
  padding: 0 8px 0 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  transition: background 0.15s ease;
}
html body .save-island.save-island .button.save-island-save:hover {
  background: color-mix(in srgb, var(--ink) 8%, var(--surface));
}
html body .save-island.save-island .button.save-island-save:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--surface) 60%, transparent);
  outline-offset: 2px;
}
.save-island-save kbd {
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  color: var(--muted);
}
/* The spinner, in the button's own ink. */
html body .save-island .save-island-save[aria-busy="true"]::after {
  border-color: color-mix(in srgb, var(--ink) 35%, transparent);
  border-right-color: var(--ink);
}
html body .save-island.save-island .button.save-island-discard:focus-visible {
  outline: 2px solid color-mix(in srgb, currentColor 45%, transparent);
  outline-offset: 1px;
}
/* Trying to leave with unsaved changes. Level 1 is a short shake with a faint red tint;
   repeated attempts (data-nudge 2, 3) shake harder and add a growing red ring and glow.
   Level 4 repeats level 3 while the page dims around a spotlight on Save. */
.save-island.is-nudged {
  animation:
    save-island-shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97),
    save-island-tint 1.2s ease-out;
}
.save-island.is-nudged[data-nudge="2"] {
  animation:
    save-island-shake-2 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97),
    save-island-glow-2 2s ease-out;
}
.save-island.is-nudged[data-nudge="3"],
.save-island.is-nudged[data-nudge="4"],
.save-island.is-nudged[data-nudge="5"] {
  animation:
    save-island-shake-3 0.7s cubic-bezier(0.36, 0.07, 0.19, 0.97),
    save-island-glow-3 2.4s ease-out;
}
/* At the top level the Save button pulses too, pointing at the way out. */
.save-island.is-nudged[data-nudge="3"] .save-island-save,
.save-island.is-nudged[data-nudge="4"] .save-island-save,
.save-island.is-nudged[data-nudge="5"] .save-island-save {
  animation: save-island-point 0.9s ease-out 0.5s 2;
}
@keyframes save-island-shake {
  10%, 90% { transform: translateX(calc(-50% - 3px)); }
  20%, 80% { transform: translateX(calc(-50% + 6px)); }
  30%, 50%, 70% { transform: translateX(calc(-50% - 11px)); }
  40%, 60% { transform: translateX(calc(-50% + 11px)); }
}
@keyframes save-island-shake-2 {
  10%, 90% { transform: translateX(calc(-50% - 4px)) rotate(-0.5deg); }
  20%, 80% { transform: translateX(calc(-50% + 9px)) rotate(0.6deg); }
  30%, 50%, 70% { transform: translateX(calc(-50% - 16px)) rotate(-1deg); }
  40%, 60% { transform: translateX(calc(-50% + 16px)) rotate(1deg); }
}
@keyframes save-island-shake-3 {
  8%, 92% { transform: translateX(calc(-50% - 6px)) rotate(-1deg) scale(1.02); }
  16%, 84% { transform: translateX(calc(-50% + 13px)) rotate(1.2deg) scale(1.04); }
  24%, 40%, 56%, 72% { transform: translateX(calc(-50% - 22px)) rotate(-1.8deg) scale(1.05); }
  32%, 48%, 64% { transform: translateX(calc(-50% + 22px)) rotate(1.8deg) scale(1.05); }
}
@keyframes save-island-tint {
  0%, 30% {
    background: color-mix(in srgb, #ef4444 8%, var(--ink));
  }
  100% {
    background: var(--ink);
  }
}
@keyframes save-island-glow-2 {
  0%, 35% {
    background: color-mix(in srgb, #ef4444 14%, var(--ink));
    box-shadow: 0 0 0 2px #ef444499, 0 0 24px 2px #ef444459, 0 14px 36px #0f172a52;
  }
  100% {
    background: var(--ink);
    box-shadow: 0 0 0 0 #ef444400, 0 0 0 0 #ef444400, 0 14px 36px #0f172a52;
  }
}
@keyframes save-island-glow-3 {
  0%, 45% {
    background: color-mix(in srgb, #ef4444 22%, var(--ink));
    box-shadow: 0 0 0 2.5px #ef4444, 0 0 40px 8px #ef444480, 0 14px 36px #0f172a52;
  }
  100% {
    background: var(--ink);
    box-shadow: 0 0 0 0 #ef444400, 0 0 0 0 #ef444400, 0 14px 36px #0f172a52;
  }
}
/* Level 4: Save lifts out of the pill and keeps ringing while the spotlight is on it. */
.save-island.is-nudged[data-nudge="4"] .save-island-save,
.save-island.is-nudged[data-nudge="5"] .save-island-save {
  animation:
    save-island-lift 2.2s cubic-bezier(0.2, 1.2, 0.4, 1) 0.45s,
    save-island-point 0.9s ease-out 0.6s 3;
}
@keyframes save-island-lift {
  0%, 100% { transform: none; }
  18%, 80% { transform: scale(1.12); }
}
/* Level 5: the bar glides up to the middle of the page area and grows, until things calm down.
   The individual scale property stacks with the shake's transform rather than replacing it. */
.save-island.is-shown.is-centered {
  scale: 1.4;
  transition:
    opacity 0.2s ease-out,
    transform 0.42s cubic-bezier(0.2, 1.4, 0.4, 1),
    visibility 0s,
    background 0.3s ease,
    bottom 0.6s cubic-bezier(0.2, 1, 0.3, 1),
    scale 0.6s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.save-island.is-shown:not(.is-centered) {
  transition:
    opacity 0.2s ease-out,
    transform 0.42s cubic-bezier(0.2, 1.4, 0.4, 1),
    visibility 0s,
    background 0.3s ease,
    bottom 0.5s cubic-bezier(0.3, 0, 0.2, 1),
    scale 0.5s cubic-bezier(0.3, 0, 0.2, 1);
}
/* The page dims to a clear circle around Save, closing in from wide to tight, then lets go. */
@property --spot-r {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
.save-island-spotlight {
  --spot-r: 900px;
  position: fixed;
  inset: 0;
  z-index: 59;
  pointer-events: none;
  background: radial-gradient(
    circle at var(--spot-x, 50%) var(--spot-y, 100%),
    transparent 0 var(--spot-r),
    #05070bb3 calc(var(--spot-r) + 70px)
  );
  opacity: 0;
  transition: opacity 0.45s ease, --spot-r 0.5s ease-in;
}
.save-island-spotlight.is-on {
  --spot-r: 46px;
  opacity: 1;
  transition: opacity 0.35s ease-out, --spot-r 0.7s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes save-island-point {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--blue, #124bce) 70%, transparent); }
  100% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--blue, #124bce) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .save-island,
  .save-island.is-shown {
    transform: translateX(-50%);
    transition: opacity 0.15s linear, visibility 0s;
  }
  .island-flash,
  .island-field-error {
    animation: none;
  }
  /* No shaking or zooming: the tint, glow and a still spotlight still escalate. */
  .save-island.is-nudged[data-nudge="4"] .save-island-save,
  .save-island.is-nudged[data-nudge="5"] .save-island-save {
    animation: none;
  }
  /* Still moves to the middle and grows, but in one step. */
  .save-island.is-shown.is-centered,
  .save-island.is-shown:not(.is-centered) {
    transition: opacity 0.15s linear, visibility 0s;
  }
  .save-island-spotlight,
  .save-island-spotlight.is-on {
    --spot-r: 46px;
    transition: opacity 0.2s linear;
  }
  .save-island.is-nudged {
    animation: save-island-tint 1.2s ease-out;
  }
  .save-island.is-nudged[data-nudge="2"] {
    animation: save-island-glow-2 2s ease-out;
  }
  .save-island.is-nudged[data-nudge="3"],
  .save-island.is-nudged[data-nudge="4"],
  .save-island.is-nudged[data-nudge="5"] {
    animation: save-island-glow-3 2.4s ease-out;
  }
}

