/* XCR9 friend ranks on /panel. Markup and numbers come from ui/rank.js (window.XRank).
   The design playground is ui/rank-lab.css (/test.html). */

:root { --rk0: #8b929c; --rk1: #c6f432; --rk2: #4cc9f0; --rk3: #eef1f5; --rk4: #f7c933; --rk4b: #fff2b0; --rk4c: #b8860b; --rk: var(--rk0); }
:root[data-theme="light"] { --rk0: #676d76; --rk1: #3f6d00; --rk2: #0b7fa8; --rk3: #3a3f46; --rk4: #9a6b00; --rk4b: #d9a520; --rk4c: #6b4a00; }
/* Panel skins: the friend rank takes the skin's colour (developers violet, traders orange); the game panel keeps lime. */
:root[data-aud="developers"], :root[data-aud="traders"] { --rk1: var(--accent); }
[data-rk="0"] { --rk: var(--rk0); }
[data-rk="1"] { --rk: var(--rk1); }
[data-rk="2"] { --rk: var(--rk2); }
[data-rk="3"] { --rk: var(--rk3); }
[data-rk="4"] { --rk: var(--rk4); }

@property --rk-a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@keyframes rk-holo { to { --rk-a: 360deg; } }
@keyframes rk-spin { to { transform: rotate(360deg); } }
@keyframes rk-pop { 0% { transform: scale(.2) rotate(-25deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes rk-shock { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(3.4); opacity: 0; } }
@keyframes rk-rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rk-float { 0%, 100% { transform: rotateX(4deg) rotateY(-7deg); } 50% { transform: rotateX(-3deg) rotateY(7deg); } }
@keyframes rk-twinkle { 0%, 100% { opacity: .35; } 50% { opacity: .9; } }

/* ---------- emblem ---------- */
.rk-em { --s: 48px; width: var(--s); height: var(--s); flex: none; display: inline-grid; place-items: center; position: relative; vertical-align: middle;
  border-radius: calc(var(--s) * .3); color: var(--rk);
  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--rk) 24%, transparent), color-mix(in srgb, var(--rk) 7%, transparent) 72%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--rk) 40%, transparent); }
.rk-em svg { width: 84%; height: 84%; display: block; overflow: visible; }
.rk-em.bare { background: none; box-shadow: none; border-radius: 0; }
.rk-em.bare svg { width: 100%; height: 100%; }
.rk-em .o { fill: none; stroke: currentColor; stroke-width: 2.6; }
.rk-em .o.thin { stroke-width: 1.6; opacity: .38; }
.rk-em .o.dash { stroke-dasharray: 5 6.5; stroke-linecap: round; opacity: .8; }
.rk-em .f { fill: currentColor; }
.rk-em .halo { fill: currentColor; opacity: .2; }
.rk-em .l { stroke: currentColor; stroke-width: 2; opacity: .6; fill: none; }
.rk-em .spin { animation: rk-spin 26s linear infinite; }
.rk-em .spin.rev { animation-duration: 38s; animation-direction: reverse; }
.rk-em[data-rk="4"]:not(.bare)::before { content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1.5px; pointer-events: none;
  background: conic-gradient(from var(--rk-a), var(--rk4), var(--rk4b), #fff, var(--rk4b), var(--rk4));
  -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);
  animation: rk-holo 5s linear infinite; }
.rk-em[data-rk="4"] svg { filter: drop-shadow(0 0 calc(var(--s) * .07) color-mix(in srgb, var(--rk) 70%, transparent)); }

.rk-chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  color: var(--rk); background: color-mix(in srgb, var(--rk) 12%, transparent); border: 1px solid color-mix(in srgb, var(--rk) 30%, transparent); }
.rk-chip .rk-em { --s: 15px; }
.rk-chip.lg { height: 32px; font-size: 13.5px; padding: 0 13px 0 11px; gap: 8px; }
.rk-chip.lg .rk-em { --s: 19px; }

