/* ===========================================================================
 * The replay library: the save / favorite control on /replay/{id} (.rp-keep),
 * the library page (/replay/saved, .rl), and the favorite card on a profile
 * (.rl-fav). One file because the three draw the same card and press the same
 * two verbs, and a card that looked different in each place would read as
 * three features.
 *
 * Theme-aware through Bulma's tokens (--bulma-text, --bulma-scheme-main-bis,
 * --bulma-border), which both html.theme-* roots define. The only colours of
 * its own are the two the replay page already spends — --win for the winner
 * and the pin, --hit for a loss — declared here so the profile page, which
 * does not load replay.css, has them too.
 * ------------------------------------------------------------------------- */
.rp-keep, .rl, .rl-fav {
    --win: 43 88% 55%;
    --hit: 4 78% 58%;
    --mend: 145 55% 42%;
    --c-beast:   #f0921f;  --c-bug:     #ff5f42;  --c-bird:    #ff6fa5;
    --c-plant:   #63b900;  --c-aquatic: #00b7d4;  --c-reptile: #b06fe0;
    --c-mech:    #8598a0;  --c-dawn:    #b79bf0;  --c-dusk:    #2b7f92;
    --c-none:    #8b8b9c;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
html.theme-light .rp-keep, html.theme-light .rl, html.theme-light .rl-fav {
    --win: 43 88% 30%;
    --hit: 4 78% 49%;
    --mend: 145 55% 33%;
}

/* Bulma's reset gives every <section> display:block, which outranks the UA's [hidden]. Said once for the
   three roots so a hidden empty-state or a hidden link is actually hidden. */
.rp-keep [hidden], .rl [hidden], .rl-fav [hidden] { display: none !important; }

/* The control in a replay page's header ------------------------------------ */
.rp-keep {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px 10px;
    margin-top: 12px;
}

.rp-keep-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border: 1px solid var(--bulma-border);
    border-radius: 999px;
    background: var(--bulma-scheme-main-bis);
    color: var(--bulma-text);
    font: inherit;
    font-size: 0.78rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}
.rp-keep-btn:hover { border-color: var(--bulma-text-weak); }
.rp-keep-btn:focus-visible { outline: 2px solid var(--bulma-text); outline-offset: 2px; }
.rp-keep.is-busy .rp-keep-btn { opacity: 0.6; pointer-events: none; }

.rp-keep-ico { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }
/* Pressed = kept: the icon fills. Same gesture as a bookmark or a star anywhere else. */
.rp-keep-btn[aria-pressed="true"] .rp-keep-ico { fill: currentColor; }
.rp-keep-btn[aria-pressed="true"] { border-color: var(--bulma-text-weak); }
.rp-keep-btn--fav[aria-pressed="true"] { color: hsl(var(--win)); border-color: hsl(var(--win) / 0.6); }

.rp-keep-lib {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--bulma-text-weak);
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}
.rp-keep-lib:hover { color: var(--bulma-text); }
.rp-keep-lib b { font-weight: 600; color: var(--bulma-text); }
.rp-keep-lib.is-full b { color: hsl(var(--hit)); }

.rp-keep-say {
    flex-basis: 100%;
    font-size: 0.76rem;
    color: var(--bulma-text-weak);
    min-height: 1.2em;
}
.rp-keep-say:empty { display: none; }
.rp-keep-say.is-ok   { color: hsl(var(--mend)); }
.rp-keep-say.is-warn { color: var(--bulma-text); }
.rp-keep-say.is-bad  { color: hsl(var(--hit)); }

/* A landscape phone hides the whole header (replay.css); the control goes with it. */

/* The library page ----------------------------------------------------------- */
.rl {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

.rl-eyebrow, .rl-fav-h {
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--bulma-text-weak);
}
.rl-eyebrow { margin-bottom: 6px; }
.rl-title { font-size: clamp(1.3rem, 3vw, 1.8rem); font-weight: 700; line-height: 1.15; }

.rl-meter {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    font-size: 0.82rem;
    color: var(--bulma-text-weak);
}
.rl-meter b { font-family: var(--mono); color: var(--bulma-text); }
.rl-meter-bar {
    flex: 0 1 220px;
    height: 6px;
    border-radius: 3px;
    background: var(--bulma-border);
    overflow: hidden;
}
.rl-meter-fill { display: block; height: 100%; background: var(--bulma-text-weak); transition: width 240ms ease; }

.rl-note { margin-top: 10px; font-size: 0.82rem; color: var(--bulma-text-weak); max-width: 64ch; }
.rl-note b { color: var(--bulma-text); }
.rl-say { margin-top: 8px; font-size: 0.8rem; min-height: 1.2em; }
.rl-say.is-ok   { color: hsl(var(--mend)); }
.rl-say.is-warn { color: var(--bulma-text); }
.rl-say.is-bad  { color: hsl(var(--hit)); }

