/**
 * TSO Period Dictionary — Chatbot styles (v1.0.11)
 *
 * Bottom-left floating bubble. Mirrors the games balloon visual language
 * (gradient FAB, white panel, pulse halo) but positioned on the opposite
 * corner so they coexist. Z-index 99994 sits below the games balloon
 * (99995) and below modals (99998+).
 */

.tso-pd-bot {
	/* Chatbot takes the TSO Teal thread — the community-facing helper is
	 * where TSO co-branding lives per the palette guide. This differentiates
	 * it visually from the games balloon (Amethyst — dictionary voice) and
	 * makes the bot feel like the human/organisational layer rather than
	 * the editorial one. */
	--tso-pd-bot-primary: #008080;             /* TSO Teal */
	--tso-pd-bot-primary-deep: #005F5F;        /* deeper TSO Teal */
	--tso-pd-bot-primary-darkest: #241730;     /* Ink Aubergine for dark surfaces */
	--tso-pd-bot-accent: #CFACDB;              /* Lilac, keeps continuity */
	--tso-pd-bot-light-accent: #E55A1C;        /* Flame accent */
	--tso-pd-bot-ink: #241730;                 /* Ink Aubergine type */
	--tso-pd-bot-ash: #5B5060;
	--tso-pd-bot-line: #E5DDE8;
	--tso-pd-bot-cream: #FAF6EF;
	--tso-pd-bot-font-serif: 'Fraunces', Georgia, serif;
	--tso-pd-bot-font-sans: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;

	position: fixed;
	bottom: 24px;
	left: 24px;
	z-index: 99994;
	font-family: var(--tso-pd-bot-font-sans);
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 14px;
}

@media (max-width: 520px) {
	.tso-pd-bot {
		bottom: 18px;
		left: 18px;
	}
}

/* ===== FAB (floating circular button) ===== */

.tso-pd-bot__fab {
	position: relative;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: 0;
	background: linear-gradient(135deg, var(--tso-pd-bot-primary) 0%, var(--tso-pd-bot-primary-deep) 100%);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(36, 23, 48, 0.32), 0 2px 6px rgba(0, 0, 0, 0.12);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.2s cubic-bezier(0.22, 0.61, 0.36, 1), box-shadow 0.2s ease;
	overflow: visible;
}

.tso-pd-bot__fab:hover {
	transform: scale(1.06);
	box-shadow: 0 12px 32px rgba(36, 23, 48, 0.42), 0 4px 10px rgba(0, 0, 0, 0.16);
}

.tso-pd-bot__fab:active {
	transform: scale(0.96);
}

.tso-pd-bot__fab-pulse {
	position: absolute;
	inset: -4px;
	border-radius: 50%;
	border: 2px solid var(--tso-pd-bot-accent);
	opacity: 0;
	animation: tso-pd-bot-pulse 2.8s ease-out infinite;
	pointer-events: none;
}

@keyframes tso-pd-bot-pulse {
	0%   { transform: scale(0.9); opacity: 0.6; }
	100% { transform: scale(1.5); opacity: 0; }
}

.tso-pd-bot.is-open .tso-pd-bot__fab-pulse {
	animation: none;
	opacity: 0;
}

.tso-pd-bot__fab-icon {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity 0.18s ease, transform 0.22s ease;
}

.tso-pd-bot__fab-icon--open {
	opacity: 1;
	transform: scale(1);
}

.tso-pd-bot__fab-icon--close {
	opacity: 0;
	transform: scale(0.6) rotate(-45deg);
}

.tso-pd-bot.is-open .tso-pd-bot__fab-icon--open {
	opacity: 0;
	transform: scale(0.6) rotate(45deg);
}

.tso-pd-bot.is-open .tso-pd-bot__fab-icon--close {
	opacity: 1;
	transform: scale(1) rotate(0);
}

/* ===== Panel ===== */

