:root {
  --page-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
  --door-border: rgba(255, 255, 255, 0.8);
  --door-border-hover: #ffffff;
  --door-bg: rgba(0, 0, 0, 0.15);
  --door-bg-hover: rgba(0, 0, 0, 0.35);
  --transition-fast: 0.3s ease;
  --transition-slow: 0.5s ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #1c2541, #0b1020 55%, #020308);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  animation: bodyFadeIn 1.2s ease both;
}

@keyframes bodyFadeIn {
  from { opacity: 0; transform: scale(0.99); }
  to   { opacity: 1; transform: scale(1); }
}

.page {
  position: relative;
  width: min(90vw, 70vh * 210 / 297); /* A4 ratio on screen */
  aspect-ratio: 210 / 297;
  background-image: url("santa_math_comic.jpg"); /* your background */
  background-size: cover;
  background-position: center;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--page-shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: stretch;
  color: #fff;
  backdrop-filter: blur(0.5px);
}

.header {
  text-align: center;
  padding-bottom: 0.5rem;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  user-select: none;
}

.header h1 {
  margin: 0.1rem 0 0.2rem;
  font-size: clamp(1.2rem, 2.5vw, 1.6rem);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 0.35rem;
  position: relative; /* important for overlay */
}

/* Each grid cell */
.door-slot {
  position: relative;
  perspective: 800px; /* for 3D flap */
  background: transparent;
}

/* When a door is active, make the whole cell white */
.door-slot.active {
  background: #ffffff;
}

/* The flap itself */
.door {
  position: absolute;
  inset: 0;
  border: 2px solid var(--door-border);
  border-radius: 4px;
  background: var(--door-bg);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform var(--transition-slow),
    box-shadow var(--transition-slow),
    border-color var(--transition-fast),
    background var(--transition-fast),
    opacity 0.25s ease;
  backdrop-filter: blur(1px);
  transform-style: preserve-3d;
  transform-origin: left center; /* default hinge on left */
  z-index: 2; /* flap above text */
}

.door.hinge-right {
  transform-origin: right center;
}

.door:hover {
  border-color: var(--door-border-hover);
  background: var(--door-bg-hover);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

.door-number {
  font-size: clamp(0.9rem, 2.2vw, 1.1rem);
  font-weight: 700;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
  z-index: 1;
  transition: opacity var(--transition-fast);
}

/* Flap open states (Advent-style) */
.door.open.hinge-left {
  transform: rotateY(-120deg);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.7);
}

.door.open.hinge-right {
  transform: rotateY(120deg);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.7);
}

.door.open .door-number {
  opacity: 0;
}

/* Small box under the door: Christmas emoji */
.question-content {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.25rem;
  text-align: center;
  font-size: 1.1rem;
  line-height: 1.3;
  color: #000;
  background: transparent;
  z-index: 0;
  border-radius: 4px;
  overflow: hidden;
}

.door-slot.active .question-content {
  background: #ffffff;
  border: none; /* pure white card under the door */
}

.emoji-behind {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.door-slot.active .emoji-behind {
  opacity: 1;
}

.close-question-small {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.65);
  color: white;
  border: none;
  border-radius: 50%;
  width: 10px;
  height: 10px;
  font-size: 6px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
}
.door-slot.active .close-question-small {
  display: flex;
}

/* FRONT PAGE STYLES */
.front-page {
  position: fixed;
  inset: 0;
  background-image: url("School.jpg");
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: white;
  text-align: center;
}

#start-button {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 0.8rem 1.8rem;
  font-size: 1.1rem;
  background: green;
  color: #ffffff;
  border: 2px solid #ffffff;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: none;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease;
}
#start-button:hover {
  transform: scale(1.05);
  background: rgba(0, 0, 0, 0.25);
  border-color: #ffffff;
}

/* 🔊 mute button on second page */
.mute-button {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.4);
  color: #ffffff;
  border: 2px solid #ffffff;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: none;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease;
  z-index: 10;
}

.mute-button:hover {
  transform: scale(1.05);
  background: rgba(0, 0, 0, 0.65);
  border-color: #ffffff;
}

/* BIG QUESTION PANEL (position depends on row) */
.question-panel {
  position: absolute;
  left: 1rem;
  right: 1rem;
  background: #ffffff;
  color: #000000;
  border-radius: 12px;
  border: 2px solid #dddddd;
  padding: 1rem 1.2rem;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  z-index: 5;
  overflow-y: auto;
}

/* lower part of calendar */
.question-panel.bottom-panel {
  bottom: 1rem;
  top: auto;
}

/* upper part of calendar */
.question-panel.top-panel {
  top: 1rem;
  bottom: auto;
}

.question-panel.active {
  display: flex;
}

#question-panel-text {
  font-size: clamp(0.8rem, 1.5vw, 1rem);
  line-height: 1.5;
  word-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  white-space: pre-line;
}

#question-panel-close {
  align-self: flex-end;
  margin-bottom: 0.5rem;
  background: rgba(0,0,0,0.75);
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
}

@media (max-width: 480px) {
  .page {
    padding: 0.7rem;
  }
  .grid {
    gap: 0.25rem;
  }
  .question-panel {
    left: 0.7rem;
    right: 0.7rem;
    padding: 0.7rem 0.8rem;
  }
  #question-panel-text {
    font-size: 0.85rem;
  }
}