/* ==========================================================================
   Kalendarz Adwentowy — tekturowa plansza z wyciętymi okienkami
   ========================================================================== */

:root {
  --table: #e6ddcc;
  --ink: #2a2522;
  --ink-soft: #6b625a;
  --cream: #f4ecdc;
  --red: #9b2f37;
  --red-dark: #7c232b;
  --green: #2f5d46;
  --night: #16202f;
  --kraft: #bca27a;

  --font-display: 'Young Serif', Georgia, serif;
  --font-body: 'Karla', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--table);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255, 252, 244, 0.7), transparent 70%),
    var(--table);
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ==========================================================================
   Strona i tryb testowy
   ========================================================================== */

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 16px 40px;
}

.test-toggle {
  display: block;
  margin: 0 0 10px auto;
  padding: 4px 2px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink-soft);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.test-toggle:hover,
.test-toggle.is-active {
  color: var(--red);
}

.test-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 14px;
  padding: 8px 10px;
  border: 1px dashed rgba(42, 37, 34, 0.35);
  border-radius: 4px;
  font-size: 0.82rem;
}

.test-bar[hidden] {
  display: none;
}

.tsep {
  width: 1px;
  height: 18px;
  background: rgba(42, 37, 34, 0.2);
  margin: 0 4px;
}

.tbtn {
  padding: 5px 10px;
  border: 1px solid rgba(42, 37, 34, 0.25);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.45);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}

.tbtn:hover:not(:disabled) {
  background: #fff;
}

.tbtn:disabled {
  opacity: 0.35;
  cursor: default;
}

.tbtn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--cream);
}

.tbtn--danger {
  color: var(--red);
  border-color: rgba(155, 47, 55, 0.4);
}

/* ==========================================================================
   Plansza
   ========================================================================== */

.board {
  position: relative;
  padding: 26px 26px 30px;
  border-radius: 5px;
  background-color: var(--night);
  background-image: url('scene.svg');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.4),
    0 2px 3px rgba(40, 30, 20, 0.25),
    0 28px 50px -18px rgba(40, 30, 20, 0.6);
}

.board-head {
  position: relative;
  z-index: 1;
  margin-bottom: 22px;
  color: var(--cream);
}

.board-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2rem, 6vw, 3.6rem);
  line-height: 1;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.board-status {
  margin: 10px 0 0;
  font-size: 1rem;
  color: rgba(244, 236, 220, 0.82);
}

/* --- Siatka: nieregularne okienka, Wigilia w środku --- */

.doors {
  display: grid;
  gap: 9px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, 118px);
  grid-template-areas:
    "d7  d7  d15 d3  d3  d19"
    "d12 d1  d15 d22 d9  d19"
    "d12 d18 d24 d24 d9  d5"
    "d2  d18 d24 d24 d14 d14"
    "d20 d13 d10 d6  d6  d23"
    "d11 d16 d17 d4  d21 d8";
}

@media (max-width: 760px) {
  .doors {
    grid-template-rows: repeat(6, 96px);
  }
}

@media (max-width: 599px) {
  .board {
    padding: 18px 14px 20px;
  }

  .board-head {
    margin-bottom: 16px;
  }

  .doors {
    gap: 6px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(9, 84px);
    grid-template-areas:
      "d7  d7  d15 d3"
      "d12 d1  d15 d3"
      "d12 d22 d9  d19"
      "d18 d5  d9  d19"
      "d18 d24 d24 d2"
      "d14 d24 d24 d13"
      "d14 d10 d6  d6"
      "d20 d23 d11 d16"
      "d17 d4  d21 d8";
  }
}

/* --- Pojedyncze okienko --- */

.door {
  position: relative;
  perspective: 2200px;
}

.door.is-open {
  z-index: 3;
}

.door-button {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
  border-radius: 3px;
  transform-style: preserve-3d;
}

.door.is-locked .door-button {
  cursor: default;
}

.door-button:focus-visible {
  outline: 3px solid var(--cream);
  outline-offset: 2px;
}

