/* obipin.com/program, "Update your ObiPin": set the pin's clock, update its
   firmware and send it its home WiFi over USB.
   The site's own grammar (styles.css): the headline and one line on the
   left, the pin on the right, hairline rows for the things to do. The
   pin's cable is out until a pin answers, then it is in and the glass
   shows the pin's own clock. program.js sets main's data-view, data-link
   and data-busy. */

.bench [hidden] {
  display: none !important;
}
.bench {
  position: relative;
  border-bottom: 1px solid var(--line);
  /* clip, not hidden: a hidden box can still be scrolled by focus or
     scrollIntoView (the cable reaches past its foot), and the copy then
     jumps up inside it */
  overflow: hidden;
  overflow: clip;
}
/* the copy is anchored at the top, so a row that grows pushes only what is
   below it; the pin keeps to the middle of its own column */
.bench__grid {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  align-items: start;
  gap: clamp(32px, 6vw, 96px);
  min-height: min(calc(100vh - 72px), 880px);
  padding-block: clamp(56px, 7vw, 104px);
}
.bench__copy {
  max-width: 720px;
  padding-top: clamp(24px, 8vh, 112px);
}
.bench__title {
  font-family: var(--display);
  font-size: clamp(36px, 5.2vw, 78px);
  line-height: 0.96;
  letter-spacing: 0.005em;
  color: var(--text);
  text-wrap: balance;
}
.bench__title span {
  display: block;
  color: var(--accent);
}
.bench__line {
  margin-top: 24px;
  max-width: 34em;
  font-size: clamp(16px, 1.3vw, 18px);
  color: var(--text-2);
}
.bench__line strong {
  color: var(--text);
  font-weight: 500;
}
.bench__act {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 36px;
}

button.btn {
  appearance: none;
  cursor: pointer;
}
/* a button that can't be pressed now keeps its place and the keyboard's
   focus (aria-disabled, not disabled) */
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}
/* CONNECTING is the longer label: the button keeps one width */
#connect {
  min-width: 164px;
}
/* where the keyboard is kept when its button goes (program.js refocus) */
[tabindex="-1"]:focus {
  box-shadow: none;
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* something went wrong, in plain words */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 38em;
  margin-top: 28px;
  padding: 14px 16px;
  border: 1px solid rgba(240, 82, 82, 0.4);
  border-radius: 4px;
  background: rgba(240, 82, 82, 0.07);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}
.alert .icon {
  margin-top: 1px;
  color: #ff7a7a;
}

/* the two things to do, in hairline rows */
.tasks {
  margin: 40px 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}
.task {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px 32px;
  padding-block: 24px;
  border-bottom: 1px solid var(--line);
}
.task h2 {
  font-family: var(--label);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.12em;
  line-height: 1.5;
  color: var(--text);
}
.task__text {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 6px;
  max-width: 34em;
  font-size: 16px;
  color: var(--text-2);
  overflow-wrap: anywhere; /* a network name of 32 wide letters wraps */
}
.task__text strong {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.task__text .icon {
  width: 18px;
  height: 18px;
  margin-top: 3px;
}
.task__text[data-tone="ok"] .icon {
  color: var(--accent-hi);
}
.task__text[data-tone="err"] {
  color: var(--text);
}
.task__text[data-tone="err"] .icon {
  color: #ff7a7a;
}
.task__notes {
  margin-top: 10px;
  max-width: 38em;
  font-size: 14px;
  color: var(--text-2);
}
.task__btn {
  margin-top: 2px;
}

/* the update's progress, across the whole row: bytes the pin has taken,
   then an even sweep while it restarts and finishes */
.meter {
  grid-column: 1 / -1;
  position: relative;
  height: 6px;
  border-radius: 2px;
  background: var(--surface-3);
  overflow: hidden;
}
.meter i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.25s linear;
}
.meter[data-wait] i {
  width: 28%;
  animation: sweep 1.3s var(--ease) infinite;
}
@keyframes sweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(360%);
  }
}

