/* SO Tally. Colors come from Tallies > Appearance (printed as CSS variables). */

:where(:root) {
	--so-tally-btn-bg: #1f3a68;
	--so-tally-btn-fg: #ffffff;
	--so-tally-btn-hover: #152a4d;
	--so-tally-btn-radius: 6px;
	--so-tally-btn-size: 18px;
	--so-tally-ticker-bg: #1f3a68;
	--so-tally-ticker-fg: #ffffff;
	--so-tally-accent: #1f3a68;
	--so-tally-track: #e9e4d8;
}

/* ---------- Numbers ---------- */
.so-tally-count,
.so-tally-mine {
	display: inline-block;
	font-variant-numeric: tabular-nums;
}

.so-tally-count {
	color: var(--so-tally-count, inherit);
}

.so-tally-bump {
	animation: soTallyBump 0.6s ease-out;
}

@keyframes soTallyBump {
	0%   { transform: scale(1); }
	35%  { transform: scale(1.18); }
	100% { transform: scale(1); }
}

/* ---------- Built-in button ---------- */
.so-tally-btn-wrap {
	display: block;
	margin: 1em 0;
}

.so-tally-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5em;
	margin: 0;
	padding: 0.8em 1.6em;
	border: 0;
	border-radius: var(--so-tally-btn-radius);
	background: var(--so-tally-btn-bg);
	color: var(--so-tally-btn-fg);
	font-family: inherit;
	font-size: var(--so-tally-btn-size);
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	text-transform: none;
	cursor: pointer;
	box-shadow: none;
	transition: background-color 0.2s ease, transform 0.1s ease;
	-webkit-appearance: none;
	appearance: none;
}

.so-tally-btn:hover,
.so-tally-btn:focus-visible {
	background: var(--so-tally-btn-hover);
	color: var(--so-tally-btn-fg);
}

.so-tally-btn:focus-visible {
	outline: 3px solid var(--so-tally-btn-hover);
	outline-offset: 3px;
}

.so-tally-btn:active {
	transform: scale(0.97);
}

.so-tally-btn--small { font-size: calc(var(--so-tally-btn-size) * 0.8); padding: 0.6em 1.2em; }
.so-tally-btn--large { font-size: calc(var(--so-tally-btn-size) * 1.3); padding: 0.9em 2em; }
.so-tally-btn--full  { display: flex; width: 100%; }

/* Any element used as a tally button (built-in, or a theme/page builder button with the class). */
[class*="so-tally-add-"] {
	cursor: pointer;
}

[class*="so-tally-add-"].so-tally-busy {
	opacity: 0.85;
	pointer-events: none;
}

/* ---------- Progress bar ---------- */
.so-tally-progress {
	display: block;
	width: 100%;
	height: var(--so-tally-progress-h, 14px);
	border-radius: 999px;
	overflow: hidden;
	background: var(--so-tally-track);
}

.so-tally-progress-fill {
	display: block;
	height: 100%;
	border-radius: inherit;
	background: var(--so-tally-accent);
	transition: width 0.6s ease;
}

/* ---------- Odometer (rolling digits) ---------- */
.so-tally-odo {
	display: inline-flex;
	align-items: flex-start;
	line-height: 1.15;
	vertical-align: bottom;
}

.so-odo-digit {
	display: inline-block;
	height: 1.15em;
	overflow: hidden;
}

