/* ==========================================================================
   usual.red — the timer (/timer): a page of its own, run by js/timer.js.

   The time in the middle of the screen; the item that will fall on its
   left (a wheel, closed on the one chosen), Edit, which lets the time be
   changed, on its right, Start under it; where the site's menu stands, a
   menu of its own: About me, Drop again, Delete all. Under all of it, the pile: a canvas the size of the screen,
   whose items can be taken and thrown.

   Colours, fonts and the glow are the site's (css/base.css), and so is how
   things come in and go (css/layout.css: .is-queued, .is-intro, .is-coming,
   .is-going — from clear and --intro-blur, over --intro); what the timer
   adds is in the tokens below. Its links are .ts-link, glow and all.

   data-state on .timer:
     idle     the time as set, Start; the item and the time can be changed
     editing  the time is being typed: it glows as the menu's current item
     running  counting down, Cancel; nothing can be changed
     over     the time is up: counting up in --timer-over, a plus left of
              it, Finish
   ========================================================================== */

:root {
  /* The time: Arial Regular as everything, as large as the screen lets it. */
  --type-timer: 400 clamp(72px, 17vw, 200px)/1 var(--font-arial);
  --timer-over: #1A9E3F;            /* the time worked over what was set */
  --timer-gap: 24px;                /* the time → the item, Edit */
  --timer-slot: 96px;               /* one item of the wheel */
  --timer-far: 0.55;                /* an item of the wheel one slot off the middle: its size */
  --timer-glow-room: 24px;          /* round the wheel, for the glow of its items */
}

@media (max-width: 768px) {
  :root {
    --timer-gap: 8px;
    --timer-slot: 64px;
  }
}

html,
body {
  height: 100%;
  overflow: hidden;
}

/* The credit: where the site's stands, but fixed to the screen; under the
   pile, which it lets through. While the time runs it goes as the menu
   does, and comes back with it. */
.credit {
  position: fixed;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity var(--intro) ease, filter var(--intro) ease, visibility 0s;
}

[data-state="running"] ~ .credit,
[data-state="over"] ~ .credit {
  opacity: 0;
  filter: blur(var(--intro-blur));
  visibility: hidden;
  transition: opacity var(--intro) ease, filter var(--intro) ease, visibility 0s linear var(--intro);
}

/* The pile: all of the screen, over everything (it is last in the page), the
   text too; drawn by js/timer.js. It lets the pointer through: the page
   listens (js/timer.js) and takes an item where one is drawn, whatever is
   under it. So the page takes no touch for itself (no scrolling, no zoom),
   except the wheel, which turns by it. */
.pile {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  touch-action: none;
}

.timer__wheel {
  touch-action: pan-y;
}

/* Over an item (or with one in hand): the hand, over whatever is beneath. */
html.is-grab,
html.is-grab *,
html.is-grabbing,
html.is-grabbing * {
  cursor: grab !important;
}

html.is-grabbing,
html.is-grabbing * {
  cursor: grabbing !important;
}

/* The timer lets the pointer through; only what can be pressed on it takes it
   (below). */
.timer {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--after-head);
  /* A little above the middle: the pile grows from below. */
  padding-bottom: 12vh;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.timer button,
.timer a {
  pointer-events: auto;
}