/* an update about to start by itself: what, in how long, and CANCEL */
.notice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 16px;
  max-width: 38em;
  margin-top: 28px;
  padding: 14px 16px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: rgba(58, 116, 254, 0.08);
  color: var(--text);
}
.notice > .icon {
  align-self: start;
  margin-top: 2px;
  color: var(--accent-hi);
}
.notice__head {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.45;
}
.notice__head strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.notice__text {
  margin-top: 2px;
  font-size: 14px;
  color: var(--text-2);
}

/* home WiFi: a name and a password, sent to the pin */
/* minmax(0, 1fr) here and in .field and .nets: a network chip of 32 wide
   letters is cut short (its ellipsis), never widens the form past the screen */
.wifi {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  max-width: 34em;
}
.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}
.field__label,
.nets__label {
  font-family: var(--label);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--text-3);
}
.field__row {
  position: relative;
}
.field__input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: 16px/1.2 var(--sans);
  font-variant-ligatures: none;
}
.field__row .field__input {
  padding-right: 78px;
}
.field__input:hover {
  border-color: var(--text-3);
}
.field__input:focus-visible,
.field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.field__input[aria-invalid="true"] {
  border-color: rgba(240, 82, 82, 0.7);
}
.field__eye {
  all: unset;
  position: absolute;
  top: 6px;
  right: 6px;
  bottom: 6px;
  display: inline-grid;
  place-items: center;
  min-width: 60px;
  border-radius: 2px;
  font-family: var(--label);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-2);
  cursor: pointer;
}
.field__eye:hover {
  color: var(--text);
  background: var(--surface-3);
}
.field__eye:focus-visible {
  box-shadow: var(--focus);
}
/* the networks the pin itself can see: a tap fills in the name */
.nets {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}
.nets__list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.net {
  all: unset;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  box-sizing: border-box;
}
.net span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.net .icon {
  width: 15px;
  height: 15px;
  flex: none;
}
.net:hover,
.net[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
}
.net:focus-visible {
  box-shadow: var(--focus);
}
.net[data-weak] .icon {
  opacity: 0.5;
}
.wifi__hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  color: var(--text-2);
}
.wifi__hint .icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex: none;
}
.wifi__hint[data-tone="err"] {
  color: var(--text);
}
.wifi__hint[data-tone="err"] .icon {
  color: #ff7a7a;
}
.wifi__hint[data-tone="ok"] .icon {
  color: var(--accent-hi);
}
.wifi__act {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------------------------------------------------------------
   The pin, seen straight on, with its USB-C cable below it. The plug
   is out (and reaches for the port) until a pin answers.
   --------------------------------------------------------------- */
.rig {
  position: relative;
  display: grid;
  place-items: center;
  align-self: stretch;
  min-height: 480px;
}
.rig__pin {
  --s: clamp(220px, 22vw, 320px);
  position: relative;
  isolation: isolate;
  width: var(--s);
  margin-bottom: calc(var(--s) * 0.5);
}
.rig__pin::before {
  /* the pin's own light on the dark, once it is on */
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 50%;
  width: calc(var(--s) * 1.9);
  height: calc(var(--s) * 1.9);
  translate: -50% -50%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(58, 116, 254, 0.2), rgba(58, 116, 254, 0.07) 55%, rgba(58, 116, 254, 0));
  opacity: 0;
  transition: opacity 0.9s var(--ease);
  pointer-events: none;
}
.rig .pinflat {
  z-index: 1;
  width: 100%;
}
.bench[data-link="on"] .rig__pin::before {
  opacity: 1;
}

/* the glass: what the pin itself shows, sized to the pin (the lit area is
   the glass less 4.98% a side, as the site's screen images sit). Its clock
   and battery come from its hello; while it takes an update, the %. */
