/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; }

/* ---- Default Theme (Flip) ---- */
:root {
  --timer-bg: #1a1a2e;
  --plate-bg: #16213e;
  --plate-bg-top: #1e2d50;
  --digit-color: #f0ede6;
  --label-color: #8892a4;
  --separator-color: #c9a84c;
  --border-radius-plate: 8px;
  --font-family: 'Oswald', sans-serif;
  --font-weight: 600;
  --font-size-digit: 80px;
  --font-size-label: 13px;
  --unit-gap: 24px;
  --plate-shadow: 0 6px 20px rgba(0,0,0,0.5), 0 1px 4px rgba(0,0,0,0.4);
  --text-shadow: none;
}

/* ---- LED Theme ---- */
[data-theme="led"] {
  --timer-bg: #0a0a0a;
  --digit-color: #ff3b3b;
  --label-color: rgba(255,59,59,0.65);
  --separator-color: #ff3b3b;
  --font-family: 'Share Tech Mono', monospace;
  --font-size-digit: 80px;
  --plate-bg: transparent;
  --plate-shadow: none;
  --text-shadow: 0 0 12px rgba(255,59,59,0.9), 0 0 30px rgba(255,59,59,0.5);
  --scanline-opacity: rgba(0,0,0,0.12);
}

/* ---- Minimal Theme ---- */
[data-theme="minimal"] {
  --timer-bg: #ffffff;
  --digit-color: #111111;
  --label-color: #999999;
  --separator-color: #cccccc;
  --font-family: 'DM Sans', sans-serif;
  --font-weight: 300;
  --font-size-digit: 96px;
  --font-size-label: 12px;
  --unit-gap: 48px;
  --plate-bg: transparent;
  --plate-shadow: none;
  --text-shadow: none;
}

