/* ===========================================================
   Grandfather Clock — vanilla CSS
   Designed on a fixed 1080 x 1920 canvas, scaled to fit.
   =========================================================== */

:root {
  /* Theme variables (overridden per data-theme) */
  --bg: #ffffff;
  --letterbox: #f2f2f2;
  --ambient: 1;          /* brightness multiplier applied to the whole clock */
  --shadow: rgba(0,0,0,0.25);

  /* Wood tones */
  --wood-light: #6b4423;
  --wood-mid:   #4e2f17;
  --wood-dark:  #2e1a0c;
  --wood-edge:  #1c0f06;
  --brass:      #d9b14a;
  --brass-dark: #8a6a1d;
  --brass-lite: #f6e6a8;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--letterbox);
  font-family: "Georgia", "Times New Roman", serif;
}

/* ---------- Themes ---------- */
body[data-theme="light"] {
  --bg: #ffffff;
  --letterbox: #ececec;
  --ambient: 1;
}
body[data-theme="dark"] {
  --bg: #14171c;
  --letterbox: #0a0c10;
  --ambient: 0.82;
}
/* Auto theme colors are set inline by JS via the #sky element + --ambient */
body[data-theme="auto"] {
  --letterbox: transparent;
}

/* ---------- Day/night sky (auto theme) ---------- */
#sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: none;
  background: linear-gradient(180deg, #0a1026 0%, #0a1026 100%);
  transition: background 1.5s linear;
}
body[data-theme="auto"] #sky { display: block; }

/* Starfield that fades in as the auto sky darkens (JS sets #stars opacity). */
#stars {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.5s linear;
  pointer-events: none;
  /* Atmospheric extinction: stars are fully clear high up and dim toward the
     horizon (the bottom, where the sky thickens behind the mountains). */
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 40%, rgba(0,0,0,0.22) 80%, rgba(0,0,0,0) 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 40%, rgba(0,0,0,0.22) 80%, rgba(0,0,0,0) 100%);
}
.starfield {
  position: absolute;
  inset: 0;
  background-repeat: repeat;
  background-size: 170px 170px;
  background-image:
    radial-gradient(2px 2px at 30px 40px, #ffffff, transparent),
    radial-gradient(1.5px 1.5px at 120px 90px, rgba(255,255,255,0.95), transparent),
    radial-gradient(2px 2px at 80px 150px, #ffffff, transparent),
    radial-gradient(1.5px 1.5px at 150px 40px, rgba(255,255,255,0.9), transparent),
    radial-gradient(2.4px 2.4px at 60px 110px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 20px 130px, rgba(255,255,255,0.85), transparent),
    radial-gradient(1.5px 1.5px at 140px 130px, rgba(255,255,255,0.8), transparent);
  filter: drop-shadow(0 0 2px rgba(255,255,255,0.5));
}
.starfield-2 {
  background-size: 240px 240px;
  background-position: 70px 50px;
}

/* A scattering of individual stars that twinkle on their own random cadence
   (size / position / duration / phase set inline in clock.js), over the steady
   tiled field above — a slight, natural shimmer rather than a global pulse. */
.twinkle-star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 3px rgba(255, 255, 255, 0.8);
  opacity: var(--dim, 0.4);
  animation: twinkleStar 5s ease-in-out infinite;
  will-change: opacity, transform;
}
@keyframes twinkleStar {
  0%, 100% { opacity: var(--dim, 0.4); transform: scale(0.85); }
  50%      { opacity: 1;               transform: scale(1); }
}

/* Satellites: a steady (non-twinkling) point of light that drifts slowly across
   the sky in a straight line. Top/size/speed are set inline per satellite, and
   --dx is the off-screen-to-off-screen travel distance (clock.js). */
.satellite {
  position: absolute;
  left: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.9);
  opacity: 0.9;
  pointer-events: none;
  will-change: transform;
}
@keyframes satellite-cross {
  from { transform: translateX(-30px); }
  to   { transform: translateX(var(--dx)); }
}

/* Shooting stars: a bright head with a tapering tail, streaking across the
   night sky. Position/angle/length/distance are set inline per meteor (JS);
   they live inside #stars so they fade in/out with the starfield. */
.shooting-star {
  position: absolute;
  height: 2px;
  border-radius: 2px;
  /* Tail fades in from nothing (left) to a bright head (right end). */
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.85) 85%, #fff 100%);
  filter: drop-shadow(0 0 6px rgba(255,255,255,0.85));
  transform-origin: 100% 50%;   /* rotate/translate about the head */
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}
@keyframes shoot {
  0%   { transform: translate(0, 0) rotate(var(--rot)); opacity: 0; }
  12%  { opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) rotate(var(--rot)); opacity: 0; }
}

