:root {
  --ink: #fc4700;
  --ink-soft: rgba(252, 71, 0, 0.7);
  --ink-text: #a83000; /* darker ink for small text: ≥4.5:1 on the blue card */
  --green: #00513b;    /* subtitle green from the Figma title */
  --sky: #cfe1ee;      /* flat soft blue, like the reference's card */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
}

body {
  /* flat card with just a whisper of light in the middle and soft edges */
  background:
    radial-gradient(ellipse 75% 65% at 50% 50%, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 120% 100% at 50% 50%, rgba(120, 150, 180, 0) 60%, rgba(120, 150, 180, 0.16) 100%),
    var(--sky);
  font-family: "Caveat", "Comic Sans MS", cursive;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

#snow, #scene, .paper, .pattern {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* paper grain + vertical fibres over the backdrop (texture set by main.js) */
.paper {
  pointer-events: none;
  background-size: 512px 512px;
  mix-blend-mode: soft-light;
  opacity: 0.85;
}

/* faint polka-dot gift-wrap motif; slides with the house */
.pattern {
  pointer-events: none;
  background-size: 420px 420px;
  opacity: 0.32;
}

#scene {
  cursor: grab;
  touch-action: none;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.55s ease, transform 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
#scene.ready { opacity: 1; transform: scale(1); }
#scene.dragging { cursor: grabbing; }

.title {
  position: fixed;
  top: clamp(16px, 4vh, 40px);
  left: 0;
  right: 0;
  padding: 0 72px; /* keeps clear of the sound button */
  text-align: center;
  pointer-events: none;
}

/* hand-drawn title from Figma ("Adventskalender" + "Für meine Carusik" + bauble) */
.title-art {
  margin: 0 auto;
  width: min(100%, 540px);
  line-height: 0;
}
.title-art svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.title-art .letters path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* the thread keeps its grey pencil colour from the drawing */
.title-art .subtitle {
  font-family: "Instrument Sans", system-ui, sans-serif;
  font-size: 36px;
  font-weight: 400;
  fill: var(--green);
}
.title-art .sparkle { fill: var(--ink); pointer-events: none; }

/* 3D bauble (its own little WebGL canvas, positioned by title.js) */
.bauble {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  will-change: transform;
}

/* intro: letters get written, subtitle and bauble follow (driven by title.js) */
.title-art.intro .letters path { stroke-dashoffset: var(--len); stroke-dasharray: var(--len); }
.title-art.intro .subtitle { opacity: 0; }
.title-art .subtitle { transition: opacity 0.8s ease 0.1s, transform 0.8s ease 0.1s; }

.hint {
  position: fixed;
  bottom: clamp(16px, 4vh, 36px);
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 500;
  color: var(--ink-text);
  pointer-events: none;
  transition: opacity 0.8s ease;
}
.hint.gone { opacity: 0; }

.sound {
  position: fixed;
  z-index: 20; /* stays tappable over the window close-up */
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2.5px solid var(--ink);
  border-radius: 48% 52% 46% 54% / 54% 46% 52% 48%; /* slightly hand-drawn circle */
  background: rgba(255, 249, 241, 0.85);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.sound:hover { transform: rotate(-6deg) scale(1.05); }
.sound:active { transform: scale(0.94); }
.sound:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }
.sound .cross { display: none; }
.sound.muted .waves { display: none; }
.sound.muted .cross { display: inline; }
.sound.muted { background: rgba(255, 249, 241, 0.6); color: var(--ink-text); border-color: var(--ink-text); }

.admin-pill {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 10;
}
body.house-open .admin-pill { visibility: hidden; }
.admin-pill-link {
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  border: 2px solid var(--ink);
  border-radius: 15px 19px 16px 18px / 18px 15px 19px 16px;
  background: rgba(255, 249, 241, 0.88);
  font: 500 13px "Instrument Sans", system-ui, sans-serif;
  color: var(--ink-text);
  text-decoration: none;
  transition: transform 0.15s ease, background 0.2s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.admin-pill-link:hover {
  transform: rotate(-1.5deg) scale(1.03);
  background: #fff9f1;
  color: var(--ink);
}
.admin-pill-link:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 4px;
}

/* phones: title sits below the sound button and can use the full width */
@media (max-width: 560px) {
  .title { top: 66px; padding: 0 12px; }
}

/* ---------------------------------------------------------------------------
   Opening the house
   --------------------------------------------------------------------------- */
#scene.can-open { cursor: pointer; }

.close-house {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  min-height: 44px;
  padding: 6px 16px 8px;
  border: 2.5px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px; /* hand-drawn pill */
  background: rgba(255, 249, 241, 0.85);
  color: var(--ink-text);
  font: 600 21px/1 "Caveat", cursive;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.5s ease;
  -webkit-tap-highlight-color: transparent;
}
.close-house:hover { transform: rotate(-2deg) scale(1.03); }
.close-house:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }
body.window-open .close-house { opacity: 0; pointer-events: none; }