/* ---- Glass Theme ---- */
[data-theme="glass"] {
  --timer-bg: transparent;
  --glass-bg: linear-gradient(135deg, rgba(255,255,255,0.15), rgba(255,255,255,0.05));
  --glass-border: rgba(255,255,255,0.25);
  --glass-blur: 24px;
  --digit-color: #ffffff;
  --label-color: rgba(255,255,255,0.65);
  --separator-color: rgba(255,255,255,0.5);
  --font-family: 'Inter', sans-serif;
  --font-weight: 300;
  --font-size-digit: 80px;
  --plate-bg: var(--glass-bg);
  --plate-shadow: inset 0 0 0 1px var(--glass-border), 0 8px 32px rgba(0,0,0,0.15);
  --text-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

/* ---- Neon Theme ---- */
[data-theme="neon"] {
  --timer-bg: #050510;
  --digit-color: #ff00ff;
  --label-color: rgba(255,0,255,0.55);
  --separator-color: #00ffff;
  --font-family: 'Orbitron', sans-serif;
  --font-weight: 700;
  --font-size-digit: 72px;
  --plate-bg: transparent;
  --plate-shadow: none;
  --text-shadow: 0 0 8px currentColor, 0 0 20px currentColor, 0 0 40px currentColor;
}

/* ---- Text-Only Theme ---- */
[data-theme="text"] {
  --timer-bg: transparent;
  --digit-color: #ffffff;
  --label-color: rgba(255,255,255,0.6);
  --separator-color: rgba(255,255,255,0.35);
  --font-family: 'DM Sans', sans-serif;
  --font-weight: 500;
  --font-size-digit: 96px;
  --plate-bg: transparent;
  --plate-shadow: none;
  --text-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

/* ============================================================
   LAYOUT
   ============================================================ */
.timer-wrap {
  position: relative;
  overflow: hidden;
  background: var(--timer-bg);
  font-family: var(--font-family);
  font-variant-numeric: tabular-nums;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* Scaler — absolutely centred, scaled by JS */
.timer-scaler {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Title */
.timer-title {
  color: var(--digit-color);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: center;
  opacity: 0.9;
  text-shadow: var(--text-shadow);
  width: 100%;
}

/* AM / PM badge */
.timer-ampm {
  color: var(--digit-color);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.1em;
  opacity: 0.75;
  text-align: center;
  text-shadow: var(--text-shadow);
  margin-top: 4px;
}

/* Display row */
.timer-display {
  display: flex;
  gap: var(--unit-gap);
  align-items: center;
  justify-content: center;
}

/* Columns layout */
.timer-display.columns {
  gap: calc(var(--unit-gap) * 2);
}
.timer-display.columns .timer-unit {
  flex-direction: column;
  gap: 8px;
}
.timer-display.columns .timer-sep {
  font-size: calc(var(--font-size-digit) * 0.8);
  color: var(--separator-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0.8;
  width: 20px;
  text-align: center;
  line-height: 1;
}

.timer-sep.blink {
  animation: timer-blink 1s steps(1) infinite;
}

@keyframes timer-blink {
  50% { opacity: 0; }
}

.timer-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  perspective: 1200px;
}

.timer-card-wrap {
  position: relative;
}

/* ============================================================
   STANDARD CARD (LED, Minimal, Glass, Neon, Text)
   ============================================================ */
.standard-card {
  background: var(--plate-bg);
  color: var(--digit-color);
  font-size: var(--font-size-digit);
  font-weight: var(--font-weight);
  border-radius: var(--border-radius-plate, 8px);
  box-shadow: var(--plate-shadow);
  text-shadow: var(--text-shadow);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fixed width — never changes as digits tick */
  width:  calc(var(--font-size-digit) * 1.5);
  height: calc(var(--font-size-digit) * 1.4);
  box-sizing: border-box;
  flex-shrink: 0;
  overflow: hidden;
}

[data-theme="glass"] .standard-card {
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}

[data-theme="text"] .standard-card {
  width: calc(var(--font-size-digit) * 1.1);
  height: auto;
  min-width: 0;
  background: transparent;
  box-shadow: none;
}

/* ============================================================
   FLIP CARD
   ============================================================ */
.flip-card {
  position: relative;
  font-size: var(--font-size-digit);
  font-weight: var(--font-weight);
  color: var(--digit-color);
  /* Fixed dimensions — never reflows on digit change */
  width:  calc(var(--font-size-digit) * 1.5);
  height: calc(var(--font-size-digit) * 1.4);
  background: var(--plate-bg);
  border-radius: var(--border-radius-plate, 8px);
  box-shadow: var(--plate-shadow);
  text-align: center;
  box-sizing: border-box;
  user-select: none;
  flex-shrink: 0;
  overflow: hidden;
}

/* Divider line */
.flip-card::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
  background: rgba(0,0,0,0.35);
  z-index: 5;
  pointer-events: none;
}

/* Half panels */
.flip-card .top,
.flip-card .bottom,
.flip-card .top-flip,
.flip-card .bottom-flip {
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  text-align: center;
  display: block;
}

.flip-card .top,
.flip-card .top-flip {
  top: 0;
  line-height: calc(var(--font-size-digit) * 1.5);
  border-top-left-radius: var(--border-radius-plate, 8px);
  border-top-right-radius: var(--border-radius-plate, 8px);
  background: var(--plate-bg-top, var(--plate-bg));
  transform-origin: bottom center;
}

.flip-card .bottom,
.flip-card .bottom-flip {
  bottom: 0;
  line-height: 0;
  border-bottom-left-radius: var(--border-radius-plate, 8px);
  border-bottom-right-radius: var(--border-radius-plate, 8px);
  background: var(--plate-bg);
  transform-origin: top center;
}

.flip-card .top-flip   { z-index: 4; }
.flip-card .bottom-flip { z-index: 3; transform: rotateX(90deg); }

.flip-card .top-flip.animate    { animation: flipTop    0.3s ease-in  forwards; }
.flip-card .bottom-flip.animate { animation: flipBottom 0.3s ease-out 0.3s forwards; }

@keyframes flipTop    { to { transform: rotateX(-90deg); } }
@keyframes flipBottom { to { transform: rotateX(0deg);   } }

/* ============================================================
   LABELS & SEPARATORS
   ============================================================ */
.timer-label {
  color: var(--label-color);
  font-size: var(--font-size-label, 12px);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-weight: 500;
  margin-top: 4px;
}

.timer-sep {
  color: var(--separator-color);
  font-size: var(--font-size-digit);
  font-weight: var(--font-weight);
  text-shadow: var(--text-shadow);
  animation: colon-pulse 1s steps(1) infinite;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding-bottom: 20px;
  /* Fixed width so it never causes reflow */
  width: calc(var(--font-size-digit) * 0.5);
  flex-shrink: 0;
  text-align: center;
}

.timer-sep .dot {
  width: 10px;
  height: 10px;
  background: currentColor;
  border-radius: 50%;
  box-shadow: var(--text-shadow);
}

@keyframes colon-pulse {
  0%, 100% { opacity: 1;    }
  50%       { opacity: 0.2; }
}

/* ============================================================
   LED SCANLINES
   ============================================================ */
[data-theme="led"] .timer-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    var(--scanline-opacity) 3px,
    var(--scanline-opacity) 4px
  );
  pointer-events: none;
  z-index: 10;
}