.so-odo-strip {
	display: flex;
	flex-direction: column;
	transition: transform 1.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.so-odo-strip > span,
.so-odo-sep {
	display: block;
	height: 1.15em;
	text-align: center;
}

/* ---------- Ticker bar ----------
   [ pinned: lead-in text, and in feed mode the clickable totals ] [ scrolling viewport ] */
.so-tally-ticker {
	display: block;
	width: 100%;
	container: sotally / inline-size;
	overflow: hidden;
	background: var(--so-tally-ticker-bg);
	color: var(--so-tally-ticker-fg);
	line-height: 1.15;
}

.so-tally-ticker-inner {
	display: flex;
	align-items: stretch;
	width: 100%;
}

.so-tally-ticker,
.so-tally-ticker * {
	box-sizing: border-box;
}

.so-tally-ticker-pin {
	position: relative;
	z-index: 1;
	display: flex;
	flex: none;
	align-items: center;
	gap: 0.2em;
	max-width: 70%;
	padding: 0.8em 1em;
	background: rgba(0, 0, 0, 0.18);
	box-shadow: 6px 0 12px -6px rgba(0, 0, 0, 0.35);
}

.so-tally-ticker-intro {
	font-weight: 700;
	white-space: nowrap;
}

.so-tally-ticker-pinned {
	display: flex;
	flex-wrap: nowrap;
	align-items: center;
	gap: 0.3em 1.2em;
}

.so-tally-ticker-pinned .so-tally-ticker-item {
	padding-left: 0;
}

.so-tally-ticker-pinned .so-tally-ticker-sep {
	display: none;
}

.so-tally-ticker-intro + .so-tally-ticker-pinned {
	margin-left: 0.8em;
}

.so-tally-ticker-viewport {
	display: flex;
	flex: 1 1 auto;
	align-items: center;
	min-width: 0;
	overflow: hidden;
	padding: 0.8em 0;
	container-type: inline-size;
}

.so-tally-ticker-track,
.so-tally-ticker-group,
.so-tally-ticker-slot {
	display: flex;
	align-items: center;
	flex-shrink: 0;
}

.so-tally-ticker--scroll .so-tally-ticker-track {
	width: max-content;
	animation: soTallyScroll var(--so-tally-speed, 20s) linear infinite;
}

/* N at a time, evenly spaced: each copy gets an equal share of the bar. */
.so-tally-ticker--spaced .so-tally-ticker-slot {
	justify-content: center;
	box-sizing: border-box;
	padding: 0 1.2em;
	min-width: calc(100vw / var(--so-tally-n, 1));
	min-width: calc(100cqw / var(--so-tally-n, 1));
}

.so-tally-ticker-slot > .so-tally-ticker-item:first-child {
	padding-left: 0;
}

.so-tally-ticker-slot > .so-tally-ticker-item:last-child .so-tally-ticker-sep {
	display: none;
}

.so-tally-ticker--moving:hover .so-tally-ticker-track,
.so-tally-ticker--moving:focus-within .so-tally-ticker-track {
	animation-play-state: paused;
}

.so-tally-ticker--static .so-tally-ticker-track,
.so-tally-ticker--static .so-tally-ticker-group {
	justify-content: center;
	flex-wrap: wrap;
	width: 100%;
}

.so-tally-ticker--static .so-tally-ticker-item:last-child .so-tally-ticker-sep {
	display: none;
}

.so-tally-ticker-item {
	display: inline-flex;
	align-items: center;
	gap: 0.4em;
	white-space: nowrap;
	padding-left: 1.4em;
}

.so-tally-ticker-num,
.so-tally-ticker .so-tally-count {
	color: inherit;
	font-weight: 700;
}

.so-tally-ticker-sep {
	padding-left: 1em;
	opacity: 0.6;
}

/* Live activity feed items */
.so-tally-feed-num {
	font-weight: 700;
	opacity: 0.8;
	font-variant-numeric: tabular-nums;
}

.so-tally-feed-empty {
	font-style: italic;
	opacity: 0.9;
}

.so-tally-ticker--feed .so-tally-ticker-viewport {
	transition: opacity 0.3s ease;
}

.so-tally-ticker--feed.so-tally-ticker--refreshing .so-tally-ticker-viewport {
	opacity: 0;
}

@keyframes soTallyScroll {
	from { transform: translateX(0); }
	to   { transform: translateX(-50%); }
}

/* In a narrow bar (a phone, or a narrow column), the pinned part sits on its own line above the scrolling part. */
@media (max-width: 640px) {
	.so-tally-ticker-inner { flex-wrap: wrap; }
	.so-tally-ticker-pin { max-width: none; width: 100%; flex-wrap: wrap; justify-content: center; gap: 0.4em 0; box-shadow: none; padding: 0.6em 0.8em; text-align: center; }
	.so-tally-ticker-intro { white-space: normal; }
	.so-tally-ticker-intro + .so-tally-ticker-pinned { margin-left: 0; }
	.so-tally-ticker-pinned { flex-wrap: wrap; justify-content: center; max-width: 100%; min-width: 0; }
	.so-tally-ticker-viewport { flex-basis: 100%; }
	.so-tally-ticker--static .so-tally-ticker-sep { display: none; }
	.so-tally-ticker--static .so-tally-ticker-item { padding: 0.15em 0.7em; }
}

@container sotally (max-width: 760px) {
	.so-tally-ticker-inner { flex-wrap: wrap; }
	.so-tally-ticker-pin { max-width: none; width: 100%; flex-wrap: wrap; justify-content: center; gap: 0.4em 0; box-shadow: none; padding: 0.6em 0.8em; text-align: center; }
	.so-tally-ticker-intro { white-space: normal; }
	.so-tally-ticker-intro + .so-tally-ticker-pinned { margin-left: 0; }
	.so-tally-ticker-pinned { flex-wrap: wrap; justify-content: center; max-width: 100%; min-width: 0; }
	.so-tally-ticker-viewport { flex-basis: 100%; }
	.so-tally-ticker--static .so-tally-ticker-sep { display: none; }
	.so-tally-ticker--static .so-tally-ticker-item { padding: 0.15em 0.7em; }
}

@media (prefers-reduced-motion: reduce) {
	.so-tally-bump { animation: none; }
	.so-tally-progress-fill,
	.so-odo-strip { transition: none; }
	.so-tally-ticker--moving .so-tally-ticker-viewport { overflow-x: auto; }
	.so-tally-ticker--moving .so-tally-ticker-track { animation: none; }
	.so-tally-ticker--moving .so-tally-ticker-group[aria-hidden="true"] { display: none; }
}

/* ---------- Ticker (+) button ---------- */
.so-tally-plus {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 1.6em;
	height: 1.6em;
	margin: 0 0 0 0.35em;
	padding: 0;
	border: 2px solid currentColor;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font-family: inherit;
	font-size: 1em;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
	box-shadow: none;
	transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

/* Bigger invisible tap area for fingers without changing the look. */
.so-tally-plus { position: relative; }
.so-tally-plus::after {
	content: "";
	position: absolute;
	inset: -0.45em;
}

.so-tally-plus:hover,
.so-tally-plus:focus-visible,
.so-tally-plus.so-tally-done {
	background: var(--so-tally-ticker-fg);
	color: var(--so-tally-ticker-bg);
	border-color: var(--so-tally-ticker-fg);
}

.so-tally-plus:focus-visible {
	outline: 2px solid var(--so-tally-ticker-fg);
	outline-offset: 3px;
}

.so-tally-plus:active,
.so-tally-plus.so-tally-done {
	transform: scale(1.15);
}

.so-tally-plus-icon {
	display: block;
	margin-top: -0.05em;
}

.so-tally-ticker--moving.so-tally-ticker--hold .so-tally-ticker-track {
	animation-play-state: paused;
}

/* ---------- Pop-up confirmation (used by the ticker +) ---------- */
.so-tally-toast {
	position: fixed;
	left: 50%;
	bottom: 24px;
	z-index: 99999;
	width: max-content;
	max-width: calc(100vw - 32px);
	padding: 0.75em 1.25em;
	text-align: center;
	border-radius: 8px;
	background: var(--so-tally-ticker-bg);
	color: var(--so-tally-ticker-fg);
	font-weight: 600;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
	opacity: 0;
	pointer-events: none;
	transform: translate(-50%, 12px);
	transition: opacity 0.25s ease, transform 0.25s ease;
}

.so-tally-toast--show {
	opacity: 1;
	transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
	.so-tally-plus,
	.so-tally-toast { transition: none; }
	.so-tally-plus:active,
	.so-tally-plus.so-tally-done { transform: none; }
}

/* ---------- Thank-you pop-up with optional name ---------- */
.so-tally-namebox {
	position: fixed;
	left: 50%;
	bottom: 24px;
	z-index: 99999;
	width: max-content;
	max-width: calc(100vw - 32px);
	padding: 1em 2.6em 1em 1.25em;
	border-radius: 10px;
	background: var(--so-tally-ticker-bg);
	color: var(--so-tally-ticker-fg);
	box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
	opacity: 0;
	visibility: hidden;
	transform: translate(-50%, 12px);
	transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.so-tally-namebox--show {
	opacity: 1;
	visibility: visible;
	transform: translate(-50%, 0);
}

.so-tally-namebox-msg {
	margin: 0 0 0.6em;
	font-weight: 700;
}

.so-tally-namebox-form {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 0.5em;
	margin: 0;
}

.so-tally-namebox-form[hidden] { display: none; }

.so-tally-namebox-label {
	display: flex;
	flex-direction: column;
	gap: 0.3em;
	font-size: 0.9em;
}

.so-tally-namebox-label input {
	width: 14em;
	max-width: 60vw;
	margin: 0;
	padding: 0.5em 0.7em;
	border: 0;
	border-radius: 6px;
	background: #ffffff;
	color: #1b1b1b;
	font: inherit;
	font-size: 1rem;
}

.so-tally-namebox-save {
	margin: 0;
	padding: 0.55em 1.1em;
	border: 2px solid currentColor;
	border-radius: 6px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-weight: 700;
	cursor: pointer;
}

.so-tally-namebox-save:hover,
.so-tally-namebox-save:focus-visible {
	background: var(--so-tally-ticker-fg);
	color: var(--so-tally-ticker-bg);
}

.so-tally-namebox-close {
	position: absolute;
	top: 0.35em;
	right: 0.45em;
	width: 1.8em;
	height: 1.8em;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	font-size: 1.2em;
	line-height: 1;
	cursor: pointer;
	opacity: 0.8;
}

.so-tally-namebox-close:hover,
.so-tally-namebox-close:focus-visible { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
	.so-tally-namebox { transition: none; }
}

.so-tally-namebox-label[hidden] { display: none; }
