/*
 * Hover flair for the index: pointing at, pressing or focusing a project turns the whole page into
 * that project's world. FM-SWITCH: the app's dark 8-bit screen. ESTAMPIE: an illuminated
 * manuscript. FM1Kit: plain reference documentation, like Apple's. flair.js marks the project
 * with .is-active (see there for touch).
 *
 * Only fonts, colours and things that don't change the list's size are swapped, so the
 * hovered card never moves out from under the pointer.
 */

/* Registered so the colours fade between themes rather than jumping. */
@property --text {
  syntax: "<color>";
  inherits: true;
  initial-value: #f1e6d4;
}

@property --muted {
  syntax: "<color>";
  inherits: true;
  initial-value: #b8a58c;
}

@property --rule {
  syntax: "<color>";
  inherits: true;
  initial-value: #4a3524;
}

@property --accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #e8a35a;
}

@property --pct {
  syntax: "<integer>";
  inherits: true;
  initial-value: 0;
}

:root {
  /* FM-SWITCH's Phosphor theme, green preset. */
  --px-green: #7be39a;
  --px-dim: rgb(123 227 154 / 50%);
  --px-faint: rgb(123 227 154 / 20%);
  --px-bg: #0d100e;
  --px-surface: #161b18;
  --px-ink: #e6eadf;
  --px-muted: #8e9a8f;

  /* ESTAMPIE's VELLUM palette. */
  --mss-vellum: #eee2c4;
  --mss-vellum-dark: #dfcca0;
  --mss-ink: #2e1e14;
  --mss-ink-soft: #5b4532;
  --mss-vermilion: #962012;
  --mss-lapis: #1a3e94;
  --mss-gold: #b8892a;
  --mss-verdigris: #3f6b3a;
  --fade: 0.4s;
  --notch: polygon(
    3px 0, calc(100% - 3px) 0, calc(100% - 3px) 3px, 100% 3px,
    100% calc(100% - 3px), calc(100% - 3px) calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%,
    3px calc(100% - 3px), 0 calc(100% - 3px), 0 3px, 3px 3px
  );

  /* FM1Kit's page: Apple's developer documentation, light (dark below). */
  --docs-font: -apple-system, blinkmacsystemfont, "SF Pro Text", "Helvetica Neue", helvetica, arial, sans-serif;
  --docs-mono: ui-monospace, "SF Mono", sfmono-regular, menlo, consolas, monospace;
  --docs-bg: #fff;
  --docs-panel: #f5f5f7;
  --docs-text: #1d1d1f;
  --docs-muted: #6e6e73;
  --docs-rule: #d2d2d7;
  --docs-link: #06c;
  --docs-struct: #ad3da4;
  --docs-class: #703daa;
  --docs-enum: #b45309;
  --docs-actor: #0e7c7b;
}

body {
  transition: --text var(--fade), --muted var(--fade), --rule var(--fade), --accent var(--fade);
}

main {
  position: relative;
  z-index: 1;
}

.projects li {
  transition: border-color var(--fade);
}

.projects a {
  position: relative;
  isolation: isolate;
}

/* Backdrops sit behind everything and fade in with their theme. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--fade);
}

.backdrop p {
  margin: 0;
}

/* Decorations live in the side margins, so only appear when there's room. */
.margin-left,
.margin-right {
  position: absolute;
  top: clamp(3rem, 14vh, 9rem);
}

.margin-left {
  right: calc(50% + 17rem + 3rem);
}

.margin-right {
  left: calc(50% + 17rem + 3rem);
}

/* Without margins, the side panels go and the left-hand art moves into the top corner. */
@media (width <= 1200px) {
  .margin-right {
    display: none;
  }

  .margin-left {
    top: 20px;
    right: 16px;
  }
}

/* ------------------------------------------------------------------------------------------ */

/* FM-SWITCH: a dark handheld-console screen.                                                 */

/* ------------------------------------------------------------------------------------------ */

.backdrop--switch {
  background:
    radial-gradient(ellipse at center, transparent 45%, rgb(0 0 0 / 30%) 100%),
    radial-gradient(circle, var(--px-faint) 1px, transparent 1.5px) 0 0 / 12px 12px,
    var(--px-bg);
}