/* ---------- Overcast haze (auto theme) ---------- */
#overcast {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 82%;
  opacity: 0;                 /* JS ramps this up with cloud density */
  transition: opacity 1.5s linear;
  pointer-events: none;
  background: linear-gradient(to bottom,
    rgba(240,244,249,0.98) 0%,
    rgba(235,240,246,0.96) 60%,
    rgba(231,237,245,0.85) 80%,
    rgba(229,235,244,0.45) 93%,
    transparent 100%);
  filter: blur(6px);
}

/* ---------- Drifting clouds (auto theme) ---------- */
#clouds {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;                 /* JS fades clouds in with daylight */
  transition: opacity 1.5s linear;
}
/* Clouds are generated by JS (count = density). Size, lane (top), opacity,
   speed and start delay are set inline per cloud; the look below is shared.
   Gradient radii are percentages so the puffiness scales with cloud size. */
.cloud {
  position: absolute;
  /* Gooey filter merges the lobes into one smooth shape; the slight blur softens
     the edges (matching the screensaver clouds). */
  filter: url(#cloud-goo) blur(1px);
  will-change: transform;
  /* Position (translateX) is driven by JS so clouds wrap promptly and stay
     evenly spaced by density — see moveClouds() in clock.js. */
}

/* Each cloud's shape (overlapping soft white lobes + a wide flat base) is
   generated procedurally in clock.js and set as an inline `background`, so the
   sky shows an unlimited variety of forms rather than a fixed set of stamps. */

/* ---------- Screensaver: full-screen drifting clouds ---------- */
#screensaver {
  position: fixed;
  inset: 0;
  z-index: 9000;              /* over the clock and the gear */
  overflow: hidden;
  pointer-events: none;       /* page stays interactive; activity dismisses it */
  opacity: 0;
  transition: opacity 1s ease;
}
#screensaver.on { opacity: 1; }
/* No backdrop tint — just clouds on top. A soft shadow keeps the white clouds
   readable on any theme (a per-cloud effect, not a full-screen mist). */
#screensaver .cloud { filter: url(#cloud-goo) blur(1px) drop-shadow(0 4px 7px rgba(55,65,85,0.22)); }

/* A single purple firefly (from purplefirefly-pump) drifts above the clouds.
   Position/rotation/opacity are driven per-frame by JS — see Firefly in clock.js. */
.screensaver-firefly {
  position: absolute;
  top: 0; left: 0;                 /* JS translate() places it; transform-origin centres it */
  z-index: 2;                      /* stays above the (later-spawned) drifting clouds */
  opacity: 0;
  will-change: transform, opacity;
  filter: drop-shadow(0 0 10px rgba(111, 66, 193, 0.5));  /* soft purple glow */
}
.screensaver-firefly img {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- Mountains (auto theme) — illustration from assets/mountains.svg ---------- */
#mountains {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  line-height: 0;          /* drop inline-image whitespace below the SVG */
  pointer-events: none;
  transition: filter 1.5s linear; /* JS dims the range at night */
}
#mountains img {
  display: block;
  width: 100%;
  height: auto;            /* full width, preserve the SVG's aspect ratio */
}

/* ---------- Viewport scaler ---------- */
#viewport {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
body[data-theme="auto"] #viewport { background: transparent; }

#stage {
  width: 1080px;
  height: 1920px;
  transform-origin: center center;
  position: relative;
  filter: brightness(var(--ambient));
  transition: filter 1.5s linear;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===========================================================
   HOOD / BONNET
   =========================================================== */
.hood {
  width: 760px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 3;
}

/* Swan-neck pediment */
.pediment {
  width: 760px;
  height: 150px;
  position: relative;
  background:
    radial-gradient(120px 120px at 50% 150px, transparent 96px, var(--wood-mid) 98px) ,
    linear-gradient(180deg, var(--wood-light), var(--wood-dark));
  border-top-left-radius: 380px 150px;
  border-top-right-radius: 380px 150px;
  box-shadow: inset 0 6px 12px rgba(255,255,255,0.15), inset 0 -10px 18px rgba(0,0,0,0.4);
  border-bottom: 8px solid var(--wood-edge);
}