/* ---------- constellation ---------- */
.rk-sky { position: relative; width: 100%; max-width: 480px; aspect-ratio: 1; margin: 0 auto; }
.rk-sky::before { content: ""; position: absolute; inset: -6%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, color-mix(in srgb, var(--rk) 20%, transparent), transparent 66%); transition: background .6s; }
.rk-sky svg { position: relative; width: 100%; height: 100%; display: block; overflow: visible; }
.rk-orb { fill: none; stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 2 7; }
.rk-ring { animation: rk-spin linear infinite; }
.rk-arc { fill: none; stroke: var(--rk); stroke-width: 1.6; stroke-linecap: round; opacity: .55; transition: stroke-dasharray .5s cubic-bezier(.2,.7,.2,1); }
.rk-node line { stroke: var(--rk); stroke-width: 1; opacity: 0; transition: opacity .4s; }
.rk-node .h { fill: var(--rk); opacity: 0; transition: opacity .4s; }
.rk-node .d { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 1.2; transform-box: fill-box; transform-origin: center; transform: scale(.72); transition: transform .45s cubic-bezier(.2,1.6,.3,1), fill .3s, stroke .3s; }
.rk-node.on line { opacity: .22; }
.rk-node.on .h { opacity: .2; }
.rk-node.on .d { fill: var(--rk); stroke: var(--rk); transform: none; }
.rk-core .h { fill: var(--rk1); opacity: 0; transition: opacity .5s; }
.rk-core .c { fill: var(--surface); stroke: var(--rk0); stroke-width: 1.6; stroke-dasharray: 4 6; transition: fill .4s, stroke .4s; }
.rk-core text { font: 700 17px var(--mono); fill: var(--muted); text-anchor: middle; dominant-baseline: central; transition: fill .4s; direction: ltr; }
.rk-core.on .h { opacity: .16; }
.rk-core.on .c { fill: var(--rk1); stroke: var(--rk1); stroke-dasharray: none; }
.rk-core.on text { fill: var(--accent-ink, #0d1200); }
.rk-sky-cap { position: absolute; inset-inline: 0; bottom: -6px; display: flex; justify-content: center; pointer-events: none; }

/* ---------- ladder ---------- */
.rk-ladder-scroll { overflow-x: auto; margin-inline: -16px; padding: 6px 16px 14px; scrollbar-width: thin; }
.rk-ladder { position: relative; display: grid; grid-template-columns: repeat(5, minmax(148px, 1fr)); gap: 12px; min-width: 780px; }
.rk-rail { position: absolute; top: 52px; inset-inline: 10%; height: 2px; background: var(--line-strong); border-radius: 2px; }
.rk-rail i { display: block; height: 100%; width: calc(var(--p, 0) * 100%); border-radius: 2px; background: linear-gradient(to left, var(--rk1), var(--rk)); transition: width .6s cubic-bezier(.2,.7,.2,1); }
[dir="ltr"] .rk-rail i { background: linear-gradient(to right, var(--rk1), var(--rk)); }
.rk-step { position: relative; display: grid; justify-items: center; align-content: start; gap: 4px; text-align: center; padding: 18px 12px 16px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); transition: border-color .3s, transform .3s, box-shadow .3s, opacity .3s; }
.rk-step .rk-em { --s: 68px; margin-bottom: 8px; background-color: var(--surface); }
.rk-step b { font-size: 16px; line-height: 1.4; }
.rk-step .en { font: 600 10.5px var(--mono); letter-spacing: .12em; color: var(--rk); direction: ltr; }
.rk-step .need { font-size: 13px; color: var(--text); margin-top: 8px; }
.rk-step .hint { font-size: 11.5px; color: var(--muted); }
.rk-step .st { margin-top: 10px; font-size: 11.5px; height: 24px; padding: 0 10px; border-radius: 999px; display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); color: var(--muted); }
.rk-step[data-st="lock"] { opacity: .55; }
.rk-step[data-st="lock"] .rk-em { filter: grayscale(.85); }
.rk-step[data-st="now"] { border-color: color-mix(in srgb, var(--rk) 55%, transparent); transform: translateY(-6px); box-shadow: 0 24px 44px -28px color-mix(in srgb, var(--rk) 70%, transparent); }
.rk-step[data-st="now"] .st { color: var(--bg); background: var(--rk); border-color: transparent; font-weight: 700; }
.rk-step[data-st="done"] .st { color: var(--rk); border-color: color-mix(in srgb, var(--rk) 30%, transparent); }
.rk-step[data-st="next"] .st { color: var(--text); border-style: dashed; border-color: var(--line-strong); }

