:root {
  --half: 70ms; /* half a flap flip; FLIP_MS in app.js = 2 × this */
  --bg: #0a1020;
  --panel: #121b33;
  --line: #2a3658;
  --text: #f4f1e8;
  --muted: #aab5cc;
  --sky: #74acdf; /* celeste */
  --gold: #f6c453;
  --ok: #7fd6a0;
  --warn: #f6c453;
  --bad: #ff8f85;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-serif, "Iowan Old Style", Georgia, "Times New Roman", serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 0 clamp(16px, 3vw, 40px) 16px;
  background: radial-gradient(1200px 600px at 50% -10%, #18264a 0%, var(--bg) 60%);
}

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.top {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 14px 0 0;
}
.chip {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  padding: 5px 12px;
  border: 1px solid var(--sky);
  border-radius: 999px;
  color: var(--sky);
}
body[data-mode="rehearsal"] .chip {
  border-color: var(--gold);
  color: var(--gold);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(16px, 4vh, 40px);
}

.stage {
  --dial: min(46vw, 62vh);
  display: grid;
  grid-template-columns: auto auto;
  align-items: start;
  justify-content: center;
  gap: clamp(20px, 4vw, 64px);
}

/* Face is a static SVG (painted once); each hand is its own layer animated by the GPU. */
.dial {
  position: relative;
  width: var(--dial);
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}
#dial,
.hand-layer,
.grape-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.hand-layer {
  overflow: visible;
  pointer-events: none;
  transform-origin: 50% 50%;
  will-change: transform;
}
/* Classic public / station-style clock: white dial, black bars and hands, red sweep seconds. */
#dial .bezel {
  fill: #161616;
}
#dial .face {
  fill: #f7f4ea;
}
#dial .tick {
  stroke: #151515;
  stroke-width: 1.1;
}
#dial .hour-mark {
  fill: #151515;
}
#dial .brand {
  fill: #2b2b2b;
  font: 700 5.2px "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0.5px;
  text-anchor: middle;
}
#dial .brand.sub {
  font-size: 4.2px;
  fill: #555;
}
.dial .hand {
  fill: #151515;
}
.dial .sec {
  stroke: #d4281c;
  stroke-width: 1.5;
}
.dial .sec-disc {
  fill: #d4281c;
}
.dial .hub {
  fill: #151515;
}
.dial .hub-dot {
  fill: #d4281c;
}

/* Right column: one block, vertically centred on the dial. */
.readout {
  --t: clamp(2rem, 7vw, 6.2rem); /* time-flap size; the date flap is scaled to the same width */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-self: stretch;
  min-width: 0;
}
/* Split-flap clock */
.digital {
  display: flex;
  align-items: center;
  gap: 0.05em;
  font-size: var(--t);
  font-family: "Helvetica Neue", Arial, "Arial Narrow", sans-serif;
  font-weight: 700;
  line-height: 1;
}
.datebar {
  display: flex;
  align-items: center;
  gap: 0.05em;
  margin-bottom: 0.7rem;
  font-size: calc(var(--t) * 0.66);
  font-family: "Helvetica Neue", Arial, "Arial Narrow", sans-serif;
  font-weight: 700;
  line-height: 1;
}
.datebar .sp {
  width: 0.45em;
}
.colon {
  width: 0.32em;
  text-align: center;
  color: var(--gold);
  font-size: 0.8em;
  padding-bottom: 0.06em;
}
.flap {
  position: relative;
  display: inline-block;
  width: 0.84em;
  height: 1.15em;
  margin-right: 0.04em;
  perspective: 0.9em;
  font-variant-numeric: tabular-nums;
}
.flap .half {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  background: linear-gradient(#23262e, #181b21);
  color: #f1eee4;
  backface-visibility: hidden;
}
.flap .half i {
  position: absolute;
  left: 0;
  right: 0;
  height: 200%;
  line-height: 1.15;
  text-align: center;
  font-style: normal;
}
.flap .half-top,
.flap .fold-top {
  top: 0;
  border-radius: 0.09em 0.09em 0 0;
  transform-origin: 50% 100%;
}
.flap .half-bottom,
.flap .fold-bottom {
  top: 50%;
  border-radius: 0 0 0.09em 0.09em;
  background: linear-gradient(#181b21, #1d2027);
  transform-origin: 50% 0;
}
.flap .half-bottom i,
.flap .fold-bottom i {
  top: -100%;
}
.flap .fold-top,
.flap .fold-bottom {
  visibility: hidden;
}
.flap.flipping .fold-top,
.flap.flipping .fold-bottom {
  visibility: visible;
}
.flap.flipping .fold-top {
  animation: fold-top var(--half) ease-in forwards;
}
.flap.flipping .fold-bottom {
  transform: rotateX(90deg);
  animation: fold-bottom var(--half) var(--half) ease-out forwards;
}
@keyframes fold-top {
  to {
    transform: rotateX(-90deg);
  }
}
@keyframes fold-bottom {
  to {
    transform: rotateX(0deg);
  }
}
/* hinge */
.flap::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - 0.012em);
  height: 0.024em;
  background: #05060a;
  z-index: 3;
}
.countdown-wrap {
  margin-top: 8px;
  font-family: system-ui, sans-serif;
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.6rem);
}
.countdown {
  font-variant-numeric: tabular-nums;
  color: var(--sky);
  font-weight: 700;
  margin-left: 0.4em;
}
.under {
  display: grid;
}
.under > * {
  grid-area: 1 / 1;
}
.message {
  margin: 14px 0 0;
  min-height: 2.6em;
  font-size: clamp(1.1rem, 2.6vw, 2rem);
  color: var(--text);
}
.happy {
  margin: 0;
  align-self: center;
  font-size: clamp(2.2rem, 8vw, 6rem);
  line-height: 1.05;
  color: var(--gold);
  text-shadow: 0 0 40px rgba(246, 196, 83, 0.45);
  visibility: hidden;
}
.happy.show {
  visibility: visible;
  animation: rise 700ms ease-out both;
}
/* Swap by visibility, never display: the clock must not move when the year turns. */
body[data-phase="happy"] .pre {
  visibility: hidden;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
}

