/* =====================================================================
   Day 30/30 - Focus timer

   The viewport is the progress meter. A field of light rises from the
   bottom as a focus session runs and drains back down through the break,
   so progress is read from how much light is on screen rather than from
   an arc you have to measure.

   The ground is locked dark. Light only reads as light against dark, and
   a light-mode version of this page would be a different product rather
   than the same one recoloured.
   ===================================================================== */

*,
*::before,
*::after { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color var(--flood) var(--ease);
}


/* ── tokens ─────────────────────────────────────────────────────────── */

:root {
  --ui:    'Archivo', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --label: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Written by script, 0 to 1. Focus fills toward 1, the break drains back
     to 0, so the field never jumps at a phase boundary. */
  --fill: 0;

  /* Exponential ease-out. A long duration on a linear curve feels slow;
     the same duration leaving fast and settling feels calm. */
  --ease:  cubic-bezier(0.16, 1, 0.3, 1);
  --flood: 1400ms;

  --pad: clamp(1.25rem, 5vw, 3rem);

  /* Focus: a cool dusk. The glow is the brightest thing the page can
     produce, and it is capped so the ink clears AA against it unaided. */
  --ground:     #07090E;
  --ground-rgb: 7, 9, 14;
  --field-deep: #16243A;
  --field-glow: #34617E;
  --accent:     #8FCADE;

  --ink:   #EDF1F6;
  --ink-2: rgba(237, 241, 246, 0.70);
  /* Measured, not chosen. At 0.46 the phase word came out 4.08:1 and the day
     label 3.69:1 against the brightest background either weather can put
     behind them, both under AA. 0.64 clears it everywhere with margin. */
  --ink-3: rgba(237, 241, 246, 0.64);
  --line:  rgba(237, 241, 246, 0.16);
}

/* The break is the same page in different weather. Warm, lower, softer. */
body[data-phase="break"] {
  --ground:     #0B0705;
  --ground-rgb: 11, 7, 5;
  --field-deep: #36201A;
  --field-glow: #96552A;
  --accent:     #E8A96B;
}


/* ── the field ──────────────────────────────────────────────────────── */

