/* Falari Genesis · The Last Context — standalone mint rite.
   Palette pulled from the artifact itself: char void, parchment amber,
   flame orange, ember red, bone text, ash muted. */

/* Font files and @font-face live in ../fonts/fonts.css
   (Space Grotesk / Inter / JetBrains Mono, self-hosted OFL). */

:root {
  --char-0: #060302;
  --char-1: #0d0805;
  --char-2: #17100a;
  --line: #2a1c10;
  --line-soft: #1d140c;
  --bone: #f2e7d5;
  --ash: #a89a89;
  --ash-dim: #6f6254;
  --parch: #e5b069;
  --flame: #ffb347;
  --ember: #ff7a29;
  --blood: #d43a1a;
  --ok: #9dc069;
  --info: #8fb6d9;
  --warn: #ffb347;
  --err: #ff6a4d;
  /* Titles use the official site's display face (Space Grotesk);
     the Falari wordmark uses the same face; Chinese body copy stays Songti. */
  --font-display: 'Space Grotesk', 'Inter', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --font-brand: 'Space Grotesk', 'Inter', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --font-serif: 'Songti SC', 'STSong', 'Noto Serif SC', 'SimSun', serif;
  --font-mono: 'JetBrains Mono', 'Courier Prime', 'Courier New', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Author display rules (e.g. .ghost's inline-flex) outrank the UA [hidden]
   rule, so hidden must win explicitly. */
[hidden] { display: none !important; }

html {
  scrollbar-color: #3a2a1a #0a0603;
  scrollbar-width: thin;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #0a0603; }
::-webkit-scrollbar-thumb {
  background: #3a2a1a;
  border-radius: 8px;
  border: 2px solid #0a0603;
}
::-webkit-scrollbar-thumb:hover { background: var(--ember); }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--char-0);
  color: var(--bone);
  font-family: var(--font-serif);
  overflow-x: hidden;
}
body.locked { overflow: hidden; }

::selection { background: var(--ember); color: #1b0d04; }

:where(a, button, pre):focus-visible {
  outline: 2px solid var(--flame);
  outline-offset: 3px;
  border-radius: 2px;
}

.mono { font-family: var(--font-mono); }

.skip {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--char-2);
  border: 1px solid var(--ember);
  color: var(--flame);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .12em;
  text-decoration: none;
  transform: translateY(-300%);
}
.skip:focus-visible { transform: none; }

/* ---------- atmosphere layers ---------- */

#embers {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.smoke { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.smoke i {
  position: absolute;
  width: 64vmax;
  height: 64vmax;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 122, 41, .055), transparent 70%);
}
.smoke i:first-child { left: -24vmax; bottom: -34vmax; }
.smoke i:last-child { right: -28vmax; top: -30vmax; background: radial-gradient(closest-side, rgba(212, 58, 26, .05), transparent 70%); }

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 55% at 50% 108%, rgba(212, 58, 26, .14), rgba(255, 122, 41, .05) 46%, transparent 72%),
    radial-gradient(90% 60% at 50% -18%, rgba(23, 16, 10, .9), transparent 60%);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- top bar ---------- */

.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: linear-gradient(180deg, rgba(6, 3, 2, .92), rgba(6, 3, 2, 0));
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  color: var(--bone);
  min-height: 40px;
}
/* Official logo: silver cube + black prompt, reads on light and dark alike. */
.brand img { width: 24px; height: 24px; display: block; object-fit: contain; }
.brand-name {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  letter-spacing: -.01em;
  font-size-adjust: from-font;
}

.top-tools { display: flex; align-items: center; gap: 6px; }

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--ash);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .14em;
  cursor: pointer;
  transition: color .18s, border-color .18s;
}
.tool:hover { color: var(--flame); border-color: #3a2a1a; }
.tool svg { width: 18px; height: 18px; }
.tool[aria-pressed="true"] { color: var(--flame); }
.tool .off { display: none; }
.tool[aria-pressed="false"] .on { display: none; }
.tool[aria-pressed="false"] .off { display: block; }
.tool[aria-pressed="false"] { color: var(--ash-dim); }
a.tool { text-decoration: none; }

/* ---------- stage ---------- */

.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 92px clamp(16px, 4vw, 40px) 40px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(28px, 5vw, 80px);
}

