/*
 * Character counter page.
 *
 * Reads from the theme's design tokens, so it follows the Customizer palette
 * and dark mode without a second set of rules.
 *
 * Grid and flex children carry min-width: 0 throughout; they default to
 * min-width: auto and refuse to shrink below their content, which is what
 * caused horizontal overflow elsewhere in this theme.
 */

.site-main.cw-char-page {
	grid-template-columns: 1fr;
	gap: 0;
}

/* ------------------------------------------------------------------ *
 * Header
 * ------------------------------------------------------------------ */

.cw-char-header { text-align: center; padding-block: 28px 20px; min-width: 0; }
.cw-char-title { font-size: clamp(1.75rem, 4vw, 2.4rem); line-height: 1.15; margin: 0 0 12px; }
.cw-char-lede { max-width: 68ch; margin-inline: auto; color: var(--cw-color-text); }

/* ------------------------------------------------------------------ *
 * The tool
 * ------------------------------------------------------------------ */

.cw-char-app {
	background: var(--cw-color-card);
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius);
	box-shadow: var(--cw-shadow);
	padding: 16px;
	min-width: 0;
}

/* Limit picker sits above the editor, clear of the mobile keyboard. */
.cw-char-picker {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px 14px;
	margin-bottom: 12px;
	min-width: 0;
}
.cw-char-picker-label {
	font-weight: 600;
	font-size: 0.9rem;
	color: var(--cw-color-heading);
	flex: 0 0 auto;
}
.cw-char-select {
	flex: 1 1 260px;
	min-width: 0;
	min-height: var(--cw-tap);
	padding: 9px 12px;
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius-sm);
	background: var(--cw-color-bg);
	color: var(--cw-color-heading);
	font: inherit;
	font-size: 0.93rem;
}
.cw-char-select:focus-visible {
	outline: 2px solid var(--cw-color-primary);
	outline-offset: 1px;
}
.cw-char-custom {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	flex: 0 0 auto;
	font-size: 0.86rem;
	color: var(--cw-color-muted);
}
.cw-char-custom input {
	width: 92px;
	min-height: var(--cw-tap);
	padding: 8px 10px;
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius-sm);
	background: var(--cw-color-bg);
	color: var(--cw-color-heading);
	font: inherit;
	font-size: 0.9rem;
}

/* ------------------------------------------------------------------ *
 * Meter
 * ------------------------------------------------------------------ */

.cw-char-meter { margin-bottom: 12px; min-width: 0; }
.cw-char-meter[hidden] { display: none; }

.cw-char-meter-bar {
	position: relative;
	height: 8px;
	border-radius: 999px;
	background: var(--cw-color-border);
	overflow: visible;
}
.cw-char-meter-fill {
	height: 100%;
	width: 0;
	border-radius: 999px;
	background: var(--cw-color-primary);
	transition: width 0.12s linear, background-color 0.15s ease;
}
.cw-char-meter-fill.is-near { background: var(--cw-color-warning); }
.cw-char-meter-fill.is-over { background: var(--cw-color-danger); width: 100% !important; }

/* Where the platform stops showing the text, marked on the same scale. */
.cw-char-meter-mark {
	position: absolute;
	top: -3px;
	width: 2px;
	height: 14px;
	background: var(--cw-color-heading);
	opacity: 0.55;
	border-radius: 1px;
}
.cw-char-meter-mark[hidden] { display: none; }

.cw-char-meter-text {
	margin: 8px 0 0;
	font-size: 0.9rem;
	color: var(--cw-color-text);
	min-height: 1.3em;
}
.cw-char-meter-text.is-over { color: var(--cw-color-danger); font-weight: 600; }

/* ------------------------------------------------------------------ *
 * Overlay editor
 *
 * The textarea and the mirror MUST share identical metrics or the highlight
 * drifts away from the text it is shading. Everything that affects line
 * breaking is set once, here, for both layers.
 * ------------------------------------------------------------------ */

.cw-char-editor {
	position: relative;
	min-width: 0;
}

.cw-char-input,
.cw-char-mirror {
	/* Shared metrics. Changing one without the other misaligns the highlight. */
	font-family: var(--cw-font-body);
	font-size: 1rem;
	line-height: 1.6;
	letter-spacing: normal;
	padding: 14px;
	border: 1px solid transparent;
	white-space: pre-wrap;
	overflow-wrap: break-word;
	word-break: normal;
	tab-size: 4;
}

