/* ==========================================================================
   7-Segment Digital Countdown — Theme Custom Properties & Layout
   ========================================================================== */

:root,
html[data-theme="red"] {
  --bg: #09090b;
  --ambient: rgba(255, 36, 36, 0.055);
  --seg-on: #ff2424;
  --seg-ghost: rgba(255, 36, 36, 0.07);
  --seg-glow:
    drop-shadow(0 0 6px rgba(255, 36, 36, 0.72))
    drop-shadow(0 0 18px rgba(255, 36, 36, 0.34));
  --colon-dim-opacity: 0.22;
  --label-color: rgba(255, 76, 76, 0.48);
  --switcher-bg: rgba(255, 255, 255, 0.045);
  --switcher-border: rgba(255, 255, 255, 0.09);
  --ring-gap: #09090b;
  --ring-color: rgba(255, 255, 255, 0.88);
  --focus-color: #ff6b6b;
  color-scheme: dark;
}

html[data-theme="green"] {
  --bg: #060c07;
  --ambient: rgba(57, 255, 20, 0.05);
  --seg-on: #39ff14;
  --seg-ghost: rgba(57, 255, 20, 0.07);
  --seg-glow:
    drop-shadow(0 0 6px rgba(57, 255, 20, 0.68))
    drop-shadow(0 0 18px rgba(57, 255, 20, 0.3));
  --colon-dim-opacity: 0.22;
  --label-color: rgba(57, 255, 20, 0.46);
  --switcher-bg: rgba(255, 255, 255, 0.045);
  --switcher-border: rgba(255, 255, 255, 0.09);
  --ring-gap: #060c07;
  --ring-color: rgba(255, 255, 255, 0.88);
  --focus-color: #6cff4f;
  color-scheme: dark;
}

html[data-theme="amber"] {
  --bg: #0d0905;
  --ambient: rgba(255, 176, 0, 0.055);
  --seg-on: #ffb000;
  --seg-ghost: rgba(255, 176, 0, 0.07);
  --seg-glow:
    drop-shadow(0 0 6px rgba(255, 176, 0, 0.7))
    drop-shadow(0 0 18px rgba(255, 176, 0, 0.32));
  --colon-dim-opacity: 0.22;
  --label-color: rgba(255, 176, 0, 0.48);
  --switcher-bg: rgba(255, 255, 255, 0.045);
  --switcher-border: rgba(255, 255, 255, 0.09);
  --ring-gap: #0d0905;
  --ring-color: rgba(255, 255, 255, 0.88);
  --focus-color: #ffd166;
  color-scheme: dark;
}

html[data-theme="cyan"] {
  --bg: #060b10;
  --ambient: rgba(0, 229, 255, 0.055);
  --seg-on: #00e5ff;
  --seg-ghost: rgba(0, 229, 255, 0.07);
  --seg-glow:
    drop-shadow(0 0 6px rgba(0, 229, 255, 0.68))
    drop-shadow(0 0 18px rgba(0, 229, 255, 0.32));
  --colon-dim-opacity: 0.22;
  --label-color: rgba(0, 229, 255, 0.48);
  --switcher-bg: rgba(255, 255, 255, 0.045);
  --switcher-border: rgba(255, 255, 255, 0.09);
  --ring-gap: #060b10;
  --ring-color: rgba(255, 255, 255, 0.88);
  --focus-color: #7df2ff;
  color-scheme: dark;
}

html[data-theme="lcd"] {
  --bg: #9ca68f;
  --ambient: rgba(255, 255, 255, 0.08);
  --seg-on: #1b1f18;
  --seg-ghost: rgba(27, 31, 24, 0.09);
  --seg-glow:
    drop-shadow(clamp(1px, 0.18vw, 2.5px) clamp(1.5px, 0.26vw, 3.5px) 0px rgba(27, 31, 24, 0.17))
    drop-shadow(0 0 0px rgba(27, 31, 24, 0));
  --colon-dim-opacity: 0.14;
  --label-color: rgba(27, 31, 24, 0.66);
  --switcher-bg: rgba(27, 31, 24, 0.1);
  --switcher-border: rgba(27, 31, 24, 0.2);
  --ring-gap: #9ca68f;
  --ring-color: #1b1f18;
  --focus-color: #1b1f18;
  color-scheme: light;
}

/* ==========================================================================
   Reset & Full-Viewport Centering
   ========================================================================== */

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  position: relative;
  min-height: 100dvh;
  height: 100dvh;
  display: grid;
  place-items: center;
  background-color: var(--bg);
  background-image: radial-gradient(
    ellipse 70% 55% at 50% 50%,
    var(--ambient) 0%,
    transparent 72%
  );
  font-family: ui-monospace, 'SFMono-Regular', 'Cascadia Mono', 'Roboto Mono', Menlo, Consolas, monospace;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 250ms ease, color 250ms ease;
}

