/* Hidden gems (assets/js/gems.js): the gem bar, the golden leaf, glinting words and the story end marker.
   The leaf uses the "h" glyph of Yarndings 20 (hosted with the site, SIL Open Font License), like the falling leaves. */
@font-face {
  font-family: "Yarndings 20";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/yarndings-20.ttf") format("truetype");
}

/* ---- Gem bar: four settings, bottom left, shown from the first gem on ---- */
.gem-bar {
  position: fixed; left: 0.6rem; bottom: 0.6rem; z-index: 15;
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.3rem 0.55rem; border-radius: 999px;
  background: rgba(255, 252, 244, 0.85); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  font: italic 0.8rem/1 var(--font-body, Georgia, serif);
}
.gem-slots { display: flex; gap: 0.2rem; }
.gem-slot { display: block; width: 1.25rem; height: 1.25rem; color: #8a8478; }
.gem-slot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.gem-body { fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }
.gem-facets { fill: none; stroke: currentColor; stroke-width: 0.7; opacity: 0; }
.gem-slot.is-set .gem-body { fill: currentColor; stroke: #7a5f22; }
.gem-slot.is-set .gem-facets { stroke: #fff; opacity: 0.55; }
.gem-slot.is-set.gem--ruby { color: #a3122e; }
.gem-slot.is-set.gem--sapphire { color: #1f4fa8; }
.gem-slot.is-set.gem--emerald { color: #127a4a; }
.gem-slot.is-set.gem--diamond { color: #cfe3ee; }
.gem-slot.is-set.gem--diamond .gem-facets { stroke: #5d7c8c; }
.gem-slot.is-new { animation: gem-pop 0.9s ease-out; }
@keyframes gem-pop {
  0%   { transform: scale(0.2) rotate(-30deg); filter: drop-shadow(0 0 0 #fff6c2); }
  55%  { transform: scale(1.5) rotate(8deg); filter: drop-shadow(0 0 6px #fff6c2); }
  100% { transform: scale(1) rotate(0); filter: drop-shadow(0 0 0 #fff6c2); }
}
.gem-open { color: #6b1424; font-weight: 700; text-decoration: none; white-space: nowrap; }
.gem-open:hover { text-decoration: underline; }
.gem-bar.is-complete { animation: gem-glow 3s ease-in-out infinite; }
@keyframes gem-glow {
  0%, 100% { box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); }
  50%      { box-shadow: 0 0 12px rgba(214, 170, 60, 0.85); }
}
.gem-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- The golden leaf: drifts down once, can be clicked ---- */
.gem-leaf {
  position: fixed; top: 0; left: var(--x, 50%); z-index: 20;
  margin: 0; padding: 0.2rem; border: 0; background: none; cursor: pointer;
  font: 400 46px/1 "Yarndings 20", serif; color: #d4a017;
  text-shadow: 0 0 6px rgba(255, 220, 120, 0.9), 0 0 2px #7a5200;
  animation: gem-leaf-fall 22s linear 1 forwards;
}
@keyframes gem-leaf-fall {
  0%   { transform: translate3d(0, -12vh, 0) rotate(0deg); }
  20%  { transform: translate3d(40px, 12vh, 0) rotate(80deg); }
  40%  { transform: translate3d(-30px, 36vh, 0) rotate(170deg); }
  60%  { transform: translate3d(35px, 60vh, 0) rotate(260deg); }
  80%  { transform: translate3d(-25px, 84vh, 0) rotate(330deg); }
  100% { transform: translate3d(10px, 112vh, 0) rotate(400deg); }
}
.gem-leaf:hover { color: #f0c13a; }
.gem-leaf:focus-visible { outline: 3px solid #7a5200; outline-offset: 2px; animation-play-state: paused; }
.gem-leaf:hover { animation-play-state: paused; }
.gem-leaf.is-caught { animation: gem-leaf-caught 0.9s ease-out forwards; cursor: default; }
@keyframes gem-leaf-caught {
  0%   { opacity: 1; filter: drop-shadow(0 0 0 #fff6c2); }
  40%  { opacity: 1; filter: drop-shadow(0 0 14px #fff6c2); }
  100% { opacity: 0; filter: drop-shadow(0 0 20px #fff6c2); }
}
/* Reduced motion: the leaf rests in the footer and never moves. */
.gem-leaf--still { position: static; display: inline-block; animation: none; font-size: 34px; vertical-align: middle; }
.gem-leaf--still.is-caught { animation: none; opacity: 0; }

/* ---- Glinting words: look like the text around them; a faint sparkle now and then ---- */
.glint {
  display: inline; margin: 0; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; letter-spacing: inherit; cursor: inherit;
  animation: glint 9s ease-in-out infinite;
}
.glint:hover { cursor: pointer; }
.glint:focus-visible { outline: 2px solid var(--focus, #1c1f24); outline-offset: 2px; }
@keyframes glint {
  0%, 88%, 100% { text-shadow: none; }
  93%           { text-shadow: 0 0 6px rgba(214, 170, 60, 0.95), 0 0 1px rgba(214, 170, 60, 0.9); }
}
.glint.is-found { animation: glint-found 1s ease-out; }
@keyframes glint-found {
  0%   { text-shadow: 0 0 0 rgba(214, 170, 60, 0); }
  40%  { text-shadow: 0 0 12px rgba(214, 170, 60, 1); }
  100% { text-shadow: 0 0 0 rgba(214, 170, 60, 0); }
}

/* ---- End-of-story marker (an invisible line the script watches) ---- */
.gem-end { display: block; height: 1px; }

@media (prefers-reduced-motion: reduce) {
  .gem-slot.is-new, .gem-bar.is-complete, .glint, .glint.is-found { animation: none; }
  .glint { text-decoration: underline dotted rgba(214, 170, 60, 0.6); text-underline-offset: 0.2em; }
}
@media print { .gem-bar, .gem-leaf { display: none; } }
