/*
 * table.css - scene 1: the kitchen table.
 *
 * Talks to: js/table.js builds the elements styled here; base.css supplies colours.
 *
 * Say it to a judge: "Each object is a button positioned on the stage by
 * percentages. Darkness is just layers on top: one for the lamp being off, one for
 * evening, with soft holes cut in them where the fire, moon and lamp give light."
 */

.table-bg {
  position: absolute;
  inset: 0;
  height: 100%;
}

/* ---------- Clickable objects ---------- */
.clickable {
  position: absolute;
  display: block;
  transition: filter 0.6s ease;
  isolation: isolate;   /* lets the contact shadow below sit behind its own object only */
}

/* A soft shadow under things that stand on the table, shelf or stove, so they look
   set down rather than pasted on. */
.clickable-lamp::before,
.clickable-flowers::before,
.clickable-sugar::before,
.clickable-mug::before,
.clickable-box::before,
.clickable-twine::before,
.clickable-binder::before,
.clickable-cat::before,
.clickable-kettle::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3%;
  height: 16%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(59, 38, 22, 0.42), transparent 70%);
  pointer-events: none;
}
.clickable-lamp::before { left: 12%; right: 12%; height: 8%; bottom: -2%; }
.clickable-flowers::before { left: 10%; right: 10%; height: 9%; bottom: -2%; }
.clickable-binder::before { left: 2%; right: 2%; height: 12%; bottom: -4%; }
.clickable-cat::before { left: 3%; right: 1%; height: 26%; bottom: -5%; }

/* WHY the turn: the shelf is painted sloping away to the right; a small turn sets
   the radio's flat base along it. */
.clickable-radio { transform: rotate(3deg); }
/* The binder is painted from straight above; tipping it back makes it lie on the table. */
.clickable-binder > .asset {
  transform: perspective(calc(var(--u) * 40)) rotateX(52deg);
  transform-origin: 50% 100%;
}

/* A picture fills its button. Buttons with an explicit height stretch their picture. */
.clickable > .asset { pointer-events: none; }

/* Desktop: a soft warm glow under the pointer. */
@media (hover: hover) {
  .clickable:not(:disabled):hover {
    filter: drop-shadow(0 0 calc(var(--u) * 0.9) var(--lamp-glow));
  }
}

/* Touch screens have no hover, so every 20 seconds each object glows faintly once
   to show it can be tapped. A glow is a fade, so it's fine with reduced motion. */
@media (hover: none) {
  .clickable:not(:disabled) {
    animation: find-me 20s ease-in-out infinite;
  }
}
@keyframes find-me {
  0%, 88%, 100% { filter: drop-shadow(0 0 0 transparent); }
  94% { filter: drop-shadow(0 0 calc(var(--u) * 0.7) var(--lamp-glow)); }
}

/* ---------- Window ---------- */
/* The glass sits exactly over the painted panes of bg-table.jpg. The clip-path
   (seven rectangles made in table.js) cuts it into panes, so the view shows through
   the glass and the painted wooden bars stay visible between them. */
