/* Rewards (js/rewards.js): XP, levels, seals and stars. Atlas is ink on paper with one lit thing; rewards are that thing,
   in brass. Dark values in dark.css. */
:root { --brass: #a8761a; --brass-bg: #f6eedb; }

/* a seal: the ring in ink, the mark in brass; not yet earned, dashed and grey */
.seal { display: block; width: 64px; height: 64px; flex: none; overflow: visible; }
.seal .o { fill: var(--card); stroke: var(--strong); stroke-width: 1.4; }
.seal .i { fill: none; stroke: var(--strong); stroke-width: .8; }
.seal .g { fill: none; stroke: var(--brass); stroke-width: 1.15; stroke-linecap: round; stroke-linejoin: round; }
.seal .t { fill: var(--brass); font-family: var(--mono); font-weight: 500; text-anchor: middle; dominant-baseline: central; }
.seal.locked .o { fill: none; stroke: var(--lo); stroke-dasharray: 3 3; }
.seal.locked .i { stroke: var(--faint); } .seal.locked .g { stroke: var(--lo); } .seal.locked .t { fill: var(--lo); }

.rw-stars { display: inline-flex; gap: 2px; vertical-align: -2px; }
.rw-stars svg { width: 13px; height: 13px; stroke-width: 1.6; stroke-linejoin: round; }
.rw-stars .on { fill: var(--brass); stroke: var(--brass); } .rw-stars .off { fill: none; stroke: var(--lo); }

.rw-bar { height: 4px; border-radius: 2px; background: var(--faint); overflow: hidden; }
.rw-bar i { display: block; height: 100%; width: var(--w, 0%); background: var(--brass); border-radius: 2px; transition: width .7s cubic-bezier(.22, 1, .36, 1); }
.rw-k { font: 500 10px/1.4 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--brass); }

/* the XP chips after an answer */
.rw-gains { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-left: 8px; vertical-align: 1px; }
.rw-gain { font: 500 11px var(--mono); letter-spacing: .02em; color: var(--brass); background: var(--brass-bg); padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  animation: rw-rise .8s cubic-bezier(.22, 1, .36, 1) both; }
.rw-gain:nth-child(2) { animation-delay: .12s; } .rw-gain:nth-child(3) { animation-delay: .24s; }
.rw-gain.ghost { color: var(--lo); background: none; border: 1px dashed var(--lo); text-decoration: line-through; }
@keyframes rw-rise { from { transform: translateY(6px) scale(.9); opacity: 0; } }

/* seal toasts: top centre, clear of the notch, above the drawer and the bottom sheet */
.rw-toasts { position: fixed; z-index: 40; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(380px, calc(100vw - 24px));
  display: grid; gap: 8px; pointer-events: none; }
.rw-toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 10px; border-radius: 14px; background: var(--card);
  box-shadow: var(--lift), 0 12px 32px -12px #0000004d; text-decoration: none; color: var(--text); animation: rw-drop .5s cubic-bezier(.2, 1.3, .4, 1) both; }
.rw-toast .seal { width: 52px; height: 52px; }
.rw-toast > span { display: grid; min-width: 0; }
.rw-toast b { font: 400 19px/1.2 var(--serif); color: var(--strong); }
.rw-toast .rw-r { font-size: 13px; color: var(--muted); }
.rw-toast.out { opacity: 0; transform: translateY(-8px); transition: opacity .4s, transform .4s; }
@keyframes rw-drop { from { transform: translateY(-16px); opacity: 0; } }

/* the level-up card: the one full-screen moment */
.rw-up { border: 0; padding: 0; background: none; max-width: none; max-height: none; width: 100%; height: 100%; display: grid; place-items: center; color: var(--text); }
.rw-up::backdrop { background: color-mix(in srgb, var(--page) 82%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.rw-up-in { width: min(380px, calc(100vw - 32px)); margin: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); padding: 28px 24px 24px; border-radius: 20px;
  background: var(--card); box-shadow: var(--lift), 0 24px 64px -24px #00000059; display: grid; justify-items: center; gap: 10px; text-align: center; }
.rw-up h2 { margin: 4px 0 0; animation: rw-letter 1s cubic-bezier(.16, 1, .3, 1) 1.1s both; font: 400 32px/1.1 var(--serif); color: var(--strong); text-wrap: balance; }
.rw-up p { margin: 0; color: var(--muted); font-size: 15px; }
.rw-up form { margin-top: 10px; }
.rw-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--hi); background: var(--hi); color: var(--card);
  font: 500 12px var(--mono); letter-spacing: .04em; padding: 10px 20px; border-radius: 999px; cursor: pointer; text-decoration: none; }