/* Wnętrze (to, co widać po otwarciu) — ciepłe, jakby w środku paliło się światło */
.door-interior {
  position: absolute;
  inset: 0;
  /* zawsze odrobinę za klapką, żeby w 3D nie migały na zmianę */
  transform: translateZ(-2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  border-radius: 3px;
  background: radial-gradient(ellipse at 50% 42%, #5a3c25 0%, #2e1e13 55%, #170f09 100%);
  color: var(--cream);
  text-align: center;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.6),
    inset 9px 9px 16px rgba(0, 0, 0, 0.65);
}

.door-interior-icon {
  display: block;
  width: min(50%, 60px);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 12px rgba(240, 192, 102, 0.35));
}

.door-interior-icon svg,
.door-interior-icon img {
  display: block;
  width: 100%;
  height: auto;
}

.door.is-wigilia .door-interior-icon {
  width: min(38%, 104px);
}

.door-interior-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  line-height: 1.15;
}

.door.is-wigilia .door-interior-title {
  font-size: 1.15rem;
}

.door-interior-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  color: rgba(244, 236, 220, 0.62);
}

.door.is-solved .door-interior-state {
  color: #f0c066;
}

.chk {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #f0c066;
  color: #2e1e13;
  font-size: 0.68rem;
  font-weight: 700;
}

.door.is-small .door-interior-title {
  display: none;
}

/* Klapka */
.door-flap {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  /* stała własna warstwa — bez tego przeglądarka przerysowuje ilustrację przy każdym najechaniu i okienko miga */
  will-change: transform;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.door.is-open .door-flap {
  transition: transform 0.75s cubic-bezier(0.3, 1.2, 0.5, 1);
}

.door-front,
.door-back {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  backface-visibility: hidden;
}

/* Przód = wycinek wspólnej ilustracji, lekko wypukły jak tekturka */
.door-front {
  transform: translateZ(0.5px);
  background-color: var(--night);
  background-image: url('scene.svg');
  background-size: var(--bw, 100%) var(--bh, 100%);
  background-position: var(--bx, 0) var(--by, 0);
  background-repeat: no-repeat;
  outline: 2px dashed rgba(244, 236, 220, 0.85);
  outline-offset: -2px;
  box-shadow:
    0 0 0 1px rgba(10, 14, 22, 0.5),
    0 3px 6px rgba(0, 0, 0, 0.35),
    inset 0 0 0 3px rgba(10, 14, 22, 0.22),
    inset 2px 2px 0 rgba(255, 255, 255, 0.2),
    inset -2px -2px 0 rgba(0, 0, 0, 0.28);
}

.door.on-snow .door-front {
  outline-color: rgba(42, 37, 34, 0.55);
  box-shadow:
    0 0 0 1px rgba(42, 37, 34, 0.35),
    0 3px 6px rgba(60, 45, 30, 0.3),
    inset 2px 2px 0 rgba(255, 255, 255, 0.6),
    inset -2px -2px 0 rgba(60, 45, 30, 0.22);
}

/* Tył klapki = tektura */
.door-back {
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.03) 0 2px, transparent 2px 5px),
    var(--kraft);
  box-shadow: inset 0 0 0 1px rgba(80, 60, 30, 0.3);
}

/* Numer — każdy w innym miejscu i rozmiarze */
.door-num {
  position: absolute;
  font-family: var(--font-display);
  line-height: 1;
  color: var(--cream);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.55), 0 0 10px rgba(16, 26, 44, 0.75);
  transform: rotate(var(--rot, 0deg));
  pointer-events: none;
}

.door.on-snow .door-num {
  color: var(--red);
  text-shadow: 0 0 6px rgba(244, 236, 220, 0.95), 0 0 2px rgba(244, 236, 220, 0.9);
}

.size-s { font-size: 1.5rem; }
.size-m { font-size: 2.1rem; }
.size-l { font-size: 2.9rem; }

.door.is-wigilia .door-num { font-size: 4.4rem; }

