/*
 * Stream Tools overlay (resources/js/stream-tools/overlay.js).
 *
 * Drawn for a 1920x1080 browser source; every size is in px at that canvas.
 * The page around it stays transparent (OBS composites it over the camera).
 * The same rules draw the preview on /stream-tools, inside a .so-stage that is
 * scaled to fit.
 *
 * Tokens: --acc (the player's accent), --acc-ink (text on the accent),
 * --so-scale (0.6 .. 1.6), all set on .so-anchor by the script.
 */

.so-stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  font-family: "Barlow Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  color: #fff;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  pointer-events: none;
  --so-panel: linear-gradient(180deg, #1a1f2a 0%, #0e121a 55%, #080b10 100%);
  --so-panel-solid: #0e121a;
  --so-line: rgba(255, 255, 255, 0.08);
  --so-dim: rgba(255, 255, 255, 0.58);
  --so-hill: #ffb020;
  --so-sd: #ff4d5e;
  --so-ease: cubic-bezier(0.2, 0.9, 0.25, 1);
}

.so-stage *,
.so-stage *::before,
.so-stage *::after {
  box-sizing: border-box;
}

/* ---- Anchor: where on the 1920x1080 canvas, and how big ------------------ */

.so-anchor {
  position: absolute;
  display: flex;
  transform: scale(var(--so-scale, 1));
}

.so-pos-bottom { left: 50%; bottom: 44px; transform: translateX(-50%) scale(var(--so-scale, 1)); transform-origin: 50% 100%; }
.so-pos-top    { left: 50%; top: 36px;    transform: translateX(-50%) scale(var(--so-scale, 1)); transform-origin: 50% 0; }
.so-pos-tl     { left: 48px;  top: 40px;    transform-origin: 0 0; }
.so-pos-tr     { right: 48px; top: 40px;    transform-origin: 100% 0; }
.so-pos-bl     { left: 48px;  bottom: 44px; transform-origin: 0 100%; }
.so-pos-br     { right: 48px; bottom: 44px; transform-origin: 100% 100%; }

/* The bar on top: its tabs hang below it instead of sitting above. */
.so-pos-top .so-bar { flex-direction: column-reverse; }
.so-pos-top .so-bar__tabs { align-items: flex-start; }
.so-pos-top .so-tab,
.so-pos-top .so-brand--tab,
.so-pos-top .so-banner { border-radius: 0 0 10px 10px; }

.is-enter > * {
  animation: so-enter 0.6s var(--so-ease) both;
}
.so-pos-top.is-enter > *,
.so-pos-tl.is-enter > *,
.so-pos-tr.is-enter > * {
  animation-name: so-enter-top;
}

@keyframes so-enter {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: none; }
}
@keyframes so-enter-top {
  from { opacity: 0; transform: translateY(-40px); }
  to   { opacity: 1; transform: none; }
}

/* ---- Shared pieces -------------------------------------------------------- */

.so-flag {
  flex: none;
  width: 42px;
  height: 31px;
  border-radius: 4px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 2px 6px rgba(0, 0, 0, 0.5);
}

.so-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.so-name__text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.so-tag {
  flex: none;
  padding: 3px 7px 2px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  color: var(--acc);
  font-size: 0.62em;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Whose break: a little cue ball with the accent glow. */
.so-break {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff 0 30%, #e6e9ee 55%, #a9b0bb 100%);
  box-shadow: 0 0 0 2px var(--acc), 0 0 14px var(--acc);
  animation: so-breathe 2.4s ease-in-out infinite;
}

@keyframes so-breathe {
  0%, 100% { box-shadow: 0 0 0 2px var(--acc), 0 0 6px var(--acc); }
  50%      { box-shadow: 0 0 0 2px var(--acc), 0 0 18px var(--acc); }
}

.so-badge {
  flex: none;
  padding: 4px 8px 3px;
  border-radius: 4px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.so-badge--hill {
  background: var(--so-hill);
  color: #1d1300;
  box-shadow: 0 0 16px rgba(255, 176, 32, 0.45);
  animation: so-hill 1.6s ease-in-out infinite;
}

@keyframes so-hill {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 176, 32, 0.35); }
  50%      { box-shadow: 0 0 20px rgba(255, 176, 32, 0.75); }
}