/* windows as buttons for the keyboard / screen readers: invisible until focused */
.doors-nav button {
  position: fixed;
  left: 50%;
  bottom: clamp(56px, 10vh, 90px);
  transform: translateX(-50%);
  padding: 6px 14px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff9f1;
  color: var(--ink-text);
  font: 600 20px/1.2 "Caveat", cursive;
  opacity: 0;
  pointer-events: none;
}
.doors-nav button:focus-visible { opacity: 1; outline: 2px dashed var(--ink); outline-offset: 3px; }

/* ---------------------------------------------------------------------------
   Window close-up
   --------------------------------------------------------------------------- */
.window-view {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10;
}
.window-view[hidden] { display: none; }

.wv-veil {
  position: absolute;
  inset: 0; /* invisible: tapping beside the window goes back */
}

/* while a window is open the house fades away and leaves it on the backdrop */
.hint, .doors-nav { transition: opacity 0.55s ease; }
body.window-open #scene,
body.window-open .hint,
body.window-open .doors-nav { opacity: 0; pointer-events: none; }

.wv-back {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  min-height: 44px;
  padding: 6px 16px 8px;
  border: 2.5px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  background: rgba(255, 249, 241, 0.9);
  color: var(--ink-text);
  font: 600 21px/1 "Caveat", cursive;
  cursor: pointer;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}
.wv-back:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }

.wv-title {
  position: absolute;
  top: clamp(64px, 9vh, 90px);
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: clamp(30px, 4.4vh, 42px);
  font-weight: 700;
  color: var(--ink-text); /* plain ink is under 3:1 on the veil */
  pointer-events: none;
}

.wv-hint {
  position: absolute;
  bottom: clamp(20px, 6vh, 56px);
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  color: var(--ink-text);
  pointer-events: none;
}

.wv-fly { position: relative; will-change: transform; }


.wv-stage {
  --stage-w: min(44vw, 52vh * 0.9, 400px);
  position: relative;
  width: var(--stage-w);
  container-type: inline-size;
  perspective: 1400px;
  transform-style: preserve-3d;
  cursor: pointer;
  touch-action: none; /* drags swing the shutters */
  -webkit-tap-highlight-color: transparent;
}
.wv-stage[data-state="open"] { cursor: grab; }
.wv-stage.is-dragging { cursor: grabbing; }
.wv-stage:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }

/* paper cut-out of the window's outline (windows.js paperFill) */
.wv-paper {
  position: absolute;
  display: block;
  max-width: none;
  pointer-events: none;
  user-select: none;
  transform: translateZ(-2px);
}

.wv-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.wv-frame { position: relative; display: block; height: auto; transform: translateZ(0); }
.wv-over { transform: translateZ(0.5px); }
.wv-lock { transform: translateZ(1px); }