.rk-bar { height: 6px; border-radius: 6px; background: color-mix(in srgb, var(--text) 9%, transparent); overflow: hidden; }
.rk-bar i { display: block; height: 100%; width: calc(var(--p, 0) * 100%); border-radius: 6px; background: var(--rk); transition: width .5s cubic-bezier(.2,.7,.2,1), background-color .4s; }

/* ---------- missions (panel) ---------- */
.rk-missions { display: grid; gap: 8px; }
.rk-mission { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); }
.rk-mission .rk-em { --s: 40px; }
.rk-mission .t { font-size: 14px; font-weight: 600; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.rk-mission .t small { font-size: 12px; font-weight: 400; color: var(--muted); }
.rk-mission .rk-bar { margin-top: 7px; height: 5px; }
.rk-mission .n { font: 600 13px var(--mono); color: var(--muted); min-width: 46px; text-align: left; }
.rk-mission.done { border-color: color-mix(in srgb, var(--rk) 32%, transparent); background: color-mix(in srgb, var(--rk) 7%, var(--surface-2)); }
.rk-mission.done .n { color: var(--rk); font-family: var(--sans); font-size: 12.5px; }
.rk-mission:not(.done) .rk-em { filter: grayscale(.7); opacity: .75; }

.rk-me { display: grid; gap: 22px; align-items: center; }
@media (min-width: 860px) { .rk-me { grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); gap: 30px; } }
.rk-me .rk-sky { max-width: 320px; }
.rk-me-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.rk-me-head .big { font-size: 26px; font-weight: 700; color: var(--rk); line-height: 1.3; }
.rk-me-head .en { font: 600 11px var(--mono); letter-spacing: .16em; color: var(--muted); direction: ltr; }
.rk-next { font-size: 13.5px; color: var(--text-2, var(--muted)); margin-bottom: 12px; }

/* ---------- rank-up moment ---------- */
.rk-up { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity .25s;
  background: radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--rk) 22%, transparent), transparent 55%), color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.rk-up.on { opacity: 1; pointer-events: auto; }
.rk-up-in { position: relative; display: grid; justify-items: center; gap: 6px; text-align: center; }
.rk-up-em { position: relative; width: 150px; height: 150px; margin-bottom: 18px; }
.rk-up-em .rk-em { --s: 150px; }
.rk-up-em i { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--rk); opacity: 0; }
.rk-up.on .rk-up-em .rk-em { animation: rk-pop .7s cubic-bezier(.2,1.5,.3,1) both; }
.rk-up.on .rk-up-em i { animation: rk-shock 1.2s ease-out both; }
.rk-up.on .rk-up-em i + i { animation-delay: .22s; }
.rk-up-k { font: 600 11px var(--mono); letter-spacing: .22em; color: var(--muted); }
.rk-up-n { font-size: clamp(34px, 9vw, 56px); font-weight: 700; line-height: 1.2; color: var(--rk); }
.rk-up-s { font-size: 14.5px; color: var(--muted); }
.rk-up.on .rk-up-k, .rk-up.on .rk-up-n, .rk-up.on .rk-up-s { animation: rk-rise .5s .25s both; }
.rk-up.on .rk-up-n { animation-delay: .34s; }
.rk-up.on .rk-up-s { animation-delay: .44s; }
.rk-fx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 201; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .rk-ring, .rk-em .spin, .rk-em[data-rk="4"]::before { animation: none !important; }
  .rk-up.on * { animation-duration: .01s !important; animation-delay: 0s !important; }
}

/* legend: metal lettering */
.rk-up[data-rk="4"] .rk-up-n, [data-rk="4"] .rk-me-head .big, .rk-step[data-rk="4"] b {
  background: linear-gradient(100deg, var(--rk4c), var(--rk4) 28%, var(--rk4b) 50%, var(--rk4) 72%, var(--rk4c)); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent; }
