/* Porkishhead — a Sims 1 interaction menu, with a head in the middle. */

:root {
  /* Size of the head on screen. Kept in sync with HEAD_FIT in main.js, then
     replaced with the head's measured box once the model is framed. */
  --head: min(29vh, 29vw);
  --head-w: var(--head);
  --head-h: var(--head);
  --gap: clamp(32px, 10vmin, 120px);

  /* Ring geometry. --n is how many plaques there are; keep it in sync with the
     markup. The vw/vh caps stop wide labels running off a small screen. */
  --n: 5;
  --start: -54deg;
  --radius: min(calc(var(--head-h) / 2 + var(--gap) + 84px), 34vw, 40vh);

  --plaque-face: #0000CD;
  /* Dimmed at rest so the lift to --ink-hover is actually visible; #f7f7f7 was
     only 2% off it, which the eye can't see. */
  --ink: #b8b8c8;
  --ink-hover: #fdfdfd;

  /* The Sims arrow cursor. */
  --cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='30' viewBox='0 0 24 30'%3E%3Cpath d='M2 1.5 2 24 8 18.5 11.5 27 15.5 25 12 17 20 16.5z' fill='%23fff' stroke='%23000' stroke-width='2.2' stroke-linejoin='round'/%3E%3C/svg%3E") 2 1;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: #07090c;
  color: var(--ink);
  /* Larger than it needs to be on purpose: the pixelate grid is a fixed 2px, so
     bigger glyphs mean more cells per letter and a smoother read. */
  font: 700 clamp(17px, 1.8vmin + 10px, 28px)/1.15 "Comic Sans MS", "Comic Sans", "Chalkboard SE", cursive;
  overflow: hidden;
  cursor: var(--cursor), default;
}

/* Aliased edges — the text renders on hard pixel boundaries instead of being
   smoothed, which reads as a light pixelation.

   Desktop only. iOS Safari treats -webkit-font-smoothing: none as "draw
   nothing", which is what was leaving the plaques as blank blue slabs. */
@media (hover: hover) and (pointer: fine) {
  body {
    -webkit-font-smoothing: none;
    text-rendering: optimizeSpeed;
  }
}

/* The bacon wordmark. The source is deliberately small (400px wide) so blowing
   it up here lands on chunky pixels rather than a smooth resample. */
.wordmark {
  position: fixed;
  top: clamp(12px, 3vh, 40px);
  left: 50%;
  translate: -50% 0;
  /* Bounded by height too, or it collides with the top plaque on short windows.
     3.31 is the wordmark's aspect ratio. */
  height: min(120px, 12vh, calc(62vw / 3.31));
  width: auto;
  image-rendering: pixelated;
  pointer-events: none;
}

/* The murky halo the head sits in, like the smoke puff in the game. */
.blob {
  position: fixed;
  left: 50%;
  top: 50%;
  width: calc(var(--head-w) * 2.6);
  aspect-ratio: 1.15;
  translate: -50% -50%;
  background:
    radial-gradient(closest-side, rgba(122, 82, 62, .38), rgba(60, 30, 22, .22) 55%, transparent 72%),
    radial-gradient(closest-side, rgba(255, 214, 170, .10), transparent 70%);
  filter: blur(6px);
  pointer-events: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- menu layout: plaques sit on a ring around the head ----

   Each plaque carries its own --i (0..n-1) and gets dropped at that fraction of
   the way round the circle. --start is rotated off vertical so nothing lands at
   the top, where the wordmark is. */

.pie {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.pie .plaque {
  position: absolute;
  left: 50%;
  top: 50%;
  --angle: calc(var(--start) + (360deg / var(--n)) * var(--i));
  translate:
    calc(-50% + var(--radius) * cos(var(--angle)))
    calc(-50% + var(--radius) * sin(var(--angle)));
  pointer-events: auto;
}

/* ---- the blue plaque ---- */

.plaque {
  display: inline-block;
  max-width: 100%;
  padding: .5em .8em .55em;
  border: none;
  border-radius: .5em;
  background: var(--plaque-face);
  box-shadow: 0 2px 7px rgba(0, 0, 0, .65);
  color: var(--ink);
  text-align: center;
  text-decoration: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .85);
  text-wrap: balance;
  letter-spacing: .01em;
  cursor: var(--cursor), pointer;
}

.filters {
  position: absolute;
  width: 0;
  height: 0;
}

/* The label sits in its own span so the pixelation hits the text and leaves the
   plaque's rounded edge alone.

   The filter is opt-in: mobile WebKit renders this feTile chain as nothing at
   all, which wipes the labels off the buttons. main.js proves the filter works
   in this browser before adding .pixel-ok, so a browser that can't do it just
   gets plain (still unsmoothed) text. */
.pie .plaque > span {
  display: inline-block;
}

.pixel-ok .pie .plaque > span {
  filter: url(#pixelate);
}

/* Hover changes the text colour and nothing else — no scale, no transition. */
.plaque:hover,
.plaque:focus-visible {
  color: var(--ink-hover);
  outline: none;
}

/* ---- entrance: plaques pop into place around the ring ----
   Only opacity and scale animate; translate is holding the ring position. */

.pie .plaque {
  opacity: 0;
  scale: .35;
}

.ready .pie .plaque {
  animation: pop .34s cubic-bezier(.2, 1.5, .5, 1) backwards;
  animation-delay: calc(var(--i) * .07s);
  opacity: 1;
  scale: 1;
}

@keyframes pop {
  from { opacity: 0; scale: .35; }
  to   { opacity: 1; scale: 1; }
}

/* ---- loading ---- */

.loading {
  position: fixed;
  left: 50%;
  top: 50%;
  margin: 0;
  translate: -50% -50%;
  transition: opacity .3s ease;
}

.ready .loading {
  opacity: 0;
  pointer-events: none;
}

/* A phone has no room to push the plaques out — the side ones would run off the
   edge — so pull them back in. */
@media (max-width: 640px) {
  :root { --gap: clamp(14px, 4vw, 28px); }
}

@media (prefers-reduced-motion: reduce) {
  .ready .pie .plaque { animation: none; }
}