.artifact {
  position: relative;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-self: center;
}

.halo {
  position: absolute;
  inset: -10% -16%;
  z-index: -1;
  background: radial-gradient(52% 44% at 50% 80%, rgba(255, 122, 41, .3), rgba(212, 58, 26, .12) 46%, transparent 72%);
  filter: blur(12px);
}

.parchment {
  position: relative;
  width: min(100%, 470px, calc((100dvh - 250px) * .714));
  transform: perspective(1200px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  will-change: transform;
}
.parchment video {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 1120;
  background: #000;
  /* Feather the baked-in black frame so the parchment floats in the void.
     Union fallback (no mask-composite) still fades the corners. */
  -webkit-mask-image:
    linear-gradient(to right, transparent 0, #000 5%, #000 95%, transparent 100%),
    linear-gradient(to bottom, transparent 0, #000 4%, #000 96%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, transparent 0, #000 5%, #000 95%, transparent 100%),
    linear-gradient(to bottom, transparent 0, #000 4%, #000 96%, transparent 100%);
  mask-composite: intersect;
}
.parchment .edge {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow:
    0 34px 90px -24px rgba(255, 122, 41, .28),
    0 0 120px rgba(255, 122, 41, .1);
}

.artifact-cap {
  margin-top: 16px;
  font-size: 11px;
  letter-spacing: .22em;
  color: var(--ash-dim);
  text-transform: uppercase;
}

/* ---------- altar ---------- */

.altar { max-width: 500px; }

.eyebrow {
  margin: 0 0 14px;
  font-size: 11px;
  letter-spacing: .3em;
  color: var(--ember);
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.1rem, 3.4vw + .9rem, 3.55rem);
  line-height: 1.07;
  letter-spacing: -.035em;
  color: var(--bone);
  text-shadow: 0 0 44px rgba(255, 122, 41, .28);
}

.lede {
  margin: 14px 0 0;
  font-size: 15px;
  line-height: 1.8;
  color: var(--ash);
}

.rite {
  position: relative;
  margin-top: 30px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: linear-gradient(180deg, #120b06, #0c0704);
}
.rite::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px dashed rgba(229, 176, 105, .14);
  border-radius: 2px;
  pointer-events: none;
}

.rite-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: .22em;
  color: var(--ash);
}
.rite-head .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--state, var(--ash-dim));
  box-shadow: 0 0 10px var(--state, transparent);
}
.rite-supply { margin-left: auto; color: var(--bone); letter-spacing: .18em; }

.rite-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 16px;
  flex-wrap: wrap;
}
.price { display: flex; align-items: baseline; gap: 8px; }
.price b {
  font-size: 34px;
  font-weight: 700;
  color: var(--flame);
  text-shadow: 0 0 26px rgba(255, 179, 71, .4);
}
.price span { font-size: 12px; letter-spacing: .2em; color: var(--ash); }

.chains { display: flex; gap: 8px; }
.chip {
  min-height: 32px;
  padding: 4px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--ash);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .1em;
  cursor: pointer;
  transition: color .18s, border-color .18s, background-color .18s;
}
.chip:hover { color: var(--flame); border-color: #4a351f; }
.chip[aria-pressed="true"] {
  color: var(--flame);
  border-color: var(--parch);
  background: rgba(255, 122, 41, .08);
}

.cta {
  position: relative;
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 3px;
  background: linear-gradient(180deg, #ff8a33, #d4511c);
  color: #1b0d04;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .26em;
  cursor: pointer;
  box-shadow: 0 8px 28px -10px rgba(255, 122, 41, .55), inset 0 1px 0 rgba(255, 255, 255, .28);
  transition: transform .15s, filter .15s, box-shadow .15s;
}
.cta:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.07); }
.cta:active:not(:disabled) { transform: translateY(0); filter: brightness(.94); }
.cta:disabled {
  background: #241a12;
  color: #7a6c5c;
  box-shadow: none;
  cursor: not-allowed;
}

