:root {
	--ascorbic-bulk-primary: var(--primary-color, var(--madara-main-color, #eb3349));
	--ascorbic-bulk-surface: #fff;
	--ascorbic-bulk-text: #333;
	--ascorbic-bulk-heading: #333;
	--ascorbic-bulk-muted: #555;
	--ascorbic-bulk-border: #e5e5e5;
	--ascorbic-bulk-divider: #e8e8e8;
	--ascorbic-bulk-control-border: #cfcfcf;
	--ascorbic-bulk-check-bg: #fff;
	--ascorbic-bulk-danger: #b42318;
	--ascorbic-bulk-success: #16794a;
}

body.text-ui-light {
	--ascorbic-bulk-surface: #262626;
	--ascorbic-bulk-text: #ccc;
	--ascorbic-bulk-heading: #fff;
	--ascorbic-bulk-muted: #ccc;
	--ascorbic-bulk-border: #383838;
	--ascorbic-bulk-divider: #383838;
	--ascorbic-bulk-control-border: #555;
	--ascorbic-bulk-check-bg: #262626;
	--ascorbic-bulk-danger: #ff9188;
	--ascorbic-bulk-success: #72d8a8;
}

.reverse-order-row {
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 18px;
}

/* Normalize both toolbar controls so their text and symbols share one baseline and visual size. */
.reverse-order-row .ascorbic-bulk-toggle,
.reverse-order-row .btn-reverse-order-2 {
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	column-gap: 4px;
	margin: 0 !important;
	padding: 0 !important;
	border: 0;
	background: transparent;
	font: inherit !important;
	font-size: .9em !important;
	font-weight: inherit;
	line-height: 1.2 !important;
	vertical-align: middle;
	text-decoration: none !important;
}

.reverse-order-row .ascorbic-bulk-toggle {
	cursor: pointer;
}

/* Keep the opened control visually aligned with the neighbouring Reverse Order link. */
.reverse-order-row .ascorbic-bulk-toggle.is-active,
.reverse-order-row .ascorbic-bulk-toggle.is-active:hover,
.reverse-order-row .ascorbic-bulk-toggle.is-active:focus {
	color: #333 !important;
	text-decoration: none !important;
	outline: none;
}

body.text-ui-light .reverse-order-row .ascorbic-bulk-toggle.is-active,
body.text-ui-light .reverse-order-row .ascorbic-bulk-toggle.is-active:hover,
body.text-ui-light .reverse-order-row .ascorbic-bulk-toggle.is-active:focus {
	color: #ccc !important;
}

.reverse-order-row .ascorbic-bulk-toggle:focus {
	text-decoration: none !important;
	outline: none;
}

/* Give both symbols the same box, size and center line so neither control sits higher or lower. */
.reverse-order-row .ascorbic-bulk-plus,
.reverse-order-row .btn-reverse-order-2 > i {
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	flex: 0 0 1em;
	width: 1em;
	height: 1em;
	margin: 0 !important;
	font-size: 1em !important;
	line-height: 1 !important;
	vertical-align: middle;
}

.reverse-order-row .ascorbic-bulk-plus {
	font-weight: inherit;
	transition: transform 180ms ease;
}

.reverse-order-row .ascorbic-bulk-toggle.is-active .ascorbic-bulk-plus {
	transform: rotate(45deg);
}

.ascorbic-bulk-buy[hidden],
.ascorbic-bulk-warning[hidden] {
	display: none !important;
}

.ascorbic-bulk-buy {
	container-name: ascorbic-bulk;
	container-type: inline-size;
	box-sizing: border-box;
	width: 100%;
	margin: -4px 0 18px;
	padding: 12px 14px;
	border: 1px solid var(--ascorbic-bulk-border);
	border-radius: 12px;
	background: var(--ascorbic-bulk-surface);
	box-shadow: none;
	color: var(--ascorbic-bulk-text);
	transform-origin: top center;
}

.ascorbic-bulk-buy.is-blooping-in,
.ascorbic-bulk-buy.is-blooping-out {
	transform-origin: top center;
	will-change: height, margin, padding, opacity, transform;
}

.ascorbic-bulk-buy.is-blooping-out {
	pointer-events: none;
}

/*
 * Sticky support for chapter wrappers that are CSS Grid containers.
 * A normal position: sticky grid item can be constrained to its own grid row,
 * so JavaScript pins the panel only after it reaches the viewport edge while
 * this invisible placeholder preserves the panel's original row in the grid.
 */
.ascorbic-bulk-sticky-placeholder {
	display: none;
	grid-column: 1 / -1;
	box-sizing: border-box;
	width: 100%;
	pointer-events: none;
	visibility: hidden;
	overflow-anchor: none;
}

.ascorbic-bulk-sticky-placeholder.is-active {
	display: block;
}

.ascorbic-bulk-buy.ascorbic-bulk-is-stuck {
	position: fixed !important;
	margin: 0 !important;
	z-index: 30;
	will-change: transform;
	overflow-anchor: none;
}

.ascorbic-bulk-warning.is-blooping-in,
.ascorbic-bulk-warning.is-blooping-out {
	transform-origin: left center;
	will-change: height, margin-top, opacity, transform;
}

.ascorbic-bulk-warning.is-blooping-out {
	pointer-events: none;
}

.ascorbic-bulk-topline,
.ascorbic-bulk-selection,
.ascorbic-bulk-wallet,
.ascorbic-bulk-actions,
.ascorbic-bulk-quick {
	display: flex;
	align-items: center;
}

.ascorbic-bulk-topline {
	justify-content: space-between;
	gap: 12px;
}

.ascorbic-bulk-purchase-row {
	--ascorbic-bulk-status-gap: 7px;
	display: grid;
	grid-template-columns: minmax(0, 1fr) max-content;
	grid-template-rows: auto auto auto;
	align-items: center;
	column-gap: 16px;
	row-gap: 0;
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid var(--ascorbic-bulk-divider);
}

.ascorbic-bulk-title {
	min-width: 0;
}

.ascorbic-bulk-title strong {
	display: inline;
	font-size: 15px;
	line-height: 1.3;
	color: var(--ascorbic-bulk-heading);
}

.ascorbic-bulk-quick {
	flex: 0 1 auto;
	justify-content: flex-end;
	flex-wrap: wrap;
	gap: 5px;
	min-width: 0;
}

.ascorbic-bulk-quick > span {
	margin-right: 2px;
	color: var(--ascorbic-bulk-muted);
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
}

.ascorbic-bulk-quick button {
	min-width: 34px;
	padding: 4px 8px;
	border: 1px solid var(--ascorbic-bulk-control-border);
	border-radius: 4px;
	background: transparent;
	color: var(--ascorbic-bulk-text);
	font-size: 12px;
	font-weight: 700;
	line-height: 1.35;
	cursor: pointer;
	transition: border-color 150ms ease, color 150ms ease, background-color 150ms ease;
}

.ascorbic-bulk-quick button:hover,
.ascorbic-bulk-quick button:focus {
	border-color: var(--ascorbic-bulk-primary);
	color: var(--ascorbic-bulk-primary);
	outline: none;
}

.ascorbic-bulk-quick .ascorbic-bulk-clear {
	min-width: 48px;
	margin-left: 2px;
	border-color: transparent;
	color: var(--ascorbic-bulk-text);
	font-weight: 600;
}

.ascorbic-bulk-quick .ascorbic-bulk-clear:hover,
.ascorbic-bulk-quick .ascorbic-bulk-clear:focus {
	border-color: var(--ascorbic-bulk-control-border);
	color: var(--ascorbic-bulk-primary);
}

.ascorbic-bulk-selection {
	grid-column: 1;
	grid-row: 1;
	justify-self: start;
	min-width: 0;
	gap: 6px;
	color: var(--ascorbic-bulk-text);
	font-size: 13px;
	line-height: 1.35;
	white-space: nowrap;
	overflow: hidden;
}

.ascorbic-bulk-selection strong {
	color: inherit;
}

.ascorbic-bulk-dot {
	color: var(--ascorbic-bulk-text);
	opacity: .65;
}

.ascorbic-bulk-wallet {
	grid-column: 2;
	grid-row: 1;
	justify-self: end;
	justify-content: flex-end;
	gap: 14px;
	color: var(--ascorbic-bulk-text);
	font-size: 11px;
	line-height: 1.35;
	white-space: nowrap;
}

.ascorbic-bulk-wallet strong {
	color: inherit;
	font-size: 12px;
}

/* Keep Balance + After as one structural unit at every width. */
.ascorbic-bulk-wallet-pair {
	display: inline-flex;
	align-items: center;
	gap: 14px;
	width: max-content;
	max-width: 100%;
	white-space: nowrap;
}

.ascorbic-bulk-actions {
	grid-column: 1 / -1;
	grid-row: 3;
	display: grid;
	justify-self: stretch;
	align-self: stretch;
	box-sizing: border-box;
	margin: var(--ascorbic-bulk-status-gap) 0 0;
	padding: 0;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 7px;
	width: 100%;
	min-width: 0;
}

.ascorbic-bulk-submit,
.ascorbic-bulk-buy-coins {
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: 100%;
	min-width: 0;
	margin: 0 !important;
	padding: 8px 13px;
	border-radius: 4px;
	font-size: 12px;
	font-weight: 700;
	line-height: 1.35;
	text-align: center;
	text-decoration: none !important;
	float: none !important;
	position: static !important;
}

.ascorbic-bulk-submit {
	border: 1px solid var(--ascorbic-bulk-primary);
	background: var(--ascorbic-bulk-primary);
	color: #fff;
	cursor: pointer;
}

.ascorbic-bulk-submit:hover:not(:disabled),
.ascorbic-bulk-submit:focus:not(:disabled) {
	filter: brightness(.92);
	color: #fff;
	outline: none;
}

.ascorbic-bulk-submit:disabled {
	opacity: .58;
	cursor: not-allowed;
}

.ascorbic-bulk-buy-coins {
	transform-origin: center;
	border: 1px solid var(--ascorbic-bulk-primary);
	background: transparent;
	color: var(--ascorbic-bulk-primary) !important;
}

.ascorbic-bulk-buy-coins:hover,
.ascorbic-bulk-buy-coins:focus {
	background: var(--ascorbic-bulk-primary);
	color: #fff !important;
	outline: none;
}

.ascorbic-bulk-warning {
	grid-column: 1 / -1;
	grid-row: 2;
	justify-self: start;
	transform-origin: left center;
	min-width: 0;
	margin: var(--ascorbic-bulk-status-gap) 0 0;
	font-size: 11px;
	font-weight: 600;
	line-height: 1.35;
	color: var(--ascorbic-bulk-danger);
	white-space: normal;
	overflow: visible;
	text-overflow: clip;
}

.ascorbic-bulk-result {
	margin: 8px 0 0;
	font-size: 12px;
}

.ascorbic-bulk-result:empty {
	display: none;
}

.ascorbic-bulk-result.is-error,
.ascorbic-bulk-buy.is-insufficient .ascorbic-bulk-after-value {
	color: var(--ascorbic-bulk-danger);
}

.ascorbic-bulk-result.is-success {
	color: var(--ascorbic-bulk-success);
	font-weight: 600;
}

.ascorbic-bulk-read-first {
	margin-left: 6px;
	font-weight: 700;
}

.wp-manga-chapter .ascorbic-bulk-check {
	display: none;
	position: relative;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	margin-right: 7px;
	vertical-align: middle;
	cursor: pointer;
	transform-origin: left center;
}

.wp-manga-chapter .ascorbic-bulk-check.is-blooping-in,
.wp-manga-chapter .ascorbic-bulk-check.is-blooping-out {
	will-change: width, margin-right, opacity, transform;
}

.wp-manga-chapter .ascorbic-bulk-check.is-blooping-out {
	pointer-events: none;
}

.listing-chapters_wrap.ascorbic-bulk-mode .wp-manga-chapter .ascorbic-bulk-check {
	display: inline-flex;
}

.wp-manga-chapter .ascorbic-bulk-check input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
}

.wp-manga-chapter .ascorbic-bulk-checkmark {
	width: 17px;
	height: 17px;
	border: 2px solid var(--ascorbic-bulk-control-border);
	border-radius: 3px;
	background: var(--ascorbic-bulk-check-bg);
}

.wp-manga-chapter .ascorbic-bulk-check input:checked + .ascorbic-bulk-checkmark {
	border-color: var(--ascorbic-bulk-primary);
	background: var(--ascorbic-bulk-primary);
	box-shadow: inset 0 0 0 3px var(--ascorbic-bulk-check-bg);
}

.wp-manga-chapter .ascorbic-bulk-check input:focus + .ascorbic-bulk-checkmark {
	outline: 2px solid var(--ascorbic-bulk-primary);
	outline-offset: 2px;
}

/* Respond to the module width itself, which is more reliable on manga pages with sidebars. */
@container ascorbic-bulk (max-width: 720px) {
	.ascorbic-bulk-purchase-row {
		column-gap: 12px;
	}
}

@container ascorbic-bulk (max-width: 520px) {
	/* Keep the title and chapter selectors on one row on narrow modules. */
	.ascorbic-bulk-topline {
		align-items: center;
		flex-direction: row;
		gap: 8px;
		flex-wrap: nowrap;
	}

	.ascorbic-bulk-title {
		flex: 1 1 auto;
		min-width: 0;
		white-space: nowrap;
	}

	.ascorbic-bulk-title strong {
		font-size: 13px;
	}

	.ascorbic-bulk-quick {
		flex: 0 0 auto;
		justify-content: flex-end;
		flex-wrap: nowrap;
		width: auto;
		gap: 3px;
		white-space: nowrap;
	}

	.ascorbic-bulk-quick > span {
		margin-right: 1px;
		font-size: 9px;
	}

	.ascorbic-bulk-quick button {
		min-width: 30px;
		padding: 3px 6px;
		font-size: 11px;
	}

	.ascorbic-bulk-quick .ascorbic-bulk-clear {
		min-width: 40px;
		margin-left: 1px;
	}

	.ascorbic-bulk-purchase-row {
		--ascorbic-bulk-status-gap: 6px;
		grid-template-columns: minmax(0, 1fr) max-content;
		column-gap: 10px;
	}

	.ascorbic-bulk-selection {
		font-size: 12px;
	}

	.ascorbic-bulk-wallet {
		width: auto;
		justify-self: end;
		justify-content: flex-end;
		flex-wrap: nowrap;
		white-space: nowrap;
	}

	.ascorbic-bulk-wallet-pair {
		gap: 10px;
	}

	.ascorbic-bulk-warning {
		white-space: normal;
		overflow: visible;
		text-overflow: clip;
	}

	/* Keep both actions in stable, equal slots on narrow modules. */
	.ascorbic-bulk-buy-coins {
		grid-column: 1;
		width: 100%;
		min-width: 0;
	}

	.ascorbic-bulk-submit {
		grid-column: 2;
		width: 100%;
		min-width: 0;
	}
}

/* Preserve the same one-row header even on compact phone widths. */
@container ascorbic-bulk (max-width: 390px) {
	.ascorbic-bulk-topline {
		gap: 5px;
	}

	.ascorbic-bulk-title strong {
		font-size: 12px;
	}

	.ascorbic-bulk-quick {
		gap: 2px;
	}

	.ascorbic-bulk-quick > span {
		font-size: 8px;
	}

	.ascorbic-bulk-quick button {
		min-width: 27px;
		padding: 3px 5px;
		font-size: 10px;
	}

	.ascorbic-bulk-quick .ascorbic-bulk-clear {
		min-width: 36px;
	}
}

/* On truly narrow modules, stack both actions. Each remains full-width before and after Coin Shop toggles. */
@container ascorbic-bulk (max-width: 340px) {
	.ascorbic-bulk-topline {
		gap: 3px;
	}

	.ascorbic-bulk-title strong {
		font-size: 11px;
		letter-spacing: -0.1px;
	}

	.ascorbic-bulk-quick > span {
		font-size: 7px;
	}

	.ascorbic-bulk-quick button {
		min-width: 24px;
		padding: 2px 4px;
		font-size: 9.5px;
	}

	.ascorbic-bulk-quick .ascorbic-bulk-clear {
		min-width: 32px;
	}

	.ascorbic-bulk-purchase-row {
		--ascorbic-bulk-status-gap: 5px;
		column-gap: 7px;
	}

	.ascorbic-bulk-selection {
		font-size: 11px;
	}

	.ascorbic-bulk-wallet {
		font-size: 10px;
	}

	.ascorbic-bulk-wallet strong {
		font-size: 11px;
	}

	.ascorbic-bulk-wallet-pair {
		gap: 7px;
	}

	.ascorbic-bulk-warning {
		font-size: 10px;
	}

	.ascorbic-bulk-actions {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.ascorbic-bulk-buy-coins,
	.ascorbic-bulk-submit {
		width: 100%;
		min-width: 0;
	}
}

@media (max-width: 480px) {
	.reverse-order-row {
		gap: 6px 14px;
	}

	.ascorbic-bulk-buy {
		padding: 11px 12px;
		border-radius: 10px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.reverse-order-row .ascorbic-bulk-plus {
		transition: none;
	}
}