/* Faint scanlines: 1px every 3px, kept quieter than the app's optional ones. */
.backdrop--switch::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom, rgb(0 0 0 / 8%) 0 1px, transparent 1px 3px);
}

.switch-icon {
  display: block;
  width: 192px;
  height: 192px;
  image-rendering: pixelated;
}

.switch-panel-wrap {
  position: relative;
  width: 268px;
  margin-top: 2.5rem;

  /* The hard offset shadow under panels: no blur. */
  filter: drop-shadow(4px 4px 0 rgb(0 0 0 / 55%));
}

.switch-tab {
  position: absolute;
  top: -8px;
  left: 12px;
  z-index: 1;
  padding: 1px 6px;
  background: var(--px-green);
  color: var(--px-bg);
  font: 10px/1.4 Silkscreen, monospace;
}

.switch-panel {
  padding: 18px 14px 14px;
  border: 2px solid var(--px-dim);
  background: var(--px-surface);
  clip-path: var(--notch);
  color: var(--px-ink);
  font: 13px/1.6 "Departure Mono", monospace;
}

.switch-title {
  padding-bottom: 8px;
  margin-bottom: 10px !important;
  border-bottom: 2px dashed var(--px-dim);
  color: var(--px-green);
  font: 16px/1.2 Silkscreen, monospace;
  text-shadow: 0 0 4px rgb(123 227 154 / 18%);
}

.switch-muted {
  color: var(--px-muted);
}

/* The segmented progress bar: 20 blocks with 3px gaps, like the FM-1's level meters. */
.switch-bar {
  position: relative;
  width: 237px;
  height: 16px;
  margin: 12px 0 8px;
  background: repeating-linear-gradient(to right, var(--px-faint) 0 9px, transparent 9px 12px);
}

.switch-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: repeating-linear-gradient(to right, var(--px-green) 0 9px, transparent 9px 12px);
}

.switch-status {
  position: relative;
  font: 22px/1 "VT323", monospace;
  color: var(--px-green);
}

.switch-pct {
  counter-reset: pct var(--pct);
}

.switch-pct::before {
  content: counter(pct) "%";
}

.switch-done {
  position: absolute;
  left: 2.55em;
  opacity: 0;
}

.switch-cursor {
  display: inline-block;
  width: 9px;
  height: 16px;
  margin-left: 4px;
  vertical-align: -1px;
  background: var(--px-green);
}

.switch-checks {
  margin-top: 12px !important;
  color: var(--px-muted);
}

@keyframes switch-fill {
  to {
    width: 240px;
  }
}

@keyframes switch-count {
  from {
    --pct: 0;
  }

  to {
    --pct: 100;
  }
}

@keyframes switch-show {
  to {
    opacity: 1;
  }
}

@keyframes switch-hide {
  to {
    opacity: 0;
  }
}

@keyframes switch-blink {
  50% {
    opacity: 0;
  }
}

@keyframes switch-bob {
  50% {
    transform: translateY(-6px);
  }
}

/* The theme itself. */
body:has(.project--switch:is(.is-active, :focus-visible)) {
  --text: var(--px-ink);
  --muted: var(--px-muted);
  --rule: var(--px-dim);
  --accent: var(--px-green);
}

body:has(.project--switch:is(.is-active, :focus-visible)) .backdrop--switch {
  opacity: 1;
}

body:has(.project--switch:is(.is-active, :focus-visible)) h1 {
  color: var(--px-green);
  font-family: Silkscreen, monospace;
  font-weight: 400;
  text-shadow: 0 0 6px rgb(123 227 154 / 25%);
}

body:has(.project--switch:is(.is-active, :focus-visible)) .projects li {
  border-bottom-style: dashed;
}

body:has(.project--switch:is(.is-active, :focus-visible)) .projects {
  border-top-style: dashed;
}

body:has(.project--switch:is(.is-active, :focus-visible)) .projects .name {
  font-family: Silkscreen, monospace;
  font-weight: 400;
  font-size: 1.35rem;
}

body:has(.project--switch:is(.is-active, :focus-visible)) .projects .kind {
  padding: 2px 6px;
  outline: 1px solid var(--px-muted);
  font: 0.65rem/1.4 Silkscreen, monospace;
  text-transform: uppercase;
  letter-spacing: 0;
}

