/* Circuit / Vacuum -- the vacuum-tube clock display (markup in
   templates/partials/circuit-display.html). .cb-lcd's position and size
   live in the shared style.css.

   Each .cb-tube holds ten bent-wire numerals (.cb-nx-0 .. .cb-nx-9) drawn
   back-to-front: 1 nearest, then 2, 3 ... 9, and 0 furthest away. --d is
   the depth, 0 (rearmost) to 9 (front). An unlit numeral is just a
   fine dark wire -- the ones in front slightly obscure the lit one behind
   them. The lit one (.on, toggled by circuit.js) glows orange. */

:root {
  /* A pan-head screw seen from the front, with a slot. */
  --screw-img: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='9' fill='%23545454'/%3E%3Ccircle cx='10' cy='10' r='7.2' fill='%23a9a9a9'/%3E%3Cpath d='M5.5 14.5L14.5 5.5' stroke='%23333' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  --nixie: #ff8a2a;
  --nixie-glow: 255, 96, 0;
  --neon: #ff9a3c;
  /* How bright the tubes are, 0-1, while every numeral is lit before the
     clock starts. */
  --all-lit-brightness: 1;
}

/* Nudged up from the shared vertical centring to leave room below the
   daughter board for the connector holes in the main PCB. */
.cb-lcd { transform: translateY(-58%); }

/* The black flat daughter board the tubes' interface card sits on, with a
   screw in each corner (the bottom two sit 4 mm up and 3 mm further out than
   the first/last tube centres, behind those tubes' glass, taking a tube as
   15 mm wide). The copper trace runs in underneath it. */
.cb-lcd-glass {
  --screw: clamp(6px, 1.1vw, 11px);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.2%;
  padding: 5% 4.5% 3.4%;
  background:
    var(--screw-img) left calc(var(--screw) * 0.7) top calc(var(--screw) * 0.7) / var(--screw) var(--screw) no-repeat,
    var(--screw-img) right calc(var(--screw) * 0.7) top calc(var(--screw) * 0.7) / var(--screw) var(--screw) no-repeat,
    var(--screw-img) left calc(8.23% - var(--screw) / 2) bottom calc(var(--screw) * 0.7 + 9.3%) / var(--screw) var(--screw) no-repeat,
    var(--screw-img) right calc(8.23% - var(--screw) / 2) bottom calc(var(--screw) * 0.7 + 9.3%) / var(--screw) var(--screw) no-repeat,
    linear-gradient(180deg, #17110e, #090706);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

/* The vertical interface card, seen edge-on: a green strip along the bottom
   of the daughter board, wider than the row of tubes so that the first and
   last sockets stand fully on it. The tube sockets sit on top of it. Its
   height is given through padding so it scales with the width. */
.cb-card {
  position: absolute;
  z-index: 0;
  left: 2%;
  right: 2%;
  bottom: 0;
  height: 0;
  padding-bottom: 3.4%;
  background: linear-gradient(180deg, #4fae72 0 14%, #25793f 14% 80%, #17502b 80%);
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.5);
}

/* The card's eight right-angle connector pins, bunched at its left-hand
   end as a 2 x 4 header at 2.54 mm pitch (a tube is taken as 15 mm wide, so
   the pitch is about 2.4% of the card's width). They leave the back of the
   card, turn down and go into plated holes in the main PCB, which is seen
   from above: each .cb-pin is one hole -- a copper ring with a dark centre,
   like the board's other vias -- with the gold pin end in its middle. The
   Every pin drops from the card: the back row's run down behind the front
   row's pads (the pads stay in front and visible, the front pins hide the
   upper part of the back ones). */
.cb-pin {
  position: absolute;
  top: 100%;
  width: 1.8%;
  aspect-ratio: 1;
  z-index: 2;
  margin: 2.6% 0 0 -0.9%;
  border-radius: 50%;
  background: radial-gradient(circle, #0b1d13 0 36%, #8c6f3b 39%);
}
.cb-pin:nth-child(n+5) { z-index: 1; margin-top: 4.96%; }
.cb-pin:nth-child(4n+1) { left: 3.2%; }
.cb-pin:nth-child(4n+2) { left: 5.56%; }
.cb-pin:nth-child(4n+3) { left: 7.92%; }
.cb-pin:nth-child(4n) { left: 10.28%; }
.cb-pin::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34%;
  height: 34%;
  margin: -17% 0 0 -17%;
  border-radius: 50%;
  background: radial-gradient(circle, #fff1c4, #d9a83a);
}
.cb-pin::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 26%;
  height: 195%;
  margin-left: -13%;
  background: linear-gradient(90deg, #f3d27a, #b88a2a);
}
.cb-pin:nth-child(n+5)::before { height: 326%; }

.cb-tube {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 24 / 46;
  margin-bottom: 3.4%;
  border-radius: 46% 46% 10% 10% / 18% 18% 4% 4%;
  border: 1px solid rgba(214, 226, 232, 0.38);
  /* Fine anode mesh behind the numerals, over a warm interior. */
  background:
    repeating-linear-gradient(60deg, transparent 0 3px, rgba(205, 128, 70, 0.30) 3px 3.7px),
    repeating-linear-gradient(-60deg, transparent 0 3px, rgba(205, 128, 70, 0.30) 3px 3.7px),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(205, 128, 70, 0.22) 3px 3.7px),
    radial-gradient(ellipse at 50% 55%, rgba(var(--nixie-glow), 0.34), rgba(70, 20, 6, 0.55) 70%, rgba(20, 8, 4, 0.9));
  box-shadow: 0 0 12px rgba(var(--nixie-glow), 0.30), inset 0 0 8px rgba(0, 0, 0, 0.7);
}
/* The little glass tip on top of the tube. */
.cb-tube::before {
  content: "";
  position: absolute;
  left: 38%;
  width: 24%;
  top: -7%;
  height: 8%;
  border-radius: 50% 50% 0 0;
  border: 1px solid rgba(214, 226, 232, 0.38);
  border-bottom: none;
}
/* Glass reflections down both edges. */
.cb-tube::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.22), transparent 16%, transparent 82%, rgba(255, 255, 255, 0.12)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.10), transparent 22%);
}
.cb-tube-wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.cb-nx {
  fill: none;
  stroke: #a98468;
  stroke-width: 0.55;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: calc(0.16 + var(--d) * 0.055);
  /* Stacked front-to-back: further numerals are a touch smaller. */
  transform-box: view-box;
  transform-origin: 12px 25px;
  transform: scale(calc(0.84 + var(--d) * 0.0178));
}
.cb-nx-0 { --d: 0; } .cb-nx-9 { --d: 1; } .cb-nx-8 { --d: 2; } .cb-nx-7 { --d: 3; } .cb-nx-6 { --d: 4; }
.cb-nx-5 { --d: 5; } .cb-nx-4 { --d: 6; } .cb-nx-3 { --d: 7; } .cb-nx-2 { --d: 8; } .cb-nx-1 { --d: 9; }
.cb-nx.on {
  stroke: var(--nixie);
  stroke: #ffa040;
  stroke-width: 1.05;
  opacity: calc(0.88 + var(--d) * 0.012);
  filter: drop-shadow(0 0 0.6px #fff0c0) drop-shadow(0 0 1.6px rgba(var(--nixie-glow), 1)) drop-shadow(0 0 4px rgba(var(--nixie-glow), 0.8));
}

/* Grey socket the tube plugs into, mounted on the board: a box with a
   sloped front (wider at the bottom) and a lighter top face. */
.cb-socket {
  position: absolute;
  left: -5%;
  right: -5%;
  top: 100%;
  /* Exactly as tall as the margin under the tube (the card's height), so the
     socket stands on the card. */
  height: calc(14.35% + 1px);
  background: linear-gradient(180deg, #8a8d91 0 26%, #4c4f53 26% 100%);
  clip-path: polygon(8% 0, 92% 0, 100% 100%, 0 100%);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.7));
}