.so-badge--win {
  background: var(--acc);
  color: var(--acc-ink);
}

.so-brand {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.so-brand__ball {
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #fff 0 46%, var(--acc) 47%);
  color: #0b0f14;
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0;
}

/* Rack won: a light sweep across that side, the score pops. */
.so-side__sweep {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.so-side__sweep::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -40%;
  width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.22) 45%, var(--acc) 50%, rgba(255, 255, 255, 0.22) 55%, transparent);
  opacity: 0;
  mix-blend-mode: screen;
}
.is-flash > .so-side__sweep::after {
  animation: so-sweep 0.9s var(--so-ease);
}

@keyframes so-sweep {
  0%   { left: -40%; opacity: 0; }
  15%  { opacity: 0.9; }
  100% { left: 110%; opacity: 0; }
}

.so-score.is-flash b {
  animation: so-pop 0.75s var(--so-ease);
}
.so-score.is-flash {
  animation: so-glow 1.4s ease-out;
}
.so-score.is-undo b {
  animation: so-undo 0.5s ease-out;
}

@keyframes so-pop {
  0%   { transform: scale(0.4); opacity: 0; }
  55%  { transform: scale(1.28); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes so-glow {
  0%   { background: var(--acc); color: var(--acc-ink); box-shadow: 0 0 40px var(--acc); }
  100% { box-shadow: 0 0 0 transparent; }
}
@keyframes so-undo {
  0%   { transform: translateY(-14px); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

/* ---- 33 Rotation round cells ------------------------------------------------ */

.so-rounds {
  display: flex;
  align-self: stretch;
}

.so-round {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 50px;
  border-left: 1px solid var(--so-line);
  background: rgba(0, 0, 0, 0.22);
}
.so-round em {
  color: var(--so-dim);
  font-size: 13px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.12em;
}
.so-round b {
  font-size: 28px;
  font-weight: 700;
}
.so-round.is-empty b { color: rgba(255, 255, 255, 0.25); }
.so-round.is-neg b { color: #ff8a95; }
.so-round.is-sd em { color: var(--so-sd); }
.so-round.is-now {
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 -3px 0 var(--acc);
}
.so-round.is-now.is-sd { box-shadow: inset 0 -3px 0 var(--so-sd); }

/* ==========================================================================
   BAR: the classic lower third
   ========================================================================== */

.so-bar {
  display: flex;
  flex-direction: column;
  width: 1340px;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.55));
}

.so-bar__tabs {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 38px;
}

.so-tab {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 36px;
  padding: 0 24px;
  border-radius: 10px 10px 0 0;
  background: var(--so-panel-solid);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}
.so-tab__title { color: rgba(255, 255, 255, 0.9); }
.so-tab__money { color: var(--acc); }
.so-tab__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}

.so-brand--tab {
  position: absolute;
  right: 0;
  bottom: 0;
  height: 30px;
  padding: 0 14px;
  border-radius: 8px 8px 0 0;
  background: rgba(8, 11, 16, 0.86);
}

.so-banner {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 46px;
  margin-bottom: -2px;
  padding: 0 30px;
  border-radius: 10px 10px 0 0;
  background: var(--acc);
  color: var(--acc-ink);
  box-shadow: 0 0 40px var(--acc-glow);
  white-space: nowrap;
  animation: so-banner 0.8s var(--so-ease) both;
}
.so-bar__tabs.has-banner { height: 46px; }
.so-banner__kicker {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  opacity: 0.75;
}
.so-banner__name {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.so-banner__score {
  font-size: 30px;
  font-weight: 600;
}

@keyframes so-banner {
  from { opacity: 0; transform: translateY(24px) scale(0.9); }
  to   { opacity: 1; transform: none; }
}

.so-bar__row {
  position: relative;
  display: flex;
  height: 84px;
  border-radius: 12px;
  background: var(--so-panel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), inset 0 -4px 0 var(--acc);
  overflow: hidden;
}

/* A player half. */
.so-side {
  position: relative;
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  align-items: stretch;
}
.so-side--r { flex-direction: row; }

.so-side__body {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 14px;
  padding: 0 22px 4px;
  font-size: 38px;
}
.so-side--r .so-side__body {
  flex-direction: row-reverse;
}
.so-side--r .so-name { flex-direction: row-reverse; }

.so-side--l { background: linear-gradient(90deg, transparent 40%, rgba(255, 255, 255, 0.035)); }
.so-side--r { background: linear-gradient(270deg, transparent 40%, rgba(255, 255, 255, 0.035)); }
.so-side.is-loser .so-side__body { opacity: 0.5; }
.so-side.is-winner .so-side__body { color: #fff; }
.so-side.is-winner .so-name__text { color: var(--acc); }

.so-score {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 96px;
  background: linear-gradient(180deg, #ffffff 0%, #e9edf2 100%);
  color: #0b0f14;
  font-size: 58px;
  font-weight: 800;
  padding-bottom: 4px;
  overflow: hidden;
}
.so-score b { display: block; font-weight: 800; }
.so-score.is-winner {
  background: var(--acc);
  color: var(--acc-ink);
}
.so-side.is-hill .so-score { box-shadow: inset 0 -4px 0 var(--so-hill); }

/* The centre: game and race. */
.so-mid {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: none;
  width: 188px;
  padding-bottom: 4px;
  background: linear-gradient(180deg, #05070a, #0b0f14);
  box-shadow: inset 1px 0 0 var(--so-line), inset -1px 0 0 var(--so-line);
}
.so-mid__game {
  color: var(--so-dim);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.so-mid__race {
  color: var(--acc);
  font-size: 27px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.so-mid.is-sd .so-mid__race {
  color: var(--so-sd);
  animation: so-sd 1.2s ease-in-out infinite;
}

@keyframes so-sd {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* 33: narrower names, round cells beside the total. */
.so-bar--33 { width: 1600px; }
.so-bar--33 .so-side__body { font-size: 34px; }
.so-bar--33 .so-score { width: 104px; }
.so-side--r .so-rounds .so-round:first-child { border-left: 1px solid var(--so-line); }
.so-side--r .so-rounds { border-right: 1px solid var(--so-line); }

/* ==========================================================================
   CORNER: a stacked card
   ========================================================================== */

.so-card,
.so-train {
  width: 520px;
  border-radius: 14px;
  background: var(--so-panel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 14px 34px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.so-card--33 { width: 640px; }

.so-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 18px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 -1px 0 var(--so-line);
}
.so-card__game {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--so-dim);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.so-card__game i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}
.so-card__game b {
  color: var(--acc);
  font-weight: 800;
}
.so-card__game b.is-sd {
  color: var(--so-sd);
  animation: so-sd 1.2s ease-in-out infinite;
}

.so-card__title {
  padding: 10px 18px 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.so-card__cols {
  display: flex;
  align-items: stretch;
  height: 30px;
  padding-top: 8px;
}
.so-card__cols .so-round { justify-content: center; }
.so-card__colname { flex: 1 1 auto; }
.so-rounds--head .so-round {
  background: none;
  border-left-color: transparent;
}
.so-card__totlabel {
  width: 84px;
  color: var(--so-dim);
  align-self: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

.so-row {
  position: relative;
  display: flex;
  align-items: stretch;
  height: 64px;
  border-top: 1px solid var(--so-line);
}
.so-card__cols + .so-row,
.so-card__title + .so-row,
.so-card__head + .so-row { border-top: 0; margin-top: 6px; }
.so-row + .so-row { margin-top: 0; }

.so-row__who {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 18px;
  font-size: 30px;
}
.so-row .so-flag { width: 36px; height: 27px; }
.so-row .so-round b { font-size: 25px; }
.so-row .so-score {
  width: 84px;
  font-size: 44px;
}
.so-row.is-loser .so-row__who { opacity: 0.5; }
.so-row.is-winner .so-name__text { color: var(--acc); }
.so-row.is-hill .so-score { box-shadow: inset 0 -4px 0 var(--so-hill); }
.so-row:last-of-type .so-score { box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.12); }
.so-row.is-hill:last-of-type .so-score { box-shadow: inset 0 -4px 0 var(--so-hill); }

.so-card__money {
  padding: 9px 18px 10px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 1px 0 var(--so-line), inset 0 -4px 0 var(--acc);
  color: var(--acc);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding-bottom: 13px;
}
.so-card.no-money { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), inset 0 -4px 0 var(--acc), 0 14px 34px rgba(0, 0, 0, 0.55); }
.so-card.no-money .so-row:last-child { height: 68px; padding-bottom: 4px; }

/* ==========================================================================
   COMPACT: a small pill
   ========================================================================== */

.so-pill {
  display: flex;
  align-items: stretch;
  height: 46px;
  border-radius: 23px;
  background: var(--so-panel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 8px 22px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  font-size: 24px;
}
.so-pill__who {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 260px;
  padding: 0 14px 0 16px;
}
.so-pill__who + .so-pill__meta { margin-left: 0; }
.so-pill .so-pill__who:nth-last-child(2) { padding: 0 16px 0 14px; }
.so-pill .so-flag { width: 28px; height: 21px; border-radius: 3px; }
.so-pill .so-break { width: 12px; height: 12px; }
.so-pill__who.is-loser { opacity: 0.5; }
.so-pill__who.is-winner .so-name__text { color: var(--acc); }
.so-pill .so-score {
  width: 46px;
  font-size: 30px;
  padding-bottom: 0;
}
.so-pill .so-score.is-hill { box-shadow: inset 0 -3px 0 var(--so-hill); }
.so-pill__sep { width: 2px; background: #0b0f14; }
.so-pill__meta {
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--acc);
  color: var(--acc-ink);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}
.so-pill__meta.is-sd { background: var(--so-sd); color: #fff; }

/* ==========================================================================
   TRAINING: the session board
   ========================================================================== */

.so-train { width: 480px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), inset 0 -4px 0 var(--acc), 0 14px 34px rgba(0, 0, 0, 0.55); }

.so-train__title {
  padding: 12px 18px 0;
  font-size: 30px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.so-train__sub {
  padding: 4px 18px 0;
  color: var(--so-dim);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.so-train__diagram {
  margin: 12px 18px 4px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.so-train__diagram svg {
  display: block;
  width: 100%;
  height: auto;
}
.so-train__players {
  margin: 0;
  padding: 6px 0 10px;
  list-style: none;
}
.so-train__players li {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 12px;
  padding: 8px 18px 10px;
}
.so-train__players li + li { border-top: 1px solid var(--so-line); }
.so-train__players li.is-up { background: rgba(255, 255, 255, 0.05); }
.so-train__who {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  font-size: 25px;
}
.so-train__tally {
  display: flex;
  align-items: baseline;
  gap: 9px;
  white-space: nowrap;
}
.so-train__tally b {
  color: var(--acc);
  font-size: 28px;
  font-weight: 800;
}
.so-train__tally em {
  color: var(--so-dim);
  font-size: 17px;
  font-style: normal;
  font-weight: 600;
}
.so-train__bar {
  grid-column: 1 / -1;
  height: 4px;
  margin-top: 7px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.so-train__bar i {
  display: block;
  height: 100%;
  background: var(--acc);
  transition: width 0.6s var(--so-ease);
}
/* "MISS · Too thin" beside the tally for ~2.5s when a tagged miss comes in
   (overlay.js removes the node afterwards). Opacity and transform only. */
.so-train__miss {
  align-self: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 77, 94, 0.18);
  box-shadow: inset 0 0 0 1px rgba(255, 77, 94, 0.55);
  color: #ffb3bb;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
  animation: so-miss 2.5s var(--so-ease) both;
}
@keyframes so-miss {
  0% { opacity: 0; transform: translateX(6px); }
  10% { opacity: 1; transform: none; }
  80% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}