.timer button {
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* The menu: where the site's stands and set as it is, a line an item. */
.timer__menu {
  position: absolute;
  top: var(--pad-top);
  left: var(--pad-x);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  transition: opacity var(--intro) ease, filter var(--intro) ease, visibility 0s;
}

/* While the time runs the menu goes as everything does, and comes back the
   same way; gone, it can be neither pressed nor reached by the keys. */
[data-state="running"] .timer__menu,
[data-state="over"] .timer__menu {
  opacity: 0;
  filter: blur(var(--intro-blur));
  visibility: hidden;
  transition: opacity var(--intro) ease, filter var(--intro) ease, visibility 0s linear var(--intro);
}

/* About me: the site's menu item (.item__name, css/layout.css), standing
   where it stands on every page. Pressed, it lights as the site's does and
   all of this page but it blurs and fades out over --leave, as the router
   leaves a page (css/layout.css); then /about opens with it lit in the same
   place (js/timer.js). */
.timer__about {
  text-decoration: none;
}

.timer__about.is-current {
  color: var(--ink-lit);
  text-shadow: 0 0 var(--glow-blur) var(--glow);
  transition-duration: var(--glow-fade);
}

.is-leaving .timer > :not(.timer__menu),
.is-leaving .timer__menu > :not(.timer__about),
.is-leaving .credit,
.is-leaving .pile {
  opacity: 0;
  filter: blur(var(--leave-blur));
  transition: opacity var(--leave) ease, filter var(--leave) ease;
}

/* Not there: unseen, its line kept, so the others stay where they are. */
.timer__menu .is-out {
  visibility: hidden;
}

.timer .is-going {
  pointer-events: none;
}

/* Edit and, in its place while the time runs, Pause: one cell as wide as
   Edit, Pause in the middle of it. Not there: unseen, its place kept. */
.timer__side {
  grid-area: 1 / 3;
  justify-self: start;
  display: grid;
}

.timer__side > * {
  grid-area: 1 / 1;
}

.timer__pause {
  justify-self: center;
}

.timer__pause.is-out {
  visibility: hidden;
}

/* Its signs, pause and play, drawn and not set in a font: a font falling
   back to whatever has them draws the two at their own sizes and heights,
   and the sign would jump as it changes. Here both are one box, 17 × 33
   (the line), in the same place, with no underline. The characters stay in the page, as its text; the
   box is the mask the colour shows through, so the glow is the button's. */
.timer__pause {
  filter: drop-shadow(0 0 var(--glow-blur) transparent);
  transition: filter var(--glow-fade-out) ease, color var(--glow-fade-out) ease;
}

.timer__pause:hover {
  filter: drop-shadow(0 0 var(--glow-blur) var(--glow));
  transition-duration: var(--glow-fade);
}

.timer__pause span {
  display: block;
  width: 17px;
  height: 33px;
  font-size: 0;
  line-height: 0;
  background: currentColor;
  -webkit-mask: var(--sign) center / 100% 100% no-repeat;
  mask: var(--sign) center / 100% 100% no-repeat;
}

.timer__pause span[data-sign="pause"] {
  --sign: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 17 33'%3E%3Crect x='2.5' y='10' width='4' height='16'/%3E%3Crect x='10.5' y='10' width='4' height='16'/%3E%3C/svg%3E");
}

.timer__pause span[data-sign="play"] {
  --sign: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 17 33'%3E%3Cpolygon points='3,10 14,18 3,26'/%3E%3C/svg%3E");
}

/* A button whose words change (js/timer.js): the old ones go pinned where
   they stood — in the middle of Start, at the left of a menu line or of
   Pause — while the new ones come in. Out of the line, they keep its underline. */
.timer__go,
.timer__pause,
.timer__wipe {
  position: relative;
}

.timer__go > .is-going,
.timer__pause > .is-going,
.timer__wipe > .is-going {
  position: absolute;
  top: 0;
  left: 0;
  white-space: nowrap;
  text-decoration: inherit;
}

.timer__go > .is-going {
  left: 50%;
  translate: -50% 0;
}

/* ---- the row: item, time, Edit ----
   The two sides as wide as each other, so the time stands in the middle. */

.timer__row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--timer-gap);
}

.timer__clock {
  position: relative;
  display: grid;
}

/* The room the time takes: five characters of its own font, whatever it
   says and however much of it is typed, so the item and Edit stay put. */
.timer__clock::before {
  content: "00:00";
  grid-area: 1 / 1;
  font: var(--type-timer);
  visibility: hidden;
}

/* In that room, over it. What is selected in it is shown by the browser
   itself (below). */
.timer__time {
  grid-area: 1 / 1;
  outline: 0;
  font: var(--type-timer);
  color: var(--ink);
  /* From the left of its room, always: it fills it, and typed or not it
     never moves. */
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
  text-shadow: 0 0 var(--glow-blur) transparent;
  transition: text-shadow var(--glow-fade-out) ease, color var(--glow-fade-out) ease;
}

/* Typed: lit as the menu's current item. */
/* Selected: a plain, very light red behind the digits, which keep their
   colour; not the site's blurred red (css/base.css clears the browser's
   highlight for js/selection.js, which this page does not load). */
