.cf-page,
.cfh {
    --cf-card: var(--c-card);
    --cf-card-2: #1b2131;
    --cf-grey: var(--c-card-2);
    --cf-border: rgba(181, 201, 255, 0.07);
    --cf-muted: rgba(181, 201, 255, 0.5);
    --cf-green: #5ec370;
    --cf-t: #3d9bff;
    --cf-h: #ff4d5e;
}
.cf-page { gap: 14px; }
.cf-page .cf-coin,
.cfv .cf-coin { width: 22px; height: 22px; }

.cf-head {
    margin-top: -14px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}
.cf-create {
    justify-self: start;
    height: 44px;
    padding: 0 30px;
    border: 0;
    border-radius: 13px;
    background: var(--cf-green);
    box-shadow: none;
    color: var(--c-on-green);
    font: inherit;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: filter 0.15s;
}
.cf-create:hover { filter: brightness(1.1); }
.cf-last {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 44px;
    padding: 0 14px;
    box-sizing: border-box;
    border-radius: 13px;
    background: var(--cf-card);
    cursor: pointer;
    transition: background 0.15s;
}
.cf-last:hover { background: #1b2131; }
.cf-last-side { display: flex; align-items: center; gap: 8px; }
.cf-last-side img { width: 24px; height: 24px; object-fit: contain; }
.cf-last-t img { filter: drop-shadow(0 0 6px rgba(0, 21, 255, 0.35)); }
.cf-last-h img { filter: drop-shadow(0 0 6px rgba(255, 0, 0, 0.3)); }
.cf-last-side b { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.cf-last-t b { color: var(--cf-t); }
.cf-last-h b { color: var(--cf-h); }
.cf-last-sep { width: 2px; height: 20px; border-radius: 1px; background: rgba(181, 201, 255, 0.15); }
.cf-mine {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 9px;
    height: 44px;
    padding: 0 6px;
    border: 0;
    background: none;
    box-shadow: none;
    color: var(--cf-muted);
    font: inherit;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: color 0.15s;
}
.cf-mine svg { width: 22px; height: 22px; margin: 0; }
.cf-mine:hover { color: var(--c-text); }
.cf-mine.active { color: var(--cf-green); }

.cf-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    border-radius: 18px;
    background: rgba(22, 27, 41, 0.45);
}
.cf-list:not(:has(> .cf-row:not(.hidden)))::before {
    content: "No matches yet";
    padding: 34px 0;
    color: var(--cf-muted);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
}
.cf-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) 48px auto 166px;
    grid-template-areas: "players items result value actions";
    align-items: center;
    gap: 22px;
    padding: 8px 12px;
    border: 1px solid var(--cf-border);
    border-radius: 16px;
    background: var(--cf-card);
}
.cf-row.hidden { display: none !important; }
/* a row's height animation (cfFold) and new rows don't make the browser lay out every other row again */
#cf-list > .cf-row { contain: layout style; }

.cf-players {
    grid-area: players;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 18px;
    border-radius: 14px;
    background: var(--cf-card-2);
}
.cf-vs { color: var(--cf-muted); font-size: 16px; font-weight: 800; letter-spacing: 0.02em; }
.cf-player { position: relative; width: 38px; height: 38px; flex-shrink: 0; }
.cf-ava {
    display: block;
    width: 38px;
    height: 38px;
    box-sizing: border-box;
    padding: 2px;
    border: 2px solid var(--side, var(--cf-t));
    border-radius: 50%;
    background: #10141f;
    object-fit: cover;
    cursor: pointer;
}
.cf-side-t { --side: var(--cf-t); }
.cf-side-h { --side: var(--cf-h); }
.cf-ava-wait {
    display: flex;
    align-items: center;
    justify-content: center;
    border-color: rgba(181, 201, 255, 0.12);
    color: rgba(181, 201, 255, 0.35);
    cursor: default;
}
.cf-ava-wait svg { width: 22px; height: 22px; margin: 0; }
.cf-badge {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 22px;
    height: 22px;
    object-fit: contain;
    z-index: 1;
}
.cf-p2 .cf-badge { left: auto; right: -8px; }
.cf-side-t .cf-badge { filter: drop-shadow(0 0 5px rgba(0, 21, 255, 0.4)); }
.cf-side-h .cf-badge { filter: drop-shadow(0 0 5px rgba(255, 0, 0, 0.35)); }
.cf-ended .cf-player:not(.cf-winner) { opacity: 0.45; }
.cf-ended.cf-just-played .cf-player:not(.cf-winner) { opacity: 1; animation: cf-loser-dim 0.3s ease 5s forwards; }
@keyframes cf-loser-dim { to { opacity: 0.45; } }