.window-glass {
  position: absolute;
  left: 17.1%;
  top: 0;
  width: 64.2%;
  height: 94.4%;
  -webkit-clip-path: url(#window-panes);
  clip-path: url(#window-panes);
}

.view {
  position: absolute;
  inset: 0;
  transition: opacity 1.5s ease;
}
.view .asset { height: 100%; aspect-ratio: auto !important; }

.view img { object-position: 50% 62%; }   /* keep the barn in the lower pane */

.mode-dark .view-day,
.mode-light .view-night { opacity: 0; }

/* Rain and snow dull the view, like a heavy sky. */
.view .asset { transition: filter 1.5s ease; }
.is-gloomy .view .asset { filter: saturate(0.55) brightness(0.82); }

/* The moon only belongs in the night view, and hides behind heavy weather. */
.moon {
  position: absolute;
  top: 5%;
  right: 6%;
  width: 17%;
  transition: opacity 1.5s ease;
}
.mode-light .moon { opacity: 0; }
.mode-dark.is-overcast .moon { opacity: 0.35; }
.moon-glow { fill: rgba(250, 243, 224, 0.18); }
.moon-dark { fill: #2a3048; }
.moon-lit { fill: var(--paper); }

.weather {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.curtain {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
}
.curtain-left { left: 0; transform-origin: left center; }
.curtain-right { right: 0; transform-origin: right center; }
.curtain-cloth { height: 100%; transform-origin: top center; }
.curtain .asset { height: 100%; aspect-ratio: auto !important; }
.curtain img { object-fit: fill; }
/* The right-hand curtain is the left-hand picture flipped... */
.curtain-right .asset { transform: scaleX(-1); }
/* ...but its placeholder label should still read left to right. */
.curtain-right .asset-label { transform: scaleX(-1); }

/* ---------- Clock ---------- */
/* A square over the round face: the top part of the clock picture. */
.clock-hands {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  aspect-ratio: 1;
  pointer-events: none;
}
.clock-hand { stroke: var(--ink); }
.clock-pin { fill: var(--walnut); }

/* The pendulum swings inside the little glass door painted under the face.
   .pendulum-window is that door's opening; anything outside it is hidden. */
.pendulum-window {
  position: absolute;
  left: 30%;
  top: 74%;
  width: 40%;
  height: 18.5%;
  overflow: hidden;
  pointer-events: none;
}
.pendulum {
  position: absolute;
  left: 48%;
  top: -40%;
  width: 4%;
  height: 105%;
  background: var(--harvest-gold);
  transform-origin: top center;
  /* WHY: 2s there-and-back means it passes the middle once a second, like the tick. */
  animation: swing 2s ease-in-out infinite;
}
.pendulum::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 700%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--harvest-gold);
  box-shadow: inset calc(var(--u) * -0.1) calc(var(--u) * -0.1) 0 rgba(92, 59, 34, 0.5);
  transform: translate(-50%, 0);
}
@keyframes swing {
  0%, 100% { transform: rotate(11deg); }
  50% { transform: rotate(-11deg); }
}

/* ---------- Radio ---------- */
/* Sits over the tuning dial painted on the radio. The radio's face is seen at an
   angle, so the round dial is squeezed a little sideways to match. */
.radio-dial {
  position: absolute;
  left: 61%;
  top: 23.5%;
  width: 31%;
  transform: scaleX(0.86) skewY(3deg);
  pointer-events: none;
}

/* ---------- Sugar pot: the lid sits on top of the body ---------- */
.sugar-body,
.sugar-lid {
  position: absolute;
  left: 0;
  width: 100%;
  pointer-events: none;
}
.sugar-body { bottom: 0; left: 4.8%; width: 90.4%; }
.sugar-lid { top: 0; transform-origin: 50% 80%; }

/* ---------- Recipe box ---------- */
/* The site's name, typed on the paper slip in the box's painted brass holder. */
.brass-label {
  position: absolute;
  left: 62.5%;
  top: 60.5%;
  width: 19%;
  transform: rotate(-9deg);
  font-family: var(--font-typed);
  font-size: calc(var(--u) * 0.3);
  line-height: 1.05;
  text-align: center;
  color: var(--walnut-dark);
  pointer-events: none;
}

/* ---------- Twine stack: tied normally, untied while it's "open" ---------- */
.twine-loose {
  position: absolute;
  inset: 0;
  opacity: 0;
}
.twine-tied,
.twine-loose { transition: opacity 0.6s ease; }
.is-untied .twine-tied { opacity: 0; }
.is-untied .twine-loose { opacity: 1; }

/* ---------- The cat: two pictures that swap with a fade ---------- */
.cat-awake {
  position: absolute;
  inset: 0;
  opacity: 0;
}
/* WHY the two different timings: if both pictures were half see-through at the same
   moment you would see the rug through the cat. So the new picture fades in on top
   first, and only then does the old one underneath fade away. */
.cat-asleep { transition: opacity 0.3s ease; }
.cat-awake { transition: opacity 0.3s ease 0.3s; }
.is-awake .cat-asleep { opacity: 0; transition: opacity 0.3s ease 0.3s; }
.is-awake .cat-awake { opacity: 1; transition: opacity 0.3s ease; }

/* ---------- Petals and steam ---------- */
.petal-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.petal {
  position: absolute;
  width: 0.9%;
}

.steam-puff {
  position: absolute;
  width: 38%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(250, 243, 224, 0.75), rgba(250, 243, 224, 0) 68%);
  opacity: 0;
  pointer-events: none;
}

/* ---------- Light and shadow ---------- */
.table-darkness,
.table-evening,
.glow {
  position: absolute;
  inset: 0;
  pointer-events: none; /* clicks pass through to the objects underneath */
}

/* Lamp off: the room is nearly dark, with two soft holes where the moonlight
   (window) and the firelight (stove) fall.
   WHY: a mask's black areas show the layer and its see-through areas hide it. Two
   radial gradients, combined with "intersect", give one dark sheet with two holes.
   The -webkit- lines are the same thing in Safari's older spelling. */
.table-darkness {
  background: var(--night);
  opacity: 0.9;
  transition: opacity 1.5s ease;
  -webkit-mask-image:
    radial-gradient(ellipse 16% 32% at 31.3% 22%, rgba(0, 0, 0, 0.4), #000),
    radial-gradient(ellipse 15% 26% at 86.5% 60%, rgba(0, 0, 0, 0.3), #000);
  mask-image:
    radial-gradient(ellipse 16% 32% at 31.3% 22%, rgba(0, 0, 0, 0.4), #000),
    radial-gradient(ellipse 15% 26% at 86.5% 60%, rgba(0, 0, 0, 0.3), #000);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}
.is-lit .table-darkness { opacity: 0; }

/* Evening with the lamp on: the corners of the room stay dim and the lamp is the
   main light, so the shadow has one big hole around the lamp. */
.table-evening {
  background: var(--night);
  opacity: 0;
  transition: opacity 1.5s ease;
  -webkit-mask-image: radial-gradient(ellipse 55% 80% at 11.7% 52%, transparent 20%, #000);
  mask-image: radial-gradient(ellipse 55% 80% at 11.7% 52%, transparent 20%, #000);
}
.is-lit.mode-dark .table-evening { opacity: 0.5; }

/* Coloured light, added on top with "screen" so it brightens what's beneath. */
.glow { mix-blend-mode: screen; }
.glow-fire {
  background: radial-gradient(ellipse 15% 24% at 86.5% 61%, rgba(226, 120, 50, 0.45), transparent);
  opacity: 0.75;
}
.glow-moon {
  background: radial-gradient(ellipse 17% 34% at 31.3% 24%, rgba(150, 170, 215, 0.28), transparent);
  transition: opacity 1.5s ease;
}
.is-lit .glow-moon,
.mode-light .glow-moon { opacity: 0; }

/* ---------- Lamp ---------- */
.clickable-lamp { z-index: 2; } /* above the darkness layers */
.lamp-picture { transition: opacity 1.5s ease, filter 1.5s ease; pointer-events: none; }
.lamp-on {
  position: absolute;
  inset: 0;
  opacity: 0;
}
.lamp-off { filter: brightness(0.55); } /* dim, but findable in the dark */
.is-lit .lamp-on { opacity: 1; }
.is-lit .lamp-off { opacity: 0; }

.lamp-halo {
  position: absolute;
  left: -60%;
  top: -40%;
  width: 220%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 207, 122, 0.45), transparent 65%);
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 1.5s ease;
  pointer-events: none;
}
.is-lit .lamp-halo { opacity: 1; }

/* The pull-chain: a thin beaded line hanging under the shade, with the tag on its end. */
.lamp-chain {
  position: absolute;
  left: 68%;
  top: 36%;
  width: calc(var(--u) * 0.14);
  height: 20%;
  background: repeating-linear-gradient(var(--harvest-gold) 0 55%, transparent 55% 100%);
  background-size: 100% calc(var(--u) * 0.3);
  transform-origin: top center;
  animation: chain-sway 3.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes chain-sway {
  0%, 100% { transform: rotate(5deg); }
  50% { transform: rotate(-5deg); }
}

.lamp-tag {
  position: absolute;
  top: 92%;
  left: 50%;
  width: calc(var(--u) * 2.9);
  transform: translateX(-50%) rotate(-4deg);
  transition: opacity 1.5s ease;
}
/* The words sit on the tag's paper, below its loop of string. */
.lamp-tag-text {
  position: absolute;
  left: 0;
  right: 0;
  top: 40%;
  bottom: 4%;
  display: grid;
  place-items: center;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: calc(var(--u) * 1.05);
  line-height: 0.95;
  text-align: center;
  color: var(--ink);
}
/* On the grey placeholder, hide the asset id so "Pull me" stays readable. */
.lamp-tag .asset-label { display: none; }
/* Once the lamp is on the tag has done its job. */
.is-lit .lamp-tag { opacity: 0; }