.face {
  position: absolute;
  inset: 4.98%;
  color: #fff;
  opacity: 0;
  transition: opacity 0.6s var(--ease) 0.15s;
}
.face:not([data-mode="off"]) {
  opacity: 1;
}
.face__bat {
  position: absolute;
  top: 3.2%;
  left: 7%;
  font-family: var(--label);
  font-weight: 700;
  font-size: 4.3cqw;
  letter-spacing: 0.06em;
  color: #9a9ca0;
}
.face__big {
  position: absolute;
  left: 0;
  right: 0;
  top: 13%;
  font-family: var(--display);
  font-size: 14.5cqw;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}
.face__label {
  position: absolute;
  left: 0;
  right: 0;
  top: 31%;
  font-family: var(--label);
  font-weight: 700;
  font-size: 4.1cqw;
  letter-spacing: 0.1em;
  text-align: center;
  color: #d9dadc;
}
.face[data-layout="update"] .face__big {
  top: 39%;
}

.cable {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: calc(var(--s) * 0.2);
  margin-left: calc(var(--s) * -0.1);
  transform: translateY(calc(var(--s) * 0.15));
  transition: transform 0.7s var(--ease);
}
.cable__plug {
  position: relative;
  width: 100%;
  height: calc(var(--s) * 0.22);
  border-radius: calc(var(--s) * 0.014) calc(var(--s) * 0.014) calc(var(--s) * 0.035) calc(var(--s) * 0.035);
  background: linear-gradient(90deg, #c2c7ce 0%, #eceef1 36%, #f7f8fa 52%, #d6dade 100%);
}
.cable__plug::before {
  /* the steel shell that goes into the pin's port */
  content: "";
  position: absolute;
  left: 20%;
  right: 20%;
  bottom: 100%;
  height: calc(var(--s) * 0.06);
  border-radius: calc(var(--s) * 0.012) calc(var(--s) * 0.012) 0 0;
  background: linear-gradient(90deg, #858b93 0%, #d2d6db 45%, #9aa0a8 100%);
}
.cable__cord {
  width: 26%;
  height: calc(var(--s) * 0.8);
  background: linear-gradient(90deg, #b8bdc5 0%, #e8eaed 50%, #c1c6cd 100%);
  -webkit-mask-image: linear-gradient(#000 0, #000 25%, transparent 100%);
  mask-image: linear-gradient(#000 0, #000 25%, transparent 100%);
}
.bench[data-view="idle"][data-link="off"] .cable {
  animation: reach 3.4s var(--ease) infinite;
}
.bench[data-link="on"] .cable {
  transform: translateY(0);
}
@keyframes reach {
  0%,
  100% {
    transform: translateY(calc(var(--s) * 0.15));
  }
  50% {
    transform: translateY(calc(var(--s) * 0.105));
  }
}

/* ---------------------------------------------------------------
   Smaller screens
   --------------------------------------------------------------- */
@media (max-width: 960px) {
  /* minmax(0, ...): a long unbroken network name must not widen the column */
  .bench__grid {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    padding-block: 48px 0;
    gap: 24px;
  }
  .bench__copy {
    padding-top: 0;
  }
  /* the pin at the top, the plug and cord below it, faded out before the edge */
  .rig {
    --rig-s: min(44vw, 220px);
    min-height: 0;
    height: calc(var(--rig-s) * 2.1);
    place-items: start center;
  }
  .rig__pin {
    --s: var(--rig-s);
    margin: calc(var(--s) * 0.06) 0 0;
  }
}
@media (max-width: 560px) {
  .task {
    grid-template-columns: minmax(0, 1fr);
  }
  .task__btn {
    width: 100%;
  }
  .bench__act .btn {
    flex: 1 1 100%;
  }
  .wifi__act .btn {
    flex: 1 1 100%;
  }
  .notice {
    grid-template-columns: auto minmax(0, 1fr);
  }
  .notice__btn {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bench[data-view="idle"][data-link="off"] .cable {
    animation: none;
  }
  .meter[data-wait] i {
    animation: none;
    width: 100%;
    opacity: 0.5;
  }
  .cable,
  .rig__pin::before,
  .face {
    transition: none;
  }
}