.tso-pd-bot__panel {
	position: absolute;
	bottom: 76px;
	left: 0;
	width: 360px;
	max-width: calc(100vw - 36px);
	height: 520px;
	max-height: calc(100vh - 130px);
	background: #fff;
	border-radius: 20px;
	box-shadow: 0 24px 60px rgba(36, 23, 48, 0.32), 0 6px 16px rgba(0, 0, 0, 0.08);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	pointer-events: none;
	transform: translateY(12px) scale(0.96);
	transform-origin: bottom left;
	transition: opacity 0.24s ease, transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.tso-pd-bot.is-open .tso-pd-bot__panel {
	opacity: 1;
	pointer-events: auto;
	transform: translateY(0) scale(1);
}

@media (max-width: 420px) {
	.tso-pd-bot__panel {
		width: calc(100vw - 36px);
		height: calc(100vh - 130px);
	}
}

/* ===== Panel head ===== */

.tso-pd-bot__head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 10px;
	padding: 16px 18px;
	background: linear-gradient(135deg, var(--tso-pd-bot-primary-darkest) 0%, #1A0E22 100%);
	color: #fff;
	position: relative;
	overflow: hidden;
}

.tso-pd-bot__head::before {
	content: "";
	position: absolute;
	inset: 0;
	background: radial-gradient(ellipse at 85% 0%, rgba(207, 172, 219, 0.22) 0%, transparent 60%);
	pointer-events: none;
}

.tso-pd-bot__head-left {
	display: flex;
	align-items: center;
	gap: 12px;
	position: relative;
	z-index: 1;
	min-width: 0;
	flex: 1;
}

.tso-pd-bot__avatar {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	background: linear-gradient(135deg, var(--tso-pd-bot-primary), var(--tso-pd-bot-primary-deep));
	border-radius: 10px;
	font-size: 16px;
	flex-shrink: 0;
}

.tso-pd-bot__head-text {
	display: flex;
	flex-direction: column;
	gap: 1px;
	min-width: 0;
}

.tso-pd-bot__head-title {
	font-family: var(--tso-pd-bot-font-serif);
	font-size: 14px;
	font-weight: 700;
	letter-spacing: -0.01em;
}

.tso-pd-bot__head-sub {
	font-size: 10.5px;
	color: rgba(255, 255, 255, 0.65);
	letter-spacing: 0.01em;
	line-height: 1.3;
	overflow: hidden;
	text-overflow: ellipsis;
}

.tso-pd-bot__head-close {
	position: relative;
	z-index: 1;
	width: 28px;
	height: 28px;
	background: rgba(255, 255, 255, 0.12);
	border: 0;
	border-radius: 50%;
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease;
	flex-shrink: 0;
}

.tso-pd-bot__head-close:hover {
	background: rgba(255, 255, 255, 0.22);
}

/* ===== Log (conversation area) ===== */

.tso-pd-bot__log {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--tso-pd-bot-cream);
}

.tso-pd-bot__log::-webkit-scrollbar {
	width: 6px;
}

.tso-pd-bot__log::-webkit-scrollbar-thumb {
	background: rgba(0, 0, 0, 0.12);
	border-radius: 3px;
}

.tso-pd-bot__msg {
	display: flex;
	max-width: 100%;
}

.tso-pd-bot__msg--user {
	justify-content: flex-end;
}

.tso-pd-bot__msg--bot {
	justify-content: flex-start;
}

.tso-pd-bot__bubble {
	max-width: 84%;
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 13.5px;
	line-height: 1.5;
	word-wrap: break-word;
}

.tso-pd-bot__msg--user .tso-pd-bot__bubble {
	background: linear-gradient(135deg, var(--tso-pd-bot-primary), var(--tso-pd-bot-primary-deep));
	color: #fff;
	border-bottom-right-radius: 4px;
}