/* A colon is two neon lamps, one above the other, each seen end-on and
   plugged straight into the board: a glass disc with its single glowing
   electrode as a dot. They pulse brighter with each tick (.cb-pulse is put
   on .cb-lcd-glass by circuit.js). */
.cb-colon {
  position: relative;
  z-index: 1;
  flex: 0 0 4.2%;
  margin-bottom: 3.4%;
}
.cb-neon {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(255, 214, 170, 0.45);
  background: radial-gradient(circle, rgba(255, 150, 50, 0.50), rgba(255, 100, 20, 0.22) 60%, rgba(60, 20, 6, 0.4));
  box-shadow: 0 0 7px rgba(var(--nixie-glow), 0.55), 0 3px 3px rgba(0, 0, 0, 0.6);
  transition: filter 0.15s ease, box-shadow 0.15s ease;
}
.cb-neon + .cb-neon { margin-top: 90%; }
.cb-neon i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36%;
  aspect-ratio: 1;
  margin: -18% 0 0 -18%;
  border-radius: 50%;
  background: radial-gradient(circle, #fff1c4, var(--neon));
  box-shadow: 0 0 4px var(--neon), 0 0 8px rgba(var(--nixie-glow), 0.8);
}
.cb-lcd-glass.cb-pulse .cb-neon {
  filter: brightness(1.45) saturate(1.1);
  box-shadow: 0 0 12px rgba(var(--nixie-glow), 0.9), 0 3px 3px rgba(0, 0, 0, 0.6);
}

/* Placeholder before the clock starts: every numeral 0-9 is lit, but the
   tube is set to --all-lit-brightness (full). */
.cb-tube.cb-all { box-shadow: 0 0 12px rgba(var(--nixie-glow), 0.30), inset 0 0 8px rgba(0, 0, 0, 0.7); }
.cb-tube.cb-all .cb-tube-wires { opacity: var(--all-lit-brightness); }