.hood-body {
  width: 700px;
  background: linear-gradient(90deg, var(--wood-dark), var(--wood-mid) 12%, var(--wood-light) 50%, var(--wood-mid) 88%, var(--wood-dark));
  border: 10px solid var(--wood-edge);
  border-top: none;
  padding: 24px 0 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 12px 30px var(--shadow);
}

/* ---------- Moon-phase arch ---------- */
.moon-arch {
  width: 360px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.moon-arch-inner {
  width: 360px;
  height: 190px;
  border-radius: 360px 360px 0 0 / 190px 190px 0 0;
  border: 8px solid var(--brass-dark);
  border-bottom: none;
  position: relative;
  overflow: hidden;
  background: #0b1430;
}
.moon-arch-sky {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 120%, #1b2b5e 0%, #0b1430 60%, #060b1e 100%);
}
.moon-arch-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 40px 40px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 120px 70px, #fff, transparent),
    radial-gradient(1px 1px at 220px 30px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 300px 60px, #fff, transparent),
    radial-gradient(1px 1px at 180px 100px, #fff, transparent),
    radial-gradient(1px 1px at 80px 110px, #fff, transparent);
  opacity: 0.8;
}
/* The moon is a full painted disc that transits the arch; JS sets its
   left/top (px) from the lunar phase. It rides BEHIND the two earth globes,
   which occlude it near the edges to produce waxing/waning crescents. */
.moon-disc {
  position: absolute;
  left: 50%;
  top: 60px;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  z-index: 1;
  background:
    /* craters: dark floor + a bright catching-the-light rim */
    radial-gradient(7px 7px at 64% 30%, rgba(120,108,84,0.60) 0 3px, rgba(255,250,232,0.55) 4px 5.2px, transparent 7px),
    radial-gradient(5px 5px at 43% 71%, rgba(120,108,84,0.60) 0 2px, rgba(255,250,232,0.5) 2.8px 3.8px, transparent 5px),
    radial-gradient(6px 6px at 73% 61%, rgba(120,108,84,0.55) 0 2.5px, rgba(255,250,232,0.5) 3.3px 4.5px, transparent 6px),
    radial-gradient(4px 4px at 31% 44%, rgba(120,108,84,0.55) 0 1.6px, rgba(255,250,232,0.5) 2.2px 3px, transparent 4px),
    radial-gradient(4.5px 4.5px at 55% 20%, rgba(120,108,84,0.5) 0 1.8px, rgba(255,250,232,0.45) 2.5px 3.4px, transparent 4.5px),
    radial-gradient(3.5px 3.5px at 24% 64%, rgba(120,108,84,0.5) 0 1.4px, rgba(255,250,232,0.45) 2px 2.7px, transparent 3.5px),
    radial-gradient(2.6px 2.6px at 48% 50%, rgba(120,108,84,0.5) 0 1px, rgba(255,250,232,0.4) 1.5px 2px, transparent 2.6px),
    radial-gradient(2.4px 2.4px at 38% 28%, rgba(120,108,84,0.45) 0 0.9px, transparent 2.4px),
    /* maria — the darker grey "seas" */
    radial-gradient(20px 17px at 42% 36%, rgba(96,92,82,0.40), transparent 74%),
    radial-gradient(15px 13px at 60% 50%, rgba(96,92,82,0.36), transparent 74%),
    radial-gradient(11px 12px at 51% 65%, rgba(96,92,82,0.32), transparent 74%),
    /* sunlit body */
    radial-gradient(circle at 38% 38%, #fffef0 0%, #f3edce 55%, #cfc69a 100%);
  box-shadow: 0 0 22px 5px rgba(255,250,210,0.55), inset -7px -6px 12px rgba(120,110,70,0.45);
  /* The whole moon is scaled up (craters, maria, glow scale with it) so a
     crescent pokes out from behind the globes near new moon instead of being
     swallowed by them. The disc is large (≈145px rendered) so that, paired
     with the lowered apex in clock.js, the globes begin occluding it within
     ~1 day of full. JS positions the 66px box by its centre, which the
     centred scale leaves unchanged. */
  transform: scale(2.2);
}

/* Two opposite earth globes flank the arch (the "lunar humps"). They sit
   above the moon so it disappears behind them at the horizons. */
.globe {
  position: absolute;
  bottom: -52px;
  width: 156px;
  height: 156px;
  border-radius: 50%;
  z-index: 2;
  overflow: hidden;
  /* ocean sphere, lit from the upper-left (land + clouds sit in ::before/::after) */
  background: radial-gradient(circle at 34% 30%, #8fcdf2 0%, #2e74b5 44%, #17507f 78%, #0a2942 100%);
  box-shadow: 0 0 16px rgba(70,140,210,0.28); /* outer glow */
}
.globe-left  { left: -50px; }
.globe-right { right: -50px; }
/* Land layer: all one green so overlapping lobes merge with NO internal edges,
   and softly blurred so the continents look like they sit under the haze. */
.globe::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  filter: blur(1.6px);
  background:
    /* desert patch */
    radial-gradient(20px 16px at 60% 33%, rgba(201,170,99,0.75) 0 52%, transparent 80%),
    /* continent A (overlapping lobes -> one irregular mass) */
    radial-gradient(40px 32px at 58% 34%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(30px 36px at 67% 45%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(28px 26px at 49% 43%, #4f9a44 0 64%, transparent 84%),
    /* continent B (lower-left) */
    radial-gradient(32px 28px at 33% 62%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(24px 34px at 39% 73%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(22px 20px at 27% 55%, #4f9a44 0 64%, transparent 84%),
    /* island */
    radial-gradient(16px 14px at 77% 65%, #4f9a44 0 60%, transparent 84%);
}
/* A different hemisphere on the opposite globe so the two aren't identical. */
.globe-right::before {
  background:
    radial-gradient(18px 14px at 42% 44%, rgba(201,170,99,0.7) 0 52%, transparent 80%),
    radial-gradient(36px 30px at 40% 44%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(28px 36px at 48% 55%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(24px 22px at 32% 36%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(30px 40px at 67% 58%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(22px 24px at 72% 44%, #4f9a44 0 64%, transparent 84%),
    radial-gradient(16px 14px at 28% 66%, #4f9a44 0 60%, transparent 84%);
}
/* Clouds + polar ice cap + sphere shading + atmosphere rim — above the land. */
.globe::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(22px 9px at 40% 24%, rgba(255,255,255,0.42), transparent 72%),
    radial-gradient(16px 7px at 64% 72%, rgba(255,255,255,0.34), transparent 72%),
    radial-gradient(46px 16px at 50% 4%, rgba(247,251,255,0.92) 0%, rgba(214,232,245,0.5) 55%, transparent 80%);
  box-shadow: inset -16px -14px 34px rgba(0,0,0,0.6),
              inset 8px 8px 18px rgba(255,255,255,0.18),
              inset 0 0 10px 2px rgba(150,210,255,0.25);
}
.moon-arch-label {
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--brass);
  margin-top: 6px;
}

/* ---------- Dial ---------- */
.dial-frame {
  width: 540px;
  height: 540px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brass-lite), var(--brass) 40%, var(--brass-dark));
  padding: 22px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5), inset 0 0 14px rgba(0,0,0,0.35);
}
.dial {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #fbf7ec, #efe7d2 70%, #ddd0b0);
  box-shadow: inset 0 0 20px rgba(0,0,0,0.25);
  position: relative;
}
.dial-face { position: absolute; inset: 0; border-radius: 50%; }

/* Maker name + subtitle, stacked just above the date window */
.maker {
  position: absolute;
  bottom: 180px; left: 0; right: 0;
  text-align: center;
  font-size: 26px;
  font-style: italic;
  color: #5b4a2c;
}
.maker-sub {
  position: absolute;
  bottom: 160px; left: 0; right: 0;
  text-align: center;
  font-size: 13px;
  letter-spacing: 2px;
  color: #7a6743;
}

/* ---------- Seconds subdial (upper) ---------- */
.sub-seconds {
  position: absolute;
  top: 96px; left: 50%;
  transform: translateX(-50%);
  width: 108px; height: 108px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #f6f0dd, #e4d8b9 75%, #d3c49f);
  border: 2px solid #b8a572;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.22);
}
.sub-ticks { position: absolute; inset: 0; }
.sub-tick {
  position: absolute;
  top: 50%; left: 50%;
  width: 1px; height: 4px;
  background: #6a5734;
  transform-origin: 50% 0;
}
.sub-tick.major { width: 2.5px; height: 8px; background: #2b2113; }
.sub-label {
  position: absolute;
  top: 16px; left: 0; right: 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: 1px;
  color: #7a6743;
}
.sub-hand {
  position: absolute;
  left: 50%; bottom: 50%;
  width: 2px; height: 44px;
  margin-left: -1px;
  background: #9a1b1b;
  transform-origin: 50% 100%;
  z-index: 2;
}
/* small counterweight tail on the seconds hand */
.sub-hand::after {
  content: "";
  position: absolute;
  left: 50%; top: 100%;
  width: 2px; height: 12px;
  margin-left: -1px;
  background: #9a1b1b;
}
.sub-cap {
  position: absolute;
  top: 50%; left: 50%;
  width: 8px; height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: #7a1414;
  z-index: 3;
}

/* Roman numerals positioned around the ring (transforms set by JS) */
.numerals, .ticks, .hands { position: absolute; inset: 0; }
.numeral {
  position: absolute;
  top: 50%; left: 50%;
  font-size: 34px;
  font-weight: bold;
  color: #2b2113;
  transform-origin: center;
}
.tick {
  position: absolute;
  top: 50%; left: 50%;
  width: 2px; height: 10px;
  background: #4a3c22;
  transform-origin: 50% 0;
}
.tick.major { width: 4px; height: 16px; background: #2b2113; }

/* Date window near the 6 o'clock position */
.date-window {
  position: absolute;
  bottom: 123px; left: 50%;
  transform: translateX(-50%);
  min-width: 120px;
  text-align: center;
  padding: 4px 10px;
  font-size: 15px;
  letter-spacing: 1px;
  color: #3a2e18;
  background: rgba(255,255,255,0.4);
  border: 1px solid #b8a572;
  border-radius: 4px;
}

/* ---------- Hands ---------- */
.hand {
  position: absolute;
  left: 50%;
  bottom: 50%;
  transform-origin: 50% 100%;
  border-radius: 6px;
}
.hour-hand {
  width: 14px; height: 130px;
  margin-left: -7px;
  background: linear-gradient(180deg, #1a1a1a, #333);
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
}
.minute-hand {
  width: 10px; height: 195px;
  margin-left: -5px;
  background: linear-gradient(180deg, #1a1a1a, #333);
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
}
.hand-cap {
  position: absolute;
  top: 50%; left: 50%;
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #555, #111);
  box-shadow: 0 0 4px rgba(0,0,0,0.6);
}

/* The hands/numerals/ticks overlays must not intercept clicks meant for the
   winding arbors beneath them (the arbors are drawn earlier so the hands
   still sweep over them visually). */
.numerals, .ticks, .hands, .date-window { pointer-events: none; }

/* ---------- Winding arbors ---------- */
.winder {
  position: absolute;
  width: 28px; height: 28px;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 2px solid var(--brass-dark);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #e7d399, #b9912f 65%, #7c5f1e);
  box-shadow: inset 0 0 5px rgba(0,0,0,0.55), 0 1px 3px rgba(0,0,0,0.45);
  cursor: pointer;
  pointer-events: auto;
}
/* Square winding hole (the arbor) at the centre. */
.winder::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 9px; height: 9px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: #241b0e;
  box-shadow: inset 0 0 2px rgba(0,0,0,0.9);
}
.winder:hover  { filter: brightness(1.12); }
.winder:active { filter: brightness(0.9); }
.winder.w9 { left: calc(50% - 150px); top: 50%; }
.winder.w3 { left: calc(50% + 150px); top: 50%; }
.winder.w6 { left: 50%; top: calc(50% + 150px); }

/* ===========================================================
   TRUNK / WAIST
   =========================================================== */
.trunk {
  width: 600px;
  flex: 1;
  margin-top: -10px;
  background: linear-gradient(90deg, var(--wood-dark), var(--wood-mid) 14%, var(--wood-light) 50%, var(--wood-mid) 86%, var(--wood-dark));
  border: 14px solid var(--wood-edge);
  border-top: none;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 30px;
  box-shadow: 0 12px 30px var(--shadow);
  position: relative;
  z-index: 2;
}
.glass-door {
  flex: 1;
  position: relative;
  background:
    linear-gradient(135deg, rgba(180,200,220,0.18), rgba(60,70,90,0.30) 50%, rgba(20,25,35,0.45));
  border: 10px solid var(--brass-dark);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.55);
}
.glass-sheen {
  position: absolute;
  top: -10%; left: -30%;
  width: 50%; height: 130%;
  background: linear-gradient(105deg, transparent, rgba(255,255,255,0.10) 45%, rgba(255,255,255,0.18) 50%, transparent 60%);
  transform: rotate(8deg);
  pointer-events: none;
}

/* Weights. Each is positioned absolutely so it sits directly below its
   winding arbor on the dial (left = strike, centre = time, right = chime),
   at ±150px from centre to match the arbors' 9/6/3 positions. */
.weights {
  position: absolute;
  left: 0; right: 0;
  z-index: 1;
}
.weight {
  position: absolute;
  top: 0; left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
}
#wStrike { transform: translateX(calc(-50% - 150px)); }
#wTime   { transform: translateX(-50%); }
#wChime  { transform: translateX(calc(-50% + 150px)); }
/* Two lines descend the sides of the sheave, tangent to the bottom wrap.
   Their length (--cable) is set by JS to move the weight as it runs/winds. */
.weight .cables {
  display: flex;
  justify-content: center;
  gap: 34px;            /* line spacing = wrap diameter (cables tangent at the sides) */
}
.weight .cable {
  width: 3px; height: var(--cable, 97px);
  background: linear-gradient(90deg, #6b6b6b, #cfcfcf, #6b6b6b);
}
/* Pulley sheave — a brass wheel with 4 spokes and an axle hub. The negative
   top margin raises it so its axle sits where the descending cables end, and
   the cable then wraps around its bottom half. */
.weight .pulley {
  position: relative;
  width: 34px; height: 34px;
  margin-top: -17px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, var(--brass-lite), var(--brass) 55%, var(--brass-dark));
  box-shadow: inset 0 0 6px rgba(0,0,0,0.5), 0 2px 5px rgba(0,0,0,0.45);
}
/* The cable wrapping the BOTTOM HALF of the sheave: a half-circle whose flat
   top sits on the axle line and whose ends meet the two descending cables. */
.weight .cable-wrap {
  position: absolute;
  top: 50%; left: 50%;
  /* Stroke centreline diameter must equal the cable-centre spacing (gap 33 +
     cable width 3 = 36px) so the arc ends line up with the two cables. With
     border-box, that means outer width = 36 + border (2.5) = 38.5px. */
  width: 38.5px; height: 19.25px;
  transform: translateX(-50%);
  border: 2.5px solid #c2c2c2;
  border-top: none;
  border-radius: 0 0 20px 20px;
  background: transparent;
  box-shadow: 0 1px 2px rgba(0,0,0,0.45);
  z-index: -1;                 /* cable sits behind the sheave + other weight parts */
}
/* 4 spokes = a horizontal bar + a vertical bar crossing the hub. */
.weight .spokes {
  position: absolute;
  top: 50%; left: 50%;
  width: 34px; height: 34px;
  transform: translate(-50%, -50%);
}
.weight .spokes::before,
.weight .spokes::after {
  content: "";
  position: absolute;
  background: var(--brass-dark);
}
.weight .spokes::before { top: 50%; left: 4px; right: 4px; height: 2px; transform: translateY(-50%); }
.weight .spokes::after  { left: 50%; top: 4px; bottom: 4px; width: 2px; transform: translateX(-50%); }
/* Axle hub at the centre. */
.weight .hub {
  position: absolute;
  top: 50%; left: 50%;
  width: 9px; height: 9px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--brass-lite), var(--brass-dark));
  box-shadow: inset 0 0 2px rgba(0,0,0,0.7);
}
/* S-hook hanging the weight from the pulley: top loop grips the sheave's
   axle, bottom loop holds the weight's eyelet. */
.weight .hook {
  position: relative;
  width: 16px; height: 30px;
  margin-top: -3px;
  margin-bottom: -5px;  /* lower loop overlaps the weight's eyelet */
  z-index: 1;
}
.weight .hook::before,
.weight .hook::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 16px; height: 17px;
  border: 3px solid var(--brass);
  box-shadow: 0 1px 2px rgba(0,0,0,0.45);
}
.weight .hook::before { top: 0;    border-bottom: none; border-radius: 50% 50% 0 0; } /* opens up to grip the sheave */
.weight .hook::after  { bottom: 0; border-top: none;    border-radius: 0 0 50% 50%; } /* opens down to the weight */
.weight .bob {
  position: relative;
  width: 56px; height: 230px;
  border-radius: 12px / 8px;
  background: linear-gradient(90deg, var(--brass-dark), var(--brass-lite) 45%, var(--brass) 55%, var(--brass-dark));
  box-shadow: inset 0 0 12px rgba(0,0,0,0.4), 0 6px 12px rgba(0,0,0,0.5);
  border-radius: 10px;
}
/* Eyelet on top of the weight that the hook's lower loop passes through. */
.weight .bob::before {
  content: "";
  position: absolute;
  top: -7px; left: 50%;
  width: 10px; height: 10px;
  transform: translateX(-50%);
  border-radius: 50%;
  border: 2.5px solid var(--brass-dark);
  background: transparent;
}

/* Pendulum — suspended from the centre of the dial (above the trunk window).
   The pivot sits 326px above the glass-door's top edge, so the upper rod is
   hidden behind the dial (clipped by the door's overflow) just like a real
   clock; only the lower rod and bob swing in view. */
.pendulum {
  position: absolute;
  top: -326px;          /* element top = dial centre (clipped above the window) */
  left: 50%;
  margin-left: -78px;   /* half the bob width, to centre the pendulum */
  width: 156px;
  transform-origin: top center;
  z-index: 2;
  --swing: 7deg;        /* JS lowers this toward 0 as the time weight runs down */
  animation: swing 2s ease-in-out infinite;
  cursor: grab;         /* drag it aside to start the clock, to rest to stop it */
  touch-action: none;   /* let pointer-drag work on touch without scrolling */
}
.pendulum:active { cursor: grabbing; }
.pendulum-rod {
  width: 7px;
  height: 626px;        /* from the dial centre down into the trunk */
  margin: 0 auto;
  background: linear-gradient(90deg, #7c7c7c, #e6e6e6, #7c7c7c);
}
.pendulum-bob {
  width: 156px; height: 156px;
  margin: -16px auto 0;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, var(--brass-lite), var(--brass) 45%, var(--brass-dark));
  box-shadow: inset -12px -12px 26px rgba(0,0,0,0.45), 0 8px 16px rgba(0,0,0,0.5);
  border: 4px solid var(--brass-dark);
}
@keyframes swing {
  0%   { transform: rotate(var(--swing)); }
  50%  { transform: rotate(calc(var(--swing) * -1)); }
  100% { transform: rotate(var(--swing)); }
}

/* ===========================================================
   BASE / PLINTH
   =========================================================== */
.base {
  width: 700px;
  background: linear-gradient(90deg, var(--wood-dark), var(--wood-mid) 14%, var(--wood-light) 50%, var(--wood-mid) 86%, var(--wood-dark));
  border: 12px solid var(--wood-edge);
  border-top: none;
  padding: 26px 30px 0;
  box-shadow: 0 14px 34px var(--shadow);
  position: relative;
  z-index: 3;
}
.base-panel {
  height: 150px;
  border: 6px solid var(--wood-edge);
  border-radius: 6px;
  background: linear-gradient(135deg, var(--wood-light), var(--wood-dark));
  box-shadow: inset 0 0 24px rgba(0,0,0,0.5);
}
.feet {
  display: flex;
  justify-content: space-between;
  margin: 16px -10px 0;
}
.foot {
  width: 90px; height: 46px;
  background: linear-gradient(180deg, var(--wood-mid), var(--wood-edge));
  border-radius: 0 0 10px 10px;
}

/* ===========================================================
   STRIKE FLASH (visual cue when a chime/strike fires)
   =========================================================== */
.dial-frame.flash {
  animation: dialFlash 0.5s ease-out;
}
@keyframes dialFlash {
  0%   { box-shadow: 0 8px 24px rgba(0,0,0,0.5), 0 0 0 0 rgba(255,230,140,0.9); }
  100% { box-shadow: 0 8px 24px rgba(0,0,0,0.5), 0 0 60px 20px rgba(255,230,140,0); }
}

/* ===========================================================
   SETTINGS DRAWER
   =========================================================== */
/* ---------- Tooltips ---------- */
/* Clean dark bubble shown above any element carrying a data-tip attribute
   (the winding arbors and the settings gear). Replaces the browser's native
   title tooltip. The host element is already positioned, so the ::before is
   placed relative to it. */
[data-tip]::before {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(3px);
  white-space: nowrap;
  padding: 6px 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.2px;
  color: #f3f4f7;
  background: rgba(24,26,32,0.94);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  z-index: 10000;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
[data-tip]:hover::before,
[data-tip]:focus-visible::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
/* While hovered, lift the winder (and its tooltip) above the hands/numerals so
   the bubble reads clearly; normally the hands still sweep over the arbors. */
.winder:hover { z-index: 60; }

.gear-btn {
  position: fixed;
  bottom: 18px; right: 18px;
  z-index: 20;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: none;
  background: rgba(40,40,40,0.55);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
/* Glyph lives in ::after so only it spins on hover — the tooltip (::before)
   stays put instead of rotating with the whole button. */
.gear-btn::after { content: "⚙"; display: block; transition: transform 0.3s; }
.gear-btn:hover { background: rgba(40,40,40,0.8); }
.gear-btn:hover::after { transform: rotate(45deg); }

.drawer {
  position: fixed;
  top: 0; right: 0;
  z-index: 30;
  width: 360px;
  max-width: 90vw;
  height: 100%;
  background: rgba(22,24,28,0.96);
  color: #eee;
  box-shadow: -8px 0 30px rgba(0,0,0,0.5);
  transform: translateX(100%);
  transition: transform 0.32s ease;
  overflow-y: auto;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: sticky; top: 0;
  background: rgba(22,24,28,0.98);
}
.drawer-head h2 { font-size: 18px; font-weight: 600; }
.close-btn {
  background: none; border: none; color: #bbb;
  font-size: 30px; line-height: 1; cursor: pointer;
}
.close-btn:hover { color: #fff; }

.drawer-body { padding: 8px 20px 40px; }
.ctl-group { padding: 16px 0; border-bottom: 1px solid rgba(255,255,255,0.08); }
.ctl-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: #9aa; margin-bottom: 12px; }

.seg { display: flex; gap: 6px; }
.seg.col { flex-direction: column; }
.seg.wrap { flex-wrap: wrap; }
.seg-btn {
  flex: 1;
  padding: 10px 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: #ddd;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, border 0.15s;
}
.seg-btn:hover { background: rgba(255,255,255,0.12); }
.seg-btn small { color: #99a; font-size: 11px; }
.seg-btn.active small { color: rgba(255,255,255,0.85); }
.seg-btn.active {
  background: #b88a2a;
  border-color: #d9b14a;
  color: #fff;
  font-weight: 600;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0;
  font-size: 14px;
}
.row small { color: #889; font-size: 11px; }
.row input[type="range"] { flex: 1; }
/* Live, prominent value display for a slider (updates as you drag). */
.slider-val {
  flex: 0 0 auto;
  min-width: 46px;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #e6e8ef;
}
.row input[type="time"] {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #eee; padding: 6px; border-radius: 6px;
}

.action-btn {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #eee;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.action-btn.small { width: auto; margin: 0; padding: 6px 12px; }
.action-btn:hover { background: rgba(255,255,255,0.16); }

.hint { font-size: 12px; color: #889; margin-top: 8px; line-height: 1.4; }

.clock-readout { text-align: center; }
.big-time {
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  color: #d9b14a;
}
.speed-readout { font-size: 13px; color: #9aa; margin-top: 4px; }

/* ===========================================================
   BEAT TIMER — full-screen mic-listening view for measuring a
   REAL pendulum clock's rate/drift. Reuses the drawer's
   .ctl-group/.seg-btn/.row/.action-btn/.hint vocabulary; only
   the bits unique to this view are defined here.
   =========================================================== */
.beat-btn { right: 84px; }
.beat-btn::after { content: "⏱"; }

.beat-view {
  position: fixed;
  inset: 0;
  z-index: 35; /* above .drawer (30) — a full swapped view, not another panel */
  background: rgba(14,16,20,0.98);
  color: #eee;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.beat-view.open { opacity: 1; pointer-events: auto; }

.beat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: sticky; top: 0;
  background: rgba(14,16,20,0.98);
}
.beat-head h2 { font-size: 18px; font-weight: 600; }

.beat-body { max-width: 480px; margin: 0 auto; }

.ro-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #e6e8ef;
}
.ro-value.good { color: #7ad67a; }
.ro-value.warn { color: #e8a33d; }

.hint.error { color: #e8807a; }

.mic-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
}
.mic-row .action-btn { flex: 1; width: auto; margin-top: 0; }

.beat-pulse {
  flex: 0 0 auto;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
}
.beat-pulse.flash { animation: beatFlash 0.3s ease-out; }
@keyframes beatFlash {
  0% { background: var(--brass-lite); box-shadow: 0 0 12px var(--brass); transform: scale(1.3); }
  100% { background: rgba(255,255,255,0.15); box-shadow: none; transform: scale(1); }
}

#beatWave {
  display: block;
  width: 100%;
  height: 60px;
  margin-top: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
}

.row input[type="number"] {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #eee; padding: 6px; border-radius: 6px;
  width: 90px; text-align: right;
}

.action-btn.active {
  background: #b88a2a;
  border-color: #d9b14a;
  color: #fff;
  font-weight: 600;
}
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.action-btn:disabled:hover { background: rgba(255,255,255,0.08); }