.tso-pd-bot__msg--bot .tso-pd-bot__bubble {
	background: #fff;
	color: var(--tso-pd-bot-ink);
	border-bottom-left-radius: 4px;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.tso-pd-bot__bubble strong {
	color: var(--tso-pd-bot-primary-deep);
	font-weight: 700;
}

.tso-pd-bot__msg--user .tso-pd-bot__bubble strong {
	color: #fff;
}

.tso-pd-bot__bubble p {
	margin: 0 0 8px 0;
}

.tso-pd-bot__bubble p:last-child {
	margin-bottom: 0;
}

/* Action token (button-like link inside a bubble) */
.tso-pd-bot__action {
	display: inline-block;
	margin-top: 8px;
	padding: 8px 14px;
	background: var(--tso-pd-bot-light-accent);
	color: #fff !important;
	text-decoration: none;
	border-radius: 99px;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.02em;
	transition: background 0.15s ease;
}

.tso-pd-bot__action:hover {
	background: #c44600;
	color: #fff !important;
}

/* Starter chips */
.tso-pd-bot__starters {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 4px;
}

.tso-pd-bot__starter {
	background: #fff;
	border: 1px solid var(--tso-pd-bot-line);
	border-radius: 99px;
	padding: 7px 12px;
	font-size: 12px;
	font-weight: 500;
	color: var(--tso-pd-bot-primary-deep);
	cursor: pointer;
	font-family: var(--tso-pd-bot-font-sans);
	transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.tso-pd-bot__starter:hover {
	background: rgba(207, 172, 219, 0.12);
	border-color: var(--tso-pd-bot-accent);
	transform: translateX(2px);
}

/* Dictionary search results inside the bubble */
.tso-pd-bot__results {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-top: 10px;
}

.tso-pd-bot__result {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
	background: rgba(207, 172, 219, 0.10);
	border: 1px solid rgba(207, 172, 219, 0.22);
	border-radius: 10px;
	padding: 9px 12px;
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
	font-family: var(--tso-pd-bot-font-sans);
	text-align: left;
}

.tso-pd-bot__result:hover {
	background: rgba(207, 172, 219, 0.22);
	border-color: var(--tso-pd-bot-accent);
	transform: translateX(2px);
}

.tso-pd-bot__result-term {
	font-family: var(--tso-pd-bot-font-serif);
	font-size: 14px;
	font-weight: 700;
	color: var(--tso-pd-bot-ink);
}

.tso-pd-bot__result-type {
	font-size: 9.5px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	font-weight: 600;
	color: var(--tso-pd-bot-primary-deep);
	background: #fff;
	padding: 2px 7px;
	border-radius: 99px;
}

/* Typing indicator (animated dots) */
.tso-pd-bot__typing .tso-pd-bot__bubble {
	display: inline-flex;
	gap: 4px;
	padding: 13px 16px;
}

.tso-pd-bot__typing .tso-pd-bot__bubble span {
	display: inline-block;
	width: 6px;
	height: 6px;
	background: var(--tso-pd-bot-ash);
	border-radius: 50%;
	animation: tso-pd-bot-typing 1.4s ease-in-out infinite;
}

.tso-pd-bot__typing .tso-pd-bot__bubble span:nth-child(2) { animation-delay: 0.15s; }
.tso-pd-bot__typing .tso-pd-bot__bubble span:nth-child(3) { animation-delay: 0.3s; }

@keyframes tso-pd-bot-typing {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
	30%           { transform: translateY(-5px); opacity: 1; }
}

/* ===== Input row ===== */

.tso-pd-bot__input-row {
	border-top: 1px solid var(--tso-pd-bot-line);
	padding: 12px;
	background: #fff;
}

.tso-pd-bot__form {
	display: flex;
	align-items: center;
	gap: 8px;
	background: var(--tso-pd-bot-cream);
	border: 1px solid var(--tso-pd-bot-line);
	border-radius: 99px;
	padding: 4px 4px 4px 14px;
	transition: border-color 0.15s ease, background 0.15s ease;
}

.tso-pd-bot__form:focus-within {
	border-color: var(--tso-pd-bot-primary);
	background: #fff;
}

.tso-pd-bot__input {
	flex: 1;
	border: 0;
	background: transparent;
	font-family: var(--tso-pd-bot-font-sans);
	font-size: 13.5px;
	padding: 8px 4px;
	outline: none;
	color: var(--tso-pd-bot-ink);
	min-width: 0;
}

.tso-pd-bot__input::placeholder {
	color: var(--tso-pd-bot-ash);
}

.tso-pd-bot__send {
	width: 36px;
	height: 36px;
	background: linear-gradient(135deg, var(--tso-pd-bot-primary), var(--tso-pd-bot-primary-deep));
	border: 0;
	border-radius: 50%;
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.12s ease, box-shadow 0.15s ease;
	flex-shrink: 0;
}

.tso-pd-bot__send:hover {
	transform: scale(1.06);
	box-shadow: 0 4px 12px rgba(36, 23, 48, 0.28);
}

.tso-pd-bot__send:active {
	transform: scale(0.94);
}

/* On very narrow screens, hide bot tooltip space */
@media (max-width: 360px) {
	.tso-pd-bot__head-sub { display: none; }
}