.cf-items {
    grid-area: items;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
}
.cf-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    flex-shrink: 0;
    box-sizing: border-box;
    overflow: hidden;
    border: 2px solid var(--c-line);
    border-radius: 10px;
    background:
        radial-gradient(60% 30% at 50% 100%, color-mix(in srgb, var(--r) 30%, transparent) 0, transparent 100%),
        #0c1120;
}
.cf-item::after {
    content: "";
    position: absolute;
    left: 26%;
    right: 26%;
    bottom: 0;
    height: 2px;
    border-radius: 2px 2px 0 0;
    background: var(--r);
    box-shadow: 0 0 8px var(--r);
}
.cf-item img { width: 40px; height: 40px; object-fit: contain; }
.cf-item[hidden], .cf-more[hidden] { display: none; }
.cf-more { flex-shrink: 0; padding: 0 6px; color: var(--cf-muted); font-size: 17px; font-weight: 800; }

.cf-value {
    grid-area: value;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 150px;
}
.cf-value b { display: inline-flex; align-items: center; gap: 8px; color: #c7d0e8; font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; white-space: nowrap; }
.cf-value b .cf-coin { width: 20px; height: 20px; }
.cf-value small { color: var(--cf-muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.cf-value small i { font-style: normal; margin: 0 5px; }

.cf-actions { grid-area: actions; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.cf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 14px;
    box-shadow: none;
    font: inherit;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: filter 0.15s, background 0.15s, color 0.15s;
}
.cf-join { width: 112px; background: var(--cf-green); color: var(--c-on-green); }
.cf-join:hover { filter: brightness(1.1); }
.cf-join { position: relative; overflow: hidden; }
.cf-btn-label { position: relative; z-index: 1; }
.cf-join .ba { --ba-r: 14px; --ba-size: 6rem; --ba-glow-size: 3rem; --ba-light: #e2ffe8; --ba-tint: rgba(94, 195, 112, 0.35); --ba-glow: #a8f0b6; }
@media (hover: hover) {
    .cf-row:hover .cf-join:not(:disabled) { --ba-on: 1; --ba-play: running; }
}
.cf-cancel { width: 112px; background: var(--cf-grey); color: rgba(181, 201, 255, 0.75); }
.cf-cancel:hover { background: var(--c-hover); color: #fff; }
.cf-eye { width: 44px; background: var(--cf-grey); color: var(--cf-muted); }
.cf-eye:hover { background: var(--c-hover); color: #fff; }
.cf-eye svg { width: 22px; height: 22px; margin: 0; }
.cf-result { grid-area: result; display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; }
.cf-result .coin { width: 46px; height: 46px; }
.cf-result:has(.coin.blue) { filter: drop-shadow(0 0 10px rgba(0, 21, 255, 0.45)); }
.cf-result:has(.coin.red) { filter: drop-shadow(0 0 10px rgba(255, 0, 0, 0.4)); }

@media (max-width: 1400px) {
    .cf-row { gap: 16px; }
    .cf-players { gap: 16px; padding: 12px 16px; }
}

@media (max-width: 760px) {
    .cf-page { gap: 10px; }
    .cf-head { margin-top: -8px; }
    .cf-create { height: 44px; padding: 0 20px; font-size: 14px; }
    .cf-last { height: 44px; padding: 0 12px; gap: 10px; }
    .cf-last-side img { width: 24px; height: 24px; }
    .cf-last-side b { font-size: 14px; }
    .cf-mine { height: 44px; }
    .cf-list { padding: 6px; border-radius: 16px; gap: 8px; }
    .cf-row {
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "players result value" "items items items" "actions actions actions";
        gap: 12px;
        padding: 12px;
    }
    .cf-players { gap: 14px; padding: 9px 14px; }
    .cf-player, .cf-ava { width: 36px; height: 36px; }
    .cf-value { justify-self: end; min-width: 0; }
    .cf-value b { font-size: 18px; gap: 6px; }
    .cf-value b .cf-coin { width: 17px; height: 17px; }
    .cf-items:empty { display: none; }
    .cf-item { width: 50px; height: 50px; }
    .cf-item img { width: 36px; height: 36px; }
    .cf-actions { gap: 8px; }
    .cf-row.cf-ended:not(.cf-hist) { grid-template-areas: "players result value" "items items actions"; }
    .cf-result { justify-self: end; width: 40px; height: 40px; }
    .cf-result .coin { width: 38px; height: 38px; }
    .cf-join, .cf-cancel { flex: 1; width: auto; height: 44px; }
    .cf-eye { height: 44px; width: 44px; }
}
@media (max-width: 420px) {
    .cf-mine span { display: none; }
    .cf-create { padding: 0 16px; }
}

.cfv {
    position: fixed;
    inset: 0;
    z-index: 990;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: var(--c-overlay);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.cfv.hidden { display: none; }
.cfv-box {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: min(624px, calc(100vw - 24px));
    max-height: min(560px, calc(100dvh - 24px));
    box-sizing: border-box;
    padding: 52px 20px 20px;
    border: 2px solid var(--c-line);
    border-radius: 15px;
    background: var(--c-card);
    color: #c7d0e8;
}
.cfv-box.cfv-has-result { margin-top: 44px; max-height: min(560px, calc(100dvh - 68px)); }
.cfv-result {
    position: absolute;
    top: -46px;
    left: 50%;
    width: 88px;
    height: 88px;
    margin-left: -44px;
    object-fit: contain;
    pointer-events: none;
}
.cfv-result .coin { width: 100%; height: 100%; }
.cfv-result-t { filter: drop-shadow(0 0 16px rgba(0, 21, 255, 0.5)); }
.cfv-result-h { filter: drop-shadow(0 0 16px rgba(255, 0, 0, 0.45)); }
.cfv-x {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
    color: rgba(181, 201, 255, 0.5);
    cursor: pointer;
}
.cfv-x svg { width: 24px; height: 24px; margin: 0; }
.cfv-x:hover { color: #fff; }

.cfv-cols { display: grid; grid-template-columns: minmax(0, 1fr) 2px minmax(0, 1fr); gap: 16px; min-height: 0; flex: 1; }
.cfv-sep { background: var(--c-line); border-radius: 1px; }
.cfv-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 0; transition: opacity 0.2s; }
.cfv-col.cfv-lost { opacity: 0.5; }

.cfv-pl { display: flex; align-items: center; gap: 16px; flex-shrink: 0; min-width: 0; padding: 0 4px; }
.cfv-right .cfv-pl { flex-direction: row-reverse; text-align: right; }
.cfv-av { position: relative; flex-shrink: 0; width: 46px; height: 46px; }
.cfv-ava {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    box-sizing: border-box;
    padding: 2px;
    border: 2px solid var(--cfv-side);
    border-radius: 50%;
    background: #10141f;
    object-fit: cover;
}
img.cfv-ava { cursor: pointer; }
.cfv-ava-wait { border-color: rgba(181, 201, 255, 0.12); }
.cfv-ava-wait svg { width: 24px; height: 24px; margin: 0; }
.cfv-t { --cfv-side: #3d9bff; }
.cfv-h { --cfv-side: #ff4d5e; }
.cfv-h .cfv-ava:not(.cfv-ava-wait) { box-shadow: 0 0 14px rgba(255, 77, 94, 0.25); }
.cfv-t .cfv-ava:not(.cfv-ava-wait) { box-shadow: 0 0 14px rgba(61, 155, 255, 0.25); }
.cfv-badge { position: absolute; top: -7px; left: -9px; z-index: 1; width: 24px; height: 24px; object-fit: contain; }
.cfv-right .cfv-badge { left: auto; right: -9px; }
.cfv-who { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cfv-who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #c7d0e8; font-size: 16px; font-weight: 800; }
.cfv-who small { color: rgba(181, 201, 255, 0.45); font-size: 11px; font-weight: 700; letter-spacing: 0.04em; }

.cfv-bet { display: flex; flex-shrink: 0; align-items: center; gap: 10px; height: 46px; padding: 0 14px; border-radius: 14px; background: var(--c-card-2); }
.cfv-bet .cf-coin { width: 20px; height: 20px; }
.cfv-bet b { color: #c7d0e8; font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }

.cfv-list { display: flex; flex-direction: column; gap: 8px; min-height: 0; max-height: 181px;  overflow-y: auto; scrollbar-width: none; overscroll-behavior: contain; }
.cfv-list::-webkit-scrollbar { display: none; }
.cfv-item {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    padding: 6px;
    border-radius: 14px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--r) 30%, transparent) 0, transparent 90%), var(--c-card-2);
}
.cfv-tile {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    flex-shrink: 0;
    box-sizing: border-box;
    border: 2px solid var(--c-line);
    border-radius: 10px;
    background: radial-gradient(60% 30% at 50% 100%, color-mix(in srgb, var(--r) 30%, transparent) 0, transparent 100%), #0c1120;
}
.cfv-tile::after { content: ""; position: absolute; left: 26%; right: 26%; bottom: 0; height: 2px; border-radius: 2px 2px 0 0; background: var(--r); box-shadow: 0 0 8px var(--r); }
.cfv-tile img { width: 40px; height: 40px; object-fit: contain; }
.cfv-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cfv-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #c7d0e8; font-size: 14px; font-weight: 800; }
.cfv-info small { display: flex; align-items: center; gap: 6px; color: #5ec370; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.cfv-info small .cf-coin { width: 18px; height: 18px; }
.cfv-empty { padding: 18px 0; color: rgba(181, 201, 255, 0.35); font-size: 12px; font-weight: 700; text-align: center; }

.cfv-foot {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    justify-content: space-between;
    gap: 10px;
    height: 26px;
    padding: 0 4px 0 12px;
    border-radius: 13px;
    background: rgba(94, 195, 112, 0.16);
    color: #5ec370;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
}
.cfv-round { display: flex; align-items: center; gap: 8px; }
.cfv-round svg { width: 14px; height: 14px; margin: 0; }
.cfv-chance { margin-left: auto; color: #8f9bbd; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cfv-ticket { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px 10px; border-radius: 10px; background: rgba(94, 195, 112, 0.18); color: #5ec370; text-decoration: none; }

@media (max-width: 480px) {
    .cfv { padding: 8px; }
    .cfv-box { width: calc(100vw - 16px); padding: 48px 14px 14px; gap: 12px; border-radius: 12px; }
    .cfv-x { top: 8px; right: 8px; }
    .cfv-cols { gap: 10px; }
    .cfv-pl { gap: 10px; padding: 0; }
    .cfv-av, .cfv-ava { width: 38px; height: 38px; }
    .cfv-badge { width: 20px; height: 20px; }
    .cfv-who b { font-size: 13px; }
    .cfv-bet { height: 40px; padding: 0 10px; gap: 8px; }
    .cfv-bet b { font-size: 13px; }
    .cfv-item { gap: 8px; padding: 5px; }
    .cfv-tile { width: 42px; height: 42px; }
    .cfv-list { max-height: 146px; }
    .cfv-tile img { width: 30px; height: 30px; }
    .cfv-info b { font-size: 11px; }
    .cfv-info small { font-size: 12px; }
    .cfv-result { width: 72px; height: 72px; top: -38px; margin-left: -36px; }
}

.cfh { z-index: 985; }
.cfh-box { height: min(704px, calc(100dvh - 24px)); max-height: none; padding: 20px; gap: 16px; }
.cfh-head { position: relative; display: flex; flex: 0 0 28px; align-items: center; justify-content: center; }
.cfh-title { color: var(--c-text); font-size: 1.05rem; font-weight: 800; letter-spacing: 0.01em; }
.cfh-head .cfv-x { top: 50%; right: 0; transform: translateY(-50%); }
.cfh-list { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: none; overscroll-behavior: contain; contain: layout paint; }
.cfh-list::-webkit-scrollbar { display: none; }
.cfh-empty { padding: 40px 0; color: rgba(181, 201, 255, 0.45); font-size: 14px; font-weight: 700; text-align: center; }
.cf-row.cf-hist {
    flex-shrink: 0;
    grid-template-columns: auto minmax(0, 1fr) 40px 104px 40px;
    grid-template-areas: "players items win value actions";
    gap: 12px;
    padding: 8px;
    border-radius: 14px;
    background: var(--c-card-2);
}
.cf-hist .cf-players { gap: 12px; padding: 8px 12px; background: var(--c-card); }
.cf-hist .cf-vs { font-size: 13px; }
.cf-hist .cf-player, .cf-hist .cf-ava { width: 32px; height: 32px; }
.cf-hist .cf-badge { width: 18px; height: 18px; top: -6px; left: -6px; }
.cf-hist .cf-p2 .cf-badge { left: auto; right: -6px; }
.cf-hist .cf-items { gap: 6px; }
.cf-hist .cf-item { width: 42px; height: 42px; }
.cf-hist .cf-item img { width: 30px; height: 30px; }
.cf-hist .cf-more { font-size: 14px; padding: 0 2px; }
.cf-histwin { grid-area: win; display: flex; align-items: center; justify-content: center; }
.cf-win { width: 32px; height: 32px; object-fit: contain; }
.cf-win-t { filter: drop-shadow(0 0 8px rgba(0, 21, 255, 0.55)); }
.cf-win-h { filter: drop-shadow(0 0 8px rgba(255, 0, 0, 0.5)); }
.cf-hist .cf-value { min-width: 0; align-items: flex-end; }
.cf-hist .cf-value b { max-width: 100%; gap: 6px; overflow: hidden; font-size: 15px; }
.cf-hist .cf-value b .cf-coin { width: 16px; height: 16px; }
.cf-hist .cf-eye { width: 40px; height: 40px; border-radius: 12px; background: var(--c-card); }

@media (max-width: 480px) {
    .cfh-box { height: calc(100dvh - 16px); padding: 14px; gap: 14px; }
    .cf-row.cf-hist {
        grid-template-columns: auto minmax(0, 1fr) 104px;
        grid-template-areas: "players win value" "items items actions";
        gap: 10px;
    }
    .cf-hist .cf-value { justify-self: end; }
    .cf-hist .cf-actions { justify-self: end; }
}

@media (max-width: 1080px) {
    body.coinflip-page-body .main { width: auto; padding-left: 9px; padding-right: 9px; }
    body.coinflip-page-body .cf-page { width: 100% !important; padding-left: 0; padding-right: 0; box-sizing: border-box; }
    .cf-page .cf-list { padding: 0; background: none; }
    .cf-head { position: fixed; left: 8px; right: 8px; width: auto; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 950; height: 60px; margin: 0; padding: 0 8px; border-radius: 18px; background: #151a28; box-shadow: 0 -6px 24px rgba(3, 8, 22, 0.6); }
    body.coinflip-page-body .main { padding-bottom: calc(164px + env(safe-area-inset-bottom)); }
}
.cfv-qty { flex-shrink: 0; margin-left: auto; margin-right: 6px; padding: 4px 9px; border-radius: 8px; background: #252c40; color: #c7d0e8; font-size: 13px; font-weight: 800; }