/**
 * TGG Brag Button (Phase E4) — "Khoe chiến tích" CTA + modal + share card.
 *
 * Depends on `tgg-frontend` style — load AFTER frontend.css so the
 * .tgg-game-controls layout override (flex-end → space-between) wins via
 * source order.
 */

/* ===== Game controls bar (override frontend.css single-button layout) ===== */
.tgg-game-controls {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
	margin-top: 8px;
	flex-wrap: wrap;
}

/* ===== Brag button base ===== */
.tgg-brag-btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 10px 20px;
	border-radius: 24px;
	background: linear-gradient(135deg, #ff8c00, #ff5722);
	color: #fff;
	font-size: 14px;
	font-weight: 700;
	border: none;
	cursor: pointer;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
	position: relative;
	overflow: hidden;
}

.tgg-brag-btn:hover {
	transform: translateY(-2px);
	box-shadow: 0 6px 16px rgba(255, 87, 34, 0.4);
}

.tgg-brag-btn:active {
	transform: translateY(0);
}

.tgg-brag-icon {
	font-size: 18px;
}

/* Glow effect — pulse halo + shine sweep */
.tgg-brag-glow {
	box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.7);
	animation: tgg-brag-pulse 2s ease-in-out infinite;
}

.tgg-brag-glow::before {
	content: '';
	position: absolute;
	top: 0;
	left: -100%;
	width: 100%;
	height: 100%;
	background: linear-gradient(90deg,
		transparent,
		rgba(255, 255, 255, 0.4),
		transparent
	);
	animation: tgg-brag-shine 3s ease-in-out infinite;
	pointer-events: none;
}

@keyframes tgg-brag-pulse {
	0%, 100% { box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.7); }
	50%      { box-shadow: 0 0 0 12px rgba(255, 152, 0, 0); }
}

@keyframes tgg-brag-shine {
	0%        { left: -100%; }
	50%, 100% { left: 200%; }
}

@media (prefers-reduced-motion: reduce) {
	.tgg-brag-glow            { animation: none; }
	.tgg-brag-glow::before    { animation: none; display: none; }
	.tgg-brag-btn             { transition: none; }
}

@media (max-width: 480px) {
	/* Game controls: 2 buttons (brag + fullscreen) share one row, 50/50. */
	.tgg-game-controls {
		flex-direction: row;
		flex-wrap: nowrap;
		align-items: stretch;
		gap: 8px;
	}
	.tgg-game-controls .tgg-brag-btn,
	.tgg-game-controls .tgg-fullscreen-btn {
		flex: 1 1 0;
		width: auto;
		justify-content: center;
		padding: 10px 12px;
		font-size: 13px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	/* Modal share actions: 2 platform buttons share one row. */
	.tgg-brag-actions {
		flex-direction: row;
		flex-wrap: nowrap;
		gap: 8px;
	}
	.tgg-brag-share-btn {
		flex: 1 1 0;
		width: auto;
		padding: 12px 8px;
		font-size: 13px;
	}
	.tgg-brag-share-icon {
		font-size: 18px;
	}
}

/* Ultra-narrow: drop icons, shrink padding so text still fits. */
@media (max-width: 360px) {
	.tgg-game-controls .tgg-brag-btn,
	.tgg-game-controls .tgg-fullscreen-btn {
		padding: 9px 8px;
		font-size: 12px;
	}
	.tgg-game-controls .tgg-brag-icon {
		display: none;
	}
	.tgg-brag-share-btn {
		font-size: 12px;
	}
}

/* ===== Modal ===== */
.tgg-brag-modal {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.7);
	z-index: 9999;
	align-items: center;
	justify-content: center;
	padding: 20px;
}

.tgg-brag-modal.is-active {
	display: flex;
}

.tgg-brag-modal-content {
	background: #fff;
	border-radius: 12px;
	max-width: 500px;
	width: 100%;
	max-height: 90vh;
	overflow-y: auto;
	padding: 24px;
	position: relative;
	color: #1f2937;
}

.tgg-brag-modal-close {
	position: absolute;
	top: 12px;
	right: 12px;
	width: 32px;
	height: 32px;
	background: none;
	border: none;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	color: #666;
}