/* Grapes on the clock ring: appear in the first 12 s of the last minute, eaten by the red disc. */
.grape-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.rg {
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
  transform: scale(0.2);
  transition: opacity 260ms ease-out, transform 260ms cubic-bezier(0.3, 1.5, 0.5, 1);
}
.rg.in {
  opacity: 1;
  transform: scale(1);
}
.rg.eaten {
  opacity: 0;
  transform: scale(1.8);
  transition: opacity 180ms ease-in, transform 180ms ease-in;
}
.rg-n {
  font: 700 5.4px system-ui, sans-serif;
  fill: #12290a;
  text-anchor: middle;
  dominant-baseline: central;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding-top: 12px;
  font-family: system-ui, sans-serif;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 0.9rem;
}
.pill i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.pill em {
  font-style: normal;
  color: var(--muted);
}
.pill[data-state="ready"] i,
.pill[data-state="on"] i {
  background: var(--ok);
}
.pill[data-state="insufficient"] i,
.pill[data-state="syncing"] i {
  background: var(--warn);
}
.pill[data-state="offline"] i,
.pill[data-state="off"] i {
  background: var(--bad);
}

.btn {
  font: inherit;
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  padding: 9px 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.btn:hover,
.btn:focus-visible {
  border-color: var(--sky);
}
.btn.primary {
  background: var(--sky);
  border-color: var(--sky);
  color: #06101f;
  font-weight: 700;
}
.btn.small {
  padding: 6px 10px;
  font-size: 0.85rem;
}
body[data-audio="on"] #btn-audio {
  display: none;
}

.settings {
  margin-top: 12px;
  font-family: system-ui, sans-serif;
  color: var(--muted);
}
.settings summary {
  cursor: pointer;
  text-align: center;
}
.settings .panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.settings fieldset {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
.settings legend {
  padding: 0 6px;
  color: var(--sky);
}
.settings label {
  display: block;
  margin: 10px 0;
  font-size: 0.9rem;
}
.settings input[type="range"] {
  width: 100%;
  accent-color: var(--sky);
}
.row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.row.wrap {
  flex-wrap: wrap;
}
.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 8px 0;
}
.warn {
  margin: 8px 0;
  padding-left: 18px;
  color: var(--warn);
  font-size: 0.85rem;
}

/* Last minute: nothing that could distract or cover the countdown. */
body.final .settings,
body.final .bar .btn {
  visibility: hidden; /* keeps the layout still at 23:59:00 */
}

@media (max-width: 720px) {
  .stage {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .stage {
    --dial: min(70vw, 300px);
  }
  .dial {
    margin: 0 auto;
  }
  .readout {
    gap: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Kiosk mode (fullscreen): only the clocks and the bell/pip indicators. */
body.kiosk header.top,
body.kiosk .bar,
body.kiosk .settings {
  display: none;
}
/* Kiosk: the clock stays centred against the dial; the greeting floats below it
   without taking any space, so nothing moves when it appears. */
body.kiosk .pre {
  display: none;
}
body.kiosk .under {
  position: relative;
  height: 0;
}
body.kiosk .under .happy {
  position: absolute;
  top: 0.5rem;
  left: 0;
  white-space: nowrap;
}
body.kiosk {
  padding: 2vh 3vw;
}
body.kiosk main {
  gap: 5vh;
}
body.kiosk .stage {
  --dial: min(48vw, 78vh);
}
body.kiosk .readout {
  --t: clamp(2.4rem, 7.2vw, 7.5rem);
}
body.kiosk .happy {
  font-size: clamp(2rem, 4.1vw, 4.4rem);
}
/* A tiny corner dot is the only chrome, and only when sound or time sync is not OK. */
.kiosk-alert {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--bad);
  opacity: 0.85;
  z-index: 10;
}
@media (max-width: 720px) {
  body.kiosk .stage {
    grid-template-columns: 1fr;
    --dial: min(80vw, 50vh);
  }
}