.wv-content {
  position: absolute;
  overflow: hidden;
  background: #f6ead9;
  box-shadow: inset 0 calc(var(--u) * 5) calc(var(--u) * 6) -2px rgba(90, 50, 30, 0.35);
  transform: translateZ(-1px);
}
.wv-content img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: contrast(0.82) saturate(0.8) brightness(1.08) sepia(0.1);
}
.wv-content svg { width: 100%; height: 100%; display: block; }

.wv-leaf {
  position: absolute;
  transform-style: preserve-3d;
}
.wv-face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.wv-front svg { width: 100%; height: 100%; display: block; }
/* the inside of a shutter: plain paper with the day's note */
.wv-inside {
  inset: calc(var(--u) * 2);
  padding: calc(var(--u) * 4);
  display: grid;
  place-items: center;
  transform: rotateY(180deg);
  background: #fff9f1;
  border: calc(var(--u) * 1.6) solid var(--ink);
  border-radius: 3% 5% 4% 6% / 4% 3% 6% 4%;
  color: var(--ink-text);
  font: 700 calc(var(--u) * 11) / 1.1 "Caveat", cursive;
  text-align: center;
}

@media (max-width: 560px) {
  .wv-stage { --stage-w: min(54vw, 46vh * 0.9); }
  .wv-hint { font-size: 21px; }
}

/* open house fills the screen: the title and its bauble step aside */
.title, .bauble { transition: opacity 0.7s ease; }
body.house-open .title { opacity: 0; visibility: hidden; transition: opacity 0.7s ease, visibility 0s 0.7s; }
/* !important: title.js sets the bauble's opacity inline every frame */
body.house-open .bauble { opacity: 0 !important; pointer-events: none; }

/* going back: the labels leave first, the window flies back into the house */
.wv-title, .wv-hint, .wv-back { transition: opacity 0.3s ease; }
.window-view.is-out .wv-title,
.window-view.is-out .wv-hint,
.window-view.is-out .wv-back { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .hint, #scene { transition: none; }
}

/* ---------------------------------------------------------------------------
   Opening the house
   --------------------------------------------------------------------------- */
#scene.can-open { cursor: pointer; }

.close-house {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  min-height: 44px;
  padding: 6px 16px 8px;
  border: 2.5px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px; /* hand-drawn pill */
  background: rgba(255, 249, 241, 0.85);
  color: var(--ink-text);
  font: 600 21px/1 "Caveat", cursive;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.5s ease;
  -webkit-tap-highlight-color: transparent;
}
.close-house:hover { transform: rotate(-2deg) scale(1.03); }
.close-house:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }
body.window-open .close-house { opacity: 0; pointer-events: none; }

/* windows as buttons for the keyboard / screen readers: invisible until focused */
.doors-nav button {
  position: fixed;
  left: 50%;
  bottom: clamp(56px, 10vh, 90px);
  transform: translateX(-50%);
  padding: 6px 14px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff9f1;
  color: var(--ink-text);
  font: 600 20px/1.2 "Caveat", cursive;
  opacity: 0;
  pointer-events: none;
}
.doors-nav button:focus-visible { opacity: 1; outline: 2px dashed var(--ink); outline-offset: 3px; }

/* ---------------------------------------------------------------------------
   Window close-up
   --------------------------------------------------------------------------- */
.window-view {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10;
}
.window-view[hidden] { display: none; }

.wv-veil {
  position: absolute;
  inset: 0; /* invisible: tapping beside the window goes back */
}

/* while a window is open the house fades away and leaves it on the backdrop */
#scene, .hint, .doors-nav { transition: opacity 0.55s ease; }
body.window-open #scene,
body.window-open .hint,
body.window-open .doors-nav { opacity: 0; pointer-events: none; }

.wv-back {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  min-height: 44px;
  padding: 6px 16px 8px;
  border: 2.5px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  background: rgba(255, 249, 241, 0.9);
  color: var(--ink-text);
  font: 600 21px/1 "Caveat", cursive;
  cursor: pointer;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}
.wv-back:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }

