/**
 * Migrant Poll 前台樣式
 *
 * 顏色優先沿用 Blocksy 主題的調色盤變數，抓不到時才用後備值，
 * 所以換主題配色時投票會自動跟著變。字型完全繼承頁面。
 * 要微調的話，在「外觀 → 自訂 → 附加 CSS」覆寫下面 .mp-poll 裡的變數即可。
 */

.mp-poll {
	--mp-accent: var(--theme-palette-color-1, #1a6b8f);
	--mp-on-accent: #fff;
	--mp-radius: 8px;
	--mp-gap: 0.625rem;
	--mp-line: color-mix(in srgb, currentColor 18%, transparent);
	--mp-muted: color-mix(in srgb, currentColor 65%, transparent);
	--mp-hover: color-mix(in srgb, var(--mp-accent) 55%, transparent);
	--mp-fill: color-mix(in srgb, var(--mp-accent) 14%, transparent);
	--mp-fill-mine: color-mix(in srgb, var(--mp-accent) 28%, transparent);
	--mp-error: #b3261e;

	max-width: 640px;
	margin-inline: auto;
	text-align: start;
}

@supports not (color: color-mix(in srgb, red 50%, blue)) {
	.mp-poll {
		--mp-line: rgba(127, 127, 127, 0.35);
		--mp-muted: rgba(127, 127, 127, 1);
		--mp-hover: rgba(26, 107, 143, 0.55);
		--mp-fill: rgba(26, 107, 143, 0.14);
		--mp-fill-mine: rgba(26, 107, 143, 0.28);
	}
}

/* 載入中：先保留高度，避免版面跳動 */
.mp-poll.is-loading {
	min-height: 18rem;
}

.mp-poll__question {
	margin: 0 0 0.375em;
	line-height: 1.35;
}

.mp-poll__desc {
	margin: 0 0 1.25rem;
	color: var(--mp-muted);
	line-height: 1.7;
}

.mp-poll__question + .mp-poll__form,
.mp-poll__question + .mp-poll__results,
.mp-poll__question + .mp-poll__options {
	margin-top: 1.25rem;
}

.mp-poll__form {
	margin: 0;
}

/* ---------- 選項列（投票畫面與結果畫面共用同一個形狀） ---------- */

.mp-poll__options,
.mp-poll__results {
	display: grid;
	gap: var(--mp-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.mp-poll__option,
.mp-poll__result {
	position: relative;
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin: 0;
	padding: 0.875rem 1rem;
	border: 1px solid var(--mp-line);
	border-radius: var(--mp-radius);
	line-height: 1.5;
}

.mp-poll__option {
	cursor: pointer;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

.mp-poll__options.is-static .mp-poll__option {
	cursor: default;
}

.mp-poll__options:not(.is-static) .mp-poll__option:hover {
	border-color: var(--mp-hover);
}

.mp-poll__option.is-checked {
	border-color: var(--mp-accent);
	background-color: var(--mp-fill);
}

.mp-poll__radio:focus-visible {
	outline: 2px solid var(--mp-accent);
	outline-offset: 2px;
}

/* 支援 :has() 的瀏覽器：鍵盤操作時改成整列外框，滑鼠點擊不顯示 */
@supports selector(:has(*)) {
	.mp-poll__option:has(.mp-poll__radio:focus-visible) {
		outline: 2px solid var(--mp-accent);
		outline-offset: 2px;
	}

	.mp-poll__radio:focus-visible {
		outline: none;
	}
}

.mp-poll__radio {
	flex: none;
	width: 1.125rem;
	height: 1.125rem;
	margin: 0;
	accent-color: var(--mp-accent);
}

.mp-poll__label {
	flex: 1;
	min-width: 0;
	overflow-wrap: anywhere;
}

/* ---------- 結果 ---------- */

.mp-poll__results:focus {
	outline: none;
}

.mp-poll__result {
	overflow: hidden;
	isolation: isolate;
}

.mp-poll__bar {
	position: absolute;
	inset: 0 auto 0 0;
	z-index: -1;
	width: var(--mp-pct, 0%);
	background-color: var(--mp-fill);
	transition: width 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.mp-poll--reveal .mp-poll__bar {
	width: 0;
	transition: none;
}

.mp-poll__result.is-mine {
	border-color: var(--mp-accent);
}

.mp-poll__result.is-mine .mp-poll__bar {
	background-color: var(--mp-fill-mine);
}

.mp-poll__pct {
	flex: none;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

.mp-poll__mine {
	display: inline-block;
	margin-inline-start: 0.5em;
	padding: 0.05em 0.55em;
	border-radius: 999px;
	background-color: var(--mp-accent);
	color: var(--mp-on-accent);
	font-size: 0.75em;
	line-height: 1.6;
	vertical-align: 0.1em;
	white-space: nowrap;
}

/* ---------- 底部：按鈕、截止時間、連結 ---------- */

.mp-poll__footer {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem 1.25rem;
	margin-top: 1.25rem;
}

.mp-poll__submit {
	cursor: pointer;
}

.mp-poll__submit:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.mp-poll__meta {
	color: var(--mp-muted);
	font-size: 0.9em;
}

.mp-poll__link {
	padding: 0;
	border: 0;
	background: none;
	color: var(--mp-accent);
	font: inherit;
	font-size: 0.9em;
	text-decoration: underline;
	text-underline-offset: 0.2em;
	cursor: pointer;
}

.mp-poll__cta {
	margin-inline-start: auto;
	color: var(--mp-accent);
	font-weight: 600;
}

.mp-poll__link:focus-visible,
.mp-poll__cta:focus-visible,
.mp-poll__submit:focus-visible {
	outline: 2px solid var(--mp-accent);
	outline-offset: 3px;
}

.mp-poll__message {
	margin: 0.75rem 0 0;
	color: var(--mp-muted);
	font-size: 0.9em;
}

.mp-poll__message:empty {
	display: none;
}

.mp-poll__message.is-error {
	color: var(--mp-error);
}

/* ---------- 隱藏元素 ---------- */

.mp-poll__hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	opacity: 0;
}

.mp-poll__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* ---------- 小螢幕 ---------- */

@media (max-width: 480px) {
	.mp-poll__cta {
		margin-inline-start: 0;
		flex-basis: 100%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.mp-poll__bar,
	.mp-poll__option {
		transition: none;
	}
}
