/*
 * Attune Accessibility Suite — front-end styles.
 * Namespace: every selector is scoped under .atx-* / html.atx-*.
 * Design tokens live on .atx-root; the accent arrives as --atx-accent
 * from the settings screen, everything else derives from it here.
 */

/* ---------------------------------------------------------------- tokens */
.atx-root {
	/* colour */
	--atx-accent: #2e5bd7;
	--atx-accent-ink: #ffffff;            /* recomputed by JS for pale accents */
	--atx-accent-strong: color-mix(in srgb, var(--atx-accent) 82%, #101828);
	--atx-accent-soft: color-mix(in srgb, var(--atx-accent) 11%, #ffffff);
	--atx-accent-line: color-mix(in srgb, var(--atx-accent) 62%, #101828);
	--atx-paper: #fbfaf7;
	--atx-paper-2: #f2f0ea;
	--atx-ink: #1c2430;
	--atx-muted: #5a6472;
	--atx-border: #d7d3ca;
	--atx-ring: #17202c;

	/* scales */
	--atx-r-s: 8px;
	--atx-r-m: 14px;
	--atx-r-l: 22px;
	--atx-sp-1: 4px;
	--atx-sp-2: 8px;
	--atx-sp-3: 12px;
	--atx-sp-4: 16px;
	--atx-sp-5: 24px;
	--atx-fs-s: 13px;
	--atx-fs-m: 15px;
	--atx-fs-l: 18px;
	--atx-shadow: 0 18px 50px rgba(18, 24, 34, 0.24), 0 2px 8px rgba(18, 24, 34, 0.14);
	--atx-dur: 190ms;
	--atx-ease: cubic-bezier(0.22, 0.7, 0.25, 1);

	position: fixed;
	z-index: 2147483000;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: var(--atx-fs-m);
	line-height: 1.35;
	color: var(--atx-ink);
	text-align: left;
	letter-spacing: normal;
}

/* the widget never inherits page-level preference styling */
.atx-root, .atx-root * {
	box-sizing: border-box;
}

/* Host themes frequently style bare semantic tags (e.g. a global
   `footer { margin-top: ... }`, `header {}`, `section {}`). The widget is
   built from those tags, so neutralise any leaked box spacing - it must
   look identical on every theme. Scoped double-class beats element and
   most single-class host rules. */
.atx-root .atx-sheet,
.atx-root .atx-head,
.atx-root .atx-body,
.atx-root .atx-foot,
.atx-root .atx-group,
.atx-root button,
.atx-root a {
	margin: 0;
}

/* Host themes also set font-family with !important on bare tags (e.g.
   `button {...!important}`, `h1,h2,h3 {...!important}` - as this project's
   sunday-skin does with Manrope / Baloo 2). An author !important declaration
   beats the widget's non-important `font: inherit` regardless of specificity,
   so re-assert the system stack with matching importance to keep the panel
   typographically identical on every theme. */
.atx-root,
.atx-root button,
.atx-root input,
.atx-root select,
.atx-root textarea,
.atx-root h1, .atx-root h2, .atx-root h3,
.atx-root h4, .atx-root h5, .atx-root h6 {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

/* corner anchoring */
.atx-pos-br { right: 20px; bottom: 20px; }
.atx-pos-bl { left: 20px; bottom: 20px; }
.atx-pos-tr { right: 20px; top: 20px; }
.atx-pos-tl { left: 20px; top: 20px; }

/* ------------------------------------------------------------ utilities */
.atx-vh {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	overflow: hidden !important;
	clip: rect(0 0 0 0) !important;
	clip-path: inset(50%) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

.atx-root :focus { outline: none; }
.atx-root :focus-visible {
	outline: 3px solid var(--atx-ring);
	outline-offset: 2px;
	box-shadow: 0 0 0 2px #ffffff, 0 0 0 7px rgba(255, 255, 255, 0.85);
	border-radius: var(--atx-r-s);
}

.atx-i {
	width: 100%;
	height: 100%;
	display: block;
}
.atx-node { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------------ FAB */
.atx-fab {
	display: grid;
	place-items: center;
	width: 60px;
	height: 60px;
	padding: 14px;
	border: 2px solid var(--atx-accent-line);
	border-radius: 50%;
	background: var(--atx-accent);
	color: var(--atx-accent-ink);
	cursor: pointer;
	box-shadow: var(--atx-shadow);
	transition: transform var(--atx-dur) var(--atx-ease), box-shadow var(--atx-dur) var(--atx-ease);
}
.atx-pos-bl .atx-fab, .atx-pos-tl .atx-fab { border-radius: 50%; }
.atx-fab:hover { transform: translateY(-2px); }
.atx-fab:active { transform: translateY(0); background: var(--atx-accent-strong); }

/* ----------------------------------------------------------- sheet frame */
.atx-scrim {
	position: fixed;
	inset: 0;
	background: transparent;
	z-index: -1;
}

.atx-sheet[hidden], .atx-scrim[hidden] { display: none !important; }

.atx-sheet {
	position: fixed;
	display: flex;
	flex-direction: column;
	width: min(440px, calc(100vw - 24px));
	top: 16px;
	bottom: 16px;
	height: auto;
	background: var(--atx-paper);
	border: 1.5px solid var(--atx-border);
	border-radius: var(--atx-r-l);
	box-shadow: var(--atx-shadow);
	overflow: hidden;
	transform-origin: center right;
}
.atx-pos-br .atx-sheet, .atx-pos-tr .atx-sheet { right: 16px; transform-origin: center right; }
.atx-pos-bl .atx-sheet, .atx-pos-tl .atx-sheet { left: 16px; transform-origin: center left; }

.atx-sheet[data-atx-open] {
	animation: atx-bloom var(--atx-dur) var(--atx-ease);
}
@keyframes atx-bloom {
	from { opacity: 0; transform: scale(0.97) translateY(8px); }
	to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* --------------------------------------------------------------- header */
.atx-head {
	display: flex;
	align-items: center;
	gap: var(--atx-sp-2);
	padding: var(--atx-sp-3) var(--atx-sp-4);
	border-bottom: 1.5px solid var(--atx-border);
	background: var(--atx-paper);
}
.atx-headmark {
	width: 26px;
	height: 26px;
	padding: 4px;
	color: var(--atx-accent-ink);
	background: var(--atx-accent);
	border-radius: 50%;
	flex: none;
}
.atx-title {
	flex: 1;
	margin: 0;
	font-size: var(--atx-fs-l);
	font-weight: 700;
	letter-spacing: 0.01em;
	color: var(--atx-ink);
}
.atx-hbtn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-width: 44px;
	min-height: 44px;
	padding: 8px 10px;
	border: 1.5px solid var(--atx-border);
	border-radius: var(--atx-r-m);
	background: #ffffff;
	color: var(--atx-ink);
	font: inherit;
	font-size: var(--atx-fs-s);
	font-weight: 600;
	cursor: pointer;
}
.atx-hbtn:hover { border-color: var(--atx-accent-line); background: var(--atx-accent-soft); }
.atx-hbtn .atx-i { width: 18px; height: 18px; flex: none; }
.atx-hbtn-close { justify-content: center; padding: 8px; }

/* ----------------------------------------------------------------- body */
.atx-body {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	padding: var(--atx-sp-4);
	display: flex;
	flex-direction: column;
	gap: var(--atx-sp-5);
	overscroll-behavior: contain;
}

.atx-gtitle {
	margin: 0 0 var(--atx-sp-3);
	font-size: var(--atx-fs-s);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.09em;
	color: var(--atx-muted);
}

.atx-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--atx-sp-3);
}
.atx-span2 { grid-column: 1 / -1; }
.atx-presets {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--atx-sp-3);
}

/* ---------------------------------------------------------------- tiles */
.atx-tile {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	gap: 8px;
	min-height: 108px;
	padding: var(--atx-sp-3);
	border: 1.5px solid var(--atx-border);
	border-radius: var(--atx-r-m);
	background: #ffffff;
	color: var(--atx-ink);
	font: inherit;
	text-align: center;
	cursor: pointer;
	transition: border-color var(--atx-dur) var(--atx-ease), background var(--atx-dur) var(--atx-ease), transform var(--atx-dur) var(--atx-ease);
}
button.atx-tile:hover { border-color: var(--atx-accent-line); transform: translateY(-1px); }

.atx-ticon {
	width: 32px;
	height: 32px;
	color: var(--atx-ink);
	flex: none;
}
.atx-tlabel {
	font-size: var(--atx-fs-m);
	font-weight: 650;
	line-height: 1.2;
}
.atx-tstate {
	margin-top: auto;
	padding: 3px 9px;
	border-radius: 999px;
	background: var(--atx-paper-2);
	border: 1px solid var(--atx-border);
	font-size: var(--atx-fs-s);
	font-weight: 700;
	color: var(--atx-muted);
	white-space: nowrap;
}

/* ON state: filled treatment, icon and chip pick up the accent */
.atx-tile[aria-checked="true"],
.atx-tile[aria-pressed="true"] {
	border-color: var(--atx-accent-line);
	border-width: 2px;
	padding: calc(var(--atx-sp-3) - 0.5px);
	background: var(--atx-accent-soft);
}
.atx-tile[aria-checked="true"] .atx-ticon,
.atx-tile[aria-pressed="true"] .atx-ticon { color: var(--atx-accent-line); }
.atx-tile[aria-checked="true"] .atx-tstate,
.atx-tile[aria-pressed="true"] .atx-tstate,
.atx-tile[data-atx-active] .atx-tstate {
	background: var(--atx-accent-line);
	border-color: var(--atx-accent-line);
	color: #ffffff;
}
.atx-tile[data-atx-active] { border-color: var(--atx-accent-line); }
.atx-tile[data-atx-active] .atx-ticon { color: var(--atx-accent-line); }

.atx-tile[aria-disabled="true"] {
	opacity: 0.55;
	cursor: not-allowed;
}

/* presets: the biggest tiles */
.atx-tile-preset {
	min-height: 116px;
	gap: 8px;
}
.atx-tile-preset .atx-ticon { width: 34px; height: 34px; }

/* steppers & segmented controls take a full row so the square tiles stay calm */
.atx-tile-step, .atx-tile-seg { grid-column: 1 / -1; }

/* steppers */
.atx-tile-step { cursor: default; }
.atx-stepper {
	margin-top: auto;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 100%;
	max-width: 320px;
}
.atx-stepper .atx-tstate {
	margin-top: 0;
	flex: 0 1 150px;
	text-align: center;
}
.atx-stepbtn {
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	flex: none;
	padding: 12px;
	border: 1.5px solid var(--atx-border);
	border-radius: var(--atx-r-s);
	background: var(--atx-paper-2);
	color: var(--atx-ink);
	cursor: pointer;
}
.atx-stepbtn:hover:not(:disabled) { border-color: var(--atx-accent-line); background: var(--atx-accent-soft); }
.atx-stepbtn:disabled { opacity: 0.4; cursor: not-allowed; }

/* segmented radios — centred header, pill row beneath */
.atx-tile-seg { cursor: default; }
.atx-tile-seg .atx-ticon { width: 28px; height: 28px; }
.atx-tile-seg .atx-tstate { margin-top: 0; }
.atx-seg {
	margin-top: 4px;
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	width: 100%;
}
.atx-segbtn {
	flex: 1 1 0;
	min-height: 44px;
	min-width: 0;
	padding: 8px 6px;
	border: 1.5px solid var(--atx-border);
	border-radius: var(--atx-r-s);
	background: var(--atx-paper-2);
	color: var(--atx-ink);
	font: inherit;
	font-size: var(--atx-fs-s);
	font-weight: 650;
	cursor: pointer;
}
.atx-segbtn:hover { border-color: var(--atx-accent-line); }
.atx-segbtn[aria-checked="true"] {
	background: var(--atx-accent-line);
	border-color: var(--atx-accent-line);
	color: #ffffff;
}

/* --------------------------------------------------------------- footer */
.atx-foot {
	padding: var(--atx-sp-3) var(--atx-sp-4);
	border-top: 1.5px solid var(--atx-border);
	background: var(--atx-paper-2);
	display: flex;
	flex-direction: column;
	gap: 4px;
}
.atx-slink {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	min-height: 44px;
	align-self: flex-start;
	color: var(--atx-accent-line);
	font-weight: 650;
	font-size: var(--atx-fs-s);
	text-decoration: underline;
	text-underline-offset: 0.16em;
}
.atx-slink:hover { color: var(--atx-accent-strong); }
.atx-slink .atx-i { width: 16px; height: 16px; }
.atx-privnote {
	margin: 0;
	font-size: var(--atx-fs-s);
	color: var(--atx-muted);
}

/* narrow viewports: single column, sheet hugs the screen */
@media (max-width: 420px) {
	.atx-grid { grid-template-columns: 1fr; }
	.atx-presets { grid-template-columns: 1fr 1fr 1fr; }
	.atx-tile { min-height: 88px; }
}

/* the widget's own motion respects the OS setting */
@media (prefers-reduced-motion: reduce) {
	.atx-root *, .atx-sheet[data-atx-open] { animation: none !important; transition: none !important; }
}
/* the in-panel Reduce Motion toggle also stills the widget itself */
html.atx-rm .atx-root * { animation: none !important; transition: none !important; }

/* =================================================================
   PAGE EFFECTS — applied via namespaced classes on <html>.
   Theme-agnostic: no assumptions about theme variables or markup.
   The widget root is exempt from every rule below.
   ================================================================= */

/* text size (percentage on the root; widget uses px so is unaffected) */
html.atx-ts { font-size: var(--atx-ts, 100%) !important; }

/* bold text */
html.atx-bold body :where(p, li, a, span, label, td, th, dd, dt, blockquote, figcaption, small, em, i, h1, h2, h3, h4, h5, h6, input, button, summary):not(.atx-root, .atx-root *) {
	font-weight: 700 !important;
}

/* readable font: forced highly-legible system stack (no bundled font,
   no network — Verdana/Tahoma have wide apertures and open counters) */
html.atx-font body *:not(.atx-root, .atx-root *, pre, pre *, code, code *, kbd, samp) {
	font-family: Verdana, "Trebuchet MS", Tahoma, "Segoe UI", Arial, sans-serif !important;
}

/* letter spacing levels */
html.atx-lt-1 body *:not(.atx-root, .atx-root *) { letter-spacing: 0.05em !important; word-spacing: 0.08em !important; }
html.atx-lt-2 body *:not(.atx-root, .atx-root *) { letter-spacing: 0.1em !important; word-spacing: 0.16em !important; }
html.atx-lt-3 body *:not(.atx-root, .atx-root *) { letter-spacing: 0.16em !important; word-spacing: 0.28em !important; }

/* line spacing levels */
html.atx-lh-1 body :where(p, li, dd, dt, blockquote, figcaption, h1, h2, h3, h4, h5, h6, td, th, div):not(.atx-root, .atx-root *) { line-height: 1.7 !important; }
html.atx-lh-2 body :where(p, li, dd, dt, blockquote, figcaption, h1, h2, h3, h4, h5, h6, td, th, div):not(.atx-root, .atx-root *) { line-height: 1.95 !important; }
html.atx-lh-3 body :where(p, li, dd, dt, blockquote, figcaption, h1, h2, h3, h4, h5, h6, td, th, div):not(.atx-root, .atx-root *) { line-height: 2.25 !important; }

/* alignment */
html.atx-al-left body :where(p, li, h1, h2, h3, h4, h5, h6, blockquote, figcaption, dd, dt):not(.atx-root, .atx-root *) { text-align: left !important; }
html.atx-al-center body :where(p, li, h1, h2, h3, h4, h5, h6, blockquote, figcaption, dd, dt):not(.atx-root, .atx-root *) { text-align: center !important; }
html.atx-al-right body :where(p, li, h1, h2, h3, h4, h5, h6, blockquote, figcaption, dd, dt):not(.atx-root, .atx-root *) { text-align: right !important; }
html.atx-al-justify body :where(p, li, blockquote, dd, dt):not(.atx-root, .atx-root *) { text-align: justify !important; }

/* underline links */
html.atx-ul body a:not(.atx-root a) {
	text-decoration: underline !important;
	text-decoration-thickness: 0.11em !important;
	text-underline-offset: 0.16em !important;
}

/* emphasise headings */
html.atx-hd body :where(h1, h2, h3, h4, h5, h6):not(.atx-root, .atx-root *) {
	text-decoration: underline !important;
	text-decoration-thickness: 0.13em !important;
	text-underline-offset: 0.2em !important;
	font-weight: 800 !important;
}

/* reduce motion */
html.atx-rm *:not(.atx-root, .atx-root *),
html.atx-rm *:not(.atx-root, .atx-root *)::before,
html.atx-rm *:not(.atx-root, .atx-root *)::after {
	animation-duration: 0.01ms !important;
	animation-iteration-count: 1 !important;
	transition-duration: 0.01ms !important;
	scroll-behavior: auto !important;
}

/* -------- contrast / colour modes (forced surfaces, media untouched) --- */
html.atx-cm-dark { background: #12161c !important; color-scheme: dark; }
html.atx-cm-dark body,
html.atx-cm-dark body *:not(.atx-root, .atx-root *, img, picture, video, iframe, svg, svg *, canvas, embed, object) {
	background-color: #12161c !important;
	background-image: none !important;
	color: #e7eaef !important;
	border-color: #47505c !important;
	text-shadow: none !important;
	box-shadow: none !important;
}
html.atx-cm-dark body a:not(.atx-root a) { color: #9dc1ff !important; }

html.atx-cm-light { background: #ffffff !important; color-scheme: light; }
html.atx-cm-light body,
html.atx-cm-light body *:not(.atx-root, .atx-root *, img, picture, video, iframe, svg, svg *, canvas, embed, object) {
	background-color: #ffffff !important;
	background-image: none !important;
	color: #171c23 !important;
	border-color: #c3c9d2 !important;
	text-shadow: none !important;
}
html.atx-cm-light body a:not(.atx-root a) { color: #1946ad !important; }

html.atx-cm-high { background: #000000 !important; color-scheme: dark; }
html.atx-cm-high body,
html.atx-cm-high body *:not(.atx-root, .atx-root *, img, picture, video, iframe, svg, svg *, canvas, embed, object) {
	background-color: #000000 !important;
	background-image: none !important;
	color: #ffffff !important;
	border-color: #ffffff !important;
	text-shadow: none !important;
	box-shadow: none !important;
}
html.atx-cm-high body a:not(.atx-root a) {
	color: #ffd84d !important;
	text-decoration: underline !important;
}
/* keep essential media usable under forced modes */
html.atx-cm-high body :where(img, video):not(.atx-root *) { filter: contrast(1.05); }

/* mono: per-element filter so the fixed widget is never trapped
   in a filtered containing block */
html.atx-cm-mono body > *:not(.atx-root) {
	filter: grayscale(1) !important;
	-webkit-filter: grayscale(1) !important;
}

/* saturation */
html.atx-sat-low body > *:not(.atx-root) {
	filter: saturate(0.4) !important;
	-webkit-filter: saturate(0.4) !important;
}
html.atx-sat-high body > *:not(.atx-root) {
	filter: saturate(1.65) !important;
	-webkit-filter: saturate(1.65) !important;
}
/* mono wins over saturation if both are set */
html.atx-cm-mono.atx-sat-low body > *:not(.atx-root),
html.atx-cm-mono.atx-sat-high body > *:not(.atx-root) {
	filter: grayscale(1) !important;
	-webkit-filter: grayscale(1) !important;
}

/* large pointer: bespoke high-visibility cursor (inline SVG data URI) */
html.atx-ptr, html.atx-ptr * {
	cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cpath d='M8 4l22 13-9.5 2.5L16 30z' fill='%23101828' stroke='%23ffffff' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E") 8 4, auto !important;
}

/* reading ruler band (element is created by JS) */
.atx-rulerband {
	position: fixed;
	left: 0;
	right: 0;
	height: 110px;
	pointer-events: none;
	z-index: 2147482998;
	border-top: 3px solid var(--atx-accent, #2e5bd7);
	border-bottom: 3px solid var(--atx-accent, #2e5bd7);
	box-shadow: 0 -2000px 0 2000px rgba(16, 21, 29, 0.22), 0 2000px 0 2000px rgba(16, 21, 29, 0.22);
}

/* read-on-click affordance */
html.atx-rc body :where(p, h1, h2, h3, h4, h5, h6, li, blockquote, figcaption, td, th, a):not(.atx-root, .atx-root *) { cursor: pointer; }
.atx-speaking { outline: 3px dashed var(--atx-accent, #2e5bd7) !important; outline-offset: 3px !important; }