.cw-char-input {
	position: relative;
	z-index: 2;
	display: block;
	width: 100%;
	min-width: 0;
	min-height: 200px;
	border-color: var(--cw-color-border);
	border-radius: var(--cw-radius-sm);
	background: var(--cw-color-editor-bg);
	color: var(--cw-color-editor-text);
	resize: vertical;
	overflow: auto;
}
/* While the backdrop is showing a highlight, the textarea goes transparent so
   the shading beneath it is visible. The caret and text stay painted. */
.cw-char-input.is-overlaid { background: transparent; }

.cw-char-input:focus-visible {
	outline: 2px solid var(--cw-color-primary);
	outline-offset: 1px;
	border-color: var(--cw-color-primary);
}

.cw-char-backdrop {
	position: absolute;
	inset: 0;
	z-index: 1;
	overflow: hidden;
	border-radius: var(--cw-radius-sm);
	background: var(--cw-color-editor-bg);
	pointer-events: none;
}
.cw-char-mirror {
	color: transparent;
	min-height: 100%;
}
.cw-char-mirror mark {
	/*
	 * The overflow shading. Both colours are explicit per-theme tokens rather
	 * than color-mix derivations: this is the one visual the feature exists to
	 * produce, so it must not depend on a function that some browsers lack.
	 *
	 * The text stays transparent because the real, readable text is painted by
	 * the textarea sitting on top.
	 */
	background: var(--cw-color-overflow);
	color: transparent;
	border-radius: 2px;
	box-shadow: 0 0 0 1px var(--cw-color-overflow-edge);
}

.cw-char-toolrow {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 10px;
	min-width: 0;
}
.cw-char-toolrow .cw-btn { gap: 6px; }
.cw-char-toolrow .cw-btn[hidden] { display: none; }
.cw-char-clear:hover,
.cw-char-clear:focus-visible { color: var(--cw-color-danger); border-color: var(--cw-color-danger); }

/* ------------------------------------------------------------------ *
 * Counts
 * ------------------------------------------------------------------ */

.cw-char-figures {
	display: grid;
	grid-template-columns: repeat(6, minmax(0, 1fr));
	gap: 10px;
	margin-top: 14px;
}
.cw-char-figure {
	min-width: 0;
	padding: 12px 8px;
	text-align: center;
	background: var(--cw-color-bg);
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius-sm);
}
.cw-char-figure strong {
	display: block;
	font-size: 1.3rem;
	line-height: 1.1;
	color: var(--cw-color-heading);
	font-variant-numeric: tabular-nums;
}
.cw-char-figure span {
	display: block;
	margin-top: 3px;
	font-size: 0.74rem;
	color: var(--cw-color-muted);
}
.cw-char-figure.is-primary { border-color: var(--cw-color-primary); background: var(--cw-color-card); }
.cw-char-figure.is-primary strong { color: var(--cw-color-primary); font-size: 1.6rem; }

.cw-char-note {
	margin: 12px 0 0;
	padding: 11px 14px;
	border-inline-start: 3px solid var(--cw-color-primary);
	background: var(--cw-color-bg);
	border-radius: var(--cw-radius-sm);
	font-size: 0.88rem;
	color: var(--cw-color-text);
}
.cw-char-note[hidden] { display: none; }

.cw-char-status {
	margin: 10px 0 0;
	min-height: 1.4em;
	font-size: 0.88rem;
	color: var(--cw-color-success);
}
.cw-char-privacy {
	display: flex;
	align-items: center;
	gap: 7px;
	margin: 6px 0 0;
	font-size: 0.85rem;
	color: var(--cw-color-muted);
}
.cw-char-privacy svg { flex: 0 0 auto; }

/* ------------------------------------------------------------------ *
 * Features
 * ------------------------------------------------------------------ */

.cw-char-feature-grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 18px;
}
.cw-char-feature { min-width: 0; }
.cw-char-feature h3 { font-size: 1rem; margin: 0 0 6px; color: var(--cw-color-primary); }
.cw-char-feature p { margin: 0; color: var(--cw-color-text); font-size: 0.93rem; }

/* ------------------------------------------------------------------ *
 * Limit reference tables
 * ------------------------------------------------------------------ */

.cw-char-group-title {
	font-size: 1.05rem;
	margin: 26px 0 10px;
	color: var(--cw-color-heading);
}

