/*
 * study-pomo — calm minimal fullscreen timer.
 * One luminous countdown in a dark, ember-tinted room; rest shifts the
 * whole room toward moss green. All motion breathes on multi-second cycles.
 */

/* ---------- palette ---------- */

:root {
  /* focus: black, lit with pale ice blue */
  --bg: oklch(9% 0.005 240);
  --ink: oklch(92% 0.04 235);
  --ink-soft: oklch(70% 0.045 235);
  --ink-faint: oklch(53% 0.035 235);
  --ink-ghost: oklch(39% 0.028 235);
  --line: oklch(82% 0.07 235 / 0.85);
  --line-track: oklch(50% 0.03 235 / 0.2);
  --glow: oklch(75% 0.08 235 / 0.16);

  --font-clock: -apple-system, ui-sans-serif, 'Helvetica Neue', sans-serif;
  --font-serif: Baskerville, 'Iowan Old Style', Palatino, Georgia, serif;
  --fade: 3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-phase='rest'] {
  /* rest: black, with the faintest moss tint */
  --bg: oklch(8.8% 0.004 165);
  --ink: oklch(92% 0.035 160);
  --ink-soft: oklch(69% 0.03 160);
  --ink-faint: oklch(53% 0.024 160);
  --ink-ghost: oklch(39% 0.02 160);
  --line: oklch(82% 0.06 160 / 0.85);
  --line-track: oklch(50% 0.025 160 / 0.2);
  --glow: oklch(76% 0.07 160 / 0.14);
}

/* ---------- room ---------- */

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

html,
body {
  height: 100%;
}

body {
  overflow: hidden;
  background-color: var(--bg);
  transition: background-color var(--fade);
  font-family: var(--font-clock);
  user-select: none;
  -webkit-user-select: none;
}

body:not(.awake) {
  cursor: none;
}

/* depth: a faint overhead light, darkness pooling at the edges and floor */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(85% 60% at 50% 34%, oklch(100% 0 0 / 0.02), transparent 62%),
    radial-gradient(125% 95% at 50% 42%, transparent 38%, oklch(0% 0 0 / 0.5) 100%),
    linear-gradient(to top, oklch(0% 0 0 / 0.34), transparent 24%);
  pointer-events: none;
}

/* faint grain so the dark field reads as material, not void */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.035;
  pointer-events: none;
}

/* ---------- breathing halo behind the numerals ---------- */

.halo {
  position: fixed;
  left: 50%;
  top: 42%;
  z-index: 0;
  width: 82vmin;
  aspect-ratio: 1;
  pointer-events: none;
  animation: breathe 9s ease-in-out infinite alternate;
}

.halo::before,
.halo::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transition: opacity var(--fade);
}

.halo::before {
  background: radial-gradient(circle, oklch(68% 0.09 235 / 0.14), transparent 62%);
  opacity: 1;
}

.halo::after {
  background: radial-gradient(circle, oklch(68% 0.07 165 / 0.12), transparent 62%);
  opacity: 0;
}

[data-phase='rest'] .halo::before { opacity: 0; }
[data-phase='rest'] .halo::after { opacity: 1; }

@keyframes breathe {
  from { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
  to   { transform: translate(-50%, -50%) scale(1.055); opacity: 1; }
}

/* ---------- the time ---------- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  text-align: center;
  padding-bottom: 14vh;
}

.phase {
  font: italic 400 clamp(15px, 2vmin, 22px) / 1 var(--font-serif);
  letter-spacing: 0.26em;
  color: var(--ink-soft);
  transition: color var(--fade);
  margin-bottom: 3.2vmin;
  min-height: 1em; /* keeps the clock from shifting when the label is empty */
}

.clock {
  font-family: var(--font-clock);
  font-weight: 200;
  font-size: min(23vw, 38vh);
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-shadow: 0 0 110px var(--glow);
  transition: color var(--fade), text-shadow var(--fade), opacity 0.9s ease;
}

.clock--long {
  font-size: min(16.5vw, 30vh);
}

/* fixed-width cells: no jitter as digits change */
.digit {
  display: inline-block;
  width: 0.6em;
  position: relative;
}

/* the calmest thing a digit can do: a brief crossfade, no movement */
.digit__in {
  display: inline-block;
  width: 100%;
  animation: digit-in 0.3s ease-out both;
}

.digit__out {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  animation: digit-out 0.18s ease-out forwards;
}

@keyframes digit-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes digit-out {
  0% { opacity: 0.6; }
  100% { opacity: 0; }
}

.colon {
  display: inline-block;
  width: 0.34em;
}

