*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  overflow-x: clip;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  background: #f6ecd9;
  color: #3b2416;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.5;
}

main {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 4rem 1rem 3rem;
  text-align: center;
}

h1 {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: 1.8rem;
  line-height: 1.15;
  margin: 0 0 0.5rem;
}

/* ---------- Fireplace ---------- */

/* Mobile: the fire sticks to the top while the chips scroll beneath it */
.stage {
  /* fireplace.png is 1339 x 997; hearth height plus mantel room fits in 38vh */
  --hearth-width: min(100%, calc((38vh - 0.5rem) / 1.1 * 1339 / 997));

  display: flow-root;
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f6ecd9;
  padding-bottom: 0.5rem;
}

.hearth {
  /* Flame placement over the grate, as fractions of the cropped image */
  --flame-x: 50%;
  --flame-bottom: 21%;
  --flame-width: 26%;
  --flame-scale: 0;
  --flicker: 0;

  position: relative;
  width: var(--hearth-width);
  container-type: inline-size;
  /* room above the beam for the tallest mantel item: 10% of the fireplace height */
  margin: calc(var(--hearth-width) * 0.1 * 997 / 1339) auto 0;
}

.fireplace {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
}

/* A copy of the beam alone, layered over the socks so they hang from behind it.
   The beam's lower edge is ~13.9% down the image. */
.beam-front {
  position: absolute;
  z-index: 3;
  inset: 0;
  width: 100%;
  height: auto;
  clip-path: inset(0 0 86.1% 0);
  pointer-events: none;
}

.flame-wrap {
  position: absolute;
  z-index: 4;
  left: var(--flame-x);
  bottom: var(--flame-bottom);
  width: var(--flame-width);
  transform: translateX(-50%) scale(var(--flame-scale));
  transform-origin: 50% 100%;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.6s ease, opacity 0.6s ease;
}

.hearth.lit .flame-wrap {
  opacity: 1;
}

.flame {
  display: block;
  width: 100%;
  height: auto;
  transform-origin: 50% 100%;
  animation: flicker 1.8s ease-in-out infinite;
}

/* --flicker runs 0 (calm) to 1 (wild) with the score */
@keyframes flicker {
  0%, 100% { transform: scale(1, 1) skewX(0deg); }
  20%      { transform: scale(calc(1 + 0.04 * var(--flicker)), calc(1 - 0.06 * var(--flicker))) skewX(calc(-3deg * var(--flicker))); }
  45%      { transform: scale(calc(1 - 0.03 * var(--flicker)), calc(1 + 0.08 * var(--flicker))) skewX(calc(2deg * var(--flicker))); }
  70%      { transform: scale(calc(1 + 0.02 * var(--flicker)), calc(1 - 0.03 * var(--flicker))) skewX(calc(-1.5deg * var(--flicker))); }
}

.score {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 7.5%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: 11cqw;
  line-height: 1;
  color: #f6ecd9;
  text-shadow: 0 2px 6px rgba(40, 20, 8, 0.55);
  font-variant-numeric: tabular-nums;
}

/* Items: positions and widths are fractions of the fireplace width
   (fireplace ~1.5m wide). The centred score spans roughly 40%-60%. */
.mantel {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.slot {
  position: absolute;
  z-index: 5;
  left: var(--x);
  width: var(--w);
}

/* On the mantel: bottoms rest on the beam's top edge */
.slot[data-item="candle"],
.slot[data-item="mug"],
.slot[data-item="soup"] {
  bottom: 98.5%;
}

.slot[data-item="candle"] { --x: 3%;    --w: 4%; }
.slot[data-item="mug"]    { --x: 22.5%; --w: 5%; }
.slot[data-item="soup"]   { --x: 71.5%; --w: 7%; }

/* Hung from the beam's lower edge beside the right-hand bracket,
   top tucked behind the beam (.beam-front sits above) */
.slot[data-item="socks"] {
  --x: 73%;
  --w: 6%;
  z-index: 2;
  top: 11.8%;
}

/* On the hearth, in front of the opening's edges */
.slot[data-item="cat"],
.slot[data-item="blanket"] {
  z-index: 7;
  bottom: 11.5%;
}

.slot[data-item="cat"]     { --x: 12%; --w: 24%; }
.slot[data-item="blanket"] { --x: 65%; --w: 22%; }

.slot[hidden] {
  display: none;
}

.slot img {
  display: block;
  width: 100%;
  height: auto;
}

/* Hygge overlord */
main.shake {
  animation: shake 0.5s ease-in-out infinite;
}

@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  /* upward only, so the shake never adds a vertical scrollbar */
  25%      { transform: translate(-1.5px, -1px); }
  50%      { transform: translate(1px, -2px); }
  75%      { transform: translate(1.5px, -0.5px); }
}