/* Subtle glass vignette on Retro LCD */
html[data-theme="lcd"] body {
  box-shadow: inset 0 0 120px rgba(27, 31, 24, 0.14);
}

.stage {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 0 clamp(12px, 3vw, 40px);
}

/* ==========================================================================
   Clock Assembly & Responsive Sizing
   ========================================================================== */

.clock {
  /*
    Total clock width is ~12.8 * --digit-w (10 digits + 3 colons + 1 decimal dot + gaps).
    Scales smoothly from tiny phones to wide desktop monitors without overflow.
  */
  --digit-w: clamp(18px, min(6.8vw, 20dvh), 94px);
  --digit-h: calc(var(--digit-w) * 1.551724); /* 180 / 116 exact viewBox ratio */
  --colon-w: calc(var(--digit-w) * 0.293103); /* 34 / 116 exact viewBox ratio */
  --dot-w: calc(var(--digit-w) * 0.241379);   /* 28 / 116 exact viewBox ratio */
  --pair-gap: calc(var(--digit-w) * 0.16);
  --group-gap: calc(var(--digit-w) * 0.11);

  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: var(--group-gap);
  max-width: 100%;
}

/* Graceful scaling if days ever exceeds 99 (3+ digits) */
.clock.clock--wide {
  --digit-w: clamp(16px, min(6.1vw, 18dvh), 84px);
}

.unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.digit-pair {
  display: flex;
  align-items: center;
  gap: var(--pair-gap);
  height: var(--digit-h);
}

.unit-label {
  margin-top: clamp(8px, calc(var(--digit-w) * 0.18), 22px);
  font-size: clamp(9px, calc(var(--digit-w) * 0.135), 14px);
  font-weight: 500;
  letter-spacing: 0.24em;
  text-indent: 0.24em; /* optically centers letter-spaced text */
  line-height: 1;
  color: var(--label-color);
  transition: color 250ms ease;
}

/* ==========================================================================
   7-Segment Digits (Layered Ghost + Active SVGs)
   ========================================================================== */

.digit {
  position: relative;
  width: var(--digit-w);
  height: var(--digit-h);
  display: grid;
  flex-shrink: 0;
}

.digit-svg {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  shape-rendering: geometricPrecision;
}

.digit-ghost {
  fill: var(--seg-ghost);
  transition: fill 250ms ease;
}

.digit-active {
  fill: var(--seg-on);
  filter: var(--seg-glow);
  transition: fill 250ms ease, filter 250ms ease;
}

.digit-active .seg {
  opacity: 0;
  transition: opacity 45ms linear;
}

/* Crisp zero-smear updates on fast 100th-of-second digits */
[data-unit="centiseconds"] .digit-active .seg {
  transition: none;
}

/* Active segment map for digits 0–9 */
.digit[data-digit="0"] .digit-active .seg-a,
.digit[data-digit="0"] .digit-active .seg-b,
.digit[data-digit="0"] .digit-active .seg-c,
.digit[data-digit="0"] .digit-active .seg-d,
.digit[data-digit="0"] .digit-active .seg-e,
.digit[data-digit="0"] .digit-active .seg-f,

.digit[data-digit="1"] .digit-active .seg-b,
.digit[data-digit="1"] .digit-active .seg-c,

.digit[data-digit="2"] .digit-active .seg-a,
.digit[data-digit="2"] .digit-active .seg-b,
.digit[data-digit="2"] .digit-active .seg-g,
.digit[data-digit="2"] .digit-active .seg-e,
.digit[data-digit="2"] .digit-active .seg-d,

.digit[data-digit="3"] .digit-active .seg-a,
.digit[data-digit="3"] .digit-active .seg-b,
.digit[data-digit="3"] .digit-active .seg-g,
.digit[data-digit="3"] .digit-active .seg-c,
.digit[data-digit="3"] .digit-active .seg-d,

.digit[data-digit="4"] .digit-active .seg-f,
.digit[data-digit="4"] .digit-active .seg-g,
.digit[data-digit="4"] .digit-active .seg-b,
.digit[data-digit="4"] .digit-active .seg-c,

.digit[data-digit="5"] .digit-active .seg-a,
.digit[data-digit="5"] .digit-active .seg-f,
.digit[data-digit="5"] .digit-active .seg-g,
.digit[data-digit="5"] .digit-active .seg-c,
.digit[data-digit="5"] .digit-active .seg-d,

