/* ==========================================================================
   Kaffee-Adventskalender – Gestaltung
   Historische botanische Tafel trifft Editorial-Magazin
   ========================================================================== */

/* ---------- 1. Farben, Schriften, Texturen ---------- */
:root {
  --paper: #F2EBDD;
  --paper-deep: #E6D9BF;
  --ink: #2B2620;
  --ink-soft: #5B5147;
  --ink-faint: rgba(43, 38, 32, 0.32);

  --leaf: #5E7849;
  --cherry-unripe: #9DAF66;
  --cherry-ripe: #A8322D;
  --ochre: #B8873A;
  --branch: #8C6B49;

  --serif: "Cormorant Garamond", "Cormorant", Garamond, "Hoefler Text", "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  /* Papierkorn: feines Rauschen als Inline-SVG (keine externen Bilder) */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .17 0 0 0 0 .14 0 0 0 0 .1 .32 0 0 0 -.09'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  /* Stockflecken: großflächiges, weiches Rauschen */
  --stains: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1400' height='1400'%3E%3Cfilter id='s'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.0045' numOctaves='3' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .4 0 0 0 0 .2 .75 0 0 0 -.33'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23s)'/%3E%3C/svg%3E");
}

/* ---------- 2. Grundlagen ---------- */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Hintergrund nicht scrollen, solange das Popup offen ist */
html:has(dialog[open]) { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  position: relative;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.5;
  font-variant-numeric: lining-nums;
  -webkit-font-smoothing: antialiased;
}

/* Papierstruktur über die ganze Fläche */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--grain), var(--stains);
  background-size: 220px 220px, 1400px 1400px;
}


.mono { font-family: var(--mono); }

a { color: inherit; }

:focus-visible {
  outline: 1.5px dashed var(--ink);
  outline-offset: 3px;
}

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

/* ---------- 3. Seite: nur die Pflanze, mittig und bildschirmfüllend ---------- */
.page {
  /* Platz, der vertikal nicht für den Busch zur Verfügung steht (Ränder + Countdown) */
  --pad: clamp(16px, 3vw, 40px);
  --chrome: calc(var(--pad) * 2 + 32px);
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding-block: var(--pad);
  padding-inline: var(--pad);
}

.countdown {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto 14px;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  color: var(--ink-soft);
}

.countdown::before,
.countdown::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--ink-faint);
}

/* Seitenverhältnis des Hochformat-Bildes (Breite / Höhe: 765 × 1485) */
:root { --ratio-m: 0.5152; }

/* Container mit festem Seitenverhältnis – alle Kirschen-Positionen sind Prozentwerte */
.stage {
  position: relative;
  /* Querformat füllt Breite bzw. Höhe; mindestens 900 px breit, sonst würden sich Tap-Flächen überlappen */
  width: clamp(min(900px, 100%), calc((100dvh - var(--chrome)) * 1.5), 100%);
  aspect-ratio: 3 / 2;
  margin-inline: auto;
}

/* Illustration (freigestellt, Papier scheint durch) */
.plant,
.plant img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

