/* =========================================================================
   timer.css — Timer page: mode bar, dial, controls, settings, readout
   Accent colour is driven by `body[data-mode]` via --mode-1 / --mode-2.
   ========================================================================= */

/* -------------------------------------------------------------------------
   These are registered as real properties rather than left as bare custom
   properties. An unregistered custom property is token substitution: it
   changes the instant `data-mode` changes and there is nothing to transition.
   That is what made switching modes look jaggy — the glider glided on
   `--t-med` while every colour on the page snapped, so the accent change
   read as a flicker next to a smooth move. Registering them makes them
   animatable, and one transition covers the dial, the glow, the drop-shadow
   and the text together.

   `--mode-r/g/b` are the same colour as three numbers, because `--mode-rgb`
   was a bare `111, 216, 207` string fed to `rgba()`. A comma list is not a
   colour and cannot be registered, so all eight call sites now use the
   space-separated `rgb(R G B / A)` form instead.

   A browser without `@property` ignores the registration and gets the old
   hard swap, not a broken one.
   ------------------------------------------------------------------------- */

@property --mode-1 {
  syntax: '<color>';
  inherits: true;
  initial-value: #8fb4ff;
}
@property --mode-2 {
  syntax: '<color>';
  inherits: true;
  initial-value: #b78cff;
}
@property --mode-r {
  syntax: '<number>';
  inherits: true;
  initial-value: 143;
}
@property --mode-g {
  syntax: '<number>';
  inherits: true;
  initial-value: 180;
}
@property --mode-b {
  syntax: '<number>';
  inherits: true;
  initial-value: 255;
}

body {
  --mode-1: #8fb4ff;
  --mode-2: #b78cff;
  --mode-r: 143;
  --mode-g: 180;
  --mode-b: 255;
  /* Shorter than --t-med and eased out, not sprung: a spring on a colour
     overshoots through hues that are not in the palette, and this should
     land inside one gesture rather than draw attention to itself.

     All five on one curve, deliberately. --mode-r/g/b is --mode-1 written
     as three numbers, so it has to travel the same path -- easing the pair
     and linearising the channels puts the drop-shadow on a different
     trajectory from the stroke it is meant to be a shadow of, and the two
     are briefly two different colours. The glow and the dial are the same
     accent; they should never disagree about what it is. */
  transition:
    --mode-1 220ms var(--ease-out),
    --mode-2 220ms var(--ease-out),
    --mode-r 220ms var(--ease-out),
    --mode-g 220ms var(--ease-out),
    --mode-b 220ms var(--ease-out);
}

body[data-mode='short'] {
  --mode-1: #6fd8cf;
  --mode-2: #8fe3b0;
  --mode-r: 111;
  --mode-g: 216;
  --mode-b: 207;
}

body[data-mode='long'] {
  --mode-1: #b78cff;
  --mode-2: #8f9bff;
  --mode-r: 183;
  --mode-g: 140;
  --mode-b: 255;
}

body[data-mode='custom'] {
  --mode-1: #ff9db4;
  --mode-2: #ffc38a;
  --mode-r: 255;
  --mode-g: 157;
  --mode-b: 180;
}

/* -------------------------------------------------------------------------
   Layout
   ------------------------------------------------------------------------- */
.stack--timer {
  align-items: center;
  gap: clamp(1.3rem, 3.5vw, 1.9rem);
}

.timer {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(1.4rem, 4vw, 1.9rem);
  padding: clamp(1.3rem, 4vw, 1.9rem) clamp(1rem, 3.5vw, 1.6rem);
  border-radius: var(--r-xl);
  border: 1px solid var(--stroke-1);
  background: linear-gradient(180deg, var(--glass-2), var(--glass-1));
  box-shadow: var(--shadow-3), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  animation: rise var(--t-slow) var(--ease-out) both;
  position: relative;
  overflow: hidden;
}

/* A whisper of mode colour bleeding in from the top */
.timer::before {
  content: '';
  position: absolute;
  inset: -40% -20% auto;
  height: 75%;
  background: radial-gradient(60% 100% at 50% 0%, rgb(var(--mode-r) var(--mode-g) var(--mode-b) / 0.14), transparent 70%);
  transition: background 900ms var(--ease-out);
  pointer-events: none;
}

.timer > * {
  position: relative;
}

/* -------------------------------------------------------------------------
   Modes
   ------------------------------------------------------------------------- */
.modes {
  width: 100%;
}

/* -------------------------------------------------------------------------
   Dial
   ------------------------------------------------------------------------- */
