/*
 * THE EZ CLOCK — clock.css
 * ez.sy
 *
 * The three displays: analog dial, digital readout, gnomon figure.
 *
 * One rule governs this whole file. The hand is never animated by CSS.
 * Its position is written by JS every frame from a single reading, so
 * its pace changes with the solar stage exactly as the mathematics
 * dictates. A CSS transition on the hand would smooth away the very
 * thing the clock exists to show. See spec §19 and §53.
 */

/* ------------------------------------------------------------------ *
 * Clock assembly
 * ------------------------------------------------------------------ */

.clock {
  display: grid;
  gap: 20px;
  justify-items: center;
}

.clock--hero {
  gap: 24px;
}

/* ------------------------------------------------------------------ *
 * Analog dial
 *
 * 21 divisions in three sectors of seven. The sectors must read as
 * three distinct territories, not a uniform ring, because the
 * three-stage structure is the system itself.
 * ------------------------------------------------------------------ */

.dial {
  width: min(78vw, 320px);
  aspect-ratio: 1;
  display: block;
}

.dial--sm {
  width: 100%;
  max-width: 128px;
}

.dial__face {
  fill: var(--bg-sunk);
  stroke: var(--line);
  stroke-width: 1;
}

/* Stage arcs. Drawn as thick strokes on the rim. */
.dial__sector {
  fill: none;
  stroke-width: 7;
  stroke-linecap: butt;
  opacity: 0.9;
}

.dial__sector--night { stroke: var(--night); }
.dial__sector--morning { stroke: var(--morning); }
.dial__sector--afternoon { stroke: var(--afternoon); }

/* The sector the clock is currently inside is brought forward. */
.dial__sector.is-active {
  opacity: 1;
  stroke-width: 10;
}

/* Hour ticks: 21 of them. The four anchors are emphasised. */
.dial__tick {
  stroke: var(--ink-faint);
  stroke-width: 1;
}

.dial__tick--anchor {
  stroke: var(--ink-soft);
  stroke-width: 2;
}

.dial__numeral {
  fill: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
}

.dial__numeral--anchor {
  fill: var(--ink);
  font-weight: 600;
}

.dial--sm .dial__numeral {
  font-size: 9px;
}

/* Anchor labels around the rim: SUNSET, SUNRISE, NOON. */
.dial__anchor-label {
  fill: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.12em;
  text-anchor: middle;
  text-transform: uppercase;
}

/* The single hand. Ez Clock has one hand because there is one thing to
   know: where you are in the solar day. No transition, ever. */
.dial__hand {
  stroke: var(--hand);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.dial--sm .dial__hand {
  stroke-width: 2;
}

.dial__hub {
  fill: var(--hand);
}

/* A small mark riding the rim at the hand's angle, so the reading is
   legible at a glance on the small grid dials. */
.dial__marker {
  fill: var(--accent);
}

/* Elapsed arc of the current stage, drawn inside the rim. */
.dial__progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.55;
}

/* ------------------------------------------------------------------ *
 * Digital readout
 * ------------------------------------------------------------------ */

.digital {
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
}

.digital__time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.5rem, 13vw, 4rem);
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--ink);

  /* Tabular figures alone are not enough at large sizes on some
     platforms. Fixing the width stops the readout jittering as the
     hundredths roll. */
  font-feature-settings: "tnum" 1;
}

.digital__time .unit {
  color: var(--ink-faint);
}

/* The seconds pair is the part that visibly changes pace. Give it
   slightly lower weight so the hours and minutes stay readable while
   the seconds do their work. */
.digital__time .secs {
  color: var(--accent);
}

.digital--sm .digital__time {
  font-size: 1.5rem;
}