body:has(.project--switch:is(.is-active, :focus-visible)) footer {
  font-family: "Departure Mono", monospace;
  font-size: 0.8rem;
  text-transform: uppercase;
}

/* The hovered card becomes a panel with a notched outline and a hard shadow. */
.project--switch::before,
.project--switch::after {
  content: "";
  position: absolute;
  inset: -2px -1rem;
  z-index: -1;
  clip-path: var(--notch);
  opacity: 0;
  transition: opacity var(--fade);
}

.project--switch::before {
  translate: 4px 4px;
  background: rgb(0 0 0 / 55%);
}

.project--switch::after {
  border: 2px solid var(--px-dim);
  background: var(--px-surface);
}

.project--switch:is(.is-active, :focus-visible)::before,
.project--switch:is(.is-active, :focus-visible)::after {
  opacity: 1;
}

/* On narrow screens the panel's edges sit closer, so its offset shadow stays inside the screen. */
@media (width <= 600px) {
  .project--switch::before,
  .project--switch::after {
    inset: -2px -12px;
  }
}

.project--switch:is(.is-active, :focus-visible) .name {
  color: var(--px-green);
}

.project--switch:is(.is-active, :focus-visible) .kind {
  outline-color: var(--px-green);
  background: var(--px-green);
  color: var(--px-bg);
}

.project--switch:is(.is-active, :focus-visible) .about {
  font-family: "Departure Mono", monospace;
  font-size: 1rem;
}

/* The FLASH panel plays through an install each time the theme comes on. */
body:has(.project--switch:is(.is-active, :focus-visible)) .switch-fill {
  animation: switch-fill 2.4s steps(20, end) 0.3s forwards;
}

body:has(.project--switch:is(.is-active, :focus-visible)) .switch-status {
  animation: switch-count 2.4s linear 0.3s forwards;
}

body:has(.project--switch:is(.is-active, :focus-visible)) .switch-writing {
  animation: switch-hide 0s 2.7s forwards;
}

body:has(.project--switch:is(.is-active, :focus-visible)) .switch-done {
  animation: switch-show 0s 2.7s forwards;
}

body:has(.project--switch:is(.is-active, :focus-visible)) .switch-cursor {
  animation: switch-blink 1s steps(1) infinite;
}

body:has(.project--switch:is(.is-active, :focus-visible)) .switch-icon {
  animation: switch-bob 1.2s steps(1) infinite;
}

/* ------------------------------------------------------------------------------------------ */

/* ESTAMPIE: an illuminated manuscript on vellum.                                             */

/* ------------------------------------------------------------------------------------------ */

.backdrop--estampie {
  background:
    /* Fine grain of the skin. */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .25 0 0 0 0 .12 .16 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E"),
    /* Broad mottling and foxing. */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='900'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.004' numOctaves='3' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .38 0 0 0 0 .16 .5 0 0 0 -.12'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E"),
    /* Darkened, handled edges. */
    radial-gradient(ellipse at center, transparent 40%, rgb(150 105 45 / 35%) 100%),
    var(--mss-vellum);
}

/* The leaf's border: a vermilion rule and a gold rule, with quatrefoils at the corners. */
.estampie-frame {
  position: absolute;
  inset: 22px;
  border: 2px solid rgb(150 32 18 / 75%);
  box-shadow:
    inset 0 0 0 4px transparent,
    inset 0 0 0 5px var(--mss-gold);
}

.estampie-frame::before {
  content: "";
  position: absolute;
  inset: -20px;

  --quatrefoil: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 36 36'%3E%3Cg fill='%231a3e94' stroke='%23b8892a' stroke-width='1.5'%3E%3Ccircle cx='18' cy='9' r='7'/%3E%3Ccircle cx='18' cy='27' r='7'/%3E%3Ccircle cx='9' cy='18' r='7'/%3E%3Ccircle cx='27' cy='18' r='7'/%3E%3C/g%3E%3Ccircle cx='18' cy='18' r='7' fill='%23962012' stroke='%23b8892a' stroke-width='1.5'/%3E%3Ccircle cx='18' cy='18' r='2.5' fill='%23b8892a'/%3E%3C/svg%3E");

  background:
    var(--quatrefoil) top left / 38px no-repeat,
    var(--quatrefoil) top right / 38px no-repeat,
    var(--quatrefoil) bottom left / 38px no-repeat,
    var(--quatrefoil) bottom right / 38px no-repeat;
}