.wv-title {
  position: absolute;
  top: clamp(64px, 9vh, 90px);
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: clamp(30px, 4.4vh, 42px);
  font-weight: 700;
  color: var(--ink-text); /* plain ink is under 3:1 on the veil */
  pointer-events: none;
}

.wv-hint {
  position: absolute;
  bottom: clamp(20px, 6vh, 56px);
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  color: var(--ink-text);
  pointer-events: none;
}

.wv-fly { position: relative; will-change: transform; }


.wv-stage {
  --stage-w: min(44vw, 52vh * 0.9, 400px);
  position: relative;
  width: var(--stage-w);
  container-type: inline-size;
  perspective: 1400px;
  transform-style: preserve-3d;
  cursor: pointer;
  touch-action: none; /* drags swing the shutters */
  -webkit-tap-highlight-color: transparent;
}
.wv-stage[data-state="open"] { cursor: grab; }
.wv-stage.is-dragging { cursor: grabbing; }

/* paper cut-out of the window's outline (windows.js paperFill) */
.wv-paper {
  position: absolute;
  display: block;
  max-width: none;
  pointer-events: none;
  user-select: none;
  transform: translateZ(-2px);
}

.wv-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.wv-frame { position: relative; display: block; height: auto; transform: translateZ(0); }
.wv-over { transform: translateZ(0.5px); }
.wv-lock { transform: translateZ(1px); }

.wv-content {
  position: absolute;
  overflow: hidden;
  background: #f6ead9;
  box-shadow: inset 0 calc(var(--u) * 5) calc(var(--u) * 6) -2px rgba(90, 50, 30, 0.35);
  transform: translateZ(-1px);
}
.wv-content img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: contrast(0.82) saturate(0.8) brightness(1.08) sepia(0.1);
}
.wv-content svg { width: 100%; height: 100%; display: block; }

.wv-leaf {
  position: absolute;
  transform-style: preserve-3d;
}
.wv-face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.wv-front svg { width: 100%; height: 100%; display: block; }
/* the inside of a shutter: plain paper with the day's note */
.wv-inside {
  inset: calc(var(--u) * 2);
  padding: calc(var(--u) * 4);
  display: grid;
  place-items: center;
  transform: rotateY(180deg);
  background: #fff9f1;
  border: calc(var(--u) * 1.6) solid var(--ink);
  border-radius: 3% 5% 4% 6% / 4% 3% 6% 4%;
  color: var(--ink-text);
  font: 700 calc(var(--u) * 11) / 1.1 "Caveat", cursive;
  text-align: center;
}

@media (max-width: 560px) {
  .wv-stage { --stage-w: min(54vw, 46vh * 0.9); }
  .wv-hint { font-size: 21px; }
}

/* open house fills the screen: the title and its bauble step aside */
.title, .bauble { transition: opacity 0.7s ease; }
body.house-open .title { opacity: 0; visibility: hidden; transition: opacity 0.7s ease, visibility 0s 0.7s; }
/* !important: title.js sets the bauble's opacity inline every frame */
body.house-open .bauble { opacity: 0 !important; pointer-events: none; }

/* going back: the labels leave first, the window flies back into the house */
.wv-title, .wv-hint, .wv-back { transition: opacity 0.3s ease; }
.window-view.is-out .wv-title,
.window-view.is-out .wv-hint,
.window-view.is-out .wv-back { opacity: 0; }

/* a door's link (e.g. a song), shown once the window is open */
.wv-link {
  position: absolute;
  bottom: calc(clamp(20px, 6vh, 56px) + 46px);
  left: 50%;
  transform: translateX(-50%);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 6px 20px 8px;
  border: 2.5px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  background: rgba(255, 249, 241, 0.92);
  color: var(--ink-text);
  font: 700 24px/1 "Caveat", cursive;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.3s ease, transform 0.15s ease;
}
.wv-link[hidden] { display: none; }
.wv-link:hover { transform: translateX(-50%) rotate(-2deg) scale(1.04); }
.wv-link:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }
.window-view.is-out .wv-link { opacity: 0; }
