: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 {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 30;
  font-family: system-ui, sans-serif;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 0.85rem;
  padding: 7px 13px;
  color: var(--text);
  background: rgba(18, 27, 51, 0.82);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.chip:hover,
.chip:focus-visible,
.chip[aria-expanded="true"] {
  border-color: var(--sky);
}
body[data-mode="rehearsal"] .chip {
  border-color: var(--gold);
}
.chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.chip[data-state="ok"] .dot {
  background: var(--ok);
}
.chip[data-state="warn"] .dot {
  background: var(--warn);
}
.chip[data-state="bad"] .dot {
  background: var(--bad);
}
.chip-audio {
  color: var(--bad);
}
.chip-audio[hidden] {
  display: none;
}
.caret {
  opacity: 0.7;
}

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(92vw, 320px);
  max-height: calc(100vh - 84px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  color: var(--text);
  background: rgba(14, 22, 43, 0.96);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
}
.menu[hidden],
.menu [hidden] {
  display: none;
}
.menu .st {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.menu .dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.menu .dot[data-state="ok"] {
  background: var(--ok);
}
.menu .dot[data-state="warn"] {
  background: var(--warn);
}
.menu .dot[data-state="bad"] {
  background: var(--bad);
}
.menu .icon {
  margin-left: auto;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.menu .icon:hover:not(:disabled),
.menu .icon:focus-visible {
  border-color: var(--sky);
}
.menu .icon:disabled {
  opacity: 0.45;
  cursor: default;
}
.menu .icon.spinning {
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.menu select {
  width: 100%;
  padding: 10px 8px;
  font: inherit;
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  background: #0e1730;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sw {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1rem;
  cursor: pointer;
}
.sw input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.sw i {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #2a3658;
  transition: background 150ms;
}
.sw i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 150ms;
}
.sw input:checked + i {
  background: var(--sky);
}
.sw input:checked + i::after {
  transform: translateX(18px);
}
.sw input:focus-visible + i {
  outline: 2px solid var(--sky);
  outline-offset: 2px;
}
.vol {
  width: 100%;
  accent-color: var(--sky);
}
.btn.wide {
  width: 100%;
}
.rh {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rh .row {
  align-items: center;
  margin: 0;
}
.mono {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}
.adv {
  font-size: 0.85rem;
  color: var(--muted);
}
.adv summary {
  cursor: pointer;
  list-style: none;
  letter-spacing: 0.04em;
}
.adv summary::-webkit-details-marker {
  display: none;
}
.adv summary::before {
  content: "▸ ";
}
.adv[open] summary::before {
  content: "▾ ";
}
.adv label {
  display: block;
  margin: 12px 0 0;
  color: var(--text);
}
.adv .row {
  margin-top: 12px;
}
.muted {
  color: var(--muted);
  font-size: 0.78rem;
}

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);
  height: var(--dial); /* square without aspect-ratio (older TV browsers) */
  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);
}
/* Swap by visibility, never display: the clock must not move when the year turns. */
body[data-phase="happy"] .pre {
  visibility: hidden; /* the overlay takes over; the slot keeps its size */
}

@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;
}

.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;
}

.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 .menu {
  display: none !important;
}
body.final .chip {
  pointer-events: none;
  opacity: 0.55;
}

@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; the chip is gone. */
body.kiosk header.top {
  display: none;
}
/* The countdown/message slot keeps no space here: the clock stays centred against the dial. */
body.kiosk .pre {
  display: none;
}
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);
}
/* 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);
  }
}

/* "¡Feliz Año Nuevo!" overlay: above everything, never intercepts input, clock stays visible. */
#sparkler {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: none;
  pointer-events: none;
}
.spk-bg {
  position: absolute;
  inset: 0;
  /* light dark band: strongest at the top, fading to nothing below the lettering */
  background: linear-gradient(to bottom, rgba(3, 6, 16, 0.78) 0%, rgba(3, 6, 16, 0.5) 26%, rgba(3, 6, 16, 0) 56%);
}
#sparkler canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Far from the event (or long after it) the page is just a clock: no countdown, no message. */
body.far .pre {
  display: none;
}

/* Keyboard feedback: small, non-interactive, never in the way. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 40;
  transform: translateX(-50%);
  padding: 9px 18px;
  font: 600 0.95rem system-ui, sans-serif;
  color: var(--text);
  background: rgba(14, 22, 43, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  white-space: nowrap;
}
.toast[hidden],
.help[hidden] {
  display: none;
}
.help {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 40;
  transform: translate(-50%, -50%);
  min-width: min(86vw, 360px);
  padding: 18px 22px;
  font: 0.95rem system-ui, sans-serif;
  color: var(--text);
  background: rgba(14, 22, 43, 0.96);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
.help h4 {
  margin: 0 0 10px;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sky);
}
.help dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 18px;
  margin: 0;
}
.help dt {
  font-weight: 700;
  color: var(--gold);
}
.help dd {
  margin: 0;
}
kbd {
  padding: 1px 6px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 5px;
}
.keyhint {
  margin: 0;
}

/* Menu sections: the clock (all year) and New Year are visibly separate. */
.msec {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msec + .msec {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.msec h3 {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sky);
}
.msec.ny h3 {
  color: var(--gold);
}
.ny-info {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.4;
}
.ny-info b {
  font-weight: 700;
}
.msec label {
  display: block;
}
.msec label.sw {
  display: flex;
}
.msec label.field {
  display: flex;
}

.keyhint a {
  color: var(--sky);
}