[data-status='running'] .colon {
  animation: colon-drift 6s ease-in-out infinite;
}

@keyframes colon-drift {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

[data-status='paused'] .clock {
  opacity: 0.5;
}

.hint {
  font: italic 400 clamp(13px, 1.7vmin, 18px) / 1.4 var(--font-serif);
  letter-spacing: 0.1em;
  color: var(--ink-ghost);
  margin-top: 4.2vmin;
  min-height: 1.4em;
  transition: color var(--fade);
}

/* ---------- horizon: the remaining time as a line of light ---------- */

.horizon {
  position: fixed;
  left: 50%;
  bottom: 17vh;
  z-index: 2;
  width: 64vw;
  height: 2px;
  transform: translateX(-50%);
  background-color: var(--line-track);
  transition: background-color var(--fade);
}

.horizon__fill {
  height: 100%;
  background-color: var(--line);
  box-shadow: 0 0 14px var(--glow);
  transform-origin: 50% 50%;
  transform: scaleX(1);
  transition: transform 0.9s linear, background-color var(--fade);
  will-change: transform;
}

/* ---------- controls: present on movement, gone during focus ---------- */

.controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 5vh;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.3rem;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.awake .controls {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* while the timer runs, mouse movement reveals a single pause button — nothing else */
[data-status='running'] .idle-only {
  display: none;
}

.controls__row {
  display: flex;
  align-items: center;
  gap: 2.2rem;
}

.controls button {
  appearance: none;
  background: color-mix(in oklab, var(--ink) 3%, transparent);
  border: 1px solid color-mix(in oklab, var(--ink-ghost) 55%, transparent);
  border-radius: 999px;
  padding: 0.55rem 1.15rem;
  font: 500 12px / 1 var(--font-clock);
  letter-spacing: 0.15em;
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.3s ease, border-color 0.3s ease, background-color 0.3s ease;
}

.controls button:hover {
  color: var(--ink-soft);
  border-color: var(--ink-ghost);
  background: color-mix(in oklab, var(--ink) 6%, transparent);
}

.controls button:active {
  background: color-mix(in oklab, var(--ink) 9%, transparent);
}

.controls button:focus-visible {
  outline: 1px solid var(--ink-faint);
  outline-offset: 2px;
}

.controls .primary {
  min-width: 7.5rem;
  font-size: 12.5px;
  color: var(--ink-soft);
  border-color: color-mix(in oklab, var(--ink-faint) 60%, transparent);
  background: color-mix(in oklab, var(--ink) 6%, transparent);
}

.controls .primary:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
  background: color-mix(in oklab, var(--ink) 10%, transparent);
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.stepper__label {
  font: italic 400 13px / 1 var(--font-serif);
  letter-spacing: 0.14em;
  color: var(--ink-ghost);
  margin-right: 0.2rem;
}

.stepper__value {
  font: 300 16px / 1 var(--font-clock);
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  min-width: 2.4ch;
  text-align: center;
}

.stepper button {
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 300;
}

.presets {
  display: inline-flex;
  gap: 0.55rem;
}

.presets button {
  padding: 0.45rem 0.85rem;
  font-size: 11px;
  color: var(--ink-ghost);
  border-color: color-mix(in oklab, var(--ink-ghost) 35%, transparent);
  background: none;
  font-variant-numeric: tabular-nums;
}

.presets button:hover {
  color: var(--ink-soft);
}

.keys {
  font: italic 400 11.5px / 1 var(--font-serif);
  letter-spacing: 0.12em;
  color: var(--ink-ghost);
  opacity: 0.75;
  margin-top: 0.2rem;
}

/* ---------- the mark ---------- */

.brand {
  position: fixed;
  left: 50%;
  bottom: 1.6vh;
  z-index: 2;
  transform: translateX(-50%);
  font: italic 400 12px / 1 var(--font-serif);
  letter-spacing: 0.3em;
  margin-left: 0.15em; /* optically recenters the tracked pair */
  color: var(--ink-ghost);
  opacity: 0.38;
  pointer-events: none;
  transition: color var(--fade);
}

/* ---------- small screens ---------- */

@media (max-width: 700px) {
  .controls__row {
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .horizon {
    width: 78vw;
  }

  .keys {
    display: none;
  }
}

/* ---------- stillness for those who ask for it ---------- */

@media (prefers-reduced-motion: reduce) {
  .halo {
    animation: none;
  }

  [data-status='running'] .colon {
    animation: none;
  }

  .digit__in {
    animation: none;
  }

  .digit__out {
    display: none;
  }
}
