/* ==========================================================================
   big-digits.app — Einbett-Widget (/embed/, /en/embed/, /es/embed/, /fr/embed/)
   Eigenständige, ablenkungsfreie Ansicht für <iframe>-Einbettungen.
   Keine Cookies, kein Tracking, selbst gehostete Schrift (Roboto Mono).
   ========================================================================== */

:root {
  color-scheme: dark;
  --ew-bg: #050608;
  --ew-bg-subtle: rgba(255, 255, 255, 0.035);
  --ew-border: rgba(255, 255, 255, 0.09);
  --ew-fg: #ffffff;
  --ew-muted: rgba(255, 255, 255, 0.58);
  --ew-accent: #38bdf8;
  --ew-glow: #0073e6;
  --ew-btn-bg: rgba(255, 255, 255, 0.08);
  --ew-btn-hover: rgba(255, 255, 255, 0.15);
  --ew-btn-active: rgba(56, 189, 248, 0.22);
  --ew-btn-border: rgba(255, 255, 255, 0.16);
  --ew-digit-weight: 100;
  --ew-shadow:
    0 0 6px rgba(255, 255, 255, 0.75),
    0 0 16px rgba(0, 115, 230, 0.55),
    0 0 34px rgba(0, 115, 230, 0.35);
}

html[data-theme="light"] {
  color-scheme: light;
  --ew-bg: #f8fafc;
  --ew-bg-subtle: rgba(15, 23, 42, 0.035);
  --ew-border: rgba(15, 23, 42, 0.1);
  --ew-fg: #0f172a;
  --ew-muted: rgba(15, 23, 42, 0.56);
  --ew-accent: #0284c7;
  --ew-glow: transparent;
  --ew-btn-bg: rgba(15, 23, 42, 0.06);
  --ew-btn-hover: rgba(15, 23, 42, 0.11);
  --ew-btn-active: rgba(2, 132, 199, 0.15);
  --ew-btn-border: rgba(15, 23, 42, 0.15);
  --ew-digit-weight: 300;
  --ew-shadow: none;
}

@media (prefers-color-scheme: light) {
  html[data-theme="auto"] {
    color-scheme: light;
    --ew-bg: #f8fafc;
    --ew-bg-subtle: rgba(15, 23, 42, 0.035);
    --ew-border: rgba(15, 23, 42, 0.1);
    --ew-fg: #0f172a;
    --ew-muted: rgba(15, 23, 42, 0.56);
    --ew-accent: #0284c7;
    --ew-glow: transparent;
    --ew-btn-bg: rgba(15, 23, 42, 0.06);
    --ew-btn-hover: rgba(15, 23, 42, 0.11);
    --ew-btn-active: rgba(2, 132, 199, 0.15);
    --ew-btn-border: rgba(15, 23, 42, 0.15);
    --ew-digit-weight: 300;
    --ew-shadow: none;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--ew-bg);
  color: var(--ew-fg);
  font-family: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  transition: background-color 0.25s ease, color 0.25s ease;
}

body.is-flash {
  background-color: var(--ew-fg) !important;
  color: var(--ew-bg) !important;
}

.ew-shell {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(8px, 2.5vmin, 18px) clamp(12px, 3vmin, 24px);
  /* Dezent angedeutetes Kachel-Kreuz wie in der Haupt-App */
  background-image:
    linear-gradient(to right, transparent calc(50% - 0.5px), var(--ew-border) calc(50% - 0.5px), var(--ew-border) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), var(--ew-border) calc(50% - 0.5px), var(--ew-border) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

/* Obere Kopfzeile: Modus-Anzeige links, dezenter Status rechts */
.ew-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 22px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: clamp(11px, 2.2vmin, 13px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ew-muted);
  z-index: 2;
}

.ew-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.ew-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--ew-muted);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

body.is-running .ew-dot {
  background-color: var(--ew-accent);
  box-shadow: 0 0 8px var(--ew-accent);
}

/* Hauptbühne für die großen Ziffern */
.ew-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
}