/* ---------- Tier, chips, combos ---------- */

.tier {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: clamp(1.9rem, 8vw, 2.75rem);
  line-height: 1.15;
  margin: 0.75rem 0 1.25rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.chip {
  font: inherit;
  font-size: 0.95rem;
  color: #3b2416;
  background: transparent;
  border: 1.5px solid #d4b98f;
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chip:focus-visible {
  outline: 2px solid #b5532a;
  outline-offset: 2px;
}

.chip.cosy[aria-pressed="true"] {
  background: #f3c27a;
  border-color: #f3c27a;
  color: #5a2e0b;
}

.chip.not-cosy[aria-pressed="true"] {
  background: #c9d3dc;
  border-color: #c9d3dc;
  color: #2c3a46;
}

.combos {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
}

.combos li {
  margin: 0.25rem 0;
}

.share {
  margin-top: 1.5rem;
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 500;
  font-size: 1.15rem;
  color: #5a2e0b;
  background: #f3c27a;
  border: 1.5px solid #f3c27a;
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.share:hover {
  background: #eeb35f;
  border-color: #eeb35f;
}

.share:focus-visible {
  outline: 2px solid #b5532a;
  outline-offset: 2px;
}

/* ---------- Ambient ---------- */

.ambient {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
}

body.rain-on .rain,
body.big-light-on .big-light {
  opacity: 1;
}

.rain {
  position: fixed;
  inset: 0;
  z-index: 0;
}

.rain::before,
.rain::after {
  content: "";
  position: absolute;
  inset: -50%;
  background: repeating-linear-gradient(
    90deg,
    rgba(160, 178, 196, 0.6) 0 1px,
    transparent 1px 29px
  );
  -webkit-mask-image: repeating-linear-gradient(180deg, #000 0 12px, transparent 12px 90px);
  mask-image: repeating-linear-gradient(180deg, #000 0 12px, transparent 12px 90px);
  transform: rotate(15deg);
  animation: rain 0.32s linear infinite;
}

.rain::after {
  background-position: 15px 0;
  -webkit-mask-image: repeating-linear-gradient(180deg, transparent 0 60px, #000 60px 70px, transparent 70px 130px);
  mask-image: repeating-linear-gradient(180deg, transparent 0 60px, #000 60px 70px, transparent 70px 130px);
  animation-name: rain-slow;
  animation-duration: 0.45s;
}

body.rain-on .rain {
  opacity: 0.4;
}

@keyframes rain {
  from { transform: rotate(15deg) translateY(0); }
  to   { transform: rotate(15deg) translateY(90px); }
}

@keyframes rain-slow {
  from { transform: rotate(15deg) translateY(0); }
  to   { transform: rotate(15deg) translateY(130px); }
}

.big-light {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(208, 226, 255, 0.5);
}

body.big-light-on .big-light {
  opacity: 1;
}

/* ---------- Desktop: two columns, no page scroll ---------- */

@media (min-width: 900px) {
  main {
    display: flex;
    flex-direction: column;
    max-width: 1400px;
    height: 100vh;
    height: 100dvh;
    padding: 2.5rem 2rem 1rem;
  }

  h1 {
    font-size: 2.5rem;
    margin: 0 0 0.25rem;
  }

  .layout {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2.5rem;
  }

  .stage {
    /* fireplace up to 72vh tall, plus mantel room, below the heading */
    --hearth-width: min(100%, calc(min(72vh, (100vh - 7rem) / 1.1) * 1339 / 997));

    position: static;
    flex: 1 1 0;
    min-width: 0;
    padding-bottom: 0;
    background: none;
  }

  .hearth {
    margin-right: 0;
  }

  .panel {
    flex: 0 1 500px;
    max-height: 100%;
    overflow-y: auto;
    text-align: left;
  }

  .tier {
    font-size: 2.25rem;
    margin: 0 0 0.6rem;
  }

  .chips {
    justify-content: flex-start;
    gap: 0.3rem;
  }

  .chip {
    font-size: 14px;
    line-height: 1.35;
    padding: 0.15rem 0.6rem;
  }

  .combos {
    margin-top: 0.7rem;
    line-height: 1.4;
  }

  .combos li {
    margin: 0;
  }

  .share {
    margin-top: 0.9rem;
    padding: 0.45rem 1.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flame-wrap {
    transition: opacity 0.2s ease;
  }
  .flame,
  .rain::before,
  .rain::after,
  main.shake {
    animation: none;
  }
}
