/* The inspector, shared by the admin console's Play preview and the player app.
   It carries its own colors so the eye, the glow, and the card look the same
   on either page, in light or dark. */

:root {
  --inspect-gold: #f0bd4f;
  --inspect-gold-bright: #ffe6a3;
  --inspect-gold-deep: #a9761a;
  --inspect-night: #14110b;
  --inspect-panel: #1d1a12;
  --inspect-ink: #f7f1e1;
  --inspect-muted: #b9ae95;
  --inspect-line: rgb(240 189 79 / .24);
}

/* ---------- The eye ---------- */

.inspector-eye {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid rgb(240 189 79 / .55);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #2c2413, var(--inspect-night) 72%);
  color: var(--inspect-gold);
  box-shadow: 0 1px 2px rgb(0 0 0 / .35);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow .2s ease, background .2s ease, color .2s ease, transform .12s ease;
}
.inspector-eye svg { width: 1.7rem; height: 1.7rem; overflow: visible; }
.inspector-eye .eye-lid, .inspector-eye .eye-iris, .inspector-eye .eye-rays {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.inspector-eye .eye-rays { opacity: 0; transition: opacity .2s ease; }
.inspector-eye .eye-pupil { fill: currentColor; }
.inspector-eye:active { transform: scale(.94); }
.inspector-eye:focus-visible { outline: 2px solid var(--inspect-gold-bright); outline-offset: 3px; }
.inspector-eye[aria-pressed='true'] {
  border-color: var(--inspect-gold-bright);
  background: radial-gradient(circle at 50% 30%, var(--inspect-gold-bright), var(--inspect-gold) 55%, var(--inspect-gold-deep));
  color: #1c1505;
  box-shadow: 0 0 0 3px rgb(240 189 79 / .28), 0 0 1.1rem .15rem rgb(240 189 79 / .6);
}
.inspector-eye[aria-pressed='true'] .eye-rays { opacity: 1; }
.inspector-eye :is(.eye-lid, .eye-iris, .eye-pupil, .eye-rays) { transform-box: fill-box; transform-origin: center; }
.inspector-eye .eye-rays { transform-origin: 50% 100%; }

@media (prefers-reduced-motion: no-preference) {
  /* The eye blinks as it opens and shuts, and the rays burst out as it opens. */
  :root:not([data-motion='reduce']) .inspector-eye.is-blinking :is(.eye-lid, .eye-iris, .eye-pupil) {
    animation: inspect-blink .42s ease-in-out;
  }
  :root:not([data-motion='reduce']) .inspector-eye.is-blinking[aria-pressed='true'] .eye-rays {
    animation: inspect-rays .55s cubic-bezier(.2, 1.6, .4, 1) .18s backwards;
  }
  :root:not([data-motion='reduce']) .inspector-eye.is-blinking[aria-pressed='true'] {
    animation: inspect-pulse .7s ease-out;
  }
  /* While it is open, the eye glances round the board now and then. */
  :root:not([data-motion='reduce']) .inspector-eye[aria-pressed='true']:not(.is-blinking) .eye-pupil {
    animation: inspect-glance 6s ease-in-out 1.2s infinite;
  }
}
@keyframes inspect-blink {
  45% { transform: scaleY(.08); }
}
@keyframes inspect-rays {
  from { opacity: 0; transform: scale(.3); }
}
@keyframes inspect-pulse {
  from { box-shadow: 0 0 0 0 rgb(255 230 163 / .9), 0 0 1.1rem .15rem rgb(240 189 79 / .6); }
  to { box-shadow: 0 0 0 1rem rgb(255 230 163 / 0), 0 0 1.1rem .15rem rgb(240 189 79 / .6); }
}
@keyframes inspect-glance {
  0%, 60%, 100% { transform: none; }
  66%, 74% { transform: translate(1.6px, -.6px); }
  80%, 88% { transform: translate(-1.6px, .4px); }
}

/* ---------- Cards that can be inspected ---------- */

.inspect-cell { position: relative; }
.inspect-answer {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--inspect-radius, .6rem);
  background: none;
  color: inherit;
  font: inherit;
  text-align: inherit;
}
.inspect-answer:disabled { cursor: default; }
/* While the eye is on, every card wears a gold rim with a spark of light
   running round it, and a soft glow outside. Without motion the rim is still. */