@media (width <= 600px) {
  .estampie-frame {
    inset: 6px;
  }

  .estampie-frame::before {
    inset: -12px;
    background-size: 24px;
  }

  .project--estampie .name::before {
    display: none;
  }
}

/* Dry-point ruling around the text block, as a scribe would prick and rule the leaf. */
.estampie-ruling {
  position: absolute;
  inset: 0 auto;
  left: 50%;
  width: calc(34rem + 3rem);
  translate: -50% 0;
  border-inline: 1px solid rgb(91 69 50 / 16%);
  background: repeating-linear-gradient(to bottom, transparent 0 27px, rgb(91 69 50 / 7%) 27px 28px);
}

/* Sliced from the top, so a small square shows just the initial without its vine. */
.estampie-initial {
  display: block;
  width: 150px;
  height: auto;
}

.estampie-gloss {
  width: 13rem;
  color: var(--mss-ink-soft);
  font: italic 1.05rem/1.45 "IM Fell English", serif;
}

.estampie-gloss .rubric {
  color: var(--mss-vermilion);
  font-style: normal;
}

.estampie-gloss + .estampie-gloss {
  margin-top: 1.25rem;
}

@keyframes estampie-gild {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* The theme itself. */
body:has(.project--estampie:is(.is-active, :focus-visible)) {
  --text: var(--mss-ink);
  --muted: var(--mss-ink-soft);
  --rule: rgb(150 32 18 / 35%);
  --accent: var(--mss-vermilion);
}

body:has(.project--estampie:is(.is-active, :focus-visible)) .backdrop--estampie {
  opacity: 1;
}

body:has(.project--estampie:is(.is-active, :focus-visible)) .estampie-initial,
body:has(.project--estampie:is(.is-active, :focus-visible)) .estampie-gloss {
  animation: estampie-gild 0.8s ease-out both;
}

body:has(.project--estampie:is(.is-active, :focus-visible)) h1 {
  color: var(--mss-vermilion);
  font-family: "IM Fell English SC", serif;
  font-weight: 400;
  letter-spacing: 0.02em;
}

body:has(.project--estampie:is(.is-active, :focus-visible)) h1::first-letter {
  color: var(--mss-lapis);
}

body:has(.project--estampie:is(.is-active, :focus-visible)) .lede,
body:has(.project--estampie:is(.is-active, :focus-visible)) footer {
  font-family: "IM Fell English", serif;
  font-style: italic;
}

body:has(.project--estampie:is(.is-active, :focus-visible)) .projects .name {
  font-family: "IM Fell English SC", serif;
  font-weight: 400;
  font-size: 1.65rem;
  line-height: calc(1.5rem * 1.55);
}

body:has(.project--estampie:is(.is-active, :focus-visible)) .projects .kind {
  font-family: "IM Fell English", serif;
  font-style: italic;
  font-size: 1rem;
  letter-spacing: 0;
}

body:has(.project--estampie:is(.is-active, :focus-visible)) .projects .about {
  font-family: "IM Fell English", serif;
  font-size: 1.15rem;
}

/* A rubricated pilcrow in the margin marks the hovered entry. */
.project--estampie .name {
  position: relative;
}

.project--estampie .name::before {
  content: "\00B6";
  position: absolute;
  right: calc(100% + 0.4em);
  color: var(--mss-vermilion);
  font-family: "IM Fell English", serif;
  opacity: 0;
  transition: opacity var(--fade);
}

.project--estampie:is(.is-active, :focus-visible) .name::before {
  opacity: 1;
}

.project--estampie:is(.is-active, :focus-visible) .name {
  color: var(--mss-lapis);
}

.project--estampie:is(.is-active, :focus-visible) .about {
  color: var(--mss-ink);
}

/* ------------------------------------------------------------------------------------------ */

/* FM1Kit: plain reference documentation, in the manner of Apple's developer docs.            */

/* ------------------------------------------------------------------------------------------ */


@media (prefers-color-scheme: dark) {
  :root {
    --docs-bg: #000;
    --docs-panel: #1c1c1e;
    --docs-text: #f5f5f7;
    --docs-muted: #a1a1a6;
    --docs-rule: #424245;
    --docs-link: #2997ff;
  }
}

.backdrop--fm1kit {
  background: var(--docs-bg);
  color: var(--docs-text);
  font: 14px/1.4 var(--docs-font);
  letter-spacing: -0.01em;
}

/* The navigation bar across the top. */
.docs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 22px;
  border-bottom: 1px solid var(--docs-rule);
  font-size: 13px;
}

