/*
 * The SBB station clock (the element in SBB Resale's footer), redrawn to fill
 * whatever viewport opens it. The SVG geometry and these variable names mirror
 * @sbb-esta/lyne-elements' <sbb-clock>; the motion is driven by clock.js.
 */

:root {
  /* The names are the reference component's, so the inline SVGs keep working. */
  --sbb-clock-background-color: #fff;
  --sbb-clock-face-color: #000;
  --sbb-clock-seconds-hand-color: #eb0000;

  --clock-backdrop: #e5e5e5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --clock-backdrop: #16161a;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  padding: clamp(0.75rem, 4vmin, 3rem);
  display: grid;
  place-items: center;
  min-height: 100dvh;
  background: var(--clock-backdrop);
}

/*
 * vmin tracks the smaller viewport side, so the clock fits a phone in portrait
 * and a widescreen monitor alike, and never overflows either axis. The padding
 * above keeps a margin once it would otherwise touch the edges.
 */
.clock {
  position: relative;
  width: min(100%, 88vmin);
  max-width: 80rem;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 50%;
  box-shadow: 0 0.25rem 1.5rem rgb(0 0 0 / 0.12);
}

/*
 * Each layer — the face and the three hands — fills the square and rotates
 * about its centre, exactly like the SVG groups in the reference component.
 */
.clock__face,
.clock__hand {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  transform: rotate(0deg);
  backface-visibility: hidden;
}

/* Only the hands move, so only they need a compositor layer. */
.clock__hand {
  will-change: transform;
}

.clock svg {
  display: block;
  width: 100%;
  height: 100%;
}

.clock__face,
.clock__hand--hours,
.clock__hand--minutes {
  fill: var(--sbb-clock-face-color);
}

.clock__hand--seconds {
  fill: var(--sbb-clock-seconds-hand-color);
}

/* The minute hand overshoots its mark and eases back, as the real one does.
 * Until the clock has read the time and set the hands (`.is-running`), the
 * transition is off so the minute hand does not spin up from twelve on load. */
.clock__hand--minutes {
  transition: transform 0.2s cubic-bezier(0.4, 2.08, 0.55, 0.44);
}

.clock:not(.is-running) .clock__hand--minutes {
  transition: none;
}

/* Only shown when scripts are blocked; the clock hands are drawn by JS. */
.fallback {
  position: fixed;
  inset-inline: 0;
  bottom: 1rem;
  margin: 0;
  text-align: center;
  color: #6b6b6b;
  font: 0.875rem/1.4 system-ui, sans-serif;
}

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