.cw-char-table {
	width: 100%;
	border-collapse: collapse;
	background: var(--cw-color-card);
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius);
	overflow: hidden;
	font-size: 0.92rem;
}
.cw-char-table th,
.cw-char-table td {
	padding: 10px 14px;
	text-align: start;
	border-bottom: 1px solid var(--cw-color-border);
}
.cw-char-table thead th {
	background: var(--cw-color-bg);
	color: var(--cw-color-heading);
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
.cw-char-table tbody th { font-weight: 500; color: var(--cw-color-text); }
.cw-char-table td { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cw-char-table tbody tr:last-child th,
.cw-char-table tbody tr:last-child td { border-bottom: 0; }

.cw-char-soft {
	display: inline-block;
	margin-inline-start: 6px;
	padding: 1px 7px;
	border-radius: 999px;
	background: var(--cw-color-bg);
	border: 1px solid var(--cw-color-border);
	font-size: 0.72rem;
	color: var(--cw-color-muted);
	text-transform: none;
	letter-spacing: 0;
}
.cw-char-dash { color: var(--cw-color-muted); }

/* ------------------------------------------------------------------ *
 * FAQ
 * ------------------------------------------------------------------ */

.cw-char-faq-item { border-bottom: 1px solid var(--cw-color-border); }
.cw-char-faq-item summary {
	cursor: pointer;
	list-style: none;
	padding: 14px 34px 14px 0;
	position: relative;
	min-height: var(--cw-tap);
	display: flex;
	align-items: center;
}
.cw-char-faq-item summary::-webkit-details-marker { display: none; }
.cw-char-faq-item summary h3 {
	margin: 0;
	font-size: 1.02rem;
	font-weight: 600;
	color: var(--cw-color-heading);
}
.cw-char-faq-item summary::after {
	content: "";
	position: absolute;
	inset-inline-end: 6px;
	top: 50%;
	width: 10px; height: 10px;
	margin-top: -6px;
	border-inline-end: 2px solid var(--cw-color-muted);
	border-block-end: 2px solid var(--cw-color-muted);
	transform: rotate(45deg);
	transition: transform 0.18s ease;
}
.cw-char-faq-item[open] summary::after { transform: rotate(-135deg); margin-top: -2px; }
.cw-char-faq-item p {
	margin: 0 0 16px;
	padding-inline-end: 34px;
	color: var(--cw-color-text);
}
.cw-char-faq-item summary:focus-visible {
	outline: 2px solid var(--cw-color-primary);
	outline-offset: 2px;
	border-radius: var(--cw-radius-sm);
}

@media (prefers-reduced-motion: reduce) {
	.cw-char-faq-item summary::after,
	.cw-char-meter-fill { transition: none; }
}

/* ------------------------------------------------------------------ *
 * Related
 * ------------------------------------------------------------------ */

.cw-char-related {
	background: var(--cw-color-card);
	border: 1px solid var(--cw-color-border);
	border-radius: var(--cw-radius);
	padding: 24px 20px;
}
.cw-char-related h2 { margin-top: 0; font-size: 1.2rem; }
.cw-char-related p { margin: 0; color: var(--cw-color-text); }

/* ------------------------------------------------------------------ *
 * Responsive
 * ------------------------------------------------------------------ */

@media (max-width: 1023px) {
	.cw-char-figures { grid-template-columns: repeat(3, minmax(0, 1fr)); }
	.cw-char-feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
	.cw-char-feature-grid { grid-template-columns: minmax(0, 1fr); }
	.cw-char-picker-label { width: 100%; }
	.cw-char-select { flex: 1 1 100%; }
	.cw-char-custom { flex: 1 1 100%; justify-content: space-between; }
	.cw-char-custom input { width: 110px; }
	.cw-char-toolrow .cw-btn { flex: 1 1 auto; justify-content: center; }
}

@media (max-width: 600px) {
	/* Three across leaves about 100px per figure, which still fits a five
	   digit count and its label. Two would waste a row. */
	.cw-char-figures { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
	.cw-char-figure { padding: 10px 4px; }
	.cw-char-figure strong { font-size: 1.1rem; }
	.cw-char-figure.is-primary strong { font-size: 1.3rem; }
	.cw-char-figure span { font-size: 0.68rem; }

	.cw-char-app { padding: 12px; }
	.cw-char-header { padding-block: 18px 14px; }
	.cw-char-title { margin-bottom: 8px; }
	.cw-char-lede { font-size: 0.95rem; }

	.cw-char-input { min-height: 170px; }
	.cw-char-input,
	.cw-char-mirror { font-size: 0.95rem; padding: 12px; }

	.cw-char-table th,
	.cw-char-table td { padding: 9px 10px; }
	.cw-char-table thead th { font-size: 0.72rem; }
}
