:root {
  --bg: #111214;
  --card: #26282c;
  --card-top: #2c2e33;
  --text: #f2f2f2;
  --muted: #9a9ca3;
  --accent: #e8b04a;
  --line: rgba(0, 0, 0, .55);
  --w: min(6.2vw, 92px);           /* bredde på ét ciffer */
  --gap: calc(var(--w) * .08);     /* mellem cifre i samme enhed */
  --unit-gap: calc(var(--w) * .45);/* mellem enheder */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, #1b1d21 0%, var(--bg) 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 3vh, 32px);
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  text-align: center;
}

header h1 {
  margin: 0;
  font-size: clamp(22px, 3.2vw, 40px);
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.sub { margin: 6px 0 0; color: var(--muted); font-size: clamp(13px, 1.4vw, 17px); }

/* ---------- Ur ---------- */
.clock { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--unit-gap); }
.row { display: flex; gap: var(--unit-gap); justify-content: center; }
.unit { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.digits { display: flex; gap: var(--gap); }
.label {
  color: var(--muted);
  font-size: clamp(11px, calc(var(--w) * .18), 16px);
  letter-spacing: .16em;
  text-transform: uppercase;
}

/* Ét flip-ciffer */
.flip {
  --h: calc(var(--w) * 1.42);
  position: relative;
  width: var(--w);
  height: var(--h);
  font-size: calc(var(--h) * .78);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: var(--h);
  perspective: calc(var(--h) * 4);
  border-radius: calc(var(--w) * .1);
  box-shadow: 0 calc(var(--w) * .06) calc(var(--w) * .18) rgba(0, 0, 0, .5);
}
.flip > span {
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip > span > b { display: block; height: var(--h); font-weight: inherit; }
.flip .top, .flip .leaf-top {
  top: 0;
  background: var(--card-top);
  border-radius: calc(var(--w) * .1) calc(var(--w) * .1) 0 0;
  transform-origin: 50% 100%;
}
.flip .bottom, .flip .leaf-bottom {
  bottom: 0;
  background: var(--card);
  border-radius: 0 0 calc(var(--w) * .1) calc(var(--w) * .1);
  transform-origin: 50% 0;
}
.flip .bottom > b, .flip .leaf-bottom > b { margin-top: calc(var(--h) / -2); }
/* Hængslet midt på */
.flip::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: max(1px, calc(var(--w) * .025));
  transform: translateY(-50%);
  background: var(--line);
  z-index: 5;
}
.flip .leaf-top, .flip .leaf-bottom { display: none; z-index: 3; }
.flip.go .leaf-top { display: block; animation: leafTop .3s ease-in forwards; }
.flip.go .leaf-bottom { display: block; transform: rotateX(90deg); animation: leafBottom .3s ease-out .3s forwards; }
@keyframes leafTop { to { transform: rotateX(-90deg); } }
@keyframes leafBottom { from { transform: rotateX(90deg); } to { transform: rotateX(0deg); } }

@media (prefers-reduced-motion: reduce) {
  .flip.go .leaf-top, .flip.go .leaf-bottom { display: none; animation: none; }
}

/* ---------- Fremdrift ---------- */
.progress {
  width: min(560px, 86vw);
  height: 4px;
  border-radius: 2px;
  background: #2a2c31;
  overflow: hidden;
}
.bar { height: 100%; width: 0; background: var(--accent); transition: width .6s ease; }
.meta { margin: -8px 0 0; color: var(--muted); font-size: clamp(12px, 1.3vw, 15px); }

/* ---------- Hændelser ---------- */
.events {
  --w: min(9vw, 64px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: clamp(8px, 3vh, 28px);
  padding: clamp(14px, 2.4vw, 24px) clamp(22px, 4vw, 44px);
  border: 1px solid #2a2c31;
  border-radius: 16px;
  background: rgba(255, 255, 255, .02);
}
.events .flip { color: var(--accent); }
.label.big { font-size: clamp(11px, 1.3vw, 15px); }

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

/* Mobil / smal skærm: År+Dage øverst, Timer/Min/Sek nederst */
@media (max-width: 820px) {
  :root { --w: min(11vw, 70px); }
  .clock { flex-direction: column; align-items: center; gap: calc(var(--unit-gap) * .9); }
  .events { --w: min(13vw, 56px); }
}
@media (max-width: 820px) and (max-height: 520px) and (orientation: landscape) {
  /* Telefon på tværs: alt på én linje */
  :root { --w: min(6.2vw, 9vh); }
  .clock { flex-direction: row; }
  main { gap: 10px; }
}