.field {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Ambient life in the dark, so an idle screen is weather rather than a
   black rectangle. These sit under the rise and never move with it. */
.drift {
  position: absolute;
  display: block;
  width: 78vmax;
  height: 78vmax;
  background-color: var(--field-glow);
  opacity: 0.20;
  -webkit-mask-image: radial-gradient(closest-side, #000 0%, rgba(0, 0, 0, 0.35) 52%, transparent 100%);
          mask-image: radial-gradient(closest-side, #000 0%, rgba(0, 0, 0, 0.35) 52%, transparent 100%);
  transition: background-color var(--flood) var(--ease);
  will-change: transform;
}

.drift-a { left: -30vmax; bottom: -32vmax; animation: drift-a 43s linear infinite; }
.drift-b { right: -34vmax; bottom: -40vmax; opacity: 0.13; animation: drift-b 61s linear infinite; }

/* Translate and rotate only. A scaling blurred layer is re-rasterised every
   frame; a translating one is rasterised once and composited. */
@keyframes drift-a {
  from { transform: translate3d(0, 0, 0) rotate(0deg); }
  to   { transform: translate3d(0, 0, 0) rotate(360deg); }
}
@keyframes drift-b {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  50%  { transform: translate3d(6vmax, -4vmax, 0) rotate(180deg); }
  100% { transform: translate3d(0, 0, 0) rotate(360deg); }
}

.rest {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: block;
  height: 38vh;
  background-color: var(--field-glow);
  opacity: 0.16;
  -webkit-mask-image: linear-gradient(to top, #000 0%, rgba(0, 0, 0, 0.25) 44%, transparent 100%);
          mask-image: linear-gradient(to top, #000 0%, rgba(0, 0, 0, 0.25) 44%, transparent 100%);
  transition: background-color var(--flood) var(--ease);
}

/* One element carries the transform. */
.rise {
  position: absolute;
  inset: 0;
  transform: translate3d(0, calc((1 - var(--fill)) * 100%), 0);
  transition: transform 320ms linear;
  will-change: transform;
}

/* Its children carry the colour. Solid background-color plus a mask, never
   a background-image gradient: CSS will not interpolate between two gradient
   functions, it hard-swaps them, and the focus-to-break crossfade is the most
   important moment on this page. A background-color interpolates natively. */
.rise-body,
.rise-glow {
  position: absolute;
  inset: 0;
  display: block;
  transition: background-color var(--flood) var(--ease);
}

.rise-body {
  background-color: var(--field-deep);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.45) 9%, #000 26%);
          mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.45) 9%, #000 26%);
}

/* The horizon: a band of light at the field's leading edge. */
.rise-glow {
  background-color: var(--field-glow);
  opacity: 0.5;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 11%, transparent 34%);
          mask-image: linear-gradient(to bottom, transparent 0%, #000 11%, transparent 34%);
}

/* Type sits in a pool, so its contrast is against something known rather
   than against wherever the horizon happens to be. */
.veil {
  position: absolute;
  inset: 0;
  display: block;
  background: radial-gradient(
    68% 44% at 50% 44%,
    rgba(var(--ground-rgb), 0.62) 0%,
    rgba(var(--ground-rgb), 0.34) 46%,
    rgba(var(--ground-rgb), 0) 100%
  );
  transition: background var(--flood) var(--ease);
}

/* A wide slow gradient bands badly on 8-bit displays. A little noise is the
   standard cure: it dithers the steps into each other. */
.grain {
  position: absolute;
  inset: 0;
  display: block;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}


/* ── stage ──────────────────────────────────────────────────────────── */

.stage {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding:
    calc(var(--pad) + env(safe-area-inset-top))
    calc(var(--pad) + env(safe-area-inset-right))
    calc(var(--pad) + env(safe-area-inset-bottom))
    calc(var(--pad) + env(safe-area-inset-left));
}

/* The readout and its controls are one composed cluster, centred as a unit.
   Splitting them to opposite ends of the viewport left a dead band between
   them that nothing in the design was doing anything with. */
.core {
  display: grid;
  justify-items: center;
  gap: clamp(1.75rem, 6.5vh, 3.75rem);
  width: 100%;
}

/* Both pieces of chrome live along the bottom edge. Top-right measured
   2.10:1 at full fill, because the field's horizon band lands there when the
   light has fully risen. It also leaves the top of the frame completely
   clear, which is where the rise reads best. */
.chrome {
  position: fixed;
  z-index: 40;
  bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  left: calc(var(--pad) + env(safe-area-inset-left));
}


/* ── readout ────────────────────────────────────────────────────────── */

.readout {
  text-align: center;
  max-width: 34rem;
}

.phase {
  margin: 0 0 clamp(0.5rem, 1.6vh, 1.1rem);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-3);
  transition: color 260ms var(--ease);
}

.clock {
  margin: 0;
  font-size: clamp(3.5rem, min(17vw, 23vh), 10rem);
  font-weight: 200;
  /* Archivo carries a width axis. A little extra width at this size reads as
     deliberate rather than as whatever the browser had lying around. */
  font-stretch: 112%;
  line-height: 0.94;
  letter-spacing: -0.03em;
  /* Without this the clock jitters sideways every single second. */
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  color: var(--ink);
}

.task {
  margin: clamp(0.75rem, 2vh, 1.35rem) 0 0;
  font-size: clamp(1rem, 3.4vw, 1.25rem);
  font-weight: 400;
  line-height: 1.35;
  color: var(--ink);
}

.queue {
  margin: 0.45rem 0 0;
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--ink-3);
}


/* ── controls ───────────────────────────────────────────────────────── */

.controls {
  display: grid;
  justify-items: center;
  gap: clamp(0.85rem, 2.4vh, 1.5rem);
}

.presets {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* One radius system on this page: everything interactive is a pill, and
   nothing that is not interactive has a radius at all. */
.chip {
  min-width: 3.75rem;
  min-height: 2.75rem;
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: center;
  cursor: pointer;
  transition: color 160ms var(--ease), border-color 160ms var(--ease), background-color 160ms var(--ease);
}

.chip:hover { color: var(--ink); border-color: rgba(237, 241, 246, 0.3); }
.chip:active { transform: scale(0.98); }

.chip.is-on {
  color: var(--ink);
  border-color: transparent;
  background: rgba(237, 241, 246, 0.13);
}

.chip-input {
  -moz-appearance: textfield;
  appearance: textfield;
}
.chip-input::-webkit-outer-spin-button,
.chip-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.chip-input::placeholder { color: var(--ink-3); opacity: 1; }

.actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.act {
  min-height: 2.875rem;
  padding: 0 1.6rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: opacity 160ms var(--ease), background-color 160ms var(--ease), color 160ms var(--ease), border-color 160ms var(--ease);
}

.act:active { transform: scale(0.98); }

.act-primary {
  min-width: 8.5rem;
  background: var(--ink);
  color: var(--ground);
}
.act-primary:hover { background: #fff; }

.act-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-2);
}
.act-ghost:hover { color: var(--ink); border-color: rgba(237, 241, 246, 0.3); }

.status {
  margin: 0;
  min-height: 1.15rem;
  font-size: 0.8125rem;
  color: var(--ink-3);
  text-align: center;
}

.sound {
  min-height: 2.75rem;
  margin-left: -0.85rem;
  padding: 0 0.85rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-3);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.sound:hover { color: var(--ink-2); border-color: var(--line); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 999px;
}


/* ── state ──────────────────────────────────────────────────────────── */

/* Length is only settable before a session starts. */
body:not([data-state="idle"]) .presets { display: none; }

[hidden] { display: none !important; }


/* The page's name is its tab title, which is the whole point of the build,
   so the heading that names it does not need to be drawn twice. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}


/* ── the day label ──────────────────────────────────────────────────── */

.day {
  position: fixed;
  z-index: 40;
  right: calc(var(--pad) + env(safe-area-inset-right));
  bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  margin: 0;
  font-family: var(--label);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-3);
  pointer-events: none;
}


