/**
 * Biofamous Nepali Matrix - converter styles.
 *
 * Design goals, in priority order:
 *   1. Work on a 360px-wide phone first. Everything stacks, nothing scrolls
 *      sideways, every tap target is at least 44px.
 *   2. Never fight the host theme. All values are custom properties, all
 *      colours inherit from the theme where possible, and the plugin only
 *      styles its own .bnm-* namespace.
 *   3. Be readable. Generous line height, large textareas, visible focus.
 *   4. Respect user preferences. Dark mode and reduced motion are honoured.
 *   5. Load no external font. A remote Google Font would be a third party
 *      request, a privacy problem and a single point of failure, and Devanagari
 *      coverage on the device is what actually decides whether Nepali renders.
 */

.bnm-app {
	--bnm-min-height: 220px;

	--bnm-bg: #ffffff;
	--bnm-fg: #1a1a1a;
	--bnm-muted: #5b6470;
	--bnm-border: #d3d8de;
	--bnm-border-strong: #9aa3ad;
	--bnm-accent: #0b5cad;
	--bnm-accent-fg: #ffffff;
	--bnm-accent-hover: #094a8c;
	--bnm-surface: #f6f8fa;
	--bnm-error: #a4262c;
	--bnm-radius: 10px;
	--bnm-gap: 12px;

	/*
	 * Devanagari font stack. The first entry that the device actually has
	 * wins. Every one of these is a font already present on the vast majority
	 * of devices, so this costs no network request.
	 *
	 *   Noto Sans Devanagari  Android, many Linux distributions
	 *   Nirmala UI           Windows 8 and newer, ships with Windows
	 *   Kohinoor Devanagari  macOS and iOS
	 *   Mangal               older Windows
	 *   Kalimati             the classic Nepali Unicode font
	 *   Lohit Devanagari     Linux
	 *   Devanagari Sangam MN macOS and iOS legacy name
	 *   sans-serif           final fallback, may not cover Devanagari
	 */
	--bnm-deva-font: "Noto Sans Devanagari", "Nirmala UI", "Kohinoor Devanagari",
		"Mangal", "Kalimati", "Lohit Devanagari", "Devanagari Sangam MN", sans-serif;

	box-sizing: border-box;
	margin: 0 auto;
	max-width: 1100px;
	color: var(--bnm-fg);
	font-size: 16px;
	line-height: 1.5;
	text-align: left;
}

@media (prefers-color-scheme: dark) {
	.bnm-app {
		--bnm-bg: #14171a;
		--bnm-fg: #e8eaed;
		--bnm-muted: #a3abb5;
		--bnm-border: #333a42;
		--bnm-border-strong: #5c6670;
		--bnm-accent: #4a9eff;
		--bnm-accent-fg: #08121f;
		--bnm-accent-hover: #74b4ff;
		--bnm-surface: #1c2024;
		--bnm-error: #ff8a8a;
	}
}

.bnm-app *,
.bnm-app *::before,
.bnm-app *::after {
	box-sizing: inherit;
}

.bnm-card {
	margin: 0;
	padding: 16px;
	background: var(--bnm-bg);
	border: 1px solid var(--bnm-border);
	border-radius: var(--bnm-radius);
}

/* ---------------------------------------------------------------------------
 * Heading
 * ------------------------------------------------------------------------ */

.bnm-title {
	margin: 0 0 16px;
	padding: 0;
	font-size: 1.25rem;
	font-weight: 700;
	line-height: 1.3;
	color: var(--bnm-fg);
}

.bnm-head {
	margin: 0;
}

/* ---------------------------------------------------------------------------
 * FROM / TO selectors
 * ------------------------------------------------------------------------ */

.bnm-controls {
	display: grid;
	grid-template-columns: 1fr;
	gap: var(--bnm-gap);
	margin: 0 0 16px;
}

.bnm-control {
	margin: 0;
	min-width: 0;
}

.bnm-control--swap {
	display: flex;
	align-items: flex-end;
	justify-content: center;
}

.bnm-label {
	display: block;
	margin: 0 0 4px;
	font-size: 0.8125rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--bnm-muted);
}