.pos-tl { top: 10px; left: 12px; }
.pos-tr { top: 10px; right: 12px; }
.pos-bl { bottom: 10px; left: 12px; }
.pos-br { bottom: 10px; right: 12px; }
.pos-c  { top: 50%; left: 50%; translate: -50% -50%; }

/* Dzisiejsze okienko — złota ramka, poświata i karteczka „dziś” */
.door.is-today:not(.is-open) {
  z-index: 2;
}

.door.is-today:not(.is-open) .door-front {
  outline: 2.5px solid #f2c46b;
  outline-offset: -1px;
  animation: todayGlow 2.4s ease-in-out infinite;
}

@keyframes todayGlow {
  0%, 100% {
    box-shadow:
      0 0 0 2px rgba(242, 196, 107, 0.35),
      0 0 18px 2px rgba(242, 196, 107, 0.45),
      inset 0 0 18px rgba(242, 196, 107, 0.3);
  }
  50% {
    box-shadow:
      0 0 0 3px rgba(242, 196, 107, 0.55),
      0 0 32px 8px rgba(242, 196, 107, 0.6),
      inset 0 0 26px rgba(242, 196, 107, 0.45);
  }
}

.door.is-today:not(.is-open) .door-num {
  color: #f6cf7c;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.6), 0 0 14px rgba(242, 196, 107, 0.7);
}

.today-sticker {
  position: absolute;
  top: -13px;
  left: 50%;
  z-index: 2;
  padding: 4px 12px 5px;
  border-radius: 3px;
  background: var(--red);
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 0.95rem;
  line-height: 1;
  white-space: nowrap;
  transform: translateX(-50%) rotate(-4deg);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

@media (max-width: 599px) {
  .size-s { font-size: 1.15rem; }
  .size-m { font-size: 1.55rem; }
  .size-l { font-size: 2rem; }
  .door.is-wigilia .door-num { font-size: 3rem; }
  .pos-tl { top: 6px; left: 7px; }
  .pos-tr { top: 6px; right: 7px; }
  .pos-bl { bottom: 6px; left: 7px; }
  .pos-br { bottom: 6px; right: 7px; }
  .today-sticker { font-size: 0.8rem; padding: 3px 8px 4px; top: -10px; }

  .door-interior-title,
  .door-interior-state .lbl {
    display: none;
  }
  .door.is-wigilia .door-interior-title {
    display: block;
    font-size: 0.95rem;
  }
  .door-interior-icon {
    width: min(70%, 46px);
  }
  .door.is-open .door-interior {
    padding-left: 28%;
  }
}

/* Stany */
.door.is-unlocked:not(.is-open):hover .door-flap {
  transform: rotateY(-16deg);
}

.door.is-open .door-flap {
  transform: rotateY(-70deg);
}

.door.is-open .door-interior {
  padding-left: 34%;
}

.door.is-shaking .door-flap {
  animation: rattle 0.35s ease;
}

@keyframes rattle {
  25% { transform: rotateY(-4deg); }
  50% { transform: rotateY(0deg); }
  75% { transform: rotateY(-3deg); }
}

/* ==========================================================================
   Okno pytania
   ========================================================================== */

html.modal-open {
  overflow: hidden;
}

html.modal-open body {
  padding-right: var(--scrollbar-gap, 0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(16, 24, 38, 0.66);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  overscroll-behavior: contain;
}

.modal-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 8px;
  background: #f7f1e4;
  color: var(--ink);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.08),
    0 40px 80px -20px rgba(0, 0, 0, 0.65);
  transform: translateY(20px) scale(0.96);
  transition: transform 0.4s cubic-bezier(0.2, 1.3, 0.4, 1);
}

.modal-backdrop.is-visible .modal-card {
  transform: translateY(0) scale(1);
}

/* Górny pasek: kawałek nocnego nieba z planszy, numer dnia i ikonka */
.modal-banner {
  position: relative;
  height: 150px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 26px 18px;
  background-color: var(--night);
  background-image: url('scene.svg');
  background-repeat: no-repeat;
  background-size: 240% auto;
}

