:root {
  --background: #1c232e;
  --digits: #c8d0db;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
}

html,
body {
  height: 100%;
  background: var(--background);
  color: var(--digits);
  overflow: hidden;
  overscroll-behavior: none;
  /* Stray touches must never zoom, select or pop a callout. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* The background fills edge to edge (viewport-fit=cover); content stays inside the safe areas. */
#tool {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid;
  place-items: center;
}

/* Ink covers the whole screen, safe areas included, underneath the Minutes Left. */
.ink {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

/*
  Minutes Left: digit height about 60% of the shorter side.
  SF Mono's digits are about 0.7em tall and 0.6em wide, so 86vmin gives 60vmin digits.
  In portrait the width caps it, so that "99" (1.2em) still fits in about 90% of the width.
*/
.minutes-left {
  position: relative; /* above the Ink */
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: min(86vmin, 75vw);
  line-height: 1;
  letter-spacing: -0.02em;
}

/*
  Small, while the Pen is on or there's Ink: "99" fits inside the center square of a
  tic-tac-toe board over the screen (a third of its width by a third of its height),
  filling it about as much as the usual size fills the screen. 43vh gives digits about
  30vh tall, and 25vw makes "99" (1.2em) about 30vw wide. Only the size changes, at once:
  the number stays centered, and Paused and Finished apply as usual.
*/
.minutes-left.small {
  font-size: min(43vh, 25vw);
}

/*
  The line at the top, which holds the Pen Label, the Time Left or the Hint. It mirrors the
  Controls strip: 12px inside the top safe area, centered in a 72px row, dim like the Controls'
  icons. Its size never changes, it holds still, and it lets touches through to the Timer.
*/
.top-line {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: env(safe-area-inset-left);
  right: env(safe-area-inset-right);
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  opacity: 0.45;
  pointer-events: none;
}

.top-line[hidden] {
  display: none;
}

/* Time Left: small, beside the Minutes Left. 40px gives digits about as tall as the icons (28px). */
.time-left {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 40px;
}

/* The Hint at 0, and the Pen Label: a short line of words, in the system font. */
.hint,
.pen-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 20px;
  white-space: nowrap;
}

/* Finished: the 0 pulses slowly and gently until a Tap or a Drag clears it. */
.minutes-left.finished {
  animation: finished-pulse 3s ease-in-out infinite;
}

@keyframes finished-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@media (prefers-reduced-motion: reduce) {
  .minutes-left.finished {
    animation: none;
    opacity: 0.5;
  }
}

/* Paused: the digits dim to about half brightness and hold still. */
.minutes-left.paused {
  opacity: 0.5;
}

/*
  Controls: a slim strip of dim icons along the bottom, inside the safe area, with no
  labels or backdrop. Only the buttons catch touches; a touch anywhere else reaches the Tool.
  The strip is always on screen: while the Controls are hidden it holds only the Controls
  Button, centered.

  Each button is a 72px tap zone with an 8px gap between them. When the strip is wider than
  the safe area (an iPhone in portrait), the gap shrinks first, then the buttons narrow evenly,
  never below 44px (Apple's minimum touch target). They stay 72px tall, so the row always
  matches the top line's. --buttons is how many there are, set by the Controls when they draw
  (7 at most: the Controls Button, Pause or Resume, three color dots, Undo and Clear; 7 x 44px
  fits an iPhone in portrait). It counts only the Tool's buttons, as the Tool Picker is hidden
  with one Tool.
*/
#controls {
  --room: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
  --gap: clamp(0px, (var(--room) - var(--buttons, 7) * 72px) / (var(--buttons, 7) - 1), 8px);
  --button: clamp(44px, var(--room) / var(--buttons, 7), 72px);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 env(safe-area-inset-right) calc(env(safe-area-inset-bottom) + 12px) env(safe-area-inset-left);
  display: flex;
  justify-content: center;
  gap: var(--gap);
  pointer-events: none;
}

#tool-picker[hidden] {
  display: none;
}

#tool-buttons {
  display: flex;
  gap: var(--gap);
}

/* The icon or dot stays 28px whatever the tap zone's size, centered in it. */
#controls button {
  pointer-events: auto;
  flex: none;
  width: var(--button);
  height: 72px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--digits);
  opacity: 0.45;
  -webkit-appearance: none;
  appearance: none;
}

#controls button:active {
  opacity: 0.8;
}

/* A color dot keeps its own color at full strength, ringed while it's the selected one. */
#controls button.color {
  opacity: 1;
}

#controls button.color .ring {
  display: none;
}

#controls button.color[aria-pressed="true"] .ring {
  display: inline;
}

#controls svg {
  display: block;
  width: 28px;
  height: 28px;
  fill: currentColor;
}

/*
  The Footer, tiny and dim in the bottom-right corner, below the Controls' buttons (which sit
  12px inside the bottom safe area). It lets touches through to the Timer, except on Try Again,
  and never wraps.
*/
#footer {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 8px);
  bottom: calc(env(safe-area-inset-bottom) + 2px);
  font: 10px ui-monospace, "SF Mono", Menlo, monospace;
  white-space: nowrap;
  opacity: 0.3;
  pointer-events: none;
}

/* Try Again looks like the rest of the Footer, underlined to show it can be tapped. */
#footer button {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  pointer-events: auto;
}
/* An invisible tap area, much bigger than the 10px words, that doesn't move anything. */
#footer button::before {
  content: '';
  position: absolute;
  inset: -16px -12px;
}
