/**
 * MadTheme Compagnon - Glossary Frontend Styles
 *
 * Handles glossary autolinks, hover tooltips, and the A-Z index block.
 * Fully compatible with light mode and dark mode via theme presets.
 */

/* ── 1. Glossary In-Content Autolink ────────────────────────────────── */
a.mw-glossary-term {
	text-decoration: none;
	border-bottom: 1.5px dotted var(--wp--preset--color--accent, #3740b9);
	cursor: help;
	color: inherit;
	transition: border-color 0.15s ease, color 0.15s ease;
}

a.mw-glossary-term:hover,
a.mw-glossary-term:focus-visible {
	border-bottom-style: solid;
	color: var(--wp--preset--color--accent, #3740b9);
}

body.dark-mode a.mw-glossary-term,
html[data-theme="dark"] a.mw-glossary-term {
	border-bottom-color: var(--wp--preset--color--accent, #6b9cff);
}

body.dark-mode a.mw-glossary-term:hover,
body.dark-mode a.mw-glossary-term:focus-visible,
html[data-theme="dark"] a.mw-glossary-term:hover,
html[data-theme="dark"] a.mw-glossary-term:focus-visible {
	color: var(--wp--preset--color--accent, #6b9cff);
}

	/* Explicit choice: the visitor picked dark, or the site starts dark.
	   Independent of the system preference. */
	body.dark-mode a.mw-glossary-term, html.dark-mode a.mw-glossary-term, body.editor-styles-wrapper:not(.dark-mode-off) a.mw-glossary-term {border-bottom-color: var(--wp--preset--color--accent, #6b9cff);}
	body.dark-mode a.mw-glossary-term:hover, html.dark-mode a.mw-glossary-term:hover, body.editor-styles-wrapper:not(.dark-mode-off) a.mw-glossary-term:hover, body.dark-mode a.mw-glossary-term:focus-visible, html.dark-mode a.mw-glossary-term:focus-visible, body.editor-styles-wrapper:not(.dark-mode-off) a.mw-glossary-term:focus-visible {color: var(--wp--preset--color--accent, #6b9cff);}
	@media (prefers-color-scheme: dark) {
		/* The site follows the system preference. */
		html:not(.dark-mode-off) body.dark-mode-auto a.mw-glossary-term {border-bottom-color: var(--wp--preset--color--accent, #6b9cff);}
		html:not(.dark-mode-off) body.dark-mode-auto a.mw-glossary-term:hover, html:not(.dark-mode-off) body.dark-mode-auto a.mw-glossary-term:focus-visible {color: var(--wp--preset--color--accent, #6b9cff);}
	}

/* ── 2. Glossary Floating Tooltip ──────────────────────────────────── */
.mw-glossary-tooltip {
	position: absolute;
	z-index: 99999;
	max-width: 320px;
	padding: 12px 16px;
	background: var(--wp--preset--color--base, #ffffff);
	color: var(--wp--preset--color--contrast, #101012);
	border: 1px solid var(--wp--preset--color--tertiary, rgba(16, 16, 18, 0.15));
	border-radius: 8px;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
	font-size: 0.875rem;
	line-height: 1.45;
	pointer-events: auto;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
	transform: translateY(4px);
}

.mw-glossary-tooltip.is-visible {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
}

.mw-glossary-tooltip__title {
	font-weight: 700;
	font-size: 0.95rem;
	margin: 0 0 4px;
	color: var(--wp--preset--color--contrast, #101012);
}

.mw-glossary-tooltip__excerpt {
	margin: 0 0 8px;
	color: var(--wp--preset--color--secondary, rgba(16, 16, 18, 0.65));
}

.mw-glossary-tooltip__link {
	display: inline-block;
	font-weight: 600;
	font-size: 0.8rem;
	color: var(--wp--preset--color--accent, #3740b9);
	text-decoration: underline;
}

body.dark-mode .mw-glossary-tooltip,
html[data-theme="dark"] .mw-glossary-tooltip {
	background: var(--wp--preset--color--base-2, #1e232c);
	color: var(--wp--preset--color--contrast, #eceff4);
	border-color: var(--wp--preset--color--tertiary, #3b4252);
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

body.dark-mode .mw-glossary-tooltip__title,
html[data-theme="dark"] .mw-glossary-tooltip__title {
	color: var(--wp--preset--color--contrast, #eceff4);
}

body.dark-mode .mw-glossary-tooltip__excerpt,
html[data-theme="dark"] .mw-glossary-tooltip__excerpt {
	color: var(--wp--preset--color--secondary, #a0aab6);
}

body.dark-mode .mw-glossary-tooltip__link,
html[data-theme="dark"] .mw-glossary-tooltip__link {
	color: var(--wp--preset--color--accent, #6b9cff);
}

	/* Explicit choice: the visitor picked dark, or the site starts dark.
	   Independent of the system preference. */
	body.dark-mode .mw-glossary-tooltip, html.dark-mode .mw-glossary-tooltip, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-tooltip {background: var(--wp--preset--color--base-2, #1e232c);
		color: var(--wp--preset--color--contrast, #eceff4);
		border-color: var(--wp--preset--color--tertiary, #3b4252);
		box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);}
	body.dark-mode .mw-glossary-tooltip__title, html.dark-mode .mw-glossary-tooltip__title, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-tooltip__title {color: var(--wp--preset--color--contrast, #eceff4);}
	body.dark-mode .mw-glossary-tooltip__excerpt, html.dark-mode .mw-glossary-tooltip__excerpt, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-tooltip__excerpt {color: var(--wp--preset--color--secondary, #a0aab6);}
	body.dark-mode .mw-glossary-tooltip__link, html.dark-mode .mw-glossary-tooltip__link, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-tooltip__link {color: var(--wp--preset--color--accent, #6b9cff);}
	@media (prefers-color-scheme: dark) {
		/* The site follows the system preference. */
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-tooltip {background: var(--wp--preset--color--base-2, #1e232c);
		color: var(--wp--preset--color--contrast, #eceff4);
		border-color: var(--wp--preset--color--tertiary, #3b4252);
		box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-tooltip__title {color: var(--wp--preset--color--contrast, #eceff4);}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-tooltip__excerpt {color: var(--wp--preset--color--secondary, #a0aab6);}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-tooltip__link {color: var(--wp--preset--color--accent, #6b9cff);}
	}

/* ── 3. Glossary Index Block ────────────────────────────────────────── */
.mw-glossary-index {
	margin: 2rem 0;
}

.mw-glossary-index__alphabet {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 2rem;
	padding: 12px;
	background: var(--wp--preset--color--base-2, #f5f5f7);
	border-radius: 8px;
}

.mw-glossary-index__alphabet a {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border-radius: 6px;
	text-decoration: none;
	font-weight: 600;
	color: var(--wp--preset--color--contrast, #101012);
	transition: background-color 0.15s ease, color 0.15s ease;
}

.mw-glossary-index__alphabet a:hover {
	background: var(--wp--preset--color--accent, #3740b9);
	color: var(--wp--preset--color--base, #ffffff);
}

.mw-glossary-index__search input {
	width: 100%;
	max-width: 400px;
	padding: 10px 14px;
	border: 1px solid var(--wp--preset--color--tertiary, rgba(16, 16, 18, 0.2));
	border-radius: 6px;
	background: var(--wp--preset--color--base, #ffffff);
	color: var(--wp--preset--color--contrast, #101012);
	margin-bottom: 1.5rem;
}

.mw-glossary-index__group {
	margin-bottom: 2.5rem;
}

.mw-glossary-index__letter {
	font-size: 1.75rem;
	font-weight: 700;
	border-bottom: 2px solid var(--wp--preset--color--tertiary, rgba(16, 16, 18, 0.15));
	padding-bottom: 6px;
	margin-bottom: 1rem;
}

.mw-glossary-index__terms {
	list-style: none;
	padding: 0;
	margin: 0;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
	gap: 12px;
}

.mw-glossary-index__term-link {
	font-weight: 600;
	text-decoration: none;
	color: var(--wp--preset--color--contrast, #101012);
}

.mw-glossary-index__term-link:hover {
	color: var(--wp--preset--color--accent, #3740b9);
	text-decoration: underline;
}

body.dark-mode .mw-glossary-index__alphabet,
html[data-theme="dark"] .mw-glossary-index__alphabet {
	background: var(--wp--preset--color--base-2, #1e232c);
}

body.dark-mode .mw-glossary-index__alphabet a,
html[data-theme="dark"] .mw-glossary-index__alphabet a {
	color: var(--wp--preset--color--contrast, #eceff4);
}

body.dark-mode .mw-glossary-index__alphabet a:hover,
html[data-theme="dark"] .mw-glossary-index__alphabet a:hover {
	background: var(--wp--preset--color--accent, #6b9cff);
	color: var(--wp--preset--color--base, #161a20);
}

body.dark-mode .mw-glossary-index__search input,
html[data-theme="dark"] .mw-glossary-index__search input {
	background: var(--wp--preset--color--base-3, #252a34);
	border-color: var(--wp--preset--color--tertiary, #3b4252);
	color: var(--wp--preset--color--contrast, #eceff4);
}

body.dark-mode .mw-glossary-index__letter,
html[data-theme="dark"] .mw-glossary-index__letter {
	border-bottom-color: var(--wp--preset--color--tertiary, #3b4252);
	color: var(--wp--preset--color--contrast, #eceff4);
}

body.dark-mode .mw-glossary-index__term-link,
html[data-theme="dark"] .mw-glossary-index__term-link {
	color: var(--wp--preset--color--contrast, #eceff4);
}

body.dark-mode .mw-glossary-index__term-link:hover,
html[data-theme="dark"] .mw-glossary-index__term-link:hover {
	color: var(--wp--preset--color--accent, #6b9cff);
}

	/* Explicit choice: the visitor picked dark, or the site starts dark.
	   Independent of the system preference. */
	body.dark-mode .mw-glossary-index__alphabet, html.dark-mode .mw-glossary-index__alphabet, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-index__alphabet {background: var(--wp--preset--color--base-2, #1e232c);}
	body.dark-mode .mw-glossary-index__alphabet a, html.dark-mode .mw-glossary-index__alphabet a, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-index__alphabet a {color: var(--wp--preset--color--contrast, #eceff4);}
	body.dark-mode .mw-glossary-index__alphabet a:hover, html.dark-mode .mw-glossary-index__alphabet a:hover, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-index__alphabet a:hover {background: var(--wp--preset--color--accent, #6b9cff);
		color: #ffffff;}
	body.dark-mode .mw-glossary-index__search input, html.dark-mode .mw-glossary-index__search input, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-index__search input {background: var(--wp--preset--color--base-3, #252a34);
		border-color: var(--wp--preset--color--tertiary, #3b4252);
		color: var(--wp--preset--color--contrast, #eceff4);}
	body.dark-mode .mw-glossary-index__letter, html.dark-mode .mw-glossary-index__letter, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-index__letter {border-bottom-color: var(--wp--preset--color--tertiary, #3b4252);
		color: var(--wp--preset--color--contrast, #eceff4);}
	body.dark-mode .mw-glossary-index__term-link, html.dark-mode .mw-glossary-index__term-link, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-index__term-link {color: var(--wp--preset--color--contrast, #eceff4);}
	body.dark-mode .mw-glossary-index__term-link:hover, html.dark-mode .mw-glossary-index__term-link:hover, body.editor-styles-wrapper:not(.dark-mode-off) .mw-glossary-index__term-link:hover {color: var(--wp--preset--color--accent, #6b9cff);}
	@media (prefers-color-scheme: dark) {
		/* The site follows the system preference. */
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-index__alphabet {background: var(--wp--preset--color--base-2, #1e232c);}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-index__alphabet a {color: var(--wp--preset--color--contrast, #eceff4);}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-index__alphabet a:hover {background: var(--wp--preset--color--accent, #6b9cff);
		color: #ffffff;}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-index__search input {background: var(--wp--preset--color--base-3, #252a34);
		border-color: var(--wp--preset--color--tertiary, #3b4252);
		color: var(--wp--preset--color--contrast, #eceff4);}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-index__letter {border-bottom-color: var(--wp--preset--color--tertiary, #3b4252);
		color: var(--wp--preset--color--contrast, #eceff4);}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-index__term-link {color: var(--wp--preset--color--contrast, #eceff4);}
		html:not(.dark-mode-off) body.dark-mode-auto .mw-glossary-index__term-link:hover {color: var(--wp--preset--color--accent, #6b9cff);}
	}