.modal-banner::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(16, 26, 44, 0) 25%, rgba(16, 26, 44, 0.6) 100%);
}

.modal-num,
.modal-illus {
  position: relative;
}

.modal-num {
  font-family: var(--font-display);
  font-size: 4.6rem;
  line-height: 0.85;
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3), 0 0 18px rgba(16, 26, 44, 0.8);
}

.modal-illus {
  width: 76px;
  height: 76px;
  color: var(--cream);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 16px rgba(240, 192, 102, 0.4));
}

.modal-illus svg,
.modal-illus img {
  display: block;
  width: 100%;
  height: 100%;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(16, 24, 38, 0.5);
  color: var(--cream);
  cursor: pointer;
  transition: background 0.15s ease;
}

.modal-close:hover {
  background: rgba(16, 24, 38, 0.85);
}

/* Perforacja między paskiem a treścią */
.modal-content {
  position: relative;
  padding: 22px 28px 26px;
  border-top: 2px dashed rgba(42, 37, 34, 0.22);
}

.modal-day {
  margin: 0 0 4px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--red);
}

.modal-title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.9rem;
  line-height: 1.1;
}

@media (max-width: 440px) {
  .modal-banner {
    height: 122px;
    padding: 0 20px 14px;
  }
  .modal-num { font-size: 3.6rem; }
  .modal-illus { width: 60px; height: 60px; }
  .modal-content { padding: 18px 20px 22px; }
  .modal-title { font-size: 1.6rem; }
}

.question-text {
  margin: 0 0 12px;
  font-size: 1.05rem;
  line-height: 1.55;
}

.hint-block {
  margin-bottom: 18px;
}

.hint-block[hidden] {
  display: none;
}

.hint-link,
.btn-link-muted {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink-soft);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.hint-link:hover,
.btn-link-muted:hover {
  color: var(--ink);
}

.hint-content {
  margin: 8px 0 0;
  padding-left: 12px;
  border-left: 3px solid var(--kraft);
  font-size: 0.95rem;
  color: var(--ink-soft);
  font-style: italic;
}

.input-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.input-row[hidden] {
  display: none;
}

.answer-input {
  flex: 1 1 200px;
  padding: 11px 12px;
  border: 1.5px solid rgba(42, 37, 34, 0.3);
  border-radius: 3px;
  background: #fffdf8;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  outline: none;
}

.answer-input:focus {
  border-color: var(--ink);
}

.answer-input.is-error {
  border-color: var(--red);
  animation: nudge 0.3s ease;
}

@keyframes nudge {
  25%, 75% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
}

.btn-submit {
  padding: 11px 20px;
  border: 0;
  border-radius: 3px;
  background: var(--red);
  color: var(--cream);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn-submit:hover {
  background: var(--red-dark);
}

@media (max-width: 440px) {
  .btn-submit {
    width: 100%;
  }
}

.choices-group {
  display: grid;
  gap: 6px;
}

.choices-group[hidden] {
  display: none;
}

.choice-btn {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid rgba(42, 37, 34, 0.25);
  border-radius: 3px;
  background: #fffdf8;
  font: inherit;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.choice-btn:hover {
  border-color: var(--ink);
}

.feedback-msg {
  margin: 10px 0 0;
  font-size: 0.92rem;
  color: var(--red);
}

.solved-header {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--green);
}

.solved-answer {
  margin: 0 0 8px;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.solved-answer strong {
  color: var(--ink);
}

.solved-note {
  margin: 0 0 14px;
  line-height: 1.5;
}

/* ==========================================================================
   Powiadomienia
   ========================================================================== */

.toast-container {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(92vw, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 9px 14px;
  border-radius: 3px;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.9rem;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  animation: toastIn 0.2s ease;
}

.toast.is-leaving {
  opacity: 0;
  transition: opacity 0.2s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(6px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
