/* The harmonograph loader: a walnut harmonograph seen from above, alone on a black page, with one line of words and
   the pills under it. The table, the pendulum, the arm, the pen and the ink are drawn by script.js with these colours. */
:root {
  --page: #000000;          /* the page */
  --text: #f1ebe2;          /* the words */
  --muted: #9a8f84;         /* the quiet words */
  --ok: #8fd7a6;            /* pattern ready */
  --wood: #6e4529;          /* the walnut table, in the light */
  --wood-dark: #3a2213;     /* the walnut table, away from the light */
  --grain: #23130a;         /* the grain of the wood */
  --brass: #cfa95f;         /* the post, the gimbal, the pendulum's bob */
  --plate: #23201d;         /* the swinging plate under the paper */
  --paper: #f3eee3;         /* the paper */
  --ink: #233056;           /* the ink while it draws */
  --tone-1: #e0503a;        /* the colours the finished pattern takes: three in a row of these five, a new start every time */
  --tone-2: #ef9f2f;
  --tone-3: #17988a;
  --tone-4: #2f55b0;
  --tone-5: #b03d7e;
  --rod: #17110d;           /* the arm, ebony */
  --pen: #12100e;           /* the pen's barrel */
  --button: #f1ebe2;        /* the main pill */
  --button-ink: #1a120c;    /* its words */
  --line: #4a4038;          /* the ring round the quiet pill */
  --focus: #e0b45e;         /* the keyboard's focus ring */
}

* {
  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(--text);
  font-family: 'Archivo 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: 40px 16px;
}

/* ---------------------------------------------------------------- the harmonograph */
.harmo {
  display: grid;
  justify-items: center;
  width: min(380px, 100%);
}

/* the table: 380 by 270 units of the drawing */
.harmo__scene {
  position: relative;
  width: 100%;
  aspect-ratio: 380 / 270;
}

.harmo__art {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

/* the plate and its paper: 188 units square, centred on 238, 135; script.js moves it with its pendulum */
.harmo__plate {
  position: absolute;
  left: 40.5263%;
  top: 15.9259%;
  width: 48.4211%;
  height: 68.1481%;
  border-radius: 3%;
  background: linear-gradient(145deg, color-mix(in srgb, var(--plate) 70%, #ffffff) 0%, var(--plate) 18%, var(--plate) 78%, color-mix(in srgb, var(--plate) 70%, #000000) 100%);
  box-shadow: inset 0 0 0 0.6px rgba(255, 255, 255, 0.09), 0 0 0 0.6px rgba(0, 0, 0, 0.7), 6px 10px 16px rgba(8, 3, 0, 0.6), 2px 3px 4px rgba(8, 3, 0, 0.45);
  will-change: transform;
}

/* the paper, 172 units on the 184 of the plate; on New pattern it is taken off and a fresh sheet is laid down */
.harmo__paper {
  position: absolute;
  left: 3.2609%;
  top: 3.2609%;
  display: block;
  width: 93.4783%;
  height: 93.4783%;
  border-radius: 1.2%;
  box-shadow: 0.6px 1.2px 2px rgba(0, 0, 0, 0.45);
}

/* ---------------------------------------------------------------- the line of words */
.harmo__status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 22px;
  margin: 16px 0 0;
  max-width: 100%;
  font-size: 15.5px;
  font-weight: 560;
  font-stretch: 96%;
  line-height: 22px;
  letter-spacing: -0.005em;
  white-space: nowrap;
}

.harmo__swap {
  display: inline-block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.harmo[data-mode='idle'] .harmo__swap,
.harmo[data-mode='reset'] .harmo__swap {
  color: var(--muted);
}

.harmo[data-mode='done'] .harmo__swap {
  color: var(--ok);
}

/* the percentage keeps its width while the figures change */
.harmo__pct {
  display: none;
  min-width: 3.1em;
  font-weight: 700;
  font-stretch: 84%;
  color: var(--muted);
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.harmo[data-mode='draw'] .harmo__pct {
  display: inline-block;
}

/* the tick of Pattern ready, drawn in by script.js */
.harmo__tick {
  display: none;
  flex: none;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: var(--ok);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}

.harmo[data-mode='done'] .harmo__tick {
  display: block;
}

/* ---------------------------------------------------------------- the pills */
.harmo__buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

/* the fill is a layer of its own that swells past the edge with a bounce, and the words widen on the width axis of
   the font; pressed, a pill squashes a little */
.pill {
  position: relative;
  display: inline-grid;
  place-items: center;
  height: 44px;
  min-width: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--button-ink);
  font: inherit;
  font-size: 14.5px;
  font-weight: 620;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: color 0.25s ease, opacity 0.25s ease;
}

.pill[hidden] {
  display: none;
}

.pill::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--button);
  transition: inset 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.25s ease, box-shadow 0.25s ease;
}

.pill__label {
  display: inline-block;
  font-stretch: 86%;
  transition: font-stretch 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pill.is-quiet {
  color: var(--text);
}

.pill.is-quiet::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line);
}

/* downloaded: the main pill turns green */
.pill.is-saved::before {
  background: var(--ok);
}

/* while the pen is drawing there is nothing to press: the main pill steps back like the quiet one */
.pill[aria-disabled='true'] {
  color: var(--muted);
  cursor: default;
}

.pill[aria-disabled='true']::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line);
}

@media (hover: hover) and (pointer: fine) {
  .pill:not([aria-disabled='true']):hover::before {
    inset: -2px -5px;
  }

  .pill:not([aria-disabled='true']):hover .pill__label {
    font-stretch: 100%;
  }

  .pill.is-quiet:not([aria-disabled='true']):hover::before {
    background: color-mix(in srgb, var(--line) 45%, transparent);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .pill::before,
  .pill__label {
    transition: none;
  }
}