/* Stiele von Ast zu Kirsche (und gemeinsamer Stiel an Tag 24) */
.stalk {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.stalk path {
  fill: none;
  stroke: #6E5A3C;
  stroke-width: 2.4px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.stalk--mobile { display: none; }

/* ---------- 4. Kirschen (Türchen) ---------- */
.cherries {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Die Tap-Fläche ist quadratisch; die Kirsche hängt vom Ankerpunkt (oben Mitte) nach unten */
.cherry {
  --size: clamp(44px, 4.4%, 62px);
  position: absolute;
  left: var(--dx);
  top: var(--dy);
  width: var(--size);
  aspect-ratio: 1 / 1; /* Prozentwerte beziehen sich auf die Breite der Tafel */
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  pointer-events: auto;
  transform: translate(-50%, -4%);
  -webkit-tap-highlight-color: transparent;
  container-type: inline-size;
}

.cherry:focus-visible {
  outline-offset: 0;
  border-radius: 40%;
}

.cherry__inner {
  position: absolute;
  inset: 0;
  transform-origin: 50% 0;
  transition: transform 220ms ease;
}

/* Hover: alle Kirschen heben sich gleich leicht an */
@media (hover: hover) {
  .cherry:hover .cherry__inner { transform: translateY(-3px); }
}
.cherry:focus-visible .cherry__inner { transform: translateY(-3px); }

.cherry__img {
  position: absolute;
  top: 0;
  left: 50%;
  height: 100%;
  width: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 1px 1.5px rgba(43, 38, 32, 0.35));
  user-select: none;
  -webkit-user-drag: none;
}

.cherry__img--ripe { opacity: 0; }

.cherry__num {
  position: absolute;
  left: 0;
  right: 0;
  top: 56%;
  transform: translateY(-50%);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 16px;
  font-size: clamp(14px, 36cqi, 22px);
  line-height: 1;
  text-align: center;
  color: var(--ink);
  text-shadow: 0 0 3px rgba(242, 235, 221, 0.95), 0 0 1px rgba(242, 235, 221, 0.95);
  pointer-events: none;
  font-variant-numeric: lining-nums;
}

/* Geöffnet: reif und rot */
.cherry.is-open .cherry__img--unripe { opacity: 0; }
.cherry.is-open .cherry__img--ripe { opacity: 1; }
.cherry.is-open .cherry__num {
  color: var(--paper);
  text-shadow: 0 0 3px rgba(60, 12, 10, 0.9), 0 0 1px rgba(60, 12, 10, 0.9);
}

/* Reife-Animation: Grün → Gelb-Orange → Rot, dazu leichtes Anschwellen */
.cherry.is-ripening .cherry__img--unripe { animation: unripe-fade 600ms ease-in forwards; }
.cherry.is-ripening .cherry__img--ripe { animation: ripen 600ms ease-in-out forwards; }
.cherry.is-ripening .cherry__inner { animation: swell 600ms ease-in-out; }
.cherry.is-ripening .cherry__num {
  color: var(--paper);
  text-shadow: 0 0 3px rgba(60, 12, 10, 0.9), 0 0 1px rgba(60, 12, 10, 0.9);
  transition: color 450ms 150ms, text-shadow 450ms 150ms;
}

@keyframes unripe-fade {
  0%   { opacity: 1; filter: none; }
  45%  { opacity: 1; filter: hue-rotate(-38deg) saturate(1.35) brightness(1.08); }
  75%  { opacity: 0.35; filter: hue-rotate(-55deg) saturate(1.5); }
  100% { opacity: 0; filter: hue-rotate(-60deg) saturate(1.5); }
}

@keyframes ripen {
  0%   { opacity: 0; filter: hue-rotate(38deg) saturate(1.2) brightness(1.1); }
  45%  { opacity: 0.2; filter: hue-rotate(34deg) saturate(1.2) brightness(1.1); }
  75%  { opacity: 0.85; filter: hue-rotate(14deg); }
  100% { opacity: 1; filter: none; }
}

@keyframes swell {
  0%   { transform: scale(1); }
  55%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* Gesperrt: sanftes Wackeln am Stiel */
.cherry.is-wobbling .cherry__inner { animation: wobble 520ms ease-in-out; }

@keyframes wobble {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-9deg); }
  40% { transform: rotate(7deg); }
  60% { transform: rotate(-4deg); }
  80% { transform: rotate(2deg); }
}

/* Hinweis "Noch nicht reif" */
.hint {
  --arrow-x: 0px;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  width: max-content;
  max-width: min(300px, 92%);
  margin: 0;
  padding: 7px 11px 6px;
  background: var(--paper);
  border: 1px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink-faint);
  font-size: 11.5px;
  line-height: 1.35;
  letter-spacing: 0.02em;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, calc(-100% - 10px));
  transition: opacity 180ms ease, visibility 0s linear 180ms;
}

.hint--below { transform: translate(-50%, 10px); }

.hint.is-visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 180ms ease;
}

/* Impressum-Link unten rechts */
.imprint {
  position: fixed;
  right: 10px;
  bottom: 6px;
  z-index: 2;
  padding: 6px 4px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-soft);
  opacity: 0.7;
}

.imprint:hover,
.imprint:focus-visible {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.noscript {
  margin: 16px 0 0;
  text-align: center;
  font-style: italic;
}

/* ---------- 5. Popup (Karteikarte) ---------- */
.card {
  width: min(580px, calc(100vw - 24px));
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}

.card::backdrop { background: rgba(35, 29, 22, 0.55); }

.card[open] .card__sheet { animation: card-in 260ms ease-out; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.card__sheet {
  position: relative;
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px clamp(18px, 5vw, 36px) 12px;
  background-color: var(--paper);
  background-image: var(--grain);
  background-size: 220px 220px;
  border: 1px solid var(--ink);
  outline: 1px solid var(--ink-faint);
  outline-offset: -6px;
  box-shadow: 0 24px 50px -14px rgba(30, 24, 16, 0.5);
}

.card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ink);
}