.rl-empty {
    margin-top: 28px;
    padding: 28px 20px;
    border: 1px dashed var(--bulma-border);
    border-radius: 12px;
    text-align: center;
    color: var(--bulma-text-weak);
    font-size: 0.86rem;
}
.rl-empty-h { font-size: 1rem; font-weight: 600; color: var(--bulma-text); margin-bottom: 4px; }

.rl-list { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }

/* The card ------------------------------------------------------------------- */
.rl-card {
    position: relative;
    display: flex;
    align-items: stretch;
    border: 1px solid var(--bulma-border);
    border-radius: 12px;
    background: var(--bulma-scheme-main-bis);
    overflow: hidden;
    transition: border-color 140ms ease, opacity 240ms ease, transform 240ms ease;
}
.rl-card:hover { border-color: var(--bulma-text-weak); }
.rl-card.is-busy { opacity: 0.6; }
.rl-card.is-leaving { opacity: 0; transform: translateX(12px); }
/* The result, said once, on the card's left edge: green won, red lost, nothing for a draw or a battle
   the chair was not in. */
.rl-card.is-won  { box-shadow: inset 4px 0 0 hsl(var(--mend)); }
.rl-card.is-lost { box-shadow: inset 4px 0 0 hsl(var(--hit)); }
.rl-card.is-favorite { border-color: hsl(var(--win) / 0.55); }

.rl-card-link {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    color: inherit;
    text-decoration: none;
    min-width: 0;
}
.rl-card-link:hover { color: inherit; }
.rl-bare { grid-column: 1 / -1; font-family: var(--mono); font-size: 0.78rem; color: var(--bulma-text-weak); }

.rl-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rl-side--right { align-items: flex-end; text-align: right; }

.rl-axies { display: flex; gap: 2px; }
.rl-side--right .rl-axies { flex-direction: row-reverse; }
.rl-axie {
    width: 56px;
    height: 42px;
    object-fit: contain;
    object-position: bottom;
    /* A plate the class hue tints, so a side reads as three colours before it reads as three pictures. */
    border-bottom: 2px solid var(--cls, var(--c-none));
    background: color-mix(in srgb, var(--cls, var(--c-none)) 14%, transparent);
    border-radius: 6px 6px 2px 2px;
}
/* The site draws its own axies facing right (renderClickableAxieImage flips the non-opponent side); the left
   side here is "this player" on the library page, so it faces the middle. */
.rl-side:not(.rl-side--right) .rl-axie { transform: scaleX(-1); }
.rl-axie[data-cls="beast"]   { --cls: var(--c-beast); }
.rl-axie[data-cls="bug"]     { --cls: var(--c-bug); }
.rl-axie[data-cls="bird"]    { --cls: var(--c-bird); }
.rl-axie[data-cls="plant"]   { --cls: var(--c-plant); }
.rl-axie[data-cls="aquatic"] { --cls: var(--c-aquatic); }
.rl-axie[data-cls="reptile"] { --cls: var(--c-reptile); }
.rl-axie[data-cls="mech"]    { --cls: var(--c-mech); }
.rl-axie[data-cls="dawn"]    { --cls: var(--c-dawn); }
.rl-axie[data-cls="dusk"]    { --cls: var(--c-dusk); }

.rl-who { display: flex; align-items: baseline; gap: 8px; min-width: 0; font-size: 0.86rem; }
.rl-side--right .rl-who { flex-direction: row-reverse; }
.rl-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The winner is marked with a rule under the name, as the replay page's title does — it survives both
   themes and does not compete with the class colours. */
.rl-side.is-winner .rl-name { box-shadow: inset 0 -0.14em 0 hsl(var(--win) / 0.85); }
.rl-side.is-mine .rl-name::after { content: " (you)"; font-weight: 400; color: var(--bulma-text-weak); }
.rl-tier { font-family: var(--mono); font-size: 0.66rem; color: var(--bulma-text-weak); white-space: nowrap; }

.rl-mid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
    padding: 0 8px;
    min-width: 96px;
}
.rl-verdict { font-weight: 700; font-size: 0.9rem; letter-spacing: 0.02em; }
.rl-card.is-won  .rl-verdict { color: hsl(var(--mend)); }
.rl-card.is-lost .rl-verdict { color: hsl(var(--hit)); }
.rl-facts {
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-family: var(--mono);
    font-size: 0.66rem;
    color: var(--bulma-text-weak);
    white-space: nowrap;
}
.rl-facts b { color: var(--bulma-text); font-weight: 600; }