.docs-crumb {
  color: var(--docs-muted);
}

/* The navigator: FM1Kit's types, as in the documentation's sidebar. */
.docs-navigator {
  width: 220px;
}

.docs-navigator-title {
  margin-bottom: 10px !important;
  font-size: 17px;
  font-weight: 600;
}

.docs-group {
  margin: 14px 0 4px !important;
  color: var(--docs-muted);
  font-size: 12px;
  font-weight: 600;
}

.docs-symbol {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  margin-left: -8px !important;
  border-radius: 6px;
  font: 13px/1.5 var(--docs-mono);
  letter-spacing: 0;
}

.docs-symbol--selected {
  background: var(--docs-panel);
}

.docs-badge {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  color: #fff;
  font: 600 10px/1 var(--docs-font);
}

.docs-badge--struct {
  background: var(--docs-struct);
}

.docs-badge--class {
  background: var(--docs-class);
}

.docs-badge--enum {
  background: var(--docs-enum);
}

.docs-badge--actor {
  background: var(--docs-actor);
}

.docs-availability {
  width: 180px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--docs-panel);
}

.docs-availability .docs-group {
  margin-top: 0 !important;
}

.docs-availability p + p {
  margin-top: 2px;
}

/* The theme itself. */
body:has(.project--fm1kit:is(.is-active, :focus-visible)) {
  --text: var(--docs-text);
  --muted: var(--docs-muted);
  --rule: var(--docs-rule);
  --accent: var(--docs-link);
}

body:has(.project--fm1kit:is(.is-active, :focus-visible)) .backdrop--fm1kit {
  opacity: 1;
}

body:has(.project--fm1kit:is(.is-active, :focus-visible)) h1 {
  font-family: var(--docs-font);
  font-weight: 600;
  letter-spacing: -0.003em;
}

body:has(.project--fm1kit:is(.is-active, :focus-visible)) .projects .name {
  font-family: var(--docs-font);
  font-weight: 600;
  letter-spacing: -0.01em;
}

body:has(.project--fm1kit:is(.is-active, :focus-visible)) .projects .kind {
  font-family: var(--docs-font);
  font-weight: 400;
  font-size: 0.85rem;
  letter-spacing: 0;
}

/* The hovered card sits on a light grey rounded panel, as Apple's cards do. */
.project--fm1kit::before {
  content: "";
  position: absolute;
  inset: 0 -1rem;
  z-index: -1;
  border-radius: 12px;
  background: var(--docs-panel);
  opacity: 0;
  transition: opacity var(--fade);
}

.project--fm1kit:is(.is-active, :focus-visible)::before {
  opacity: 1;
}

/* The page's light weight is too thin in the system font; Apple's text is regular. */
.project--fm1kit:is(.is-active, :focus-visible) .about {
  font-family: var(--docs-font);
  font-weight: 400;
}

/* Without margins, the navigator and availability go; the bar stays. */
@media (width <= 1200px) {
  .backdrop--fm1kit .margin-left {
    display: none;
  }
}

/* ------------------------------------------------------------------------------------------ */

/* Small versions of the corner art, for the top corner on narrow screens. */
@media (width <= 1200px) {
  .switch-icon {
    width: 80px;
    height: 80px;
  }

  .estampie-initial {
    width: 72px;
    height: 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --fade: 0.01s;
  }

  .backdrop *,
  .backdrop *::before {
    animation: none !important;
  }

  .switch-fill {
    width: 240px;
  }

  .switch-status {
    --pct: 100;
  }

  .switch-writing {
    opacity: 0;
  }

  .switch-done {
    opacity: 1;
  }
}
