/* ─── Dictionary panel ───────────────────────────────────────────────────────
   A slide-over anchored to the inline end of the viewport. The host stays in the
   DOM at all times so opening and closing can animate; `visibility` is what
   actually takes it out of the a11y tree and off the hit-testing surface, and it
   flips late on close (transition-delay) so the slide-out is still visible.

   Above .reader (z-index 80) on purpose — looking a word up while reading is the
   main way in, so the panel has to sit over the reader's own overlays. */
dictionary-panel {
	position: fixed;
	inset: 0;
	z-index: 90;
	visibility: hidden;
	transition: visibility 0s linear 0.25s;
}

dictionary-panel[open] {
	visibility: visible;
	transition-delay: 0s;
}

.dict-scrim {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.45);
	opacity: 0;
	transition: opacity 0.25s ease;

	dictionary-panel[open] & {
		opacity: 1;
	}
}

/* Rows: fixed header / fixed search / scrolling results. */
.dict-panel {
	position: absolute;
	inset-block: 0;
	inset-inline-end: 0;
	width: min(430px, 100%);
	display: grid;
	grid-template-rows: auto auto 1fr;
	background: var(--surface);
	border-inline-start: 1px solid var(--border);
	box-shadow: -8px 0 30px rgba(0, 0, 0, 0.35);
	transform: translateX(100%);
	transition: transform 0.25s ease;
	padding-block-end: env(safe-area-inset-bottom, 0px);

	dictionary-panel[open] & {
		transform: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.dict-scrim,
	.dict-panel {
		transition: none;
	}
}

.dict-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-s);
	padding: calc(var(--space-m) + env(safe-area-inset-top, 0px)) var(--space-m) var(--space-s);
	border-block-end: 1px solid var(--border);

	& h2 {
		display: flex;
		align-items: center;
		gap: var(--space-xs);
		margin: 0;
		font: var(--font-h5);
	}

	& h2 .icon {
		color: var(--color-primary);
		font-size: 22px;
	}
}

.dict-head-actions {
	display: grid;
	grid-auto-flow: column;
	align-items: center;
	gap: var(--space-xs);
}

/* Grid, not flex: the input takes the free column and the button its content
   width, and the global `form` rule (flex-direction: column) would otherwise
   stack them. */
.dict-search {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: var(--space-xs);
	padding: var(--space-m) var(--space-m) var(--space-s);

	& .search-input {
		margin-bottom: 0;
	}

	& .btn {
		padding-inline: var(--space-m);
	}
}

.dict-body {
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 0 var(--space-m) var(--space-xl);
}

/* ─── Entry ──────────────────────────────────────────────────────────────── */
.dict-word {
	display: flex;
	align-items: baseline;
	gap: var(--space-s);
	flex-wrap: wrap;
	margin-block: var(--space-xs) var(--space-m);

	& h3 {
		margin: 0;
		font: var(--font-h4);
	}

	/* Slightly smaller than the 40px default so it sits with the headword rather
	   than over it. padding: 0 keeps the glyph centred (see css/buttons.css). */
	& .icon-btn {
		width: 34px;
		height: 34px;
		padding: 0;
		align-self: center;
	}
}

.dict-phonetic {
	font: var(--font-body-large-regular);
	color: var(--text-dim);
}

.dict-sense + .dict-sense {
	margin-block-start: var(--space-l);
}

.dict-pos {
	margin: 0 0 var(--space-xs);
	font: var(--font-body-small-bold);
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--color-primary-on-surface);
}

.dict-defs {
	margin: 0;
	padding-inline-start: var(--space-l);
	display: grid;
	gap: var(--space-s);

	& li {
		font: var(--font-body-large-regular);
	}

	& p {
		margin: 0;
	}
}

.dict-example {
	margin-block-start: var(--space-3xs) !important;
	color: var(--text-dim);
	font: var(--font-body-medium-regular);
	font-style: italic;
}

.dict-related {
	margin-block-start: var(--space-s);
	display: grid;
	gap: var(--space-2xs);
}

.dict-related-label {
	font: var(--font-body-small-semibold);
	color: var(--text-faint);
}

.dict-recent .section-title {
	margin-block: var(--space-m) var(--space-xs);
	font: var(--font-body-large-bold);
}

/* ─── "Look up" popup over a reader selection ────────────────────────────── */
.lookup-pop {
	position: fixed;
	z-index: 10;
	transform: translate(-50%, -100%);
	background: var(--surface-2);
	color: var(--text);
	border: 1px solid var(--border);
	border-radius: var(--radius-button);
	padding: var(--space-xs) var(--space-m);
	font: var(--font-body-medium-bold);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
	animation: fade-in 0.12s ease;

	&.below {
		transform: translate(-50%, 0);
	}

	& .icon {
		font-size: 18px;
		color: var(--color-primary);
	}
}

.dict-credit {
	margin-block-start: var(--space-m);
	font: var(--font-body-small-regular);
	color: var(--text-faint);

	& a {
		color: inherit;
		text-underline-offset: 0.2em;
	}
}