.bnm-select {
	display: block;
	width: 100%;
	min-height: 44px;
	padding: 8px 10px;
	font-family: inherit;
	font-size: 1rem;
	line-height: 1.4;
	color: var(--bnm-fg);
	background: var(--bnm-bg);
	border: 1px solid var(--bnm-border-strong);
	border-radius: 8px;
	appearance: none;
	-webkit-appearance: none;
	background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
		linear-gradient(135deg, currentColor 50%, transparent 50%);
	background-position: calc(100% - 18px) calc(50% + 2px), calc(100% - 13px) calc(50% + 2px);
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
	padding-right: 34px;
}

.bnm-select:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

/* ---------------------------------------------------------------------------
 * Textareas
 * ------------------------------------------------------------------------ */

.bnm-panes {
	display: grid;
	grid-template-columns: 1fr;
	gap: var(--bnm-gap);
}

.bnm-pane {
	min-width: 0;
}

.bnm-textarea {
	display: block;
	width: 100%;
	min-height: var(--bnm-min-height);
	padding: 12px;
	font-family: var(--bnm-deva-font);
	font-size: 1.125rem;
	line-height: 1.9;
	color: var(--bnm-fg);
	background: var(--bnm-bg);
	border: 1px solid var(--bnm-border-strong);
	border-radius: 8px;
	resize: vertical;
	/* Stop iOS Safari zooming in when a field is focused. */
	-webkit-text-size-adjust: 100%;
}

/* The input holds keystrokes, so a normal UI font is more honest. */
.bnm-textarea--input {
	font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
		"Liberation Mono", monospace;
	font-size: 1rem;
	line-height: 1.7;
}

.bnm-textarea--output {
	background: var(--bnm-surface);
}

.bnm-textarea:read-only {
	cursor: text;
}

.bnm-textarea::placeholder {
	color: var(--bnm-muted);
	opacity: 1;
}

.bnm-hint {
	margin: 6px 0 0;
	font-size: 0.8125rem;
	line-height: 1.5;
	color: var(--bnm-muted);
}

/* ---------------------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------------------ */

.bnm-toolbar {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
	margin: 16px 0 0;
}

.bnm-button,
.bnm-icon-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	margin: 0;
	padding: 10px 16px;
	font-family: inherit;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.2;
	color: var(--bnm-fg);
	background: var(--bnm-bg);
	border: 1px solid var(--bnm-border-strong);
	border-radius: 8px;
	cursor: pointer;
	touch-action: manipulation;
	-webkit-appearance: none;
	appearance: none;
}

.bnm-button:hover,
.bnm-icon-button:hover {
	background: var(--bnm-surface);
}

.bnm-button--primary {
	color: var(--bnm-accent-fg);
	background: var(--bnm-accent);
	border-color: var(--bnm-accent);
}

.bnm-button--primary:hover {
	background: var(--bnm-accent-hover);
	border-color: var(--bnm-accent-hover);
}

.bnm-icon-button {
	width: 44px;
	padding: 0;
	font-size: 1.25rem;
}

.bnm-icon {
	line-height: 1;
	pointer-events: none;
}

.bnm-count {
	margin: 0 0 0 auto;
	font-size: 0.8125rem;
	color: var(--bnm-muted);
	white-space: nowrap;
}

/* ---------------------------------------------------------------------------
 * Status line
 * ------------------------------------------------------------------------ */

.bnm-status {
	min-height: 1.5em;
	margin: 10px 0 0;
	font-size: 0.875rem;
	line-height: 1.5;
	color: var(--bnm-muted);
}

.bnm-status:empty {
	margin: 0;
	min-height: 0;
}

/* ---------------------------------------------------------------------------
 * Help panel
 * ------------------------------------------------------------------------ */

.bnm-help {
	margin: 16px 0 0;
	background: var(--bnm-surface);
	border: 1px solid var(--bnm-border);
	border-radius: var(--bnm-radius);
}