.digital__stage {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.clock[data-stage="night"] .digital__stage { color: var(--night); }
.clock[data-stage="morning"] .digital__stage { color: var(--morning); }
.clock[data-stage="afternoon"] .digital__stage { color: var(--afternoon); }

/* Night on a dark background needs a floor on contrast. */
.clock[data-stage="night"] .digital__stage {
  color: var(--ink-soft);
}

/* ------------------------------------------------------------------ *
 * Pace indicator
 *
 * How long one Ez Second currently lasts, and whether the stage is
 * stretched or compressed. This is the number that makes the concept
 * click for most people.
 * ------------------------------------------------------------------ */

.pace {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

.pace__bar {
  width: 84px;
  height: 3px;
  background: var(--bg-sunk);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

/* Centre tick marks a pace of 1, a stage exactly one third of the
   cycle. The fill grows left for compressed, right for stretched. */
.pace__bar::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: var(--line);
}

.pace__fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: left var(--transition), width var(--transition);
}

/* ------------------------------------------------------------------ *
 * Gnomon figure
 *
 * A stick and its cast shadow, derived from the same solar altitude
 * and azimuth the clock uses. This is the visual proof that the site
 * is tracking the sun rather than animating a decoration.
 * ------------------------------------------------------------------ */

.gnomon {
  width: min(72vw, 260px);
  aspect-ratio: 1 / 1;
  display: block;
}

/* The rim of the disc. Drawn last, over the clipped interior, so the
   clip never shaves half its stroke off. */
.gnomon__rim {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
}

.gnomon__sky {
  fill: var(--bg-sunk);
}

.gnomon__ground {
  fill: var(--bg-raised);
}

.gnomon__horizon {
  stroke: var(--line);
  stroke-width: 1;
}

.gnomon__stick {
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
}

.gnomon__base {
  fill: var(--ink-faint);
}

/* The shadow. Length and direction both come from solar geometry.
   No transition: when the sun moves, the shadow moves with it. */
.gnomon__shadow {
  fill: var(--shadow);
  opacity: 0.85;
}

.gnomon__sun {
  fill: var(--sun);
}

/* Sun below the horizon: dim the disc and drop the shadow entirely,
   since a shadow with no sun is a lie. */
.gnomon[data-below="true"] .gnomon__sun {
  opacity: 0.25;
}

.gnomon[data-below="true"] .gnomon__shadow {
  opacity: 0;
}

.gnomon__ray {
  stroke: var(--sun);
  stroke-width: 1;
  stroke-dasharray: 2 4;
  opacity: 0.4;
}

.gnomon[data-below="true"] .gnomon__ray {
  opacity: 0;
}

.gnomon__caption {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
  text-align: center;
  margin-top: 8px;
}

/* ------------------------------------------------------------------ *
 * Compact clock for the city wall
 *
 * Whether the grid tiles show analog, digital, or both is undecided.
 * All three arrangements are supported here so the choice can be made
 * by looking rather than guessing. JS sets .wall[data-display].
 * ------------------------------------------------------------------ */

.wall[data-display="digital"] .city .dial { display: none; }
.wall[data-display="analog"] .city .digital__time { display: none; }

/* The lead city always shows both, whatever the grid is set to. */
.wall[data-display="digital"] .city--lead .dial { display: block; }
.wall[data-display="analog"] .city--lead .digital__time { display: block; }

.city .clock {
  gap: 10px;
}

.city--lead .clock {
  gap: 16px;
}

/* ------------------------------------------------------------------ *
 * Loading state
 *
 * Before the first reading resolves, the readout holds its shape so
 * the page does not shift. Never show a fake time.
 * ------------------------------------------------------------------ */

.clock[data-state="pending"] .digital__time,
.clock[data-state="pending"] .digital__stage {
  color: var(--ink-faint);
  opacity: 0.4;
}

.clock[data-state="pending"] .dial__hand,
.clock[data-state="pending"] .dial__marker,
.clock[data-state="pending"] .dial__progress {
  opacity: 0;
}

/* ------------------------------------------------------------------ *
 * Reduced motion
 *
 * The hand's changing pace is information and stays. Only the
 * decorative transitions on the pace bar are suppressed, and that is
 * handled by the --transition token in themes.css.
 * ------------------------------------------------------------------ */