@property --inspect-spin {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}
.is-inspecting :is(.inspect-cell, .inspect-answer)::before,
.is-inspecting :is(.inspect-cell, .inspect-answer)::after,
.inspect-leaving :is(.inspect-cell, .inspect-answer)::before,
.inspect-leaving :is(.inspect-cell, .inspect-answer)::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: var(--inspect-radius, .7rem);
  pointer-events: none;
}
/* The glow sits outside the card, so it never covers the picture. */
.is-inspecting :is(.inspect-cell, .inspect-answer)::before {
  box-shadow: 0 0 .75rem .05rem rgb(240 189 79 / .55);
}
.is-inspecting :is(.inspect-cell, .inspect-answer)::after {
  box-shadow: inset 0 0 0 2px var(--inspect-gold);
}
.is-inspecting .inspect-cell > button, .is-inspecting .inspect-answer { cursor: zoom-in; }
.is-inspecting .inspect-answer:focus-visible { outline: 2px solid var(--inspect-gold-bright); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
  /* The rim is a ring cut from a turning gold gradient, with one bright spark. */
  :root:not([data-motion='reduce']) .is-inspecting :is(.inspect-cell, .inspect-answer)::after {
    padding: 2.5px;
    box-shadow: none;
    background: conic-gradient(from var(--inspect-spin),
      var(--inspect-gold-deep) 0deg, var(--inspect-gold) 60deg, var(--inspect-gold-bright) 104deg,
      #fffaf0 118deg, var(--inspect-gold-bright) 132deg, var(--inspect-gold) 176deg,
      var(--inspect-gold-deep) 250deg, var(--inspect-gold) 320deg, var(--inspect-gold-deep) 360deg);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
    /* Each card's spark starts a little behind its neighbour's, so the light
       rolls across the board instead of turning in step. */
    animation: inspect-spin 3.6s linear calc(var(--inspect-wave, 0ms) * -5) infinite;
  }
  :root:not([data-motion='reduce']) .is-inspecting :is(.inspect-cell, .inspect-answer)::before {
    animation: inspect-breathe 2.8s ease-in-out calc(var(--inspect-wave, 0ms) * -3) infinite;
  }

  /* Turning the eye on sends a ripple out from it. Each card hops and flashes
     as the ripple reaches it. --inspect-wave is set from its distance. */
  :root:not([data-motion='reduce']) .inspect-arriving :is(.inspect-cell, .inspect-answer) {
    animation: inspect-hop .5s cubic-bezier(.3, 1.7, .5, 1) var(--inspect-wave, 0ms) backwards;
  }
  :root:not([data-motion='reduce']) .inspect-arriving :is(.inspect-cell, .inspect-answer)::before {
    animation: inspect-flash .7s ease-out var(--inspect-wave, 0ms) backwards,
      inspect-breathe 2.8s ease-in-out calc(var(--inspect-wave, 0ms) * -3) infinite;
  }
  :root:not([data-motion='reduce']) .inspect-arriving :is(.inspect-cell, .inspect-answer)::after {
    animation: inspect-draw .45s ease-out var(--inspect-wave, 0ms) backwards,
      inspect-spin 3.6s linear calc(var(--inspect-wave, 0ms) * -5) infinite;
  }

  /* Turning the eye off lets the rims fade rather than vanish. */
  :root:not([data-motion='reduce']) .inspect-leaving:not(.is-inspecting) :is(.inspect-cell, .inspect-answer)::after {
    box-shadow: inset 0 0 0 2px var(--inspect-gold);
    animation: inspect-fade .28s ease-in var(--inspect-wave, 0ms) forwards;
  }
  :root:not([data-motion='reduce']) .inspect-leaving:not(.is-inspecting) :is(.inspect-cell, .inspect-answer)::before {
    box-shadow: 0 0 .75rem .05rem rgb(240 189 79 / .55);
    animation: inspect-fade .28s ease-in var(--inspect-wave, 0ms) forwards;
  }
}
@keyframes inspect-spin { to { --inspect-spin: 360deg; } }
@keyframes inspect-breathe {
  50% { box-shadow: 0 0 1.15rem .2rem rgb(240 189 79 / .78); }
}
@keyframes inspect-hop {
  45% { transform: translateY(-3px) scale(1.06); }
}
@keyframes inspect-flash {
  from { box-shadow: 0 0 0 0 rgb(255 240 200 / .95), 0 0 1.6rem .5rem rgb(240 189 79 / .9); }
}
@keyframes inspect-draw {
  from { opacity: 0; transform: scale(1.18); }
}
@keyframes inspect-fade { to { opacity: 0; } }