.timer__time::selection {
  background-color: #FFDDD6;
  background-color: color-mix(in srgb, var(--accent) 16%, #FFFFFF);
}

[data-state="editing"] .timer__time {
  color: var(--ink-lit);
  text-shadow: 0 0 var(--glow-blur) var(--glow);
  transition-duration: var(--glow-fade);
  cursor: text;
}

[data-state="running"] .timer__time,
[data-state="over"] .timer__time {
  cursor: default;
}

[data-state="over"] .timer__time {
  color: var(--timer-over);
}

/* The plus of the time worked over: hung left of the digits, out of the
   row, so the digits stay where they stood. */
.timer__plus {
  position: absolute;
  top: 0;
  right: 100%;
  font: var(--type-timer);
  color: var(--timer-over);
  /* It comes and goes as everything does. */
  opacity: 0;
  filter: blur(var(--intro-blur));
  transition: opacity var(--intro) ease, filter var(--intro) ease;
}

[data-state="over"] .timer__plus {
  opacity: 1;
  filter: none;
}

/* Every digit as wide as any other and no pair drawn closer, in the time,
   its room and its plus alike: the time is as wide whatever it says, and
   its digits stand still as they change. After their font: the shorthand
   puts both back to normal. */
.timer__clock::before,
.timer__time,
.timer__plus {
  font-feature-settings: "tnum";
  font-kerning: none;
}

/* Edit: a link as every other; glowing while the time is typed. */
.timer__edit {
  justify-self: start;
  transition: text-shadow var(--glow-fade-out) ease, color var(--glow-fade-out) ease, opacity var(--intro) ease, filter var(--intro) ease;
}

[data-state="editing"] .timer__edit {
  color: var(--ink-lit);
  text-shadow: 0 0 var(--glow-blur) var(--glow);
  transition-duration: var(--glow-fade);
}

/* ---- the wheel ----
   A column of the items, five slots tall, the one chosen in its middle
   slot and at full size; those above and below it smaller the further they
   are (--at, set by js/timer.js as the wheel turns). Closed, only the one
   chosen shows. It takes one slot of the row and hangs two above and two
   below; --timer-glow-room wider each side (and as much out of the row), so
   the glow of an item is not cut at its slot.

   The glow is the site's, on a picture instead of letters. Open, the item
   chosen glows, and so does any other under the pointer; closed, the one
   chosen glows under the pointer only. */

.timer__wheel {
  justify-self: end;
  width: calc(var(--timer-slot) + 2 * var(--timer-glow-room));
  height: calc(5 * var(--timer-slot));
  margin: calc(-2 * var(--timer-slot)) calc(-1 * var(--timer-glow-room));
  padding: calc(2 * var(--timer-slot)) var(--timer-glow-room);
  overflow: hidden;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  overscroll-behavior: contain;
  transition: opacity var(--intro) ease, filter var(--intro) ease;
}

.timer__wheel::-webkit-scrollbar {
  display: none;
}

.timer__wheel[aria-expanded="true"] {
  overflow-y: auto;
  pointer-events: auto;
  /* The far ends fade into the page. */
  mask-image: linear-gradient(transparent, #000 20%, #000 80%, transparent);
}

.timer__option {
  display: grid;
  place-items: center;
  width: var(--timer-slot);
  height: var(--timer-slot);
  scroll-snap-align: center;
  /* --at: 0 in the middle of the wheel, 1 a slot away or further. */
  scale: calc(1 - var(--at, 1) * (1 - var(--timer-far)));
  opacity: calc(1 - var(--at, 1) * 0.5);
  filter: drop-shadow(0 0 var(--glow-blur) transparent);
  transition: filter var(--glow-fade-out) ease;
}

.timer__option:hover,
.timer__wheel[aria-expanded="true"] .timer__option[aria-selected="true"] {
  filter: drop-shadow(0 0 var(--glow-blur) var(--glow));
  transition-duration: var(--glow-fade);
}

.timer__wheel[aria-expanded="false"] .timer__option:not([aria-selected="true"]) {
  pointer-events: none;
}

/* The picture: the others come and go with the wheel opening and closing,
   as everything does (the glow is the button's, so the two do not mix). */
.timer__option img {
  max-width: calc(0.78 * var(--timer-slot));
  max-height: calc(0.78 * var(--timer-slot));
  width: auto;
  height: auto;
  pointer-events: none;
  transition: opacity var(--intro) ease, filter var(--intro) ease;
}

/* The same picture textured (js/timer.js draws it in a canvas, its size
   set there, with room round it for the texture: as it is in the pile). */
.timer__option canvas {
  pointer-events: none;
  transition: opacity var(--intro) ease, filter var(--intro) ease;
}

.timer__wheel[aria-expanded="false"] .timer__option:not([aria-selected="true"]) img,
.timer__wheel[aria-expanded="false"] .timer__option:not([aria-selected="true"]) canvas {
  opacity: 0;
  filter: blur(var(--intro-blur));
}

/* ---- running: nothing can be changed ---- */

/* The item and Edit go as everything does, and come back the same way. */
[data-state="running"] .timer__wheel,
[data-state="over"] .timer__wheel,
[data-state="running"] .timer__edit,
[data-state="over"] .timer__edit {
  opacity: 0;
  filter: blur(var(--intro-blur));
}

.timer[data-state="running"] .timer__option,
.timer[data-state="over"] .timer__option,
.timer[data-state="running"] .timer__edit,
.timer[data-state="over"] .timer__edit {
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .timer__wheel,
  .timer__option,
  .timer__option img,
  .timer__option canvas,
  .timer__time,
  .timer__plus,
  .timer__menu,
  [data-state="running"] .timer__menu,
  [data-state="over"] .timer__menu,
  .credit,
  [data-state="running"] ~ .credit,
  [data-state="over"] ~ .credit,
  .timer__edit {
    transition: none;
  }
}