.tgg-brag-modal-close:hover { color: #111; }

.tgg-brag-modal h3 {
	margin: 0 0 16px;
	font-size: 20px;
}

.tgg-brag-intro {
	color: #6b7280;
	font-size: 14px;
	line-height: 1.5;
	margin: 0 0 18px;
}

.tgg-brag-required {
	color: #dc3545;
	margin-left: 2px;
}

.tgg-brag-form-group {
	margin-bottom: 14px;
}

.tgg-brag-form-group label {
	display: block;
	margin-bottom: 6px;
	font-weight: 600;
	color: #333;
}

.tgg-brag-form-group input {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid #ddd;
	border-radius: 6px;
	font-size: 14px;
	box-sizing: border-box;
	background: #fff;
	color: #111;
}

.tgg-brag-form-group input:focus {
	outline: none;
	border-color: #ff8c00;
	box-shadow: 0 0 0 3px rgba(255, 140, 0, 0.15);
}

.tgg-brag-actions {
	display: flex;
	gap: 12px;
	margin-top: 20px;
}

.tgg-brag-share-btn {
	flex: 1;
	padding: 14px 16px;
	border-radius: 10px;
	font-weight: 600;
	font-size: 15px;
	border: none;
	cursor: pointer;
	color: #fff;
	transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
}

.tgg-brag-share-btn:hover:not(:disabled) {
	transform: translateY(-2px);
	box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.tgg-brag-share-btn:disabled {
	cursor: wait;
	opacity: 0.6;
}

.tgg-brag-share-icon {
	font-size: 20px;
	line-height: 1;
}

.tgg-brag-share-fb   { background: linear-gradient(135deg, #1877f2, #0d65d9); }
.tgg-brag-share-zalo { background: linear-gradient(135deg, #0068ff, #0052cc); }

.tgg-brag-status {
	margin-top: 16px;
	padding: 10px 12px;
	border-radius: 6px;
	font-size: 14px;
	line-height: 1.4;
	min-height: 1em;
}

.tgg-brag-status:empty {
	display: none;
}

.tgg-brag-status-success {
	background: #d4edda;
	color: #155724;
	border: 1px solid #c3e6cb;
}

.tgg-brag-status-error {
	background: #f8d7da;
	color: #721c24;
	border: 1px solid #f5c6cb;
}

.tgg-brag-status-info {
	background: #d1ecf1;
	color: #0c5460;
	border: 1px solid #bee5eb;
}

/* ===== Hidden card render area (rasterized via html2canvas) ===== */
.tgg-brag-card-container {
	position: fixed;
	left: -9999px;
	top: -9999px;
	width: 600px;
	height: 400px;
	pointer-events: none;
}

.tgg-brag-card {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	padding: 32px;
	box-sizing: border-box;
	position: relative;
	background: linear-gradient(135deg, #ff8c00, #ff5722);
	color: #fff;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	border-radius: 16px;
	overflow: hidden;
}

.tgg-brag-card-trophy {
	position: absolute;
	top: 16px;
	right: 24px;
	font-size: 96px;
	line-height: 1;
	opacity: 0.18;
}

.tgg-brag-card-header {
	display: flex;
	align-items: center;
	gap: 14px;
	margin-bottom: 8px;
	z-index: 2;
}

.tgg-brag-card-thumb {
	width: 80px;
	height: 80px;
	border-radius: 12px;
	background-size: cover;
	background-position: center;
	background-color: rgba(255, 255, 255, 0.15);
	border: 3px solid rgba(255, 255, 255, 0.35);
	flex-shrink: 0;
}

.tgg-brag-card-title {
	font-size: 22px;
	font-weight: 800;
	line-height: 1.2;
	margin: 0;
	flex: 1;
	text-shadow: 1px 2px 4px rgba(0, 0, 0, 0.25);
	overflow: hidden;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

.tgg-brag-card-score {
	font-size: 64px;
	font-weight: 900;
	text-align: center;
	margin: 8px 0 0;
	line-height: 1.05;
	text-shadow: 2px 4px 8px rgba(0, 0, 0, 0.3);
	word-break: break-word;
}

.tgg-brag-card-score-label {
	font-size: 14px;
	text-align: center;
	opacity: 0.9;
	text-transform: uppercase;
	letter-spacing: 3px;
	margin-top: 4px;
}

.tgg-brag-card-footer {
	margin-top: auto;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding-top: 14px;
	border-top: 1px solid rgba(255, 255, 255, 0.3);
}

.tgg-brag-card-brand {
	font-size: 17px;
	font-weight: 700;
}

.tgg-brag-card-url {
	font-size: 13px;
	opacity: 0.85;
}