.rw-btn:hover { background: var(--lit); }
.rw-btn.ghost { background: var(--card); color: var(--hi); border-color: var(--faint); }
.rw-btn:focus-visible, .rw-toast:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) { .rw-gain, .rw-toast { animation: none; } .rw-bar i { transition: none; } }

/* ---------- the level-up, played out: the page sinks back under a vignette, the seal slams down, and on impact
   shockwaves, brass sparks (js/rewards.js), a shake and a glow; slow rays turn behind the seal from then on ---------- */
.rw-up::backdrop { background: radial-gradient(circle at 50% 46%, color-mix(in srgb, var(--page) 60%, transparent), color-mix(in srgb, var(--page) 94%, transparent) 70%);
  animation: rw-fade .35s ease both; }
html:is(.rw-lvl, .rw-back) body > :not(dialog):not(.rw-toasts) { transition: transform .7s cubic-bezier(.22, 1, .36, 1), filter .7s ease; transform-origin: 50% 40%; }
html.rw-lvl body > :not(dialog):not(.rw-toasts) { transform: scale(.965); filter: saturate(.4); }
.rw-up-in { position: relative; animation: rw-rise .55s cubic-bezier(.2, 1.25, .4, 1) both, rw-shake .42s linear .96s, rw-glow 1.6s ease-out .96s; }
.rw-up.out .rw-up-in { opacity: 0; transform: translateY(12px) scale(.97); transition: opacity .3s ease, transform .3s ease; }
.rw-up.out::backdrop { opacity: 0; transition: opacity .3s ease; }
.rw-up-in > :not(.rw-sw):not(h2) { animation: rw-in .5s cubic-bezier(.22, 1, .36, 1) both; }
.rw-up-in > .rw-k { animation-delay: .15s; } .rw-up-in > p { animation-delay: 1.45s; } .rw-up-in > form { animation-delay: 1.6s; }
.rw-sw { position: relative; width: 148px; height: 148px; display: grid; place-items: center; }
.rw-sw > * { grid-area: 1 / 1; }
.rw-sw .seal { width: 148px; height: 148px; position: relative; animation: rw-slam .9s cubic-bezier(.3, 0, .2, 1) .35s both; }
.rw-rays { position: absolute; inset: -80px; pointer-events: none; animation: rw-rays .9s ease-out 1s both;
  -webkit-mask: radial-gradient(circle, #000 22%, transparent 66%); mask: radial-gradient(circle, #000 22%, transparent 66%); }
.rw-rays::before { content: ''; position: absolute; inset: 0; border-radius: 50%; animation: rw-spin 28s linear infinite;
  background: repeating-conic-gradient(color-mix(in srgb, var(--brass) 42%, transparent) 0 5deg, transparent 5deg 15deg); }
.rw-shock { position: absolute; inset: 0; pointer-events: none; }
.rw-shock i { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--brass); opacity: 0; animation: rw-shock 1s cubic-bezier(.1, .6, .3, 1) .98s both; }
.rw-shock i:nth-child(2) { animation-delay: 1.1s; border-width: 1.5px; } .rw-shock i:nth-child(3) { animation-delay: 1.24s; border-width: 1px; }
.rw-sparks { position: absolute; left: 50%; top: 50%; width: 420px; height: 420px; margin: -210px 0 0 -210px; pointer-events: none; }
@keyframes rw-fade { from { opacity: 0; } }
@keyframes rw-rise { from { opacity: 0; transform: translateY(20px) scale(.94); } }
@keyframes rw-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes rw-letter { from { opacity: 0; letter-spacing: .4em; filter: blur(6px); } 60% { opacity: 1; } }
@keyframes rw-slam { 0% { transform: scale(2.8) rotate(-18deg); opacity: 0; } 50% { opacity: 1; } 70% { transform: scale(.9) rotate(2deg); } 84% { transform: scale(1.05) rotate(-1deg); } 100% { transform: none; } }
@keyframes rw-shake { 15% { transform: translate(-5px, 3px) rotate(-.6deg); } 30% { transform: translate(5px, -2px) rotate(.5deg); } 45% { transform: translate(-3px, -2px); } 60% { transform: translate(3px, 2px); } 80% { transform: translate(-1px, 1px); } }
@keyframes rw-glow { from { box-shadow: var(--lift), 0 0 0 0 color-mix(in srgb, var(--brass) 60%, transparent), 0 24px 64px -24px #00000059; } to { box-shadow: var(--lift), 0 0 0 28px transparent, 0 24px 64px -24px #00000059; } }
@keyframes rw-rays { from { opacity: 0; transform: scale(.5); } }
@keyframes rw-spin { to { transform: rotate(360deg); } }
@keyframes rw-shock { 0% { opacity: .95; transform: scale(.92); } 100% { opacity: 0; transform: scale(2.6); } }
@media (prefers-reduced-motion: reduce) {
  html.rw-lvl body > :not(dialog):not(.rw-toasts) { transform: none; }
  .rw-up::backdrop, .rw-up-in, .rw-up-in > *, .rw-up h2, .rw-sw .seal, .rw-rays, .rw-rays::before, .rw-shock i { animation: none; } .rw-shock { display: none; } }

/* ---------- portraits (site/portraits/): an engraving in the page's ink on paper, fading into the paper at the rim.
   Always a print: in dark mode the paper dims, it never inverts (a negative face looks ghostly) ---------- */
:root { --pf-ink: var(--strong); --pf-paper: var(--card); }
.pfp { --s: 32px; position: relative; display: inline-block; flex: none; width: var(--s); height: var(--s); border-radius: 50%; overflow: hidden; vertical-align: middle;
  background: radial-gradient(circle closest-side, var(--pf-paper) 72%, color-mix(in srgb, var(--pf-paper) 86%, #3c321e)); }
.pfp::after { content: ''; position: absolute; inset: 0; background: var(--pf-ink);
  -webkit-mask: var(--pf) center / cover no-repeat, radial-gradient(circle closest-side, #000 60%, rgba(0, 0, 0, .75) 80%, transparent);
  -webkit-mask-composite: source-in; mask: var(--pf) center / cover no-repeat, radial-gradient(circle closest-side, #000 60%, rgba(0, 0, 0, .75) 80%, transparent); mask-composite: intersect; }
.pfp.sm::after { -webkit-mask: var(--pf) center / cover no-repeat, radial-gradient(circle closest-side, #000 78%, transparent); -webkit-mask-composite: source-in;
  mask: var(--pf) center / cover no-repeat, radial-gradient(circle closest-side, #000 78%, transparent); mask-composite: intersect; }
.pfp[data-k="philosopher"] { --pf: url(/portraits/philosopher.webp); } .pfp[data-k="sailor"] { --pf: url(/portraits/sailor.webp); }
.pfp[data-k="astronomer"] { --pf: url(/portraits/astronomer.webp); } .pfp[data-k="mapmaker"] { --pf: url(/portraits/mapmaker.webp); }
.pfp.sm[data-k="philosopher"] { --pf: url(/portraits/philosopher-s.webp); } .pfp.sm[data-k="sailor"] { --pf: url(/portraits/sailor-s.webp); }
.pfp.sm[data-k="astronomer"] { --pf: url(/portraits/astronomer-s.webp); } .pfp.sm[data-k="mapmaker"] { --pf: url(/portraits/mapmaker-s.webp); }
.pfp:not([data-k])::after { display: none; }

/* ---------- the Profile pill, signed in (js/chip.js), in the site nav and a chapter's bar: the portrait inside the level
   ring, the level on a brass badge; +N XP drops in under it after an answer; hover or keyboard focus opens the dropdown ---------- */
@property --p { syntax: '<number>'; inherits: true; initial-value: 0; }
.pfw { position: relative; display: inline-flex; }
/* the site nav is its own layer (its view-transition-name makes it one), so the bar itself sits over the page for the
   dropdown to; below the seal toasts (z-index 40). A chapter's bar is lifted the same way in drawer.css */
#top { position: sticky; top: 0; z-index: 35; }
:is(#top, .sitelinks) #nav-auth.lvl { display: inline-flex; align-items: center; gap: 8px; padding: 3px 12px 3px 3px; }
#top .pfw { align-self: center; margin: -6px 0 -10px; }   /* the row lines its links up by baseline; the pill has none worth using (its first box is the ring), so it centres, 2px low to sit level with the links' text */
#top .pfw #nav-auth { margin: 0; }
@media (max-width: 900px) { .sitelinks .pfw { display: none; } }   /* a chapter's bar folds the pill into its menu there (drawer.css .mid) */
#nav-auth .ring { position: relative; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--brass) calc(var(--p, 0) * 360deg), var(--faint) 0); transition: --p .6s cubic-bezier(.22, 1, .36, 1), box-shadow .3s ease; }
#nav-auth .ring .pfp { --s: 24px; }
#nav-auth .lv { position: absolute; right: -6px; bottom: -4px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 999px; background: var(--brass); color: var(--card);
  font: 600 9px/15px var(--mono); font-style: normal; letter-spacing: 0; text-align: center; box-shadow: 0 0 0 2px var(--card); }
#nav-auth .lv:empty { display: none; }
#nav-auth .ring.full { box-shadow: 0 0 0 4px color-mix(in srgb, var(--brass) 35%, transparent); }
#nav-auth .ring.flare::after { content: ''; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--brass); animation: rw-shock .8s ease-out both; }
#nav-auth .ring.pulse { animation: rw-pulse .6s ease-out; } @keyframes rw-pulse { 40% { transform: scale(1.12); } }
.rw-plus { position: absolute; left: 2px; top: calc(100% + 8px); z-index: 31; font: 500 11px var(--mono); letter-spacing: .02em; text-transform: none; color: var(--brass); background: var(--brass-bg);
  padding: 2px 8px; border-radius: 999px; white-space: nowrap; pointer-events: none; animation: rw-plus 1.6s cubic-bezier(.22, 1, .36, 1) both; }
@keyframes rw-plus { 0% { opacity: 0; transform: translateY(-4px); } 15%, 70% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(4px); } }
.pfd { position: absolute; right: 0; top: calc(100% + 10px); z-index: 30; width: 280px; display: grid; gap: 10px; padding: 14px 16px; border-radius: 14px; background: var(--card);
  box-shadow: var(--lift), 0 12px 40px #00000026; font: 14px/1.5 var(--sans); letter-spacing: 0; text-transform: none; color: var(--text); text-align: left;
  opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.97); transform-origin: top right;
  transition: opacity .16s ease .12s, transform .2s cubic-bezier(.22, 1, .36, 1) .12s, visibility 0s .32s; }
.pfd::before { content: ''; position: absolute; left: 0; right: 0; top: -12px; height: 12px; }   /* the gap between pill and dropdown still counts as hovering */
@media (hover: hover) { .pfw:hover .pfd { opacity: 1; visibility: visible; transform: none; transition: opacity .18s ease, transform .26s cubic-bezier(.22, 1, .36, 1), visibility 0s; } }
.pfw:has(:focus-visible) .pfd { opacity: 1; visibility: visible; transform: none; transition: opacity .18s ease, transform .26s cubic-bezier(.22, 1, .36, 1), visibility 0s; }
.pfd .hd { display: flex; align-items: center; gap: 12px; }
.pfd .hd > span { display: grid; }
.pfd .hd .pfp { --s: 56px; }
.pfd .hd b { font: 400 24px/1.1 var(--serif); color: var(--strong); }
.pfd .rw-bar { height: 6px; }
.pfd .xp { font: 12px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.pfd .ln { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pfd .ln .v { font: 500 12px var(--mono); color: var(--strong); display: inline-flex; align-items: center; gap: 4px; }
.pfd .ln .v svg { width: 13px; height: 13px; fill: var(--brass); stroke: var(--brass); stroke-width: 1.6; stroke-linejoin: round; }
.pfd .goal { display: flex; gap: 4px; margin-top: -4px; } .pfd .goal i { flex: 1; height: 5px; border-radius: 3px; background: var(--faint); } .pfd .goal i.on { background: var(--brass); }
.pfd hr { border: 0; border-top: 1px solid var(--faint); margin: 2px -16px; }
.pfd .lk { display: grid; margin: -4px -8px -6px; }
.pfd .lk > :is(a, button) { display: block; padding: 7px 8px; border: 0; border-radius: 8px; background: none; font: inherit; color: var(--strong); text-align: left; text-decoration: none; cursor: pointer; }
.pfd .lk > :is(a, button):hover, .pfd .lk > :is(a, button):focus-visible { background: var(--page); outline: none; }
@media (prefers-reduced-motion: reduce) { .pfd, #nav-auth .ring { transition: none; } .pfd { transform: none !important; } .rw-plus, #nav-auth .ring.pulse, #nav-auth .ring.flare::after { animation: none; } }
