/* Puzzle Box V1 by CraftBook Magazine
   Phase 1 stylesheet: stage frame, dormant cube preview, title bar.
   Later phases extend this file; class prefix pbx- throughout. */

.pbx-stage {
	position: relative;
	width: 100%;
	height: var(--pbx-height, 78vh);
	min-height: 380px;
	background: var(--pbx-bg, #0b0e17);
	border-radius: 10px;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	user-select: none;
	-webkit-user-select: none;
	touch-action: none;
}

.pbx-stage.pbx-has-bg-image {
	background-image: var(--pbx-bg-image);
	background-size: cover;
	background-position: center;
}

.pbx-stage.pbx-fullscreen {
	position: fixed;
	top: 0; right: 0; bottom: 0; left: 0;
	inset: 0;
	z-index: 99999;
	height: 100vh;
	height: 100dvh;
	border-radius: 0;
}

.pbx-viewport {
	position: relative;
	flex: 1 1 auto;
	overflow: hidden;
	perspective: 1400px;
	perspective-origin: 50% 45%;
}

.pbx-noscript {
	color: #cfd6e4;
	text-align: center;
	padding: 2em;
}

/* Title bar */
.pbx-titlebar {
	flex: 0 0 auto;
	text-align: center;
	padding: 8px 12px;
	font-size: 12px;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: rgba(220, 230, 245, 0.55);
	background: rgba(0, 0, 0, 0.25);
}

/* Phase 1 dormant cube preview (replaced by the full engine in Phase 2) */
.pbx-dormant {
	position: absolute;
	top: 0; right: 0; bottom: 0; left: 0;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	gap: 28px;
}

.pbx-dormant-cube {
	width: min(38vmin, 240px);
	height: min(38vmin, 240px);
	position: relative;
	transform: rotateX(18deg) rotateZ(45deg) scale(0.9);
	transform-style: preserve-3d;
}

.pbx-dormant-face {
	position: absolute;
	top: 0; right: 0; bottom: 0; left: 0;
	inset: 0;
	border-radius: 6px;
	background:
		linear-gradient(135deg, #3a4152 0%, #232838 45%, #444d63 60%, #1c2130 100%);
	box-shadow:
		inset 0 0 0 1px rgba(255, 255, 255, 0.06),
		0 0 40px rgba(0, 0, 0, 0.55);
}

.pbx-dormant-face::after {
	content: "";
	position: absolute;
	inset: 12%;
	border: 1px solid var(--pbx-accent, #7fd4ff);
	border-radius: 4px;
	opacity: 0.35;
	box-shadow: 0 0 12px var(--pbx-accent, #7fd4ff);
	animation: pbx-etch-pulse 3.8s ease-in-out infinite;
}

@keyframes pbx-etch-pulse {
	0%, 100% { opacity: 0.22; }
	50%      { opacity: 0.55; }
}

.pbx-begin {
	appearance: none;
	border: 1px solid var(--pbx-accent, #7fd4ff);
	background: rgba(10, 14, 24, 0.7);
	color: #e8f2ff;
	font-size: 15px;
	letter-spacing: 0.18em;
	text-transform: uppercase;
	padding: 12px 34px;
	min-height: 44px;
	border-radius: 999px;
	cursor: pointer;
	transition: box-shadow 0.25s ease, transform 0.25s ease;
}

.pbx-begin:hover,
.pbx-begin:focus-visible {
	box-shadow: 0 0 18px var(--pbx-accent, #7fd4ff);
	transform: translateY(-1px);
	outline: none;
}

.pbx-begin:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 3px;
}

/* Small screens */
@media (max-width: 600px) {
	.pbx-stage { min-height: 320px; border-radius: 0; }
	.pbx-titlebar { font-size: 10px; }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
	.pbx-dormant-face::after { animation: none; opacity: 0.4; }
	.pbx-begin { transition: none; }
}

/* ==================================================================== */
/* Phase 2: cube, camera and HUD                                        */
/* ==================================================================== */

.pbx-scene {
	position: absolute;
	top: 0; right: 0; bottom: 0; left: 0;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	transform-style: preserve-3d;
	will-change: transform;
}

.pbx-cube3d {
	width: var(--pbx-cube, 300px);
	height: var(--pbx-cube, 300px);
	position: relative;
	transform-style: preserve-3d;
	will-change: transform;
}

.pbx-face {
	position: absolute;
	top: 0; right: 0; bottom: 0; left: 0;
	inset: 0;
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
}

.pbx-face svg {
	width: 100%;
	height: 100%;
	display: block;
	border-radius: 6px;
}

/* Etched-line glow, scaled by quality tier */
.pbx-etch { filter: drop-shadow(0 0 6px var(--pbx-accent, #7fd4ff)); }
.pbx-stage[data-quality="balanced"] .pbx-etch { filter: drop-shadow(0 0 3px var(--pbx-accent, #7fd4ff)); }
.pbx-stage[data-quality="lite"] .pbx-etch { filter: none; }

/* HUD */
.pbx-hud {
	position: absolute;
	left: 50%;
	bottom: 44px;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 14px;
	border-radius: 999px;
	background: rgba(8, 12, 22, 0.62);
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	border: 1px solid rgba(255, 255, 255, 0.09);
	z-index: 5;
}

.pbx-stage[data-quality="lite"] .pbx-hud {
	backdrop-filter: none;
	-webkit-backdrop-filter: none;
	background: rgba(8, 12, 22, 0.85);
}

.pbx-btn {
	appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	border: 1px solid rgba(255, 255, 255, 0.14);
	background: rgba(255, 255, 255, 0.05);
	color: #dfe9f7;
	cursor: pointer;
	transition: background 0.2s ease, box-shadow 0.2s ease;
	padding: 0;
}

.pbx-btn:hover { background: rgba(255, 255, 255, 0.13); }
.pbx-btn:focus-visible {
	outline: 2px solid var(--pbx-accent, #7fd4ff);
	outline-offset: 2px;
}
.pbx-btn:active { box-shadow: 0 0 12px var(--pbx-accent, #7fd4ff) inset; }

.pbx-zoom-slider {
	appearance: none;
	-webkit-appearance: none;
	width: 130px;
	height: 4px;
	border-radius: 2px;
	background: rgba(255, 255, 255, 0.22);
	cursor: pointer;
	margin: 0 2px;
}
.pbx-zoom-slider::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: var(--pbx-accent, #7fd4ff);
	border: 2px solid #0b0e17;
	box-shadow: 0 0 8px var(--pbx-accent, #7fd4ff);
}
.pbx-zoom-slider::-moz-range-thumb {
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: var(--pbx-accent, #7fd4ff);
	border: 2px solid #0b0e17;
	box-shadow: 0 0 8px var(--pbx-accent, #7fd4ff);
}
.pbx-zoom-slider:focus-visible {
	outline: 2px solid var(--pbx-accent, #7fd4ff);
	outline-offset: 4px;
}

/* Gesture hint */
.pbx-gesture-hint {
	position: absolute;
	left: 50%;
	top: 20px;
	transform: translateX(-50%);
	padding: 8px 18px;
	border-radius: 999px;
	background: rgba(8, 12, 22, 0.6);
	color: rgba(223, 233, 247, 0.85);
	font-size: 13px;
	letter-spacing: 0.04em;
	pointer-events: none;
	transition: opacity 1s ease;
	z-index: 5;
}
.pbx-gesture-hint.pbx-hide { opacity: 0; }

/* Viewport focus and cursor */
.pbx-viewport { cursor: grab; outline: none; }
.pbx-viewport:active { cursor: grabbing; }
.pbx-viewport:focus-visible {
	box-shadow: inset 0 0 0 2px var(--pbx-accent, #7fd4ff);
}

/* Scroll lock for the CSS fullscreen fallback */
.pbx-noscroll, .pbx-noscroll body { overflow: hidden !important; }

/* Native fullscreen sizing */
.pbx-stage:fullscreen { width: 100%; height: 100%; border-radius: 0; }
.pbx-stage:-webkit-full-screen { width: 100%; height: 100%; border-radius: 0; }

/* Small screens: compact HUD */
@media (max-width: 600px) {
	.pbx-hud { bottom: 38px; gap: 6px; padding: 6px 10px; }
	.pbx-zoom-slider { width: 84px; }
	.pbx-gesture-hint { font-size: 11px; top: 12px; }
}

/* Landscape phones: HUD moves to the right edge, vertical */
@media (max-height: 460px) and (orientation: landscape) {
	.pbx-hud {
		left: auto;
		right: 14px;
		bottom: 50%;
		transform: translateY(50%);
		flex-direction: column;
		padding: 12px 8px;
	}
	.pbx-zoom-slider { width: 84px; transform: rotate(-90deg); margin: 34px 0; }
}

@media (prefers-reduced-motion: reduce) {
	.pbx-gesture-hint { transition: none; }
	.pbx-btn { transition: none; }
}

/* ==================================================================== */
/* Phase 3: engine, chapter UI, hints, overlay, transformation          */
/* ==================================================================== */

.pbx-begin-secondary {
	font-size: 12px;
	padding: 8px 22px;
	opacity: 0.75;
	border-color: rgba(255, 255, 255, 0.25);
}

/* Topbar: chapter label and progress pips */
.pbx-topbar {
	position: absolute;
	top: 14px;
	left: 16px;
	right: 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	pointer-events: none;
	z-index: 5;
}
.pbx-chapter-label {
	color: rgba(230, 238, 250, 0.85);
	font-size: 14px;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}
.pbx-pips { display: flex; gap: 7px; }
.pbx-pip {
	width: 9px; height: 9px;
	border-radius: 50%;
	border: 1px solid rgba(230, 238, 250, 0.5);
	background: transparent;
}
.pbx-pip-now {
	border-color: var(--pbx-accent, #7fd4ff);
	box-shadow: 0 0 8px var(--pbx-accent, #7fd4ff);
}
.pbx-pip-done { background: var(--pbx-accent, #7fd4ff); border-color: var(--pbx-accent, #7fd4ff); }

/* Toast */
.pbx-toast {
	position: absolute;
	left: 50%;
	bottom: 108px;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 12px;
	max-width: min(86%, 460px);
	padding: 10px 18px;
	border-radius: 14px;
	background: rgba(8, 12, 22, 0.82);
	border: 1px solid rgba(255, 255, 255, 0.12);
	color: rgba(230, 238, 250, 0.92);
	font-size: 14px;
	line-height: 1.45;
	z-index: 6;
	transition: opacity 0.4s ease, transform 0.4s ease;
}
.pbx-toast.pbx-hidden {
	opacity: 0;
	transform: translateX(-50%) translateY(8px);
	pointer-events: none;
}
.pbx-toast-btn {
	appearance: none;
	flex: 0 0 auto;
	border: 1px solid var(--pbx-accent, #7fd4ff);
	background: transparent;
	color: var(--pbx-accent, #7fd4ff);
	border-radius: 999px;
	padding: 6px 16px;
	min-height: 34px;
	font-size: 13px;
	cursor: pointer;
}
.pbx-toast-btn:hover { background: rgba(127, 212, 255, 0.12); }
.pbx-toast-btn:focus-visible { outline: 2px solid var(--pbx-accent, #7fd4ff); outline-offset: 2px; }

/* Chapter complete overlay */
.pbx-overlay {
	position: absolute;
	top: 0; right: 0; bottom: 0; left: 0;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(4, 6, 12, 0.66);
	z-index: 8;
	transition: opacity 0.35s ease;
}
.pbx-overlay.pbx-hidden { opacity: 0; pointer-events: none; }
.pbx-panel {
	text-align: center;
	background: rgba(12, 17, 30, 0.94);
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 18px;
	padding: 30px 40px 28px;
	max-width: min(88%, 400px);
	box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}
.pbx-panel-kicker {
	font-size: 11px;
	letter-spacing: 0.28em;
	text-transform: uppercase;
	color: var(--pbx-accent, #7fd4ff);
	margin-bottom: 6px;
}
.pbx-panel-title {
	margin: 0 0 10px;
	font-family: Georgia, "Times New Roman", serif;
	font-weight: 400;
	font-size: 24px;
	color: #eef4fc;
}
.pbx-stars { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; }
.pbx-stats {
	display: flex;
	justify-content: center;
	gap: 26px;
	margin-bottom: 22px;
}
.pbx-stats > div { display: flex; flex-direction: column; gap: 2px; }
.pbx-stat-n { font-size: 20px; color: #eef4fc; font-variant-numeric: tabular-nums; }
.pbx-stat-l { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(230, 238, 250, 0.55); }
.pbx-continue {
	appearance: none;
	border: 1px solid var(--pbx-accent, #7fd4ff);
	background: rgba(127, 212, 255, 0.1);
	color: #eef4fc;
	font-size: 14px;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	padding: 12px 36px;
	min-height: 44px;
	border-radius: 999px;
	cursor: pointer;
}
.pbx-continue:hover { box-shadow: 0 0 16px var(--pbx-accent, #7fd4ff); }
.pbx-continue:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

/* Mechanism affordances */
.pbx-mech { touch-action: none; }
.pbx-hint-pulse { animation: pbx-hint 1.1s ease-in-out infinite; }
@keyframes pbx-hint {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.35; }
}
.pbx-seal-ready { animation: pbx-seal 2.2s ease-in-out infinite; }
@keyframes pbx-seal {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.72; }
}

/* Transformation choreography */
.pbx-anim-faces .pbx-face {
	transition: transform 0.75s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.75s ease;
}
.pbx-waking .pbx-etch {
	animation: pbx-surge 0.85s ease-in-out;
}
@keyframes pbx-surge {
	0% { opacity: 0.4; }
	60% { opacity: 1; }
	100% { opacity: 0.8; }
}
.pbx-flash {
	position: absolute;
	top: 0; right: 0; bottom: 0; left: 0;
	inset: 0;
	background: radial-gradient(circle at 50% 46%, var(--pbx-accent, #7fd4ff) 0%, transparent 62%);
	opacity: 0;
	pointer-events: none;
	z-index: 7;
	transition: opacity 0.5s ease;
}
.pbx-flash-on { opacity: 0.5; }
.pbx-fade-swap .pbx-cube3d { transition: opacity 0.4s ease; opacity: 0.15; }

@media (max-width: 600px) {
	.pbx-chapter-label { font-size: 11px; }
	.pbx-toast { bottom: 96px; font-size: 13px; }
	.pbx-panel { padding: 22px 24px 20px; }
	.pbx-stats { gap: 18px; }
}
@media (prefers-reduced-motion: reduce) {
	.pbx-hint-pulse, .pbx-seal-ready { animation: none; }
	.pbx-waking .pbx-etch { animation: none; }
	.pbx-toast { transition: none; }
}

/* ==================================================================== */
/* Phase 4: gear spin animations for the Harmonic Vault                 */
/* ==================================================================== */
.pbx-spin { animation-name: pbx-rot; animation-timing-function: linear; animation-iteration-count: infinite; }
.pbx-spin-rev { animation-name: pbx-rot-rev; animation-timing-function: linear; animation-iteration-count: infinite; }
@keyframes pbx-rot { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes pbx-rot-rev { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }
.pbx-stage[data-quality="lite"] .pbx-spin,
.pbx-stage[data-quality="lite"] .pbx-spin-rev { animation-duration: 24s !important; }
@media (prefers-reduced-motion: reduce) {
	.pbx-spin, .pbx-spin-rev { animation: none; }
}

/* ==================================================================== */
/* Phase 6: intro cinematic, finale reveals, audio panel, leaderboard   */
/* ==================================================================== */

/* Intro: the cube descends from darkness while the etches ignite */
.pbx-intro .pbx-cube3d { animation: pbx-descend 2.4s cubic-bezier(0.22, 0.8, 0.3, 1); }
.pbx-intro .pbx-etch { animation: pbx-ignite 2.4s ease-out; }
@keyframes pbx-descend {
	0% { opacity: 0; margin-top: -14%; }
	45% { opacity: 1; }
	100% { opacity: 1; margin-top: 0; }
}
@keyframes pbx-ignite {
	0%, 35% { opacity: 0; }
	70% { opacity: 1; }
	100% { opacity: 0.85; }
}

/* Audio panel */
.pbx-audio-panel {
	position: absolute;
	left: 50%;
	bottom: 108px;
	transform: translateX(-50%);
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 14px 18px;
	border-radius: 14px;
	background: rgba(8, 12, 22, 0.92);
	border: 1px solid rgba(255, 255, 255, 0.12);
	color: rgba(230, 238, 250, 0.9);
	font-size: 13px;
	z-index: 7;
	transition: opacity 0.25s ease;
}
.pbx-audio-panel.pbx-hidden { opacity: 0; pointer-events: none; }
.pbx-ap-row { display: flex; align-items: center; gap: 10px; min-height: 28px; cursor: pointer; }
.pbx-ap-row input[type="range"] { width: 130px; accent-color: var(--pbx-accent, #7fd4ff); }
.pbx-ap-row input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--pbx-accent, #7fd4ff); }

/* Leaderboard */
.pbx-board { margin-bottom: 20px; }
.pbx-board-title {
	font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase;
	color: rgba(230, 238, 250, 0.55); margin-bottom: 8px;
}
.pbx-board-row {
	display: flex; justify-content: center; gap: 14px;
	font-size: 14px; color: #dfe9f7; padding: 4px 0;
	font-variant-numeric: tabular-nums;
}
.pbx-board-diff { text-transform: capitalize; color: rgba(230, 238, 250, 0.6); }
.pbx-board-empty { color: rgba(230, 238, 250, 0.6); font-size: 13px; }
.pbx-board-mini { margin-top: 4px; }

/* Finale */
.pbx-finale { max-width: min(92%, 440px); max-height: 92%; overflow-y: auto; }
.pbx-reveal-wrap { display: flex; justify-content: center; margin: 4px 0 10px; }
.pbx-reveal { width: min(58vmin, 240px); height: auto; }
.pbx-finale-msg {
	font-family: Georgia, "Times New Roman", serif;
	font-size: 17px; line-height: 1.55; color: #eef4fc;
	margin: 0 0 12px; white-space: pre-line;
}
.pbx-finale-link {
	display: inline-block;
	margin-bottom: 16px;
	color: var(--pbx-accent, #7fd4ff);
	border: 1px solid var(--pbx-accent, #7fd4ff);
	border-radius: 999px;
	padding: 9px 24px;
	min-height: 40px;
	text-decoration: none;
	font-size: 14px;
	letter-spacing: 0.08em;
}
.pbx-finale-link:hover { box-shadow: 0 0 14px var(--pbx-accent, #7fd4ff); }

.pbx-orb-spin { animation: pbx-rot 30s linear infinite; }
.pbx-twinkle { animation: pbx-twinkle 3.4s ease-in-out infinite; }
@keyframes pbx-twinkle {
	0%, 100% { opacity: 0.25; }
	50% { opacity: 1; }
}
.pbx-petal { animation: pbx-bloom 1.6s cubic-bezier(0.34, 1.3, 0.5, 1) both; }
@keyframes pbx-bloom {
	0% { opacity: 0; transform: rotate(var(--pbx-petal-a, 0deg)) scale(0.2); }
	100% { opacity: 1; transform: rotate(var(--pbx-petal-a, 0deg)) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	.pbx-intro .pbx-cube3d, .pbx-intro .pbx-etch { animation: none; }
	.pbx-orb-spin, .pbx-twinkle, .pbx-petal { animation: none; }
	.pbx-audio-panel { transition: none; }
}

/* ==================================================================== */
/* 1.0.1: genuine duplicate shortcode instances render as a quiet note  */
/* ==================================================================== */
.pbx-stage-duplicate {
	height: auto;
	min-height: 0;
	padding: 1em 1.4em;
	background: rgba(11, 14, 23, 0.6);
}
.pbx-duplicate-note {
	color: rgba(220, 230, 245, 0.7);
	font-size: 13px;
	margin: 0;
	text-align: center;
}