.ghost {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  background: transparent;
  border: 1px solid #3a2a1a;
  border-radius: 3px;
  color: var(--ash);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .2em;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color .18s, border-color .18s;
}
.ghost:hover { color: var(--flame); border-color: var(--parch); }

.status {
  min-height: 1.5em;
  margin: 12px 0 0;
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--ash);
}
.status[data-tone="err"] { color: var(--err); }
.status[data-tone="ok"] { color: var(--ok); }

.owner {
  margin: 8px 0 0;
  font-size: 12px;
  letter-spacing: .08em;
  color: var(--ok);
}

.hint {
  margin: 14px 2px 0;
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--ash-dim);
}

/* ---------- footer ---------- */

.foot {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px clamp(16px, 4vw, 40px);
  border-top: 1px solid var(--line-soft);
  color: var(--ash-dim);
  font-size: 11px;
  letter-spacing: .16em;
}
.addr {
  background: none;
  border: 0;
  padding: 4px 6px;
  color: var(--ash);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .1em;
  cursor: copy;
}
.addr:hover { color: var(--flame); }

/* ---------- language blocks ---------- */

html[data-lang="zh"] .lang-block[data-lang="en"] { display: none; }
html[data-lang="en"] .lang-block[data-lang="zh"] { display: none; }

/* ---------- dialogs ---------- */

dialog {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  background: transparent;
  color: var(--bone);
}
#paperDialog[open] { display: grid; place-items: center; }
dialog::backdrop {
  background: rgba(4, 2, 1, .88);
  backdrop-filter: blur(8px);
}

.rite-stage {
  position: relative;
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 28px 20px;
  overflow: hidden;
}
#burst { position: absolute; inset: 0; pointer-events: none; }

.rite-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: .3em;
  color: var(--ash);
}
.rite-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.4rem, 2.4vw, 2rem);
  letter-spacing: -.01em;
  color: var(--bone);
}

