/* home.css: the room.
   Layout: one 16:10 scene scaled to fit the viewport, no scrollbars.
   --w is the scene width; --u is one scene pixel (the scene is 320 wide). */

body.home {
  --w: min(100vw, 100dvh * 1.6);
  --u: calc(var(--w) / 320);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.stage {
  position: relative;
  width: var(--w);
}

.scene {
  width: var(--w);
  aspect-ratio: 16 / 10;
  background: var(--wood-1);
}

.scene__art {
  display: block;
  width: 100%;
  height: 100%;
}

/* --- title ---------------------------------------------------------------- */
.title {
  position: absolute;
  z-index: 1;
  left: calc(8 * var(--u));
  top: calc(8 * var(--u));
  text-shadow:
    var(--u) var(--u) 0 var(--wood-0),
    calc(2 * var(--u)) calc(2 * var(--u)) 0 rgb(13 6 3 / 0.6);
}

.title h1 {
  font-size: calc(10 * var(--u));
  line-height: 1;
  color: var(--parchment-light);
}

.title p {
  margin-top: calc(3 * var(--u));
  font-size: calc(8 * var(--u));
  line-height: 1;
  color: var(--parchment);
  font-variant-ligatures: none;
  text-shadow: var(--u) var(--u) 0 var(--wood-0);
}

/* --- signs over the scene -------------------------------------------------- */
.signs ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.signs .sign {
  position: absolute;
  z-index: 1;
  left: calc(var(--x) * var(--u));
  top: calc(var(--y) * var(--u));
  min-height: 0;
  height: calc(14 * var(--u));
  padding: 0 calc(4 * var(--u));
  font-size: calc(5 * var(--u));
}

/* Stretch the hit area to 18 scene pixels without changing how the sign looks. */
.signs .sign::after {
  content: "";
  position: absolute;
  inset: calc(-2 * var(--u)) 0;
}

/* Grid coordinates (top-left corner) on the 320x200 scene. */
.sign--projects { --x: 239; --y: 18; }  /* header of the notice board above the bookshelf */
.sign--about    { --x: 14;  --y: 169; }  /* the spine of the big book on the floor */
.sign--chair    { --x: 64;  --y: 134; }

/* ABOUT is not a plank but the title on a book's spine (drawn in the scene).
   Only over the scene: on small screens it is an ordinary button again. */
@media (min-width: 780px) and (min-height: 488px) {
  .signs .sign--about {
    width: calc(48 * var(--u));
    height: calc(12 * var(--u));
    padding: 0;
    color: var(--fire-yellow);
    background: transparent;
    box-shadow: none;
    text-shadow: var(--u) var(--u) 0 var(--brick-dark);
  }
  .signs .sign--about:hover {
    color: var(--fire-white);
    background: rgb(255 210 122 / 0.12);
    box-shadow: none;
  }
}

/* two lines, so it fits on the armchair seat */
.signs .sign--chair {
  height: calc(20 * var(--u));
  line-height: 1.4;
  text-align: center;
}

/* --- small screens: the signs become a plain list -------------------------- */
/* Below 780px of scene width a sign's hit area drops under 44px, so the same
   links leave the scene and turn into ordinary full-size buttons. */
@media (max-width: 779px), (max-height: 487px) {
  body.home {
    --gap: 12px;
    overflow: auto;
  }

  .stage {
    display: grid;
    gap: var(--gap);
    width: auto;
  }

  .title {
    position: static;
    text-shadow: none;
    padding: 0 12px;
  }

  .title h1 { font-size: 18px; }
  .title p  { margin-top: 6px; font-size: 22px; }

  .signs ul {
    display: grid;
    gap: 14px;
    padding: 4px 12px 12px;
  }

  .signs .sign {
    position: relative;
    left: auto;
    top: auto;
    display: flex;
    height: auto;
    min-height: 48px;
    padding: 0 12px;
    font-size: 12px;
    --u: 3px;
  }

  .signs .sign::after { content: none; }
  .signs .sign--chair br { display: none; }

  /* the chains and post that held the signs have nothing to hold now */
  .sign-prop { display: none; }
}

/* tall and narrow: title, scene, then links in a 2x2 grid underneath */
@media (max-width: 779px) and (max-aspect-ratio: 3/2),
       (max-height: 487px) and (max-aspect-ratio: 3/2) {
  body.home { --w: min(100vw, (100dvh - 220px) * 1.6); }
  .stage { justify-items: center; }
  .title, .signs { width: min(100vw, 480px); }
  .signs ul { grid-template-columns: 1fr 1fr; }
  /* PROJECTS first and full width: what an employer is looking for */
  .signs li:first-child { grid-column: 1 / -1; }
}

/* short and wide: scene on the left, title and links in a side column */
@media (max-width: 779px) and (min-aspect-ratio: 3/2),
       (max-height: 487px) and (min-aspect-ratio: 3/2) {
  body.home { --w: min(100vw - 212px, 100dvh * 1.6); }
  .stage {
    grid-template-columns: var(--w) 200px;
    grid-template-rows: auto 1fr;
    align-items: start;
  }
  .scene { grid-row: 1 / 3; }
  .title { grid-column: 2; padding-top: 8px; }
  .signs { grid-column: 2; }
}

/* --- animation -------------------------------------------------------------- */
/* Static defaults first: this is what prefers-reduced-motion users see.
   One flame frame, one lantern frame, a little still smoke. */
.flame--2,
.flame--3,
.lantern-flame--2 {
  visibility: hidden;
}

.puff { opacity: 0.45; }

/* Everything below moves in steps: steps(1) holds each keyframe, steps(n)
   chops a tween into n jumps. Nothing eases. */
@media (prefers-reduced-motion: no-preference) {
  /* fire: three frames, one full cycle every 0.7s */
  .flame { animation: 0.7s steps(1) infinite; }
  .flame--1 { animation-name: flame-1; }
  .flame--2 { animation-name: flame-2; }
  .flame--3 { animation-name: flame-3; }

  @keyframes flame-1 {
    0%     { visibility: visible; }
    33.3%  { visibility: hidden; }
  }
  @keyframes flame-2 {
    0%     { visibility: hidden; }
    33.3%  { visibility: visible; }
    66.6%  { visibility: hidden; }
  }
  @keyframes flame-3 {
    0%     { visibility: hidden; }
    66.6%  { visibility: visible; }
  }

  /* warm glow over the room */
  .glow { animation: glow 1.9s steps(1) infinite; }
  .firebox-glow { animation: glow 1.1s steps(1) infinite; }

  @keyframes glow {
    0%   { opacity: 0.85; }
    14%  { opacity: 0.6; }
    30%  { opacity: 1; }
    46%  { opacity: 0.7; }
    58%  { opacity: 0.9; }
    74%  { opacity: 0.55; }
    88%  { opacity: 0.95; }
  }

  /* smoke: square puffs rise, drift and fade in 7 jumps */
  .puff { animation: 3s steps(7) infinite; }
  .puff--fire { animation-name: puff-fire; }
  .puff--flue { animation-name: puff-flue; animation-duration: 2.8s; }

  @keyframes puff-fire {
    from { transform: translate(0, 0);        opacity: 0.75; }
    to   { transform: translate(3px, -21px);  opacity: 0; }
  }
  @keyframes puff-flue {
    from { transform: translate(0, 0);        opacity: 0.8; }
    to   { transform: translate(-2px, -21px); opacity: 0.1; }
  }

  /* embers */
  .ember { animation: 2.6s steps(9) infinite; }
  .ember--l { animation-name: ember-l; }
  .ember--r { animation-name: ember-r; animation-duration: 3.1s; }

  @keyframes ember-l {
    from { transform: translate(0, 0);        opacity: 1; }
    to   { transform: translate(-5px, -30px); opacity: 0; }
  }
  @keyframes ember-r {
    from { transform: translate(0, 0);        opacity: 1; }
    to   { transform: translate(4px, -26px);  opacity: 0; }
  }

  /* stars */
  .star { animation: twinkle steps(1) infinite; }
  .star--1 { animation-duration: 2.3s; }
  .star--2 { animation-duration: 3.1s; animation-delay: -1s; }
  .star--3 { animation-duration: 4.3s; animation-delay: -2s; }

  @keyframes twinkle {
    0%   { opacity: 1; }
    60%  { opacity: 0.25; }
    80%  { opacity: 0.7; }
  }

  /* lantern */
  .lantern-flame { animation: 0.9s steps(1) infinite; }
  .lantern-flame--1 { animation-name: flick-a; }
  .lantern-flame--2 { animation-name: flick-b; }
  .lantern-glow { animation: lantern-glow 0.9s steps(1) infinite; }

  @keyframes flick-a {
    0%   { visibility: visible; }
    55%  { visibility: hidden; }
  }
  @keyframes flick-b {
    0%   { visibility: hidden; }
    55%  { visibility: visible; }
  }
  @keyframes lantern-glow {
    0%   { opacity: 0.12; }
    55%  { opacity: 0.07; }
  }

  /* the cat's z's appear one by one, then clear */
  .z { animation: 3.2s steps(1) infinite; }
  .z--1 { animation-name: z-1; }
  .z--2 { animation-name: z-2; }
  .z--3 { animation-name: z-3; }

  @keyframes z-1 {
    0%   { visibility: visible; }
    75%  { visibility: hidden; }
  }
  @keyframes z-2 {
    0%   { visibility: hidden; }
    25%  { visibility: visible; }
    75%  { visibility: hidden; }
  }
  @keyframes z-3 {
    0%   { visibility: hidden; }
    50%  { visibility: visible; }
    75%  { visibility: hidden; }
  }
}

/* --- the hangout ------------------------------------------------------------ */
/* Sized in real pixels, not scene pixels: chat text has to stay readable. */
.chat {
  --u: 3px;
  width: min(100vw - 24px, 460px);
  max-height: min(100dvh - 24px, 640px);
  padding: 18px;
  border: 0;
  color: var(--parchment-light);
  background: var(--wood-1);
  box-shadow:
    inset 0 3px 0 0 var(--wood-2),
    0 0 0 3px var(--wood-0),
    6px 6px 0 3px rgb(13 6 3 / 0.6);
}

.chat[open] {
  display: grid;
  gap: 14px;
  grid-template-rows: auto auto minmax(120px, 1fr) auto auto;
}

.chat::backdrop {
  background: rgb(13 6 3 / 0.55);
}

.chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat h2 {
  margin: 0;
  font-family: var(--font-title);
  font-size: 14px;
  font-weight: normal;
  color: var(--fire-yellow);
}

.chat__who {
  font-size: 20px;
  color: var(--parchment);
}

.chat__log {
  margin: 0;
  padding: 10px 12px;
  list-style: none;
  overflow-y: auto;
  min-height: 120px;
  font-size: 22px;
  line-height: 1.15;
  color: var(--wood-0);
  background: var(--parchment-light);
  box-shadow: inset 3px 3px 0 0 var(--parchment), 0 0 0 3px var(--wood-0);
  overflow-wrap: anywhere;
}

.chat__log:focus-visible {
  outline: 3px solid var(--fire-yellow);
  outline-offset: 5px;
}

.chat__log li + li { margin-top: 6px; }
.chat__log b { font-weight: normal; color: var(--brick-dark); }
.chat__log .is-me b { color: var(--forest); }
.chat__log time { color: #6b4426; font-size: 18px; }
.chat__log .chat__system { color: #6b4426; }

.chat__say {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
}

.chat__leave {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 20px;
  color: var(--parchment);
}