/* ---------- The card ---------- */

.inspector {
  display: none;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: var(--inspect-panel);
  color: var(--inspect-ink);
  font: 400 1rem/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
  text-align: left;
}
.inspector[open] { display: flex; }
.inspector::backdrop { background: rgb(8 6 3 / .78); }
.inspector * { box-sizing: border-box; }

/* The top 40% belongs to the Title Card. */
.inspector-hero {
  flex: 0 0 40%;
  display: grid;
  place-items: center;
  min-height: 0;
  container-type: size;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem 1rem;
  border-bottom: 1px solid var(--inspect-line);
  background: radial-gradient(ellipse at 50% 42%, #3d3013 0, #1f1a0e 52%, var(--inspect-night) 100%);
  /* A double tap here turns the card, so it must not zoom the page or select the lettering. */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
/* A square as tall as the space allows, kept clear of the close button. */
.inspector-card {
  position: relative;
  width: min(100cqh, 100cqw - 5.2rem);
  aspect-ratio: 1;
  perspective: 60rem;
}
.inspector-turn {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.3, .1, .2, 1);
}
.inspector-turn.is-turned { transform: rotateY(180deg); }
.inspector-side {
  position: absolute;
  inset: 0;
  display: grid;
  filter: drop-shadow(0 0 1px rgb(240 189 79 / .85)) drop-shadow(0 .5rem .8rem rgb(0 0 0 / .5));
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.inspector-side-back { transform: rotateY(180deg); }
.inspector-side > * { width: 100%; height: 100%; min-height: 0; overflow: hidden; border-radius: .9rem; }
.inspector-hero .title-card-image { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.inspector-hero .text-card { padding: 7%; }
.inspector-hero .text-card-line { font-size: 15cqi; }
.inspector-hero .text-card[data-card-size='short'] .text-card-line { font-size: 20cqi; }
.inspector-hero .text-card[data-card-size='long'] .text-card-line { font-size: 12.7cqi; }
.inspector-hero .text-card[data-card-size='extra-long'] .text-card-line { font-size: 11.4cqi; }
.inspector-picture { position: relative; display: grid; place-items: center; overflow: hidden; background: #fbf7ee; }
.inspector-picture img { display: block; width: 100%; height: 100%; object-fit: contain; }
.inspector-picture img.pixel { image-rendering: pixelated; }
.inspector-lettering {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #1b1915;
  font-weight: 800;
  font-size: clamp(1rem, 5vw, 2rem);
}
.inspector-replay {
  position: absolute;
  left: .5rem;
  bottom: .5rem;
  min-height: 2rem;
  padding: .2rem .7rem;
  border: 0;
  border-radius: 2rem;
  background: rgb(20 17 11 / .72);
  color: var(--inspect-ink);
  font: 650 .8rem/1 system-ui, sans-serif;
  cursor: pointer;
}

.inspector-close {
  position: absolute;
  top: calc(.6rem + env(safe-area-inset-top));
  right: .6rem;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid var(--inspect-line);
  border-radius: 50%;
  background: rgb(20 17 11 / .7);
  color: var(--inspect-gold);
  cursor: pointer;
}
.inspector-close svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.inspector :is(.inspector-close, .inspector-flip, .inspector-replay, .inspector-body):focus-visible {
  outline: 2px solid var(--inspect-gold-bright);
  outline-offset: 2px;
}
.inspector-body:focus-visible { outline-offset: -2px; }

.inspector-body {
  flex: 1 1 0;
  min-height: 0;
  padding: 1.1rem 1.3rem calc(1.4rem + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.inspector-body > * { margin: 0; }
.inspector-kicker, .inspector-heading, .inspector-fields dt {
  color: var(--inspect-gold);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.inspector-title {
  margin-top: .2rem;
  color: var(--inspect-ink);
  font-family: 'Bricolage Grotesque', system-ui, sans-serif;
  font-size: clamp(1.7rem, 7.5vw, 2.3rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.03em;
  text-wrap: balance;
}
.inspector-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: .9rem 1.2rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--inspect-line);
}
.inspector-fields dt { color: var(--inspect-muted); }
.inspector-fields dd { margin: .15rem 0 0; font-size: 1.1rem; font-weight: 650; line-height: 1.25; }
.inspector-heading { margin-top: 1.15rem; padding-top: 1rem; border-top: 1px solid var(--inspect-line); }
.inspector-trivia { display: grid; gap: .7rem; margin-top: .55rem; padding: 0; list-style: none; }
.inspector-trivia li { position: relative; padding-left: 1.25rem; }
.inspector-trivia li::before {
  content: '';
  position: absolute;
  left: .1rem;
  top: .5em;
  width: .42rem;
  height: .42rem;
  background: var(--inspect-gold);
  transform: rotate(45deg);
}
.inspector-note { margin-top: .6rem; color: var(--inspect-muted); }
/* A sourced image's credit. Its links open outside the app. */
.inspector-credit { font-size: .9rem; line-height: 1.45; overflow-wrap: anywhere; }
.inspector-body .inspector-credit { margin-top: .55rem; color: var(--inspect-muted); }
.inspector-credit a { color: inherit; font-weight: 650; text-decoration: underline; text-underline-offset: .15em; }
.inspector-body .inspector-credit a { color: var(--inspect-gold); }
.inspector-credit a:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; border-radius: 2px; }
/* A card that can turn over has its bottom corner peeled up, showing the gold
   back. The peel is the button. --curl is the length of the peeled edge. */
@property --curl {
  syntax: '<length>';
  inherits: true;
  initial-value: 0px;
}
.inspector-card.can-turn { --curl: 3.5rem; }
.can-turn .inspector-side > * {
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--curl)), calc(100% - var(--curl)) 100%, 0 100%);
}
.inspector-flip {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 1;
  width: var(--curl);
  height: var(--curl);
  padding: 0;
  border: 0;
  border-top-left-radius: .9rem;
  /* Gold above the fold line, and nothing below it where the corner was. */
  background: linear-gradient(135deg, var(--inspect-gold-deep) 0, var(--inspect-gold) 22%, var(--inspect-gold-bright) 44%, #fff4cf 49.5%, transparent 50%);
  color: #1c1505;
  filter: drop-shadow(-.15rem -.15rem .3rem rgb(0 0 0 / .5));
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s ease;
}
.inspector-flip svg {
  position: absolute;
  left: 16%;
  top: 16%;
  width: 34%;
  height: 34%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.inspector-flip:focus-visible { outline-offset: 4px; }
/* The peel steps aside while the card is in the air. */
.inspector-card.is-turning .inspector-flip { opacity: 0; }
.inspector-card.is-turning { --curl: 0px; }

@media (prefers-reduced-motion: no-preference) {
  /* The corner lifts as the card opens, to show there is a back. */
  :root:not([data-motion='reduce']) .inspector-card.can-turn { animation: inspector-peel .7s cubic-bezier(.2, .9, .3, 1.2) .3s backwards; }
  :root:not([data-motion='reduce']) .inspector-flip:disabled svg { animation: inspector-wait .7s ease-in-out infinite alternate; }
}
@media (prefers-reduced-motion: reduce) {
  .inspector-turn { transition: none; }
}
:root[data-motion='reduce'] .inspector-turn { transition: none; }
@keyframes inspector-peel { from { --curl: 0px; } }
@keyframes inspector-wait { to { opacity: .35; } }

/* On a wide screen the card sits in the middle and keeps the same split. */
@media (min-width: 600px) {
  .inspector {
    width: 26rem;
    height: min(100dvh - 2.5rem, 46rem);
    margin: auto;
    border: 1px solid var(--inspect-line);
    border-radius: 1.35rem;
    box-shadow: 0 1.5rem 4rem rgb(0 0 0 / .6);
  }
  .inspector-hero { padding-top: 1rem; }
  .inspector-close { top: .6rem; }
}
@media (prefers-reduced-motion: no-preference) {
  :root:not([data-motion='reduce']) .inspector[open] { animation: inspector-in .26s cubic-bezier(.2, .9, .3, 1); }
  :root:not([data-motion='reduce']) .inspector[open]::backdrop { animation: inspector-fade .26s ease; }
}
@keyframes inspector-in { from { opacity: 0; transform: translateY(1.5rem); } }
@keyframes inspector-fade { from { opacity: 0; } }