.digit[data-digit="6"] .digit-active .seg-a,
.digit[data-digit="6"] .digit-active .seg-f,
.digit[data-digit="6"] .digit-active .seg-g,
.digit[data-digit="6"] .digit-active .seg-e,
.digit[data-digit="6"] .digit-active .seg-d,
.digit[data-digit="6"] .digit-active .seg-c,

.digit[data-digit="7"] .digit-active .seg-a,
.digit[data-digit="7"] .digit-active .seg-b,
.digit[data-digit="7"] .digit-active .seg-c,

.digit[data-digit="8"] .digit-active .seg-a,
.digit[data-digit="8"] .digit-active .seg-b,
.digit[data-digit="8"] .digit-active .seg-c,
.digit[data-digit="8"] .digit-active .seg-d,
.digit[data-digit="8"] .digit-active .seg-e,
.digit[data-digit="8"] .digit-active .seg-f,
.digit[data-digit="8"] .digit-active .seg-g,

.digit[data-digit="9"] .digit-active .seg-a,
.digit[data-digit="9"] .digit-active .seg-b,
.digit[data-digit="9"] .digit-active .seg-c,
.digit[data-digit="9"] .digit-active .seg-d,
.digit[data-digit="9"] .digit-active .seg-f,
.digit[data-digit="9"] .digit-active .seg-g {
  opacity: 1;
}

/* ==========================================================================
   2-Dot Colons
   ========================================================================== */

.colon {
  position: relative;
  width: var(--colon-w);
  height: var(--digit-h);
  display: grid;
  flex-shrink: 0;
}

.colon-svg {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  shape-rendering: geometricPrecision;
}

.colon-ghost {
  fill: var(--seg-ghost);
  transition: fill 250ms ease;
}

.colon-active {
  fill: var(--seg-on);
  filter: var(--seg-glow);
  opacity: 1;
  transition: opacity 220ms ease-in-out, fill 250ms ease, filter 250ms ease;
}

.clock.colon-dim .colon-active {
  opacity: var(--colon-dim-opacity);
}

/* ==========================================================================
   Decimal Point Separator (Seconds . Hundredths)
   ========================================================================== */

.decimal-dot {
  position: relative;
  width: var(--dot-w);
  height: var(--digit-h);
  display: grid;
  flex-shrink: 0;
}

.dot-svg {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  shape-rendering: geometricPrecision;
}

.dot-ghost {
  fill: var(--seg-ghost);
  transition: fill 250ms ease;
}

.dot-active {
  fill: var(--seg-on);
  filter: var(--seg-glow);
  opacity: 1;
  transition: fill 250ms ease, filter 250ms ease;
}

/* ==========================================================================
   Completion State: Classic Digital Clock Blinking on 00:00:00:00.00
   ========================================================================== */

@keyframes complete-blink {
  0%, 54% {
    opacity: 1;
  }
  54.01%, 100% {
    opacity: 0;
  }
}

.clock.is-complete .digit-active,
.clock.is-complete .colon-active,
.clock.is-complete .dot-active {
  animation: complete-blink 1s linear infinite;
}

/* ==========================================================================
   Minimal Bottom Theme Switcher Bar
   ========================================================================== */

.theme-switcher {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-radius: 999px;
  background-color: var(--switcher-bg);
  border: 1px solid var(--switcher-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0.35;
  transition:
    opacity 250ms ease,
    background-color 250ms ease,
    border-color 250ms ease;
}

.theme-switcher:hover,
.theme-switcher:focus-within {
  opacity: 1;
}

.swatch {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 180ms ease,
    box-shadow 250ms ease,
    border-color 250ms ease;
}

.swatch:hover {
  transform: scale(1.16);
}

.swatch:active {
  transform: scale(0.95);
}

.swatch[aria-pressed="true"] {
  box-shadow:
    0 0 0 2px var(--ring-gap),
    0 0 0 3.5px var(--ring-color);
}

.swatch:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 4px;
}

.swatch--red   { background-color: #ff2424; }
.swatch--green { background-color: #39ff14; }
.swatch--amber { background-color: #ffb000; }
.swatch--cyan  { background-color: #00e5ff; }
.swatch--lcd   {
  background: radial-gradient(circle at 50% 50%, #1b1f18 0%, #1b1f18 28%, #9ca68f 32%, #9ca68f 100%);
  border-color: rgba(27, 31, 24, 0.35);
}

html[data-theme="lcd"] .swatch {
  border-color: rgba(27, 31, 24, 0.28);
}

/* ==========================================================================
   Accessibility Utilities
   ========================================================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .theme-switcher {
    gap: 14px;
    padding: 10px 16px;
  }

  .swatch {
    width: 20px;
    height: 20px;
  }
}
