/* Mobile first: Standard = Hochformat, 4 Spalten x 7 Zeilen (= 28 Zellen) */
:root {
  --nacht: #111b2e;
  --nacht-hell: #1b2a45;
  --schnee: #f3f5f4;
  --beere: #8f2f3b;
  --tanne: #2f5d50;
  --honig: #d6a23f;
  --schrift: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: .5rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  background: var(--nacht);
  color: var(--schnee);
  font-family: var(--schrift);
}

h1 { margin: 0; font-size: 1.25rem; text-align: center; }
#hinweis { margin: 0; min-height: 1.4em; padding: 0 1rem; font-size: .875rem; text-align: center; opacity: .85; }

/* Kalender: ca. 80 % des Viewports */
#calendar {
  width: 80vw;
  height: 80vh;
  height: 80dvh;
}

.calendar-grid {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: dense;
  gap: .4rem;
}

/* Querformat: 7 Spalten x 4 Zeilen (ebenfalls 28 Zellen) */
@media (min-aspect-ratio: 1/1) {
  .calendar-grid {
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(4, 1fr);
  }
}

.col-span-2 { grid-column: span 2; }
.row-span-2 { grid-row: span 2; }

/* Kästchen */
.calendar-item {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  container-type: size;
  background: var(--tanne);
  border: 1px dashed var(--honig);
  color: var(--schnee);
  cursor: pointer;
  transition: transform .2s ease;
}
.calendar-item[data-farbe="1"] { background: var(--beere); border: 1px dashed var(--honig); }
.calendar-item[data-farbe="2"] { background: var(--nacht-hell); border: 1px dashed var(--honig); color: var(--schnee); }

.calendar-item:hover { transform: translateY(-2px); }
.calendar-item:focus-visible { outline: 3px solid var(--honig); outline-offset: 2px; }

.calendar-front {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.6rem;                 /* Fallback */
  font-size: clamp(1rem, 42cqmin, 4.5rem);
  font-weight: 600;
}

/* Inhalt ist zunächst unsichtbar */
.calendar-content { display: none; }

/* Geöffnet: Vorderseite weg, Inhalt klein im Kästchen */
.calendar-item.is-open { background: var(--schnee); color: var(--nacht); box-shadow: none; }
.is-open .calendar-front { display: none; }
.is-open .calendar-content {
  display: block;
  position: absolute;
  inset: 0;
  padding: .35rem;
  overflow: hidden;
  font-size: .6rem;
  line-height: 1.25;
  pointer-events: none;              /* Klick geht ans Kästchen */
}
.is-open .calendar-content > * { margin: 0 0 .25em; font-size: inherit; }
.is-open .calendar-content img { display: block; width: 100%; height: auto; max-height: 100%; object-fit: cover; }
.is-open .calendar-content::after {  /* sanftes Ausblenden unten */
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 1.2rem;
  background: linear-gradient(transparent, var(--schnee));
}
.is-open::before {                   /* Türchen-Nummer als kleines Etikett */
  content: attr(data-day);
  position: absolute;
  top: 3px; right: 3px;
  z-index: 1;
  padding: 0 .35em;
  border-radius: 3px;
  background: var(--nacht);
  color: var(--schnee);
  font-size: .65rem;
}

/* Falsches Datum */
.calendar-item.wackeln { animation: wackeln .45s; }
@keyframes wackeln {
  20% { transform: translateX(-5px) rotate(-2deg); }
  40% { transform: translateX(5px) rotate(2deg); }
  60% { transform: translateX(-3px) rotate(-1deg); }
  80% { transform: translateX(3px) rotate(1deg); }
}

/* Popup */
#popup {
  width: min(32rem, 90vw);
  max-height: 85vh;
  max-height: 85dvh;
  overflow: auto;
  border: 0;
  border-radius: 10px;
  padding: 1.75rem 1.5rem 1.5rem;
  background: var(--schnee);
  color: var(--nacht);
  font-family: var(--schrift);
  line-height: 1.55;
}
#popup::backdrop { background: rgb(5 10 20 / .75); }
#popup[open]::backdrop { animation: einblenden .35s both; }
@keyframes einblenden { from { opacity: 0; } }

.popup-tag { margin: 0 0 .25rem; color: var(--beere); font-weight: 600; }
.popup-inhalt > :first-child { margin-top: 0; }
.popup-inhalt > :last-child { margin-bottom: 0; }
.popup-inhalt img { max-width: 100%; height: auto; border-radius: 6px; }

.popup-close {
  position: absolute; top: .4rem; right: .6rem;
  border: 0; background: none;
  font-size: 2rem; line-height: 1;
  color: var(--nacht); cursor: pointer;
}
.popup-close:focus-visible { outline: 3px solid var(--beere); border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  .calendar-item, .calendar-item.wackeln { transition: none; animation: none; }
  #popup[open]::backdrop { animation: none; }
}