.rite-parchment { position: relative; box-shadow: 0 30px 100px -20px rgba(255, 122, 41, .35); }
.rite-parchment video {
  display: block;
  width: min(72vw, 400px, calc((100dvh - 300px) * .714));
  height: auto;
  aspect-ratio: 800 / 1120;
  background: #000;
  -webkit-mask-image:
    linear-gradient(to right, transparent 0, #000 5%, #000 95%, transparent 100%),
    linear-gradient(to bottom, transparent 0, #000 4%, #000 96%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, transparent 0, #000 5%, #000 95%, transparent 100%),
    linear-gradient(to bottom, transparent 0, #000 4%, #000 96%, transparent 100%);
  mask-composite: intersect;
}

.stamp {
  position: absolute;
  top: 14%;
  right: -6%;
  padding: 8px 14px;
  border: 3px double currentColor;
  border-radius: 2px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .3em;
  color: var(--stamp, var(--flame));
  opacity: 0;
  transform: rotate(-12deg) scale(1.9);
  pointer-events: none;
}
.rite-stage.stamped .stamp { opacity: 1; transform: rotate(-12deg) scale(1); }

.rite-meta {
  margin: 0;
  font-size: 12px;
  letter-spacing: .14em;
  color: var(--ash);
  max-width: 80vw;
  overflow-wrap: anywhere;
  text-align: center;
}

.rite-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.rite-actions .cta { width: auto; min-width: 180px; padding: 0 26px; }
.rite-actions .ghost { width: auto; margin-top: 0; padding: 0 22px; }

.paper {
  width: min(660px, calc(100vw - 40px));
  max-height: min(84dvh, 900px);
  margin: auto;
  padding: 30px clamp(20px, 4vw, 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #140c07, #0d0704);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.paper-scroll {
  overflow: auto;
  min-height: 0;
  scrollbar-color: #3a2a1a #0d0704;
  scrollbar-width: thin;
}
/* Chrome gives overflowing scroll containers sequential focus; the dialog's
   autofocus lands here, so the ring must speak the palette, inset. */
.paper-scroll:focus-visible {
  outline: 2px solid var(--flame);
  outline-offset: -2px;
  border-radius: 2px;
}
.paper h2 {
  margin: 0 0 18px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -.01em;
  color: var(--parch);
}
.paper-text {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.9;
  color: var(--parch);
  white-space: pre-wrap;
}
.paper-zh {
  margin: 20px 0 0;
  padding-top: 18px;
  border-top: 1px dashed rgba(229, 176, 105, .2);
  font-size: 13px;
  line-height: 1.9;
  color: var(--ash);
  white-space: pre-wrap;
}
.paper .ghost { margin-top: 18px; flex: none; }

/* ---------- motion (opt-in, compositor-only) ---------- */

@media (prefers-reduced-motion: no-preference) {
  :root:not([data-motion="off"]) .smoke i:first-child { animation: drift-a 26s ease-in-out infinite alternate; }
  :root:not([data-motion="off"]) .smoke i:last-child { animation: drift-b 31s ease-in-out infinite alternate; }
  :root:not([data-motion="off"]) .halo { animation: flicker 3.4s ease-in-out infinite alternate; }
  :root:not([data-motion="off"]) .top { animation: fall .7s .05s backwards; }
  :root:not([data-motion="off"]) .artifact { animation: rise 1s .12s backwards; }
  :root:not([data-motion="off"]) .altar > * { animation: rise .8s backwards; }
  :root:not([data-motion="off"]) .altar > :nth-child(1) { animation-delay: .25s; }
  :root:not([data-motion="off"]) .altar > :nth-child(2) { animation-delay: .33s; }
  :root:not([data-motion="off"]) .altar > :nth-child(3) { animation-delay: .41s; }
  :root:not([data-motion="off"]) .altar > :nth-child(4) { animation-delay: .49s; }
  :root:not([data-motion="off"]) .altar > :nth-child(5) { animation-delay: .57s; }
  :root:not([data-motion="off"]) .rite-stage.stamped .stamp { animation: stamp-in .5s cubic-bezier(.2, 1.4, .4, 1) forwards; }
  :root:not([data-motion="off"]) dialog[open] .rite-stage { animation: rise .55s backwards; }
}

@keyframes drift-a { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(9vmax, -6vmax, 0); } }
@keyframes drift-b { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(-8vmax, 7vmax, 0); } }
@keyframes flicker { from { opacity: .78; transform: scale(1); } to { opacity: 1; transform: scale(1.045); } }
@keyframes fall { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes stamp-in {
  from { opacity: 0; transform: rotate(-12deg) scale(1.9); }
  to { opacity: 1; transform: rotate(-12deg) scale(1); }
}

/* ---------- responsive ---------- */

@media (max-width: 920px) {
  .stage {
    grid-template-columns: 1fr;
    gap: 34px;
    padding-top: 84px;
    align-items: start;
  }
  .parchment { width: min(72vw, 340px); }
  .altar { max-width: 560px; margin: 0 auto; width: 100%; }
  .artifact-cap { margin-top: 12px; }
}

@media (max-width: 480px) {
  .top { padding: 10px 14px; }
  a.tool.home { display: none; }
  .rite-row { align-items: center; }
  .price b { font-size: 28px; }
  .stamp { right: -2%; font-size: 12px; }
}

@media (pointer: coarse) {
  .tool { min-width: 44px; min-height: 44px; }
  .chip { min-height: 40px; }
}