/* Coinflip (PvP) - lobby, CT/T coin art and the 3D flip modal */
:root {
  --cf-ct: #5b8def;
  --cf-ct-hi: #a9c8ff;
  --cf-t: #f5a524;
  --cf-t-hi: #ffd58a;
}

/* ------------------------------------------------------------------ coin art */
.cf-coin {
  --s: 26px;
  position: relative; display: inline-block; flex: none; vertical-align: middle;
  width: var(--s); height: var(--s); border-radius: 50%;
}
.cf-coin svg { display: block; width: 100%; height: 100%; }
.cf-coin::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background: linear-gradient(125deg, transparent 34%, rgba(255, 255, 255, .26) 47%, transparent 60%);
}
.cf-coin--ct {
  background: radial-gradient(circle at 32% 26%, #b7d3ff 0%, #5d91f0 30%, #2b5cc7 60%, #14306f 100%);
  box-shadow:
    inset 0 0 0 calc(var(--s) * .05) rgba(200, 222, 255, .55),
    inset 0 calc(var(--s) * -.08) calc(var(--s) * .14) rgba(0, 0, 0, .35),
    0 calc(var(--s) * .06) calc(var(--s) * .22) rgba(43, 92, 199, .45);
}
.cf-coin--t {
  background: radial-gradient(circle at 32% 26%, #ffe6b0 0%, #f8ae3c 30%, #da7511 60%, #7b3a05 100%);
  box-shadow:
    inset 0 0 0 calc(var(--s) * .05) rgba(255, 228, 180, .55),
    inset 0 calc(var(--s) * -.08) calc(var(--s) * .14) rgba(0, 0, 0, .35),
    0 calc(var(--s) * .06) calc(var(--s) * .22) rgba(218, 117, 17, .45);
}
.cf-coin--badge { --s: 17px; }
.cf-coin--sm { --s: 20px; }
.cf-coin--md { --s: 36px; }
.cf-coin--lg { --s: 56px; }
.cf-coin--xl { --s: 74px; }

/* ------------------------------------------------------------------ create panel */
/* The bet <input> has an intrinsic width that would stretch the one-column phone grid past 390px */
.cf-page .game-layout > * { min-width: 0; }
.cf-page .bet-input .input { width: 0; }
.cf-create { display: flex; flex-direction: column; gap: 14px; }
.cf-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cf-side {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 14px 8px 12px;
  border-radius: 12px; border: 1px solid var(--line2); background: var(--bg2); color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .2s, transform .1s;
}
.cf-side:active { transform: translateY(1px); }
.cf-side b { font-family: var(--display); font-weight: 400; font-size: 18px; color: var(--text); letter-spacing: .05em; line-height: 1; margin-top: 4px; }
.cf-side small { font-size: 11.5px; line-height: 1.2; text-align: center; }
.cf-side .cf-coin { transition: transform .6s cubic-bezier(.2, .9, .3, 1.25), filter .2s; filter: grayscale(.6) brightness(.75); }
.cf-side:hover .cf-coin { filter: grayscale(.2) brightness(.95); }
.cf-side.active .cf-coin { filter: none; transform: rotateY(360deg) scale(1.06); }
.cf-side[data-side="ct"].active {
  border-color: var(--cf-ct); background: rgba(91, 141, 239, .1);
  box-shadow: inset 0 0 0 1px var(--cf-ct), 0 10px 28px -12px rgba(91, 141, 239, .8);
}
.cf-side[data-side="t"].active {
  border-color: var(--cf-t); background: rgba(245, 165, 36, .09);
  box-shadow: inset 0 0 0 1px var(--cf-t), 0 10px 28px -12px rgba(245, 165, 36, .75);
}
.cf-side[data-side="ct"].active small { color: var(--cf-ct-hi); }
.cf-side[data-side="t"].active small { color: var(--cf-t-hi); }
.cf-note { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }

/* ------------------------------------------------------------------ lists */
.cf-stage-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cf-total { font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px; }
.cf-list { display: flex; flex-direction: column; gap: 8px; container-type: inline-size; }

.cf-row, .cf-hist {
  --side: var(--cf-ct);
  position: relative; display: grid; align-items: center; gap: 12px;
  grid-template-columns: minmax(0, 1fr) 30px minmax(0, 1fr) 118px minmax(120px, auto);
  padding: 10px 12px 10px 16px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line);
  cursor: pointer; transition: border-color .15s, background .15s, transform .15s;
}
.cf-hist { grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr) 118px auto; }
.cf-row:hover, .cf-hist:hover { border-color: var(--line2); background: var(--panel3); }
.cf-row::before {
  content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--side); box-shadow: 0 0 12px var(--side);
}
.cf-row--t { --side: var(--cf-t); }
.cf-row.is-mine {
  border-color: rgba(228, 174, 57, .35);
  background: linear-gradient(90deg, rgba(228, 174, 57, .07), transparent 55%), var(--panel2);
}
.cf-row.is-mine:hover { background: linear-gradient(90deg, rgba(228, 174, 57, .1), transparent 55%), var(--panel3); }
.cf-hist.is-won { border-color: rgba(52, 211, 153, .35); }
.cf-hist.is-lost { border-color: rgba(255, 92, 92, .22); }
.cf-enter { animation: cfEnter .5s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes cfEnter { from { opacity: 0; transform: translateY(-10px) scale(.97); } }

.cf-player { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cf-player--right { flex-direction: row-reverse; text-align: right; }
.cf-av { position: relative; flex: none; display: block; }
.cf-av .avatar { width: 36px; height: 36px; font-size: 15px; }
.cf-av .cf-coin { position: absolute; right: -5px; bottom: -4px; outline: 2px solid var(--panel2); }
.cf-player--right .cf-av .cf-coin { right: auto; left: -5px; }
.cf-av-empty {
  width: 36px; height: 36px; border-radius: 50%; border: 2px dashed var(--line2); display: grid; place-items: center;
  color: var(--dim); font-family: var(--display); font-size: 15px; animation: cfPulse 1.8s ease-in-out infinite;
}
@keyframes cfPulse { 50% { border-color: var(--dim); color: var(--muted); } }
.cf-pname { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.cf-pname b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cf-pname small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cf-player--empty .cf-pname b { color: var(--muted); font-weight: 500; }
.cf-crown { width: 13px; height: 13px; color: var(--gold); vertical-align: -1px; margin-right: 4px; }
.cf-player.is-winner .cf-pname b { color: var(--gold); }
.cf-player.is-loser { opacity: .5; }
.cf-vs { font-family: var(--display); color: var(--dim); font-size: 12px; text-align: center; letter-spacing: .04em; }
.cf-hist-coin { display: grid; place-items: center; }
.cf-hist-coin .cf-coin { animation: cfCoinIn .5s cubic-bezier(.2, .9, .3, 1.3); }
@keyframes cfCoinIn { from { transform: rotateY(180deg) scale(.7); opacity: 0; } }
.cf-amount { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; }
.cf-amount > .price { font-size: 15.5px; }
.cf-amount small { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.cf-amount small .price { color: var(--green); font-weight: 600; }
.cf-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.cf-actions .btn { gap: 6px; }
.cf-actions .btn svg { flex: none; }
.cf-join { min-width: 88px; }
.cf-join .cf-coin { --s: 18px; }

.cf-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 46px 16px; }
.cf-empty b { font-size: 17px; }
.cf-empty-coins { display: flex; margin-bottom: 12px; }
.cf-empty-coins .cf-coin:first-child { transform: rotate(-12deg); animation: cfFloat 3.2s ease-in-out infinite; }
.cf-empty-coins .cf-coin:last-child { margin-left: -18px; transform: rotate(10deg); animation: cfFloat 3.2s ease-in-out -1.6s infinite; }
@keyframes cfFloat { 50% { translate: 0 -8px; } }
.cf-recent .empty { padding: 30px 16px; }

/* Narrow list (phones, or the stage next to the controls on small laptops): two lines per flip */
@container (max-width: 600px) {
  .cf-row, .cf-hist { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); row-gap: 10px; padding: 12px 12px 12px 14px; }
  .cf-amount { grid-column: 1 / 2; flex-direction: row; align-items: center; justify-content: flex-start; gap: 10px; }
  .cf-actions { grid-column: 2 / 4; }
  .cf-av .avatar, .cf-av-empty { width: 32px; height: 32px; font-size: 14px; }
  .cf-player { gap: 8px; }
}
@container (max-width: 360px) {
  .cf-amount small { display: none; }
}

/* ------------------------------------------------------------------ flip modal */
.modal.cf-modal { max-width: 600px; overflow-x: hidden; }
.cf-m-head { display: flex; align-items: center; gap: 12px; padding-right: 44px; margin-bottom: 10px; }
.cf-m-head h2 { margin: 0; }
.cf-m-pot { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }

.cf-duel {
  --cf-size: 150px; --cf-th: 12px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 10px;
}
.cf-seat {
  position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 3px; min-width: 0;
  padding: 16px 8px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel2);
  transition: border-color .35s, box-shadow .35s, opacity .35s, filter .35s;
}
.cf-seat-av { position: relative; margin-bottom: 6px; }
.cf-seat-av .avatar.lg { width: 60px; height: 60px; font-size: 24px; }
.cf-seat-empty {
  width: 60px; height: 60px; border-radius: 50%; border: 2px dashed var(--line2); display: grid; place-items: center;
  font-family: var(--display); color: var(--dim); font-size: 24px; animation: cfPulse 1.8s ease-in-out infinite;
}
.cf-seat-av .cf-coin { --s: 26px; position: absolute; right: -8px; bottom: -4px; outline: 2px solid var(--panel2); }
.cf-seat-name { max-width: 100%; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cf-seat-side { font-size: 12px; color: var(--muted); }
.cf-you { color: var(--accent-hi); font-weight: 700; }
.cf-seat-win { min-height: 22px; font-weight: 800; color: var(--green); display: inline-flex; align-items: center; gap: 2px; }
.cf-seat-win:not(:empty) { animation: cfWinPop .55s cubic-bezier(.2, .9, .3, 1.5); }
.cf-seat-win .price { color: var(--green); }
@keyframes cfWinPop { from { transform: translateY(8px) scale(.6); opacity: 0; } }
.cf-seat.cf-pop .cf-seat-av { animation: cfSeatIn .5s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes cfSeatIn { from { transform: scale(.4); opacity: 0; } }
.cf-seat.is-winner {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold), 0 0 38px -8px rgba(228, 174, 57, .6);
  background: linear-gradient(180deg, rgba(228, 174, 57, .1), transparent 70%), var(--panel2);
}
.cf-seat.is-winner::before {
  content: 'WINNER'; position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  padding: 2px 9px; border-radius: 6px; background: linear-gradient(180deg, #f3c55a, var(--gold)); color: #231703;
  font-family: var(--display); font-size: 11px; letter-spacing: .1em; box-shadow: 0 4px 14px rgba(228, 174, 57, .45);
  animation: cfWinPop .5s cubic-bezier(.2, .9, .3, 1.5);
}
.cf-seat.is-loser { opacity: .45; filter: grayscale(.75); }

/* The coin: two faces + stacked edge discs, spun with requestAnimationFrame */
.cf-arena {
  position: relative; display: flex; align-items: flex-end; justify-content: center;
  width: calc(var(--cf-size) + 20px); height: calc(var(--cf-size) * 1.78); padding-bottom: 16px;
}
.cf-coin3d { position: relative; width: var(--cf-size); height: var(--cf-size); perspective: 900px; }
.cf-toss, .cf-spin { position: absolute; inset: 0; transform-style: preserve-3d; will-change: transform; }
.cf-face { position: absolute; inset: 0; width: 100%; height: 100%; --s: var(--cf-size); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.cf-face--front { transform: translateZ(calc(var(--cf-th) / 2)); }
.cf-face--back { transform: rotateY(180deg) translateZ(calc(var(--cf-th) / 2)); }
/* Edge discs stay strictly between the faces (same depth as a face = z-fighting) */
.cf-edge {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, #2c2f37 0 64%, #aab1bf 88%, #626876 100%);
  transform: translateZ(calc(((var(--i) + .5) / 12 - .5) * var(--cf-th) * .92));
}
.cf-shadow {
  position: absolute; left: 14%; right: 14%; bottom: -16px; height: 14px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .65), transparent); will-change: transform, opacity;
}
.cf-glow {
  --glow: rgba(91, 141, 239, .55);
  position: absolute; inset: -45%; border-radius: 50%; opacity: 0; pointer-events: none;
  background: radial-gradient(closest-side, var(--glow), transparent 72%); transition: opacity .5s;
}
.cf-landed--t .cf-glow { --glow: rgba(245, 165, 36, .5); }
.cf-landed .cf-glow { opacity: 1; animation: cfGlow 1.8s ease-in-out infinite alternate; }
@keyframes cfGlow { to { transform: scale(1.12); opacity: .7; } }
.cf-coin3d::after {
  content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 3px solid var(--cf-ct-hi);
  opacity: 0; pointer-events: none;
}
.cf-landed--t::after { border-color: var(--cf-t-hi); }
.cf-landed:not(.cf-static)::after { animation: cfBurst .9s cubic-bezier(.2, .7, .3, 1) forwards; }
@keyframes cfBurst { 0% { opacity: .9; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.9); } }
.cf-landed:not(.cf-static) .cf-toss { animation: cfSquash .35s ease-out; }
@keyframes cfSquash { 40% { transform: scale(1.06, .94); } }

/* Waiting: the coin hovers and sways */
.cf-idle .cf-toss { animation: cfBob 2.6s ease-in-out infinite; }
.cf-idle .cf-spin { animation: cfSway 3.4s ease-in-out infinite; }
.cf-idle .cf-shadow { animation: cfShadow 2.6s ease-in-out infinite; }
@keyframes cfBob { 50% { transform: translateY(-12px); } }
@keyframes cfSway { 0%, 100% { transform: rotateX(8deg) rotateY(-28deg); } 50% { transform: rotateX(-4deg) rotateY(28deg); } }
@keyframes cfShadow { 50% { transform: scale(.82); opacity: .7; } }

.cf-verdict { min-height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; margin: 14px 0 6px; }
.cf-verdict > * { animation: cfVerdictIn .4s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes cfVerdictIn { from { opacity: 0; transform: translateY(6px); } }
.cf-verdict-wait { color: var(--muted); font-weight: 600; }
.cf-verdict-main { display: flex; align-items: center; gap: 9px; font-family: var(--display); font-size: 23px; letter-spacing: .02em; }
.cf-verdict-main--ct { color: var(--cf-ct-hi); }
.cf-verdict-main--t { color: var(--cf-t-hi); }
.cf-verdict-sub { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.cf-verdict-sub.is-win { color: var(--green); font-weight: 800; font-size: 17px; }
.cf-verdict-sub.is-win .price { color: var(--green); }
.cf-verdict-sub.is-lose { color: var(--red); font-weight: 600; }
.cf-dots i { font-style: normal; animation: cfDot 1.2s infinite; }
.cf-dots i:nth-child(2) { animation-delay: .2s; }
.cf-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes cfDot { 0%, 60%, 100% { opacity: .2; } 30% { opacity: 1; } }

.cf-m-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 4px 0 2px; }
.cf-m-actions:empty { display: none; }
.cf-m-join { gap: 7px; }

/* Provably fair details */
.cf-fair { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.cf-fair summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; color: var(--muted); font-weight: 600; font-size: 14px;
}
.cf-fair summary::-webkit-details-marker { display: none; }
.cf-fair summary::after { content: '▾'; margin-left: auto; transition: transform .2s; }
.cf-fair[open] summary::after { transform: rotate(180deg); }
.cf-fair summary:hover { color: var(--text); }
.cf-fair-grid { display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 8px 12px; margin: 12px 0 8px; font-size: 13px; align-items: center; }
.cf-fair-grid dt { color: var(--muted); }
.cf-fair-grid dd { margin: 0; min-width: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cf-mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace; font-size: 12px; word-break: break-all;
  user-select: all; background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 7px;
}
.cf-fair-how { font-size: 12.5px; color: var(--muted); margin: 6px 0 10px; line-height: 1.5; }
.cf-fair-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cf-verify-out { display: inline-flex; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.cf-verify-out .ok { color: var(--green); font-weight: 700; }
.cf-verify-out .bad { color: var(--red); font-weight: 700; }

@media (max-width: 640px) {
  .modal.cf-modal { padding: 22px 14px 18px; }
  .cf-duel { --cf-size: 100px; --cf-th: 9px; gap: 6px; }
  .cf-seat { padding: 14px 4px 10px; }
  .cf-seat-av .avatar.lg, .cf-seat-empty { width: 46px; height: 46px; font-size: 19px; }
  .cf-seat-av .cf-coin { --s: 20px; right: -6px; }
  .cf-seat-name { font-size: 13.5px; }
  .cf-arena { width: calc(var(--cf-size) + 8px); }
  .cf-verdict-main { font-size: 19px; }
  .cf-fair-grid { grid-template-columns: 1fr; gap: 4px; }
  .cf-fair-grid dt { margin-top: 6px; }
  .cf-m-join { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .cf-idle .cf-toss, .cf-idle .cf-spin, .cf-idle .cf-shadow, .cf-landed .cf-glow,
  .cf-empty-coins .cf-coin, .cf-av-empty, .cf-seat-empty { animation: none; }
}
