/* The sync braid: a pale panel on a white page, three coloured cords and two steel end caps.
   The cords are painted by script.js with these colours; the panel, the words and the caps are plain CSS. */
:root {
  --page: #ffffff;          /* the page */
  --panel: #f1f2f4;         /* the sync panel */
  --ink: #16171b;           /* the words */
  --muted: #696d77;         /* the quieter words */
  --cord-1: #3a4bd6;        /* the first device's cord (the top one) */
  --cord-2: #0e8c79;        /* the second device's cord */
  --cord-3: #ee5536;        /* the third device's cord (the bottom one) */
  --offline: #b4b7be;       /* a cord whose device went offline */
  --shadow: #23262f;        /* the cords' shadow on the panel */
  --steel-hi: #fbfbfc;      /* the end caps: the light along the top */
  --steel-lo: #8e949d;      /* the end caps: the dark underside */
  --error: #cf3a22;         /* the words that say what went wrong */
  --button: #16171b;        /* the button */
  --button-ink: #ffffff;    /* its words */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap, no zoom */
html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Radio Canada Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

/* ---------------------------------------------------------------- the panel */
.sync {
  position: relative;
  width: min(380px, 100%);
  padding: 18px 20px 16px;
  border-radius: 22px;
  background: var(--panel);
  color: var(--ink);
}

.sync__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.sync__words {
  min-width: 0;
}

.sync__title {
  margin: 0;
  font-size: 16px;
  font-weight: 620;
  font-stretch: 96%;
  line-height: 1.25;
  letter-spacing: -0.012em;
}

.sync__meta {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 430;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

/* the words that change slide by themselves; the name of a device can be coloured inside them */
.sync__swap {
  display: inline-block;
}

.sync__swap b {
  font-weight: 620;
}

.sync__swap .is-error {
  color: var(--error);
}

/* the figure on the right: the percentage, then the tick */
.sync__figure {
  position: relative;
  flex: none;
  min-width: 52px;
  height: 20px;
  margin: 0;
  font-size: 16px;
  font-weight: 620;
  line-height: 20px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.sync__pct {
  display: inline-block;
}

.sync__pct.is-quiet {
  color: var(--muted);
  font-weight: 480;
  font-size: 13px;
}

.sync__tick {
  position: absolute;
  right: -2px;
  top: -2px;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--cord-2);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  visibility: hidden;
}

/* ---------------------------------------------------------------- the braid */
/* the canvas is bigger than its place: the cords' shadows and the slack cords need room round it */
.sync__bar {
  position: relative;
  height: 48px;
  margin: 14px 0 12px;
}

.sync__paint {
  position: absolute;
  pointer-events: none;
}

/* the steel end caps, a short brushed tube at each end of the braid */
.sync__cap {
  position: absolute;
  top: 50%;
  width: 20px;
  height: 26px;
  margin-top: -13px;
  border-radius: 6px;
  background:
    linear-gradient(90deg, transparent 5px, rgba(0, 0, 0, 0.16) 5px, rgba(0, 0, 0, 0.16) 6px, transparent 6px, transparent 14px, rgba(0, 0, 0, 0.16) 14px, rgba(0, 0, 0, 0.16) 15px, transparent 15px),
    linear-gradient(180deg, var(--steel-hi) 0%, #dfe2e6 26%, #b9bec5 52%, var(--steel-lo) 78%, #c5c9cf 100%);
  box-shadow:
    0 2px 3px -1px rgba(20, 22, 28, 0.32),
    0 6px 10px -6px rgba(20, 22, 28, 0.4),
    inset 0 0 0 0.5px rgba(0, 0, 0, 0.18);
}

.sync__cap--start {
  left: 0;
  box-shadow:
    3px 0 5px -2px rgba(20, 22, 28, 0.3),
    0 2px 3px -1px rgba(20, 22, 28, 0.32),
    0 6px 10px -6px rgba(20, 22, 28, 0.4),
    inset 0 0 0 0.5px rgba(0, 0, 0, 0.18);
}

.sync__cap {
  z-index: 1;
}

/* the clamp at the far end is open while the cords run into it: tall enough for all three, without the crimps; its
   shadow on the left tucks the cords under it */
.sync__cap--end {
  right: 0;
  box-shadow:
    -3px 0 5px -2px rgba(20, 22, 28, 0.3),
    0 2px 3px -1px rgba(20, 22, 28, 0.32),
    0 6px 10px -6px rgba(20, 22, 28, 0.4),
    inset 0 0 0 0.5px rgba(0, 0, 0, 0.18);
  height: 46px;
  margin-top: -23px;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--steel-hi) 0%, #dfe2e6 18%, #c3c7cd 50%, var(--steel-lo) 84%, #c5c9cf 100%);
}

.sync__cap--end.is-shut {
  background:
    linear-gradient(90deg, transparent 5px, rgba(0, 0, 0, 0.16) 5px, rgba(0, 0, 0, 0.16) 6px, transparent 6px, transparent 14px, rgba(0, 0, 0, 0.16) 14px, rgba(0, 0, 0, 0.16) 15px, transparent 15px),
    linear-gradient(180deg, var(--steel-hi) 0%, #dfe2e6 26%, #b9bec5 52%, var(--steel-lo) 78%, #c5c9cf 100%);
}

/* without WebGL the cords are three plain stripes drawn by the CSS, and everything else still works */
.sync.is-flat .sync__bar::before {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  top: 50%;
  height: 18px;
  margin-top: -9px;
  border-radius: 9px;
  background: linear-gradient(180deg, var(--cord-1) 0 33%, var(--cord-2) 33% 66%, var(--cord-3) 66%);
  opacity: 0.22;
}

.sync.is-flat .sync__bar::after {
  content: '';
  position: absolute;
  left: 10px;
  top: 50%;
  width: calc((100% - 20px) * var(--done, 0));
  height: 18px;
  margin-top: -9px;
  border-radius: 9px;
  background: linear-gradient(180deg, var(--cord-1) 0 33%, var(--cord-2) 33% 66%, var(--cord-3) 66%);
}

/* ---------------------------------------------------------------- the devices and the button */
.sync__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sync__devices {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12.5px;
  font-weight: 560;
  line-height: 1.3;
  white-space: nowrap;
}

/* the names in the colours of their cords, a little deeper so that they read well */
.sync__devices span {
  transition: color 0.4s ease;
}

.sync__devices [data-dev='0'] {
  color: color-mix(in srgb, var(--cord-1) 86%, var(--ink));
}

.sync__devices [data-dev='1'] {
  color: color-mix(in srgb, var(--cord-2) 80%, var(--ink));
}

.sync__devices [data-dev='2'] {
  color: color-mix(in srgb, var(--cord-3) 80%, var(--ink));
}

.sync__devices .sep {
  color: var(--muted);
  font-weight: 400;
}

.sync__devices [data-dev].is-off {
  color: color-mix(in srgb, var(--offline) 70%, var(--ink));
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

/* the button: its words widen on the variable width axis under the pointer, and it squashes a little when pressed */
.sync__btn {
  position: relative;
  flex: none;
  height: 34px;
  padding: 0 16px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 34px;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.sync__label {
  display: inline-block;
  font-stretch: 88%;
  transition: font-stretch 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* while the sync runs the button only pauses it: it steps back */
.sync__btn.is-quiet {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--ink) 16%, transparent);
}

@media (hover: hover) and (pointer: fine) {
  .sync__btn:hover .sync__label {
    font-stretch: 100%;
  }

  .sync__btn:hover {
    background: color-mix(in srgb, var(--button) 86%, var(--panel));
  }

  .sync__btn.is-quiet:hover {
    background: color-mix(in srgb, var(--ink) 6%, transparent);
  }
}

.sync__btn:focus-visible {
  outline: 2px solid var(--cord-1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .sync__label {
    transition: none;
  }
}