body[data-mode="countdown"] .ew-stage,
body[data-mode="stopwatch"] .ew-stage {
  cursor: pointer;
}

.ew-digits {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  white-space: nowrap;
  line-height: 1;
  font-weight: var(--ew-digit-weight);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--ew-fg);
  text-shadow: var(--ew-shadow);
  /* Fallback vor JS-Messung */
  font-size: clamp(2.2rem, min(18vw, 48vh), 14rem);
  transition: transform 0.15s ease-out, opacity 0.2s ease;
  will-change: contents;
}

body[data-mode="countdown"] .ew-stage:active .ew-digits,
body[data-mode="stopwatch"] .ew-stage:active .ew-digits {
  transform: scale(0.985);
}

.ew-sep {
  opacity: 0.72;
  margin: 0 -0.04em;
}

body.is-running .ew-sep {
  animation: ew-blink 1s steps(2, start) infinite;
}

@keyframes ew-blink {
  to {
    opacity: 0.28;
  }
}

.ew-frac {
  font-size: 0.48em;
  opacity: 0.78;
  margin-left: 0.04em;
}

/* Fortschrittsbalken beim Countdown */
.ew-progress-track {
  width: 100%;
  height: 3px;
  background: var(--ew-border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
  z-index: 2;
}

.ew-progress-Track-hidden {
  display: none;
}

.ew-progress-bar {
  width: 0%;
  height: 100%;
  background: var(--ew-accent);
  border-radius: 999px;
  transition: width 0.12s linear;
}

/* Untere Leiste: Steuerung + dezenter Quellenlink */
.ew-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-height: 34px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  z-index: 2;
}

body[data-mode="clock"] .ew-bar {
  justify-content: flex-end;
}

.ew-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

body[data-mode="clock"] .ew-controls {
  display: none;
}

.ew-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--ew-btn-border);
  background: var(--ew-btn-bg);
  color: var(--ew-fg);
  font: inherit;
  font-size: clamp(12px, 2.4vmin, 13.5px);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.15s ease;
}

.ew-btn:hover {
  background: var(--ew-btn-hover);
}

.ew-btn:active {
  transform: scale(0.96);
}

.ew-btn:focus-visible {
  outline: 2px solid var(--ew-accent);
  outline-offset: 2px;
}

body.is-running .ew-btn-primary {
  background: var(--ew-btn-active);
  border-color: var(--ew-accent);
}

/* Morphendes Play/Pause-Icon (Checkliste B.3) */
.ew-icon-morph {
  position: relative;
  width: 14px;
  height: 14px;
  display: inline-block;
  flex: 0 0 14px;
}

.ew-icon-morph svg {
  position: absolute;
  inset: 0;
  width: 14px;
  height: 14px;
  fill: currentColor;
  transition: transform 0.22s ease-out, opacity 0.22s ease-out;
}

.ew-icon-pause {
  opacity: 0;
  transform: scale(0.6) rotate(-45deg);
}

body.is-running .ew-icon-play {
  opacity: 0;
  transform: scale(0.6) rotate(45deg);
}

body.is-running .ew-icon-pause {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.ew-btn svg.ew-icon-single {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 14px;
  transition: transform 0.25s ease;
}

#ew-reset:active svg.ew-icon-single {
  transform: rotate(-90deg);
}

/* Dezenter Quellenlink unten rechts/mittig */
.ew-source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--ew-muted);
  text-decoration: none;
  font-size: clamp(11px, 2.1vmin, 12.5px);
  line-height: 1.2;
  transition: color 0.18s ease, background-color 0.18s ease;
}

.ew-source:hover,
.ew-source:focus-visible {
  color: var(--ew-fg);
  background: var(--ew-bg-subtle);
}

.ew-source svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.8;
}

/* Sehr flache iframes (< 150px Höhe): Kopfzeile ausblenden, maximaler Platz für Ziffern */
@media (max-height: 155px) {
  .ew-top {
    display: none;
  }
  .ew-shell {
    padding: 4px 10px;
  }
  .ew-btn {
    min-height: 28px;
    padding: 3px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
