/* Chat battle (replay screen at /analysis/<id>): black, white side vs black side, eval bar on the left. */
body.replay-open { overflow: hidden; }
body.replay-open .top, body.replay-open .page { display: none; }

.replay {
  --white-bubble: #ffffff;
  --black-bubble: #1c1c1e;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  color: #fff;
  display: flex;
  flex-direction: row; /* eval bar | everything else */
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  animation: fadeIn 0.35s var(--ease) both;
}

/* thin rating-progress line instead of a top bar */
.rp-progress { position: absolute; top: 0; left: 0; right: 0; height: 2px; z-index: 5; }
.rp-progress > div { height: 100%; width: 0; background: #fff; transition: width 0.4s var(--ease); }

.rp-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rp-main { flex: 1; min-height: 0; display: flex; padding-top: max(16px, env(safe-area-inset-top)); }
.rp-scroll { flex: 1; min-width: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; scrollbar-width: none; }
.rp-scroll::-webkit-scrollbar { display: none; }
.rp-thread { max-width: 720px; margin: 0 auto; padding: 8px 16px 28px; min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }

/* evaluation bar, like chess.com: runs the full height, white grows from the bottom */
.evalbar {
  position: relative;
  flex: none;
  align-self: stretch;
  width: 28px;
  overflow: hidden;
  background: #403d39;
}
.eval-white {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #fff;
  transition: height 0.7s var(--ease);
}
.eval-num {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(8px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: #403d39;
  font-variant-numeric: tabular-nums;
}
.evalbar.black-ahead .eval-num { bottom: auto; top: max(8px, env(safe-area-inset-top)); color: #fff; }

/* empty / loading states */
.rp-empty { margin: auto; text-align: center; color: #8e8e93; font-size: 15px; animation: fadeUp 0.5s var(--ease) both; }
.rp-empty .big { font-size: 20px; font-weight: 600; color: #fff; margin-bottom: 6px; }
.rp-empty .rp-hint-keys { margin-top: 14px; font-size: 12px; color: #636366; }
.spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 2.5px solid #2c2c2e;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- messages ---------- */
.rp-row { margin-top: 8px; }
.rp-row.first { margin-top: 16px; }
.rp-who { font-size: 12px; color: #8e8e93; margin: 0 0 3px 58px; }
.sent .rp-who { text-align: right; margin: 0 58px 3px 0; }
.solo .rp-who { display: none; }
.rp-line { display: flex; align-items: flex-end; gap: 14px; }
.sent .rp-line { flex-direction: row-reverse; }

/* avatar: first letter, colour seeded from the name */
.av {
  position: relative;
  z-index: 2; /* above the corner piece that shapes the bubble tail */
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: grid;
  place-items: center;
  background: #5865f2;
}
/* the rating, shown like a Discord status dot (a bit bigger) */
.rdot {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #000;
  display: grid;
  place-items: center;
  animation: statusIn 0.45s cubic-bezier(0.34, 1.7, 0.64, 1) both;
}
@keyframes statusIn {
  from { opacity: 0; transform: scale(0.2); }
  to { opacity: 1; transform: none; }
}
.rdot.wait::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #636366;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; transform: scale(0.8); } }
.rdot.fail::after { content: ""; width: 14px; height: 14px; border-radius: 50%; background: #ff453a; }

.bubble {
  position: relative;
  max-width: min(72%, 520px);
  padding: 6px 12px 7px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 22px;
  letter-spacing: -0.43px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}
.sent .bubble { background: var(--white-bubble); color: #000; transform-origin: 100% 100%; }
.recv .bubble { background: var(--black-bubble); color: #fff; transform-origin: 0 100%; }
.bubble .t { position: relative; z-index: 2; }

/* iMessage tail, pointing at the avatar */
.bubble::before, .bubble::after { content: ""; position: absolute; bottom: 0; height: 20px; transition: background-color 0.4s var(--ease); }
.sent .bubble::before { right: -7px; width: 20px; background: var(--white-bubble); border-bottom-left-radius: 16px 14px; z-index: 0; }
.sent .bubble::after { right: -26px; width: 26px; background: #000; border-bottom-left-radius: 10px; z-index: 1; }
.recv .bubble::before { left: -7px; width: 20px; background: var(--black-bubble); border-bottom-right-radius: 16px 14px; z-index: 0; }
.recv .bubble::after { left: -26px; width: 26px; background: #000; border-bottom-right-radius: 10px; z-index: 1; }

.rp-row.enter .bubble { animation: bubbleIn 0.42s cubic-bezier(0.2, 0.9, 0.3, 1.18) both; }
.rp-row.enter .av { animation: statusIn 0.4s cubic-bezier(0.34, 1.5, 0.64, 1) both; }
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(18px) scale(0.9); }
  to { opacity: 1; transform: none; }
}
.rp-row.enter .rp-who { animation: fadeIn 0.35s var(--ease) both; }
.rp-row.leave { animation: rowOut 0.22s var(--ease) forwards; pointer-events: none; }
@keyframes rowOut { to { opacity: 0; transform: translateY(10px) scale(0.96); } }

/* end-of-chat summary */
.rp-summary {
  margin: 30px auto 6px;
  width: 100%;
  max-width: 440px;
  background: #1c1c1e;
  border-radius: 22px;
  padding: 18px 18px 14px;
  animation: fadeUp 0.5s var(--ease) both;
}
.rp-summary.leave { animation: rowOut 0.22s var(--ease) forwards; }
.rp-summary h3 { margin: 0 0 6px; font-size: 17px; font-weight: 600; text-align: center; }
/* each player: same padding above and below, rating counts lined up under the name */
.sum-player { padding: 12px 4px; border-top: 0.5px solid rgba(255, 255, 255, 0.1); }
.sum-row { display: flex; align-items: center; gap: 10px; }
.sum-row .side { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 1px solid #636366; background: #000; }
.sum-player.white .side { background: #fff; border-color: #fff; }
.sum-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.sum-row .ac { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.sum-icons { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; padding-left: 22px; font-size: 12px; color: #8e8e93; }
.sum-icons span { display: inline-flex; align-items: center; gap: 5px; }
.sum-actions { display: flex; justify-content: center; margin-top: 10px; }
.sum-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: #2c2c2e;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), transform 0.15s var(--ease);
}
.sum-btn:hover { background: #3a3a3c; }
.sum-btn:active { transform: scale(0.96); }

/* coach line: the rating and why */
.rp-coach {
  flex: none;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  min-height: 112px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px 4px 54px;
}
.rp-coach-icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; }
.rp-coach-icon:empty { display: none; }
.rp-coach-text { min-width: 0; }
.rp-coach-title { font-size: 21px; font-weight: 700; letter-spacing: -0.3px; }
.rp-coach-sub { font-size: 14px; color: #aeaeb2; line-height: 1.4; margin-top: 3px; max-width: 600px; }
.rp-coach-sub:empty { display: none; }
.rp-coach.swap .rp-coach-icon { animation: statusIn 0.45s cubic-bezier(0.34, 1.7, 0.64, 1) both; }
.rp-coach.swap .rp-coach-text { animation: coachIn 0.35s var(--ease) both; }
@keyframes coachIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* controls: no bar, just the buttons */
.rp-controls {
  position: relative;
  flex: none;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.rp-round {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #1c1c1e;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), transform 0.15s var(--ease), opacity 0.2s var(--ease);
}
.rp-round svg { width: 18px; height: 18px; }
.rp-round:hover { background: #2c2c2e; }
.rp-round:active { transform: scale(0.9); }
.rp-round:disabled { opacity: 0.3; cursor: default; transform: none; }
.rp-round.play { width: 50px; height: 50px; background: #fff; color: #000; }
.rp-round.play svg { width: 20px; height: 20px; }
.rp-round.play:hover { background: #e3e3e3; }
.rp-round .i-pause { display: none; }
.rp-round.playing .i-play { display: none; }
.rp-round.playing .i-pause { display: block; }
.rp-mute {
  position: absolute;
  right: 16px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: #8e8e93;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.rp-mute:hover { color: #fff; background: #1c1c1e; }
.rp-mute .snd-off { display: none; }
.rp-mute[aria-pressed="true"] .snd-on { display: none; }
.rp-mute[aria-pressed="true"] .snd-off { display: block; }

@media (max-width: 640px) {
  .evalbar { width: 20px; }
  .eval-num { font-size: 9px; }
  .rp-thread { padding: 8px 10px 24px; }
  .bubble { max-width: 76%; }
  .rp-coach { padding-left: 30px; }
  .rp-coach-title { font-size: 19px; }
  .rp-mute { right: 6px; }
  .set-row { grid-template-columns: 1fr; gap: 4px; }
  .set-row > label, .set-row > .lab { text-align: left; padding-top: 0; }
  .intro h1 { font-size: 28px; }
}