/* ── short viewports ────────────────────────────────────────────────── */

/* A phone held sideways has height to spare in the wrong direction. */
@media (max-height: 560px) {
  .stage { gap: 0.5rem; --pad: clamp(0.75rem, 3vw, 1.25rem); }
  .controls { gap: 0.6rem; }
  .status { display: none; }
  .phase { margin-bottom: 0.35rem; }
}


/* ── reduced motion ─────────────────────────────────────────────────── */

/* The field is the content, so it stays and keeps tracking progress. The
   drift and the crossfade are the decoration, so that is what goes. */
@media (prefers-reduced-motion: reduce) {
  :root { --flood: 1ms; }
  .drift { animation: none; }
  .rise { transition: none; }
  .act, .chip { transition: none; }
  .act:active, .chip:active { transform: none; }
}


/* ── the planner ────────────────────────────────────────────────────────

   An optional layer. While it is open it takes the readout's place in the
   same centred cluster, so the field behind it never changes and there is
   no modal to trap anyone. Closing it puts the timer back untouched.
   ------------------------------------------------------------------- */

.entry {
  margin-top: 0.15rem;
  padding: 0.5rem 0.75rem;
  min-height: 2.75rem;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: rgba(237, 241, 246, 0.28);
  text-underline-offset: 0.28em;
  cursor: pointer;
  transition: color 160ms var(--ease), text-decoration-color 160ms var(--ease);
}
.entry:hover { color: var(--ink); text-decoration-color: var(--ink); }

/* The entry is only offered from a standing start, and only when a plan is
   not already loaded. */
body:not([data-state="idle"]) .entry,
body[data-planned="yes"] .entry,
body:not([data-planner="off"]) .entry { display: none; }

.planner { display: none; width: 100%; max-width: 30rem; text-align: center; }
.pl { display: none; }

body:not([data-planner="off"]) .planner { display: block; }
body:not([data-planner="off"]) .readout,
body:not([data-planner="off"]) .controls { display: none; }

body[data-planner="ask"]  .pl-ask  { display: block; }
body[data-planner="wait"] .pl-wait { display: block; }
body[data-planner="plan"] .pl-plan { display: block; }

.pl-title {
  margin: 0 0 1.1rem;
  font-size: clamp(1.35rem, 5.5vw, 1.85rem);
  font-weight: 400;
  letter-spacing: -0.015em;
  color: var(--ink);
}

#brain {
  display: block;
  width: 100%;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: rgba(237, 241, 246, 0.05);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;          /* 16px, or iOS zooms the whole page on focus */
  line-height: 1.5;
  text-align: left;
  resize: none;
}
#brain::placeholder { color: var(--ink-3); opacity: 1; }
#brain:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pl-note {
  margin: 0.85rem 0 1.4rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--ink-3);
}

.pl-error {
  margin: 0.85rem 0 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ink);
}

/* The loading state is a line of text over the field, not a spinner. The
   field already says something is happening; this says what. */
.pl-line {
  margin: 0;
  min-height: 4.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 4.5vw, 1.6rem);
  font-weight: 300;
  color: var(--ink-2);
  animation: breathe 2400ms var(--ease) infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

/* A plan can run to eight blocks, which does not fit a 320x568 screen. The
   list scrolls inside itself rather than pushing "Start this plan" below the
   fold, which is the one control the screen exists to offer. */
.pl-list {
  margin: 0 0 0.4rem;
  padding: 0;
  list-style: none;
  text-align: left;
  max-height: min(44vh, 22rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.pl-list:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.pl-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}
.pl-row:last-child { border-bottom: 0; }

.pl-task {
  font-size: 0.9375rem;
  line-height: 1.4;
  color: var(--ink);
}

.pl-min {
  flex: none;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}

/* Rare moment, so it is allowed to be expressive. Rows arrive in the order
   they will be worked. */
@media (prefers-reduced-motion: no-preference) {
  .pl-row {
    opacity: 0;
    transform: translateY(6px);
    animation: row-in 420ms var(--ease) forwards;
    animation-delay: calc(var(--i) * 60ms);
  }
}

@keyframes row-in {
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .pl-line { animation: none; opacity: 0.9; }
}
