/*
 * 1問ずつの舞台（診断・検定）。assets/js/games-stage.js
 *
 * プラグインのフォームの中に、画面いっぱいの舞台を重ねる（フォームの中に置くので、答えはそのまま送られる）。
 * 問題はカード1枚・選択肢は押しボタン（左に番号のキー）・二択は左右の「どっち？」。
 * 検定の答え合わせは下から出るシート（正解＝緑・不正解＝赤）。種類の色は --ga-c（札の色）だけ。
 * ルートの文字サイズは 62.5%（1rem = 10px）なので px で書く。
 */

/* プラグインの前置きと進み具合は、タイトル画面と舞台が引き受ける */
.gst-form .lp-diagnosis-form__intro,
.gst-form .lp-diagnosis-form__body {
	display: none !important;
}
.gst-host {
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
}
html.gst-open,
html.gst-open body {
	overflow: hidden !important;
}
html.gst-open .gp-nav,
html.gst-open .gp-notice {
	visibility: hidden;
}

.gst {
	--gst-ink: #1d1813;
	--gst-text: #2b2620;
	--gst-muted: #6f6052;
	--gst-line: #e8e1d4;
	--gst-paper: #fff;
	--gst-ground: #fff4e1;
	--gst-accent: #ff5b00;
	--gst-ok: #1e7a45;
	--gst-ok-soft: #e3f5ea;
	--gst-ng: #c0341d;
	--gst-ng-soft: #fdebe7;
	--gst-num: "Din1451Alt", "Bahnschrift", "DIN Alternate", "Arial Narrow", system-ui, sans-serif;
	--gst-brandfont: var(--font-site-brand, "linuxPro-CPL"), "Hiragino Sans", "Noto Sans JP", sans-serif;
	--gst-pop: cubic-bezier(0.2, 1.5, 0.4, 1);
	position: fixed;
	inset: 0;
	z-index: 100020;
	display: grid;
	grid-template-rows: auto auto minmax(0, 1fr) auto;
	overflow: hidden;
	background:
		radial-gradient(circle at 50% -20%, color-mix(in srgb, var(--ga-c) 22%, transparent), transparent 55%),
		linear-gradient(rgba(29, 24, 19, 0.035) 1px, transparent 1px) 0 0 / 28px 28px,
		linear-gradient(90deg, rgba(29, 24, 19, 0.035) 1px, transparent 1px) 0 0 / 28px 28px,
		var(--gst-ground);
	color: var(--gst-text);
	font: 400 16px/1.7 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
	padding-bottom: env(safe-area-inset-bottom, 0px);
	animation: gst-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.gst[hidden] {
	display: none;
}
@keyframes gst-in {
	from { opacity: 0; transform: scale(1.02); }
}
.gst *,
.gst *::before,
.gst *::after {
	box-sizing: border-box;
}
.gst :where(p, ol, li) {
	margin: 0;
	padding: 0;
}
.gst ol {
	list-style: none;
}
.gst [hidden] {
	display: none !important;
}
.gst :where(button):focus-visible {
	outline: 3px solid var(--gst-accent);
	outline-offset: 3px;
}

/* ---------- 上の帯 ---------- */

.gst-bar {
	position: relative;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 10px;
}
.gst-quit {
	flex: none;
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 3px solid var(--gst-ink);
	border-radius: 50%;
	background: var(--gst-paper);
	color: var(--gst-ink);
	cursor: pointer;
	box-shadow: 0 3px 0 var(--gst-ink);
	transition: transform 0.12s ease;
}
.gst-quit:active {
	transform: translateY(2px);
	box-shadow: 0 1px 0 var(--gst-ink);
}
/* 音のボタン（games-sound.js） */
.gst-sound {
	flex: none;
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 2px solid var(--gst-ink);
	border-radius: 50%;
	background: var(--gst-paper);
	color: var(--gst-muted);
	cursor: pointer;
}
.gst-sound[aria-pressed="true"] {
	background: var(--gst-ink);
	color: #ffd84d;
}
.gst-track {
	flex: 1;
	display: flex;
	gap: 4px;
	min-width: 0;
}
.gst-track li {
	flex: 1;
	height: 10px;
	border: 2px solid var(--gst-ink);
	border-radius: 999px;
	background: var(--gst-paper);
	transition: background-color 0.25s ease, transform 0.25s var(--gst-pop);
}
.gst-track li.is-done {
	background: var(--ga-c);
}
.gst-track li.is-right {
	background: var(--gst-ok);
}
.gst-track li.is-wrong {
	background: var(--gst-ng);
}
.gst-track li.is-current {
	transform: scaleY(1.45);
}
.gst-count {
	flex: none;
	font: 400 22px/1 var(--gst-num);
	color: var(--gst-ink);
	font-variant-numeric: tabular-nums;
}
.gst-count span {
	font-size: 15px;
	color: var(--gst-muted);
}
.gst-score {
	flex: none;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 10px 3px;
	border: 2px solid var(--gst-ink);
	border-radius: 999px;
	background: var(--gst-ok);
	color: #fff;
	font: 400 18px/1 var(--gst-num);
}
.gst-combo {
	flex: none;
	display: inline-flex;
	align-items: baseline;
	gap: 4px;
	padding: 5px 10px 4px;
	border: 2px solid var(--gst-ink);
	border-radius: 10px;
	background: var(--gst-ink);
	color: #ffd84d;
	font: 400 20px/1 var(--gst-num);
	transform: rotate(-4deg);
}
.gst-combo span {
	font-size: 11px;
	letter-spacing: 0.12em;
	color: #ffb071;
}
.is-bump {
	animation: gst-bump 0.4s var(--gst-pop);
}
@keyframes gst-bump {
	40% { transform: scale(1.35) rotate(-6deg); }
}
.gst-time {
	position: absolute;
	left: 16px;
	right: 16px;
	bottom: 0;
	height: 4px;
	border-radius: 999px;
	background: rgba(29, 24, 19, 0.12);
}
.gst-time__fill {
	position: absolute;
	inset: 0;
	border-radius: inherit;
	background: var(--gst-ink);
	transform-origin: left;
	transition: transform 0.25s linear;
}
.gst-time b {
	position: absolute;
	right: 0;
	top: 8px;
	font: 400 15px/1 var(--gst-num);
	color: var(--gst-ink);
	font-variant-numeric: tabular-nums;
}
.gst-time.is-warn .gst-time__fill {
	background: var(--gst-ng);
}
.gst-time.is-warn b {
	color: var(--gst-ng);
	animation: gst-beat 1s ease-in-out infinite;
}
@keyframes gst-beat {
	50% { transform: scale(1.18); }
}
.gst-name {
	padding: 6px 16px 0;
	text-align: center;
	font: 700 13px/1.4 var(--gst-brandfont);
	color: var(--gst-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* ---------- 問題カード ---------- */

.gst-deck {
	display: grid;
	align-items: center;
	justify-items: center;
	min-height: 0;
	overflow-y: auto;
	padding: 14px 16px 18px;
	overscroll-behavior: contain;
}
.gst .lp-diagnosis-step.gst-q {
	width: 100%;
	max-width: 780px;
	margin: 0;
	padding: clamp(20px, 3.4vw, 34px);
	border: 3px solid var(--gst-ink);
	border-radius: 26px;
	background: var(--gst-paper);
	box-shadow: 8px 8px 0 var(--gst-ink);
	min-inline-size: 0;
}
.gst .lp-diagnosis-step__head {
	display: grid;
	gap: 6px;
	margin: 0 0 6px;
}
.gst .lp-diagnosis-step__index {
	justify-self: start;
	margin: 0;
	padding: 4px 12px 3px;
	border: 2px solid var(--gst-ink);
	border-radius: 999px;
	background: var(--ga-c);
	color: var(--ga-on);
	font: 400 16px/1 var(--gst-num);
	letter-spacing: 0.08em;
}
.gst .lp-diagnosis-step__question {
	float: none;
	width: 100%;
	margin: 0;
	padding: 0;
	font: 700 clamp(20px, 3.2vw, 28px)/1.45 var(--gst-brandfont);
	color: var(--gst-ink);
	text-wrap: balance;
}
.gst .lp-exam-step__meta {
	margin: 4px 0 0;
	font-size: 12px;
	color: var(--gst-muted);
}
.gst .lp-diagnosis-step__description {
	margin: 4px 0 0;
	font-size: 14px;
	color: var(--gst-muted);
}
.gst .lp-diagnosis-step__choices {
	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 12px;
	max-width: none;
	margin-top: 20px;
}
/* 二択は左右（「どっち？」） */
.gst .is-vs .lp-diagnosis-step__choices {
	grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
	gap: 18px;
}
.gst .is-vs .lp-diagnosis-step__choices::before {
	content: "or";
	position: absolute;
	top: 50%;
	left: 50%;
	z-index: 2;
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	border: 3px solid var(--gst-ink);
	border-radius: 50%;
	background: var(--gst-ink);
	color: #ffb071;
	font: 400 15px/1 var(--gst-num);
	transform: translate(-50%, -50%);
	pointer-events: none;
}
@media (max-width: 560px) {
	.gst .is-vs .lp-diagnosis-step__choices {
		grid-template-columns: minmax(0, 1fr);
		gap: 22px;
	}
}

/* 選択肢＝押しボタン */
.gst .lp-choice {
	position: relative;
	display: flex;
	align-items: center;
	gap: 14px;
	min-height: 64px;
	margin: 0;
	padding: 14px 18px 14px 14px;
	overflow: hidden;
	border: 3px solid var(--gst-ink);
	border-radius: 18px;
	background: var(--gst-paper);
	color: var(--gst-ink);
	font-weight: 700;
	line-height: 1.55;
	cursor: pointer;
	box-shadow: 0 5px 0 var(--gst-ink);
	transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.18s ease;
	-webkit-tap-highlight-color: transparent;
}
.gst .is-vs .lp-choice {
	flex-direction: column;
	justify-content: center;
	min-height: 150px;
	padding: 22px 18px;
	text-align: center;
}
.gst .lp-choice:hover {
	transform: translateY(-2px);
	box-shadow: 0 7px 0 var(--gst-ink);
}
.gst .lp-choice:active {
	transform: translateY(4px);
	box-shadow: 0 1px 0 var(--gst-ink);
}
.gst .lp-choice input[type="radio"] {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
	margin: 0;
	pointer-events: none;
}
.gst .lp-choice:has(input:focus-visible) {
	outline: 3px solid var(--gst-accent);
	outline-offset: 3px;
}
.gst-key {
	flex: none;
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	border: 2px solid var(--gst-ink);
	border-radius: 9px;
	background: var(--gst-ground);
	box-shadow: 0 2px 0 var(--gst-ink);
	font: 400 18px/1 var(--gst-num);
	color: var(--gst-ink);
}
.gst .lp-choice__label {
	min-width: 0;
}
/* 押した波紋 */
.gst .lp-choice::after {
	content: "";
	position: absolute;
	left: var(--x, 50%);
	top: var(--y, 50%);
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background: var(--ga-c);
	opacity: 0;
	transform: translate(-50%, -50%) scale(1);
	pointer-events: none;
}
.gst .lp-choice.is-press::after {
	animation: gst-ripple 0.5s ease-out;
}
@keyframes gst-ripple {
	from { opacity: 0.45; transform: translate(-50%, -50%) scale(1); }
	to { opacity: 0; transform: translate(-50%, -50%) scale(46); }
}
.gst .lp-choice.is-picked {
	background: color-mix(in srgb, var(--ga-c) 20%, #fff);
}
.gst .lp-choice.is-picked .gst-key {
	background: var(--ga-c);
	color: var(--ga-on);
}
/* 答え合わせ */
.gst .is-locked .lp-choice {
	cursor: default;
}
.gst .is-locked .lp-choice:not(.is-picked):not(.is-answer) {
	opacity: 0.55;
}
.gst .lp-choice.is-checking .gst-key {
	animation: gst-spin 0.8s linear infinite;
}
@keyframes gst-spin {
	to { transform: rotate(360deg); }
}
.gst .lp-choice.is-right {
	background: var(--gst-ok-soft);
	border-color: var(--gst-ok);
	box-shadow: 0 5px 0 var(--gst-ok);
	animation: gst-right 0.45s var(--gst-pop);
}
.gst .lp-choice.is-right .gst-key {
	background: var(--gst-ok);
	border-color: var(--gst-ok);
	color: #fff;
	font-size: 0;
}
.gst .lp-choice.is-right .gst-key::before {
	content: "";
	width: 18px;
	height: 18px;
	background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}
@keyframes gst-right {
	40% { transform: scale(1.04); }
}
.gst .lp-choice.is-wrong {
	background: var(--gst-ng-soft);
	border-color: var(--gst-ng);
	box-shadow: 0 5px 0 var(--gst-ng);
	animation: gst-shake 0.42s ease;
}
.gst .lp-choice.is-wrong .gst-key {
	background: var(--gst-ng);
	border-color: var(--gst-ng);
	color: #fff;
}
@keyframes gst-shake {
	20% { transform: translateX(-8px); }
	40% { transform: translateX(7px); }
	60% { transform: translateX(-5px); }
	80% { transform: translateX(3px); }
}
.gst .lp-choice.is-answer {
	opacity: 1 !important;
	border-color: var(--gst-ok);
	box-shadow: 0 5px 0 var(--gst-ok), 0 0 0 4px color-mix(in srgb, var(--gst-ok) 30%, transparent);
	animation: gst-glow 1.2s ease-in-out 2;
}
@keyframes gst-glow {
	50% { box-shadow: 0 5px 0 var(--gst-ok), 0 0 0 9px color-mix(in srgb, var(--gst-ok) 18%, transparent); }
}

/* ---------- 下 ---------- */

.gst-foot {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 14px;
	min-height: 54px;
	padding: 6px 16px 14px;
}
.gst-back {
	padding: 8px 14px;
	border: 2px solid var(--gst-ink);
	border-radius: 999px;
	background: var(--gst-paper);
	color: var(--gst-ink);
	font: inherit;
	font-size: 14px;
	font-weight: 700;
	cursor: pointer;
}
.gst-back:disabled {
	opacity: 0.35;
	cursor: default;
}
.gst-hint {
	font-size: 13px;
	color: var(--gst-muted);
}

/* 答え合わせのシート */
.gst-sheet {
	position: absolute;
	left: 50%;
	bottom: calc(14px + env(safe-area-inset-bottom, 0px));
	z-index: 5;
	display: grid;
	gap: 8px;
	width: min(780px, calc(100% - 24px));
	max-height: 55vh;
	overflow-y: auto;
	padding: 18px 20px 16px;
	border: 3px solid var(--gst-ink);
	border-radius: 22px;
	background: var(--gst-paper);
	box-shadow: 0 -6px 0 rgba(29, 24, 19, 0.08), 6px 6px 0 var(--gst-ink);
	transform: translateX(-50%);
}
.gst-sheet.is-in {
	animation: gst-sheet 0.36s var(--gst-pop) both;
}
@keyframes gst-sheet {
	from { opacity: 0; transform: translate(-50%, 40px); }
	to { opacity: 1; transform: translate(-50%, 0); }
}
.gst-sheet.is-right {
	border-color: var(--gst-ok);
	background: var(--gst-ok-soft);
}
.gst-sheet.is-wrong {
	border-color: var(--gst-ng);
	background: var(--gst-ng-soft);
}
.gst-sheet__verdict {
	font: 700 20px/1.4 var(--gst-brandfont);
}
.gst-sheet.is-right .gst-sheet__verdict {
	color: var(--gst-ok);
}
.gst-sheet.is-wrong .gst-sheet__verdict {
	color: var(--gst-ng);
}
.gst-sheet__why {
	font-size: 15px;
	color: var(--gst-text);
}
.gst-next {
	position: relative;
	justify-self: end;
	min-height: 48px;
	padding: 8px 30px;
	overflow: hidden;
	border: 3px solid var(--gst-ink);
	border-radius: 999px;
	background: var(--gst-ink);
	color: #fff;
	font: inherit;
	font-weight: 800;
	cursor: pointer;
	box-shadow: 0 4px 0 rgba(29, 24, 19, 0.35);
}
.gst-next i {
	position: absolute;
	left: 0;
	bottom: 0;
	height: 4px;
	width: 0;
	background: #5ad08a;
}
.gst-next i.is-run {
	animation: gst-auto 2.2s linear forwards;
}
@keyframes gst-auto {
	to { width: 100%; }
}

/* READY → GO */
.gst-splash {
	position: absolute;
	inset: 0;
	z-index: 8;
	display: grid;
	place-items: center;
	background: rgba(23, 18, 14, 0.82);
}
.gst-splash__word {
	font: 400 clamp(64px, 14vw, 140px)/1 var(--gst-num);
	letter-spacing: 0.12em;
	color: #fff;
	text-shadow: 6px 6px 0 var(--ga-c);
	animation: gst-word 0.5s var(--gst-pop) both;
}
.gst-splash__word.is-go {
	color: #ffd84d;
	text-shadow: 6px 6px 0 var(--gst-accent);
}
@keyframes gst-word {
	from { opacity: 0; transform: scale(2.2) rotate(-6deg); }
	to { opacity: 1; transform: scale(1) rotate(-3deg); }
}

/* 集計中 */
.gst-tally {
	position: absolute;
	inset: 0;
	z-index: 9;
	display: grid;
	place-content: center;
	justify-items: center;
	gap: 16px;
	padding: 24px;
	text-align: center;
	background: var(--gst-ground);
	animation: gst-in 0.3s ease both;
}
.gst-tally__ring {
	position: relative;
	width: 120px;
	height: 120px;
	border: 4px solid var(--gst-ink);
	border-radius: 50%;
	background: conic-gradient(var(--ga-c) 0 25%, transparent 25% 50%, var(--ga-c) 50% 75%, transparent 75%), var(--gst-paper);
	animation: gst-spin 1.1s linear infinite;
}
.gst-tally__ring i {
	position: absolute;
	inset: 18px;
	border: 4px solid var(--gst-ink);
	border-radius: 50%;
	background: var(--gst-ground);
}
.gst-tally__title {
	font: 700 22px/1.4 var(--gst-brandfont);
	color: var(--gst-ink);
}
.gst-tally__nums {
	font: 400 20px/1.3 var(--gst-num);
	color: var(--gst-muted);
}

/* やめますか？ */
.gst-confirm {
	position: absolute;
	inset: 0;
	z-index: 10;
	display: grid;
	place-items: center;
	padding: 24px;
	background: rgba(23, 18, 14, 0.55);
}
.gst-confirm__card {
	display: grid;
	gap: 8px;
	width: min(380px, 100%);
	padding: 22px;
	border: 3px solid var(--gst-ink);
	border-radius: 22px;
	background: var(--gst-paper);
	box-shadow: 6px 6px 0 var(--gst-ink);
	animation: gst-sheet-pop 0.3s var(--gst-pop) both;
}
@keyframes gst-sheet-pop {
	from { opacity: 0; transform: scale(0.92); }
}
.gst-confirm__h {
	font: 700 20px/1.4 var(--gst-brandfont);
	color: var(--gst-ink);
}
.gst-confirm__actions {
	display: flex;
	gap: 10px;
	justify-content: flex-end;
	margin-top: 8px;
}
.gst-btn {
	min-height: 46px;
	padding: 6px 20px;
	border: 3px solid var(--gst-ink);
	border-radius: 999px;
	background: var(--gst-accent);
	color: #fff;
	font: inherit;
	font-weight: 800;
	cursor: pointer;
}
.gst-btn--ghost {
	background: var(--gst-paper);
	color: var(--gst-ink);
}
.gst-sparks {
	position: absolute;
	inset: 0;
	z-index: 6;
	width: 100%;
	height: 100%;
	pointer-events: none;
}
.gst .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

@media (max-width: 560px) {
	.gst-bar {
		gap: 8px;
		padding-inline: 12px;
	}
	.gst-quit {
		width: 40px;
		height: 40px;
	}
	.gst .lp-choice {
		min-height: 58px;
		padding: 12px 14px 12px 12px;
	}
	.gst .is-vs .lp-choice {
		min-height: 104px;
	}
	.gst .lp-diagnosis-step.gst-q {
		box-shadow: 5px 5px 0 var(--gst-ink);
	}
}

@media (prefers-reduced-motion: reduce) {
	.gst,
	.gst *,
	.gst *::before,
	.gst *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}
