:root {
  color-scheme: dark;
  --bg: #000000;
  --fg: #f5f5f7;
  --dim: #8a8a8e;
  --faint: #2a2a2c;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  /*
   * Pad ALL FOUR sides. env() is the live value where the WebView forwards
   * real insets (modern WebView + viewport-fit=cover); the Capacitor-injected
   * --safe-area-inset-* vars cover the fallback branch, where they are set to
   * 0px while the shell pads natively. max() is therefore safe in both
   * branches. The base clearance keeps content clear of display cutouts even
   * on devices that under-report insets (e.g. foldable cover screens).
   */
  padding:
    calc(max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px)) + clamp(16px, 6vmin, 48px))
    calc(max(env(safe-area-inset-right, 0px), var(--safe-area-inset-right, 0px)) + clamp(16px, 5vmin, 48px))
    calc(max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px)) + clamp(16px, 6vmin, 48px))
    calc(max(env(safe-area-inset-left, 0px), var(--safe-area-inset-left, 0px)) + clamp(16px, 5vmin, 48px));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overflow: hidden;
}

/* ---------- main ---------- */

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: clamp(8px, 3vmin, 32px);
}

.phase {
  flex: 0 0 auto;
}

#phase-label {
  font-size: clamp(11px, 3.6vmin, 17px);
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: var(--dim);
  font-weight: 600;
}

.timer {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4.5vmin, 44px);
  width: 100%;
}

#digits {
  background: none;
  border: 0;
  color: var(--fg);
  font: inherit;
  font-size: clamp(56px, 25vmin, 220px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  cursor: pointer;
}

.progress {
  width: min(72%, 460px);
  height: 3px;
  border-radius: 2px;
  background: var(--faint);
  overflow: hidden;
}

#bar {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: var(--fg);
  transition: width 0.25s linear;
}

.dots {
  display: flex;
  gap: clamp(9px, 2.2vmin, 22px);
  min-height: 8px;
}

.dots span {
  width: clamp(7px, 1.9vmin, 18px);
  height: clamp(7px, 1.9vmin, 18px);
  border-radius: 50%;
  background: var(--faint);
}

.dots span.done {
  background: var(--dim);
}

/* ---------- controls ---------- */

.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 8vmin, 72px);
  width: 100%;
}

.controls button {
  background: none;
  border: 0;
  color: var(--dim);
  font: inherit;
  font-size: clamp(13px, 4.2vmin, 18px);
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 12px 18px;
  min-width: 64px;
  min-height: 44px;
  cursor: pointer;
}

.controls button.primary {
  color: var(--fg);
}

.controls button:active {
  opacity: 0.55;
}

/* ---------- ambient mode (long-press) ----------
 * The glance hero: the countdown, the progress bar and the activity label
 * form ONE block, centred as a unit so the void above and below it match.
 * #app detaches to a fixed, full-viewport box: the block therefore centres
 * on the SCREEN, and body's safe-area padding (env()/--safe-area-inset-*)
 * can no longer skew the centre when the top and bottom insets differ.
 * .phase and .progress rejoin the flow as plain column items — .timer
 * stacks the digits over the bar, and .phase orders last, under the bar.
 * Cycle dots and controls stay out. The drift shifts the whole block a few
 * pixels every 45s to spare AMOLED panels from burn-in during all-night
 * dock duty. Steps, not glides — it must be imperceptible.
 */

#app.ambient {
  position: fixed;
  inset: 0;
  justify-content: center;
  gap: clamp(12px, 4.5vmin, 44px);
  animation: drift 360s steps(1, end) infinite;
}

#app.ambient .phase {
  position: static;
  order: 2;
  flex: 0 0 auto;
  text-align: center;
}

#app.ambient .phase #phase-label {
  line-height: 1.2;
}

#app.ambient .timer {
  position: static;
  flex: 0 0 auto;
  order: 1;
}

/* Glance bar: track stays faint, the fill matches the grey digits. */
#app.ambient .progress {
  position: static;
}

#app.ambient #bar {
  background: var(--dim);
}

#app.ambient .dots,
#app.ambient .controls {
  display: none;
}

#app.ambient #phase-label {
  color: #3c3c40;
}

#app.ambient #digits {
  color: #7c7c82;
  cursor: default;
}

@keyframes drift {
  0% {
    transform: translate(0, 0);
  }
  12% {
    transform: translate(3px, -2px);
  }
  25% {
    transform: translate(-2px, 3px);
  }
  37% {
    transform: translate(4px, 2px);
  }
  50% {
    transform: translate(-3px, -3px);
  }
  62% {
    transform: translate(2px, 4px);
  }
  75% {
    transform: translate(-4px, 1px);
  }
  87% {
    transform: translate(1px, -4px);
  }
  100% {
    transform: translate(0, 0);
  }
}