.card__kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.card__close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
}

.card__close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

.card__content.is-turning { animation: card-turn 220ms ease-out; }

@keyframes card-turn {
  from { opacity: 0.2; }
  to   { opacity: 1; }
}

.card__hero {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 16px;
  margin-top: 14px;
}

.card__day {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 0.18em;
  margin: 0;
  font-weight: 500;
  line-height: 0.9;
}

/* Überschrift erhält beim Öffnen programmatisch den Fokus – ohne Rahmen */
.card__day:focus,
.card__day:focus-visible { outline: none; }

.card__day-label { font-size: 30px; font-style: italic; font-weight: 400; }
.card__day-num   { font-size: clamp(64px, 16vw, 84px); letter-spacing: -0.02em; }
.card__day-slot  { font-size: 38px; font-style: italic; font-weight: 400; color: var(--cherry-ripe); }

.card__fig {
  display: grid;
  justify-items: center;
  gap: 2px;
  margin: 0;
}

.card__fig img {
  display: block;
  width: 40px;
  height: 56px;
}

.card__fig figcaption {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.card__name {
  margin: 14px 0 4px;
  font-size: clamp(26px, 6vw, 32px);
  font-style: italic;
  font-weight: 500;
  line-height: 1.08;
}

.card__roaster {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.card__by {
  margin: 8px 0 0;
  font-size: 17px;
  color: var(--ink-soft);
}

.card__by strong { color: var(--ink); font-weight: 600; }

/* doppelte Trennlinie */
.card__rule {
  height: 4px;
  margin: 16px 0 6px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.card__meta {
  display: grid;
  grid-template-columns: minmax(7.5em, max-content) 1fr;
  column-gap: 18px;
  margin: 0;
}

.card__meta dt,
.card__meta dd {
  padding: 7px 0 6px;
  border-bottom: 1px dotted var(--ink-faint);
}

.card__meta dt {
  padding-top: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.card__meta dd {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

.card__label {
  margin: 18px 0 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.card__notes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card__notes li {
  padding: 4px 9px 3px;
  border: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.card__comment {
  margin: 20px 0 0;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--ochre);
}

.card__comment blockquote {
  margin: 0;
  font-size: 19px;
  font-style: italic;
  line-height: 1.4;
}

.card__comment figcaption {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.card__link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin-top: 22px;
  padding: 10px 16px 9px;
  border: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink);
  transition: background-color 150ms, color 150ms;
}

.card__link:hover {
  background: var(--ink);
  color: var(--paper);
}

.card__empty {
  margin: 18px 0 0;
  font-style: italic;
  color: var(--ink-soft);
}

.card__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
  padding-top: 4px;
  border-top: 1px solid var(--ink);
}

.card__nav-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.card__nav-btn:disabled {
  opacity: 0.28;
  cursor: default;
}

.card__nav-btn:not(:disabled):hover { text-decoration: underline; text-underline-offset: 3px; }

.card__pos {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

/* ---------- 6. Mobile und Tablet: eigene Hochformat-Komposition ---------- */
@media (max-width: 1023px) {
  .page { --pad: 12px; }

  .stage {
    aspect-ratio: var(--ratio-m);
    /* Hochformat füllt die Höhe; mindestens 336 px breit (Tap-Flächen überlappen sonst) */
    width: clamp(min(336px, 100%), calc((100dvh - var(--chrome)) * var(--ratio-m)), 100%);
  }

  .stalk--desktop { display: none; }
  .stalk--mobile  { display: block; }

  /* Das Hochformat-Bild ist seitlich beschnitten: Blattspitzen weich ausblenden */
  .plant img {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 7%, #000 93%, transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 7%, #000 93%, transparent 100%);
  }

  .cherry {
    --size: clamp(44px, 13%, 58px);
    left: var(--mx);
    top: var(--my);
  }
}

/* Bewegung reduzieren */
@media (prefers-reduced-motion: reduce) {
  .cherry__inner,
  .card__link,
  .hint { transition: none; }
  .cherry.is-wobbling .cherry__inner,
  .cherry.is-ripening .cherry__inner,
  .cherry.is-ripening .cherry__img,
  .card[open] .card__sheet,
  .card__content.is-turning { animation: none; }
}