.rk-chip[data-rk="4"] { border-color: color-mix(in srgb, var(--rk4) 55%, transparent); background: linear-gradient(100deg, color-mix(in srgb, var(--rk4) 20%, transparent), color-mix(in srgb, var(--rk4b) 12%, transparent)); }

/* guest: the two ways in, shown only at rank 0 */
.rk-guest { display: none; gap: 10px; margin-bottom: 12px; }
[data-rk-cur][data-rk="0"] .rk-guest { display: grid; }
@media (min-width: 560px) { .rk-guest { grid-template-columns: 1fr 1fr; } }
.rk-way { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; align-items: center; padding: 14px; border-radius: 16px; text-decoration: none; color: var(--text);
  border: 1px solid color-mix(in srgb, var(--rk) 40%, var(--line)); background: linear-gradient(160deg, color-mix(in srgb, var(--rk) 13%, transparent), transparent 70%), var(--surface-2); transition: transform .2s, border-color .2s; }
.rk-way:hover { transform: translateY(-2px); border-color: var(--rk); }
.rk-way > [data-rk-emblem] { grid-row: span 2; display: grid; }
.rk-way .k { align-self: end; }
.rk-way b { align-self: start; }
.rk-way .k { font-size: 12px; color: var(--muted); }
.rk-way b { font-size: 15px; line-height: 1.5; }
.rk-way b em { font-style: normal; color: var(--rk); }
.rk-way .go { grid-column: 1 / -1; margin-top: 8px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 13.5px; font-weight: 700; background: var(--rk); color: var(--bg); }
[data-rk-cur][data-rk="0"] .rk-sky .rk-core .c { animation: rk-twinkle 2.4s ease-in-out infinite; }

/* an invited user who bought: brighter star with a white rim */
.rk-node.on.paid .d { stroke: #fff; stroke-width: 2.2; }
.rk-node.on.paid .h { opacity: .5; }
.rk-node.on:not(.paid) .d { fill: color-mix(in srgb, var(--rk) 55%, var(--surface)); }
.rk-node.on:not(.paid) .h { opacity: 0; }

/* perks and rules */
.rk-step .perk { font-size: 11.5px; line-height: 1.7; color: var(--muted); margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line-strong); width: 100%; }
.rk-step:not([data-st="lock"]) .perk { color: color-mix(in srgb, var(--rk) 75%, var(--text)); }
.rk-step .need { min-height: 3.2em; display: grid; align-items: center; }
.rk-perks { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.rk-perks:empty { display: none; }
.rk-perk { display: inline-flex; align-items: center; height: 28px; padding: 0 11px; border-radius: 999px; font-size: 12.5px; white-space: nowrap; color: var(--faint); border: 1px dashed var(--line-strong); }
.rk-perk.on { color: var(--rk); border: 1px solid color-mix(in srgb, var(--rk) 35%, transparent); background: color-mix(in srgb, var(--rk) 10%, transparent); font-weight: 600; }
.rk-rules { display: grid; gap: 10px; }
@media (min-width: 760px) { .rk-rules { grid-template-columns: 1fr 1fr; } }
.rk-rule { display: grid; gap: 4px; align-content: start; padding: 14px 16px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; color: var(--muted); }
.rk-rule b { color: var(--text); font-size: 14.5px; }
.rk-rule.tbd { border: 1px dashed color-mix(in srgb, var(--warn) 55%, transparent); }
.rk-rule.tbd span { color: var(--warn); }
.rk-det { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.rk-det summary { cursor: pointer; font-size: 13.5px; color: var(--muted); }
.rk-det[open] summary { margin-bottom: 14px; color: var(--text); }
.rk-det .rk-rules { margin-top: 14px; }

/* ---------- on /panel ---------- */
html:not(.rk-ready) [data-rk-live] { display: none !important; }   /* hidden until the account's numbers have loaded */
.app .who .rk-em { margin-inline-start: 2px; }
.app .tile .rk-chip { margin-top: 3px; }
.app a.tile { display: block; }
.app .side a .rk-em { margin-inline-start: auto; opacity: 1; }

/* the public home page: plain ladder, no account state */
.rk-ladder[data-static] .rk-step { opacity: 1; }