.bnm-help > summary {
	min-height: 44px;
	padding: 12px 16px;
	font-size: 0.9375rem;
	font-weight: 600;
	color: var(--bnm-fg);
	cursor: pointer;
	list-style: none;
	display: flex;
	align-items: center;
}

.bnm-help > summary::-webkit-details-marker {
	display: none;
}

.bnm-help > summary::before {
	content: "\25B8";
	margin-right: 8px;
	font-size: 0.75em;
	transition: transform 0.15s ease;
}

.bnm-help[open] > summary::before {
	transform: rotate(90deg);
}

.bnm-help-body {
	padding: 0 16px 16px;
	font-size: 0.9375rem;
	line-height: 1.65;
}

.bnm-help-list {
	margin: 0 0 12px;
	padding-left: 20px;
}

.bnm-help-list li {
	margin-bottom: 6px;
}

.bnm-help-note {
	margin: 0;
	padding: 12px;
	background: var(--bnm-bg);
	border-left: 3px solid var(--bnm-accent);
	border-radius: 0 6px 6px 0;
	font-size: 0.875rem;
}

.bnm-help-note strong {
	display: block;
	margin-bottom: 4px;
}

/* ---------------------------------------------------------------------------
 * Focus. Never remove focus styling: this tool is keyboard operated.
 * ------------------------------------------------------------------------ */

.bnm-select:focus-visible,
.bnm-textarea:focus-visible,
.bnm-button:focus-visible,
.bnm-icon-button:focus-visible,
.bnm-help > summary:focus-visible {
	outline: 3px solid var(--bnm-accent);
	outline-offset: 2px;
}

/* Fallback for engines without :focus-visible. */
.bnm-select:focus,
.bnm-textarea:focus,
.bnm-button:focus,
.bnm-icon-button:focus {
	outline: 3px solid var(--bnm-accent);
	outline-offset: 2px;
}

.bnm-select:focus:not(:focus-visible),
.bnm-textarea:focus:not(:focus-visible),
.bnm-button:focus:not(:focus-visible),
.bnm-icon-button:focus:not(:focus-visible) {
	outline: none;
}

/* ---------------------------------------------------------------------------
 * Visually hidden text, used for the swap button label.
 * ------------------------------------------------------------------------ */

.bnm-app .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* ---------------------------------------------------------------------------
 * Breakpoints. Mobile first: the rules above are the phone layout.
 * ------------------------------------------------------------------------ */

@media (min-width: 480px) {
	.bnm-card {
		padding: 20px;
	}

	.bnm-controls {
		grid-template-columns: 1fr auto 1fr;
		align-items: end;
	}

	.bnm-control--swap {
		padding-bottom: 0;
	}
}

@media (min-width: 720px) {
	.bnm-panes {
		grid-template-columns: 1fr 1fr;
	}

	.bnm-card {
		padding: 24px;
	}

	.bnm-title {
		font-size: 1.375rem;
	}
}

@media (min-width: 1000px) {
	.bnm-textarea {
		min-height: calc(var(--bnm-min-height) + 40px);
	}
}

/* ---------------------------------------------------------------------------
 * Forced colours / high contrast mode on Windows.
 * ------------------------------------------------------------------------ */

@media (forced-colors: active) {
	.bnm-card,
	.bnm-textarea,
	.bnm-select,
	.bnm-button,
	.bnm-icon-button,
	.bnm-help {
		border: 1px solid CanvasText;
	}

	.bnm-button--primary {
		background: Highlight;
		color: HighlightText;
	}
}

/* ---------------------------------------------------------------------------
 * Reduced motion.
 * ------------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
	.bnm-app * {
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
	}
}

/* ---------------------------------------------------------------------------
 * Print. Nobody wants a converter card in a printed article.
 * ------------------------------------------------------------------------ */

@media print {
	.bnm-toolbar,
	.bnm-help,
	.bnm-control--swap {
		display: none !important;
	}
}

/* ---------------------------------------------------------------------------
 * Theme overrides. A site can restyle the card without touching this file:
 *
 *   .bnm-card { --bnm-accent: #b45309; }
 * ------------------------------------------------------------------------ */