.rl-actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px 10px 0;
}
.rl-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--bulma-border);
    border-radius: 999px;
    background: var(--bulma-scheme-main);
    color: var(--bulma-text-weak);
    font: inherit;
    font-size: 0.72rem;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 140ms ease, color 140ms ease;
}
.rl-btn:hover { color: var(--bulma-text); border-color: var(--bulma-text-weak); }
.rl-btn:focus-visible { outline: 2px solid var(--bulma-text); outline-offset: 2px; }
.rl-ico { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }
.rl-btn--fav[aria-pressed="true"] { color: hsl(var(--win)); border-color: hsl(var(--win) / 0.6); }
.rl-btn--fav[aria-pressed="true"] .rl-ico { fill: currentColor; }
.rl-btn--remove:hover { color: hsl(var(--hit)); border-color: hsl(var(--hit) / 0.6); }

/* The advice history (/replay/advice) ---------------------------------------
   The same card, stacked: the battle on top, the review's headline under it. The verdict is a pill in
   the outcome's colour, the opening sentence is the coach's own words, and the whole strip is quiet
   because the card above it already carries the picture. */
.rl-card--advice { flex-direction: column; }
.rl-adv {
    display: grid;
    gap: 6px;
    padding: 10px 14px 12px;
    border-top: 1px solid var(--bulma-border);
    font-size: 0.82rem;
}
.rl-adv-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; min-width: 0; }
.rl-adv-sum {
    color: var(--bulma-text);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.45;
}
.rl-adv-tag {
    font-family: var(--mono);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid currentColor;
    color: var(--bulma-text-weak);
    white-space: nowrap;
    flex: none;
}
.rl-adv-tag--verdict.is-won  { color: hsl(var(--mend)); }
.rl-adv-tag--verdict.is-lost { color: hsl(var(--hit)); }
.rl-adv-tag--failed { color: hsl(var(--hit)); }
.rl-adv-tag--admin { color: hsl(var(--win)); }
.rl-adv-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 14px;
    font-family: var(--mono);
    font-size: 0.68rem;
    color: var(--bulma-text-weak);
}
.rl-adv-open { margin-inline-start: auto; font-family: inherit; font-size: 0.78rem; }
.rl-adv.is-failed .rl-adv-sum { color: var(--bulma-text-weak); }
/* An axie's name inside a stored report's sentence, as the replay page's coach draws it (.rp-adv-name): a pill, so a
   player-chosen name such as "Fire And Ice" does not run into the Russian or Japanese words around it. No class dot
   here — this page has no fighters to colour from. */
.rl-adv-name {
    display: inline-block;
    margin: 0 1px;
    padding: 0 6px;
    border: 1px solid var(--bulma-border);
    border-radius: 999px;
    background: var(--bulma-scheme-main-bis);
    color: var(--bulma-text-strong, var(--bulma-text));
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.45;
    white-space: nowrap;
    unicode-bidi: isolate;
}
.rl-sub-h { margin-top: 30px; font-size: 1.05rem; font-weight: 700; }

/* The favorite on a profile ------------------------------------------------ */
.rl-fav { margin: 0 0 20px; }
.rl-fav-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.rl-fav-h { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.rl-fav-h .rl-ico { fill: hsl(var(--win)); stroke: none; }
.rl-fav-manage { font-size: 0.8rem; }
.rl-fav--empty {
    padding: 12px 16px;
    border: 1px dashed var(--bulma-border);
    border-radius: 12px;
    font-size: 0.84rem;
    color: var(--bulma-text-weak);
}
.rl-fav--empty b { color: var(--bulma-text); }

/* Narrow screens: the two sides stack over the middle instead of squeezing three columns. */
@media (max-width: 640px) {
    .rl-card { flex-direction: column; }
    .rl-card-link {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas: "left right" "mid mid";
        row-gap: 8px;
    }
    .rl-side { grid-area: left; }
    .rl-side--right { grid-area: right; }
    .rl-mid { grid-area: mid; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 4px 12px; }
    /* The verdict can be a whole name ("ALiPc - DC: alipc6 won"); on its own line it never breaks mid-name. */
    .rl-verdict { flex-basis: 100%; }
    .rl-facts { flex-direction: row; gap: 10px; }
    .rl-axie { width: 44px; height: 34px; }
    .rl-actions { flex-direction: row; justify-content: flex-end; padding: 0 12px 10px; }
}

.rl-adv-archive { margin-top: 0.75rem; }
.rl-adv-archive > summary { cursor: pointer; font-weight: 600; }
.rl-adv-archive .content { margin-top: 1rem; overflow-wrap: anywhere; }
