/**
 * Match Chat + Open Ranked — PESBUL arena styling.
 *
 * Built to sit inside the ELO hub's card language rather than beside it: the same
 * dark glass panels, the same cyan accent, the same rounded geometry. A chat that
 * looked like a WordPress comment form would announce itself as bolted on.
 *
 * Mobile is not an afterthought here — most players coordinating a match are on a
 * phone. Bubbles cap at 82% of the column, the composer is a full-width row, and
 * nothing has a fixed pixel width, so the panel never pushes the page sideways.
 */

/* ══ OPEN RANKED CARD ═══════════════════════════════════════════════════════ */

.pb-openranked {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 22px;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.pb-openranked::after {
    /* A soft cyan bloom out of the top-right, so the card reads as the "new
       thing" on the page without needing a badge to say so. */
    content: "";
    position: absolute;
    inset: -40% -30% auto auto;
    width: 340px;
    height: 340px;
    background: radial-gradient(circle, rgba(34, 211, 238, .18), transparent 70%);
    pointer-events: none;
}

/* EVERY inline SVG in this card gets a size, without exception.
   The theme's $icon() helper emits <svg viewBox="0 0 24 24"> with no width or
   height — sized by whichever rule owns the context. Miss one and the icon does
   not render small and wrong, it renders as a 700px circle that eats the card.
   This is the backstop; the specific rules below refine it. */
.pb-openranked svg { width: 14px; height: 14px; flex: 0 0 auto; }

.pb-openranked__copy { position: relative; z-index: 1; }

.pb-openranked__kicker {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0 0 10px;
    padding: 4px 11px;
    border: 1px solid rgba(34, 211, 238, .35);
    border-radius: 999px;
    background: rgba(34, 211, 238, .1);
    color: #67e8f9;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.pb-openranked__kicker svg { width: 13px; height: 13px; }

.pb-openranked h2 { margin: 0 0 8px; font-size: 1.35rem; letter-spacing: -.01em; }
.pb-openranked p { margin: 0 0 12px; color: rgba(226, 232, 240, .78); line-height: 1.6; font-size: .93rem; }

.pb-openranked__points { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }

.pb-openranked__points li {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    color: rgba(226, 232, 240, .8);
    font-size: .88rem;
    line-height: 1.5;
}

.pb-openranked__points svg { flex: 0 0 16px; width: 16px; height: 16px; margin-top: 2px; color: #22d3ee; }

/* The one bullet in this list that is a warning rather than a reassurance. */
.pb-openranked__points li.is-warning { color: rgba(252, 211, 153, .92); }
.pb-openranked__points li.is-warning svg { color: #fbbf24; }

/* The code itself — the one thing a player has to copy accurately. */
.pb-openranked__code {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 20px;
    border: 1px solid rgba(148, 163, 184, .2);
    border-radius: 16px;
    background: linear-gradient(160deg, rgba(15, 23, 42, .85), rgba(8, 12, 24, .9));
}

.pb-openranked__label {
    margin: 0;
    color: rgba(148, 163, 184, .9);
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.pb-openranked__value {
    display: block;
    max-width: 100%;
    overflow-wrap: anywhere;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: clamp(1.5rem, 4.5vw, 2.1rem);
    font-weight: 700;
    letter-spacing: .06em;
    color: #e2f6ff;
    text-shadow: 0 0 22px rgba(34, 211, 238, .35);
}

.pb-openranked__copybtn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border: 1px solid rgba(34, 211, 238, .4);
    border-radius: 999px;
    background: rgba(34, 211, 238, .12);
    color: #a5f3fc;
    font: inherit;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .16s ease, border-color .16s ease;
}

.pb-openranked__copybtn:hover { background: rgba(34, 211, 238, .2); border-color: rgba(34, 211, 238, .65); }
.pb-openranked__copybtn.is-done { background: rgba(53, 229, 111, .16); border-color: rgba(53, 229, 111, .45); color: #86efac; }
.pb-openranked__copybtn svg { width: 15px; height: 15px; }

.pb-openranked__note { margin: 0; color: rgba(148, 163, 184, .75); font-size: .78rem; text-align: center; }

/* ══ HOW TO PLAY ════════════════════════════════════════════════════════════ */

/* Lives inside the "How the rating works" card, below its explainer list, so it
   is separated by a rule rather than by a second panel. */
.pb-howto {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid rgba(148, 163, 184, .14);
}

.pb-howto__title {
    margin: 0 0 14px;
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: rgba(148, 163, 184, .95);
}

.pb-howto__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
    margin: 4px 0 18px;
}

.pb-howto__route {
    padding: 18px;
    border: 1px solid rgba(148, 163, 184, .16);
    border-radius: 14px;
    background: rgba(8, 12, 24, .45);
}

.pb-howto__route h3 {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
    margin: 0 0 14px;
    font-size: .98rem;
    font-weight: 600;
    color: #e2e8f0;
}

.pb-howto__tag {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .64rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.pb-howto__tag--open { background: rgba(34, 211, 238, .15); color: #67e8f9; border: 1px solid rgba(34, 211, 238, .32); }
.pb-howto__tag--challenge { background: rgba(168, 85, 247, .15); color: #d8b4fe; border: 1px solid rgba(168, 85, 247, .32); }

/* Numbered steps, with the numeral as a token rather than a list marker so it
   lines up whatever the language and however long the step runs. */
.pb-howto__steps { counter-reset: pbstep; margin: 0; padding: 0; list-style: none; display: grid; gap: 11px; }

.pb-howto__steps li { display: flex; align-items: flex-start; gap: 11px; }

.pb-howto__steps li::before {
    counter-increment: pbstep;
    content: counter(pbstep);
    flex: 0 0 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-top: 1px;
    border: 1px solid rgba(34, 211, 238, .3);
    border-radius: 50%;
    background: rgba(34, 211, 238, .1);
    color: #a5f3fc;
    font-size: .72rem;
    font-weight: 700;
}

.pb-howto__steps li span { color: rgba(226, 232, 240, .82); font-size: .89rem; line-height: 1.55; }

.pb-howto__note {
    margin: 14px 0 0;
    padding-top: 12px;
    border-top: 1px solid rgba(148, 163, 184, .12);
    color: rgba(148, 163, 184, .82);
    font-size: .81rem;
    line-height: 1.55;
}

.pb-howto__rules {
    margin: 0;
    padding: 16px 18px;
    border: 1px solid rgba(148, 163, 184, .14);
    border-radius: 14px;
    background: rgba(15, 23, 42, .4);
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px 22px;
}

.pb-howto__rules li { color: rgba(203, 213, 225, .78); font-size: .84rem; line-height: 1.5; }
.pb-howto__rules b { color: #e2e8f0; font-weight: 600; }

/* Fair play. Amber rather than red: this is a rule to read, not an error that
   has happened — but it is the only thing on the page with a ban behind it, so
   it does not get to look like the paragraphs around it. */
.pb-howto__warn {
    display: flex;
    align-items: flex-start;
    gap: 13px;
    margin-top: 14px;
    padding: 16px 18px;
    border: 1px solid rgba(251, 191, 36, .3);
    border-left: 3px solid #fbbf24;
    border-radius: 12px;
    background: rgba(251, 191, 36, .07);
}

.pb-howto__warn-ic {
    flex: 0 0 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 6px;
    border-radius: 9px;
    background: rgba(251, 191, 36, .14);
    color: #fbbf24;
}

.pb-howto__warn-ic svg { width: 100%; height: 100%; }

.pb-howto__warn strong {
    display: block;
    margin-bottom: 5px;
    color: #fcd34d;
    font-size: .86rem;
    font-weight: 700;
}

.pb-howto__warn p { margin: 0 0 7px; color: rgba(226, 232, 240, .8); font-size: .84rem; line-height: 1.55; }
.pb-howto__warn p:last-child { margin-bottom: 0; }
.pb-howto__warn-foot { color: rgba(148, 163, 184, .8) !important; font-size: .79rem !important; }

/* ══ SOURCE BADGE (match history) ═══════════════════════════════════════════ */

.pb-elo3-source {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    vertical-align: middle;
}

.pb-elo3-source--open { background: rgba(34, 211, 238, .14); color: #67e8f9; border: 1px solid rgba(34, 211, 238, .3); }
.pb-elo3-source--challenge { background: rgba(148, 163, 184, .12); color: rgba(203, 213, 225, .9); border: 1px solid rgba(148, 163, 184, .25); }

/* ══ CHAT TOGGLE ON A MATCH CARD ════════════════════════════════════════════ */

.pb-chat-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    border: 1px solid rgba(34, 211, 238, .35);
    border-radius: 999px;
    background: rgba(34, 211, 238, .1);
    color: #a5f3fc;
    font: inherit;
    font-size: .84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .16s ease;
}

.pb-chat-toggle:hover { background: rgba(34, 211, 238, .18); }
.pb-chat-toggle svg { width: 16px; height: 16px; }

.pb-chat-toggle__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: .66rem;
    font-weight: 700;
}

/* ══ THE THREAD ═════════════════════════════════════════════════════════════ */

.pb-chat {
    position: relative;
    display: flex;
    flex-direction: column;
    margin-top: 14px;
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 14px;
    background: rgba(8, 12, 24, .55);
    overflow: hidden;
}

.pb-chat__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(148, 163, 184, .14);
    background: rgba(15, 23, 42, .6);
}

.pb-chat__who { display: flex; align-items: center; gap: 11px; min-width: 0; }
.pb-chat__meta { min-width: 0; }
.pb-chat__name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pb-chat__name a, .pb-chat__name b { color: #e2e8f0; font-weight: 600; font-size: .95rem; text-decoration: none; }
.pb-chat__name a:hover { color: #67e8f9; }

.pb-chat__rating {
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(148, 163, 184, .14);
    color: rgba(203, 213, 225, .9);
    font-size: .7rem;
    font-weight: 600;
}

.pb-chat__presence { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: rgba(148, 163, 184, .85); font-size: .74rem; }
.pb-chat__dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(148, 163, 184, .6); flex: 0 0 7px; }
.pb-chat__presence.is-online { color: #86efac; }
.pb-chat__presence.is-online .pb-chat__dot { background: #35e56f; box-shadow: 0 0 0 3px rgba(53, 229, 111, .18); }

.pb-chat__closed {
    padding: 3px 10px;
    border: 1px solid rgba(148, 163, 184, .25);
    border-radius: 999px;
    background: rgba(148, 163, 184, .1);
    color: rgba(203, 213, 225, .85);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* The scrolling log. A fixed height band keeps the fixture card a card — the
   thread scrolls inside it rather than pushing the page down as it grows. */
.pb-chat__log {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: clamp(220px, 38vh, 340px);
    padding: 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.pb-chat__log::-webkit-scrollbar { width: 8px; }
.pb-chat__log::-webkit-scrollbar-thumb { border-radius: 8px; background: rgba(148, 163, 184, .25); }

.pb-chat__state { margin: auto 0; color: rgba(148, 163, 184, .7); font-size: .86rem; text-align: center; }

.pb-chat__row { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.pb-chat__row.is-mine { flex-direction: row-reverse; }

.pb-chat__bubble {
    max-width: 82%;
    padding: 9px 13px;
    border: 1px solid rgba(148, 163, 184, .16);
    border-radius: 14px 14px 14px 4px;
    background: rgba(30, 41, 59, .75);
    color: #e2e8f0;
}

.pb-chat__row.is-mine .pb-chat__bubble {
    border-color: rgba(34, 211, 238, .28);
    border-radius: 14px 14px 4px 14px;
    background: rgba(34, 211, 238, .13);
}

.pb-chat__bubble p { margin: 0; font-size: .9rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.pb-chat__bubble.is-removed p { color: rgba(148, 163, 184, .7); font-style: italic; }
.pb-chat__author { display: block; margin-bottom: 2px; color: #67e8f9; font-size: .72rem; font-weight: 700; }
.pb-chat__bubble time { display: block; margin-top: 3px; color: rgba(148, 163, 184, .6); font-size: .66rem; text-align: right; }

/* A system line is the site talking, not a player — centred, quieter, and
   visually unable to be mistaken for something somebody typed. */
.pb-chat__system {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    align-self: center;
    max-width: 92%;
    padding: 5px 12px;
    border: 1px dashed rgba(148, 163, 184, .22);
    border-radius: 999px;
    background: rgba(15, 23, 42, .55);
    color: rgba(203, 213, 225, .8);
    font-size: .76rem;
    text-align: center;
}

.pb-chat__system time { color: rgba(148, 163, 184, .55); font-size: .66rem; white-space: nowrap; }

.pb-chat__jump {
    position: absolute;
    left: 50%;
    bottom: 74px;
    transform: translateX(-50%);
    padding: 6px 14px;
    border: 1px solid rgba(34, 211, 238, .4);
    border-radius: 999px;
    background: rgba(8, 12, 24, .95);
    color: #a5f3fc;
    font: inherit;
    font-size: .76rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 2;
}

.pb-chat__compose {
    display: flex;
    align-items: flex-end;
    gap: 9px;
    padding: 11px 12px;
    border-top: 1px solid rgba(148, 163, 184, .14);
    background: rgba(15, 23, 42, .6);
}

.pb-chat__input {
    flex: 1 1 auto;
    min-width: 0;
    max-height: 120px;
    padding: 9px 12px;
    border: 1px solid rgba(148, 163, 184, .22);
    border-radius: 12px;
    background: rgba(8, 12, 24, .7);
    color: #e2e8f0;
    font: inherit;
    font-size: .9rem;
    line-height: 1.45;
    resize: none;
}

.pb-chat__input:focus { outline: none; border-color: rgba(34, 211, 238, .55); box-shadow: 0 0 0 3px rgba(34, 211, 238, .12); }
.pb-chat__input::placeholder { color: rgba(148, 163, 184, .55); }

.pb-chat__send {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(140deg, #22d3ee, #0ea5e9);
    color: #04121a;
    cursor: pointer;
    transition: filter .16s ease;
}

.pb-chat__send:hover { filter: brightness(1.12); }
.pb-chat__send:disabled { opacity: .5; cursor: default; }
.pb-chat__send svg { width: 17px; height: 17px; }

.pb-chat__notice { margin: 0; padding: 8px 14px; color: rgba(148, 163, 184, .85); font-size: .78rem; }
.pb-chat__notice.is-error { color: #fca5a5; }

/* Faces. The initial sits underneath, so a missing avatar is still a person. */
.pb-chat-face {
    position: relative;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(34, 211, 238, .16);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pb-chat-face--lg { flex-basis: 38px; width: 38px; height: 38px; }
.pb-chat-face__initial { color: #a5f3fc; font-size: .8rem; font-weight: 700; }
.pb-chat-face img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ══ RESPONSIVE ═════════════════════════════════════════════════════════════ */

@media (max-width: 860px) {
    .pb-openranked { grid-template-columns: minmax(0, 1fr); gap: 16px; }
    .pb-openranked__code { padding: 18px 14px; }
}

@media (max-width: 560px) {
    .pb-chat__log { height: clamp(200px, 46vh, 320px); padding: 12px 10px; }
    .pb-chat__bubble { max-width: 88%; }
    .pb-chat__head { flex-wrap: wrap; }
    .pb-chat__compose { padding: 9px 10px; }
    .pb-chat__jump { bottom: 68px; }
}