.dial {
  position: relative;
  width: min(280px, 78vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.dial__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dial__ticks circle {
  fill: none;
  stroke: var(--stroke-2);
  stroke-width: 1.5;
  stroke-linecap: round;
  /* 60 ticks around the circumference */
  stroke-dasharray: 1.2 12.1;
  transform-origin: 140px 140px;
  animation: spin 220s linear infinite;
  opacity: 0.75;
}

.dial__track {
  fill: none;
  stroke: var(--glass-2);
  stroke-width: 7;
}

.dial__value {
  fill: none;
  stroke: url(#dialGrad);
  stroke-width: 7;
  stroke-linecap: round;
  /* r = 112 → C = 703.72 */
  stroke-dasharray: 703.72;
  stroke-dashoffset: 0;
  transform: rotate(-90deg);
  transform-origin: 140px 140px;
  transition: stroke-dashoffset 950ms linear;
}

body.is-timer-running .dial__value {
  transition: stroke-dashoffset 950ms linear, filter 600ms var(--ease-out);
  filter: drop-shadow(0 0 12px rgb(var(--mode-r) var(--mode-g) var(--mode-b) / 0.55));
}

/* A wider, fainter ring that breathes only while the session is live */
.dial::after {
  content: '';
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 1px solid rgb(var(--mode-r) var(--mode-g) var(--mode-b) / 0.16);
  opacity: 0;
  scale: 0.94;
  transition: opacity 800ms var(--ease-out), scale 800ms var(--ease-out);
  pointer-events: none;
}

body.is-timer-running .dial::after {
  opacity: 1;
  animation: halo 6.5s var(--ease-in-out) infinite;
}

@keyframes halo {
  0%,
  100% {
    scale: 0.96;
    opacity: 0.4;
  }
  50% {
    scale: 1.04;
    opacity: 0.9;
  }
}

/* Centre readout */
.dial__center {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  text-align: center;
}

.dial__label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgb(var(--mode-r) var(--mode-g) var(--mode-b) / 0.95);
  transition: color 600ms var(--ease-out);
}

.dial__time {
  font-family: var(--font-mono);
  font-size: clamp(3rem, 13vw, 3.65rem);
  font-weight: 300;
  line-height: 1.05;
  letter-spacing: -0.045em;
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 34px rgb(var(--mode-r) var(--mode-g) var(--mode-b) / 0.35);
  transition: text-shadow 600ms var(--ease-out);
}

body.is-timer-running .dial__time {
  text-shadow: 0 0 46px rgb(var(--mode-r) var(--mode-g) var(--mode-b) / 0.6);
}

/* The last 10 seconds tick a little harder */
.dial__time.is-urgent {
  animation: urgent 1s var(--ease-in-out) infinite;
}

@keyframes urgent {
  0%,
  100% {
    scale: 1;
  }
  50% {
    scale: 1.035;
  }
}

.dial__sub {
  font-size: 0.76rem;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------------------
   Controls
   ------------------------------------------------------------------------- */
.controls {
  display: flex;
  align-items: center;
  gap: clamp(0.7rem, 3vw, 1.1rem);
}

.btn--start {
  min-width: 148px;
  padding: 0.82rem 1.7rem;
  font-size: 0.95rem;
  background: linear-gradient(135deg, var(--mode-1), var(--mode-2));
  box-shadow: 0 8px 30px -10px rgb(var(--mode-r) var(--mode-g) var(--mode-b) / 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: background 600ms var(--ease-out), box-shadow 600ms var(--ease-out),
    transform var(--t-fast) var(--ease-out), filter var(--t-med) var(--ease-out);
}

.btn--start:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--mode-1), var(--mode-2));
  filter: brightness(1.12);
  box-shadow: 0 10px 40px -10px rgb(var(--mode-r) var(--mode-g) var(--mode-b) / 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.controls .btn--icon {
  border-color: var(--stroke-1);
}

/* -------------------------------------------------------------------------
   Custom duration
   ------------------------------------------------------------------------- */
.custom {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--stroke-1);
  background: rgba(0, 0, 0, 0.24);
  animation: rise var(--t-med) var(--ease-out) both;
}

.custom__label {
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-4);
}

.custom__stepper {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.stepper__btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--stroke-1);
  background: var(--glass-1);
  color: var(--ink-2);
  font-size: 1rem;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}

.stepper__btn:hover {
  background: var(--glass-3);
  color: var(--ink-1);
}

.stepper__btn:active {
  scale: 0.9;
}

.custom__input {
  width: 3.2ch;
  padding: 0.1rem 0.2rem;
  border: 0;
  background: none;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

.custom__input::-webkit-outer-spin-button,
.custom__input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.custom__input:focus-visible {
  outline: none;
  color: var(--accent-1);
}

/* -------------------------------------------------------------------------
   Settings
   ------------------------------------------------------------------------- */
.settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  padding-top: 0.2rem;
}

/* -------------------------------------------------------------------------
   Readout
   ------------------------------------------------------------------------- */
.readout {
  width: 100%;
  max-width: 460px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 0.5rem;
  padding: 1rem clamp(0.9rem, 3vw, 1.3rem);
  animation: rise var(--t-slow) 90ms var(--ease-out) both;
}

.readout__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  text-align: center;
}

.readout__value {
  font-family: var(--font-mono);
  font-size: 1.32rem;
  font-weight: 400;
  letter-spacing: -0.045em;
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
}

.readout__label {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-4);
}

.readout__divider {
  width: 1px;
  align-self: stretch;
  background: linear-gradient(180deg, transparent, var(--stroke-2), transparent);
}

/* -------------------------------------------------------------------------
   Small screens
   ------------------------------------------------------------------------- */
@media (max-width: 380px) {
  .btn--start {
    min-width: 128px;
    padding: 0.78rem 1.3rem;
  }
  .modes__tab {
    padding: 0.42rem 0.5rem;
    font-size: 0.75rem;
  }
}

/* -------------------------------------------------------------------------
   Reduced motion
   ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .dial__ticks circle,
  .dial__time.is-urgent,
  .empty--done .empty__title {
    animation: none !important;
  }
  .dial__ticks circle {
    opacity: 0.4;
  }
}
