/* LadyQR: the design tokens, the shared components, and the editor.
   One centered card: text field, QR code, settings, download. See DESIGN.md. */

/* Tokens. There is one theme, light. */

:root {
	--bg: #f4f4f5;
	--surface: #ffffff;
	--zebra: #f7f7f8;
	--ink: #18181b;
	--muted: #5f5f66;
	--placeholder: #72727b;
	--line: #e4e4e7;
	--border: #8a8a93;
	--accent: #d9261c;
	--accent-ink: #ffffff;
	--accent-deep: #b81d14;
	--primary: #3f3f46;
	--primary-ink: #ffffff;
	--primary-deep: #27272a;
	--warn: #a35200;
	--radius-sm: 4px;
	--radius: 6px;
	--radius-lg: 10px;
	--control: 44px;
	--font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	color-scheme: light;
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	padding: var(--page-top, 72px) max(16px, env(safe-area-inset-right, 0px)) 20px max(16px, env(safe-area-inset-left, 0px));
	background: var(--bg);
	color: var(--ink);
	font-family: var(--font);
	font-size: 16px;
	line-height: 1.5;
}

main {
	flex: 1;
	width: 100%;
	max-width: 560px;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

a {
	color: var(--accent);
}

a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

/* Card */

.card {
	display: flex;
	flex-direction: column;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius-lg);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-body {
	display: flex;
	flex-direction: column;
	gap: 20px;
	padding: 24px;
}

@media (max-width: 480px) {
	.card-body {
		padding: 16px;
	}
}

/* Shared form controls. Every control is --control tall, with a 1 px --border
   outline and the same radius, so fields, selects and buttons line up. */

.label {
	display: block;
	margin-bottom: 6px;
	font-size: 0.875rem;
	font-weight: 600;
	color: var(--ink);
}

.input {
	display: block;
	width: 100%;
	height: var(--control);
	padding: 0 12px;
	font: inherit;
	font-size: 1rem;
	color: var(--ink);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.input::placeholder {
	color: var(--placeholder);
}

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

.input[aria-invalid="true"] {
	border-color: var(--accent);
}

select.input {
	padding-right: 8px;
}

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	height: var(--control);
	padding: 0 20px;
	font: inherit;
	font-size: 1rem;
	font-weight: 600;
	color: var(--primary-ink);
	text-decoration: none;
	white-space: nowrap;
	background: var(--primary);
	border: 1px solid var(--primary);
	border-radius: var(--radius);
	cursor: pointer;
}

.btn:hover {
	background: var(--primary-deep);
	border-color: var(--primary-deep);
}

.btn.secondary {
	color: var(--ink);
	background: var(--surface);
	border-color: var(--border);
}

.btn.secondary:hover {
	background: var(--bg);
}

.btn.block {
	width: 100%;
}

.notice {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	margin: 0;
	font-size: 0.9rem;
	font-weight: 500;
	color: var(--warn);
}

.notice svg {
	flex: none;
	margin-top: 3px;
}

.notice.error {
	color: var(--accent);
}

.notice.info {
	color: var(--muted);
}

/* Text field */

.field {
	width: 100%;
	padding: 14px 16px;
	font: inherit;
	font-size: 1.35rem;
	font-weight: 500;
	color: var(--ink);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.field::placeholder {
	color: var(--muted);
	font-weight: 400;
}

.field:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: -1px;
	border-color: var(--accent);
}

@media (max-width: 480px) {
	.field {
		font-size: 1.15rem;
	}
}

/* Settings */

/* On a narrow screen the settings are a folded box under the QR code, before
   the download: a control of the code, not a section of the page. Folded, it
   shows the current values. */

.settings {
	overflow: hidden;
	border: 1px solid var(--line);
	border-radius: var(--radius);
}

.settings summary {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: var(--control);
	padding: 0 14px;
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--ink);
	background: var(--surface);
	cursor: pointer;
	list-style: none;
}

.settings[open] summary {
	border-bottom: 1px solid var(--line);
}

.settings summary::-webkit-details-marker {
	display: none;
}

.settings summary::after {
	content: "";
	flex: none;
	width: 7px;
	height: 7px;
	margin: 0 4px 3px 0;
	border-right: 2px solid var(--muted);
	border-bottom: 2px solid var(--muted);
	transform: rotate(45deg);
	transition: transform 0.15s;
}

.settings[open] summary::after {
	margin-bottom: -3px;
	transform: rotate(-135deg);
}

.settings-icon {
	flex: none;
	color: var(--muted);
}

.settings-state {
	display: flex;
	align-items: center;
	gap: 4px;
	margin-left: auto;
	font-size: 0.85rem;
	font-weight: 400;
	color: var(--muted);
	white-space: nowrap;
}

.settings-state span:first-child {
	margin-right: 6px;
}

.settings[open] .settings-state {
	display: none;
}

.settings[open] summary::after {
	margin-left: auto;
}

.swatch {
	width: 14px;
	height: 14px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
}

.settings-body {
	display: flex;
	flex-direction: column;
	gap: 18px;
	padding: 16px 14px 18px;
	background: var(--zebra);
}

/* Wide screens: the settings are a column on the right of the card, always
   open. app.js keeps them open and takes the toggle out of the tab order.
   The card body's own box steps aside so its parts and the settings share one
   grid; the outer columns are the card's padding. */

/* The website's editor has a .compact class: it keeps the narrow layout at every
   width, so it can share the screen with the welcome. */

@media (min-width: 900px) {
	main {
		max-width: 940px;
	}

	.card.editor:not(.compact) {
		display: grid;
		grid-template-columns: 28px minmax(0, 1fr) 28px 300px;
		grid-template-rows: auto auto auto 1fr;
	}

	.card.editor:not(.compact) .card-body {
		display: contents;
	}

	.card.editor:not(.compact) .card-body > * {
		grid-column: 2;
		margin-top: 20px;
	}

	.card.editor:not(.compact) .field {
		margin-top: 28px;
	}

	.card.editor:not(.compact) .qr {
		justify-self: center;
	}

	.card.editor:not(.compact) .download {
		grid-row: 4;
		align-self: start;
		margin-bottom: 28px;
	}

	.card.editor:not(.compact) .settings {
		grid-column: 4;
		grid-row: 1 / -1;
		margin: 0;
		background: var(--zebra);
		border: 0;
		border-left: 1px solid var(--line);
		border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
	}

	.editor:not(.compact) .settings summary {
		cursor: default;
		padding: 16px 24px;
		background: none;
	}

	.editor:not(.compact) .settings summary::after,
	.editor:not(.compact) .settings-state {
		display: none;
	}

	.editor:not(.compact) .settings-body {
		padding: 20px 24px 22px;
	}
}

.segmented {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	overflow: hidden;
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.segmented button {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 6px 4px;
	font: inherit;
	font-weight: 600;
	line-height: 1.25;
	color: var(--ink);
	background: var(--surface);
	border: 0;
	border-right: 1px solid var(--border);
	cursor: pointer;
}

.segmented button:last-child {
	border-right: 0;
}

.segmented button:focus-visible {
	outline-offset: -3px;
}

.segmented small {
	font-size: 0.72rem;
	font-weight: 400;
	color: var(--muted);
}

.segmented button[aria-pressed="true"] {
	color: var(--accent-ink);
	background: var(--accent);
}

.segmented button[aria-pressed="true"] small {
	color: inherit;
}

.range {
	display: flex;
	align-items: center;
	gap: 12px;
}

.range input {
	flex: 1;
	min-width: 0;
	accent-color: var(--accent);
}

.range output {
	min-width: 2ch;
	font-family: var(--mono);
	font-size: 0.9rem;
	text-align: right;
}

/* Two columns at every width. A label may wrap in the narrow wide-screen
   column, so the inputs line up at the bottom. */
.colors {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	align-items: end;
	gap: 16px;
}

.colors input {
	width: 56px;
	height: 36px;
	padding: 2px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
}

/* QR code */

.qr {
	align-self: center;
	width: 100%;
	max-width: 360px;
	aspect-ratio: 1;
	overflow: hidden;
	border: 1px solid var(--line);
}

.qr svg {
	display: block;
	width: 100%;
	height: 100%;
}

/* Empty state: a faint drawing of a QR code with a message on top. */

.qr-empty {
	position: relative;
	height: 100%;
	display: grid;
	place-items: center;
	background: var(--zebra);
}

.qr-skeleton {
	position: absolute;
	inset: 0;
	color: var(--muted);
	opacity: 0.14;
}

.qr-message {
	position: relative;
	max-width: 80%;
	margin: 0;
	padding: 8px 14px;
	font-size: 0.95rem;
	text-align: center;
	color: var(--muted);
	background: var(--zebra);
}

.reset {
	align-self: flex-start;
	height: 36px;
	padding: 0 14px;
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	color: var(--ink);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	cursor: pointer;
}

.reset:hover:not(:disabled) {
	background: var(--bg);
}

.reset:disabled {
	color: var(--muted);
	opacity: 0.6;
	cursor: default;
}

.warning {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	margin: -8px 0 0;
	font-size: 0.85rem;
	font-weight: 500;
	text-align: center;
	color: var(--warn);
}

.warning[hidden] {
	display: none;
}

.warning svg {
	flex: none;
}

/* Download: a big button with a format menu attached */

.download {
	position: relative;
	display: flex;
	width: 100%;
}

.download-main {
	flex: 1;
	height: 52px;
	padding: 0 20px;
	font: inherit;
	font-size: 1.1rem;
	font-weight: 600;
	color: var(--accent-ink);
	background: var(--accent);
	border: 0;
	border-radius: var(--radius) 0 0 var(--radius);
	cursor: pointer;
}

.download-main small {
	margin-left: 6px;
	font-weight: 400;
}

.download-more {
	display: grid;
	place-items: center;
	width: 56px;
	color: var(--accent-ink);
	background: var(--accent);
	border: 0;
	border-left: 1px solid var(--accent-deep);
	border-radius: 0 var(--radius) var(--radius) 0;
	cursor: pointer;
}

.download-more svg {
	transition: transform 0.15s;
}

.download-more[aria-expanded="true"] svg {
	transform: rotate(180deg);
}

.download-main:hover:not(:disabled),
.download-more:hover:not(:disabled) {
	background: var(--accent-deep);
}

.download-main:disabled,
.download-more:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.download-menu {
	position: absolute;
	top: calc(100% + 4px);
	left: 0;
	right: 0;
	z-index: 5;
	overflow: hidden;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.download-menu[hidden] {
	display: none;
}

.download-menu button {
	display: flex;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	padding: 12px 16px;
	font: inherit;
	font-size: 1rem;
	text-align: left;
	color: var(--ink);
	background: transparent;
	border: 0;
	cursor: pointer;
}

.download-menu button + button {
	border-top: 1px solid var(--line);
}

.download-menu button:hover {
	background: var(--zebra);
}

.download-menu button:focus-visible {
	outline-offset: -3px;
}

.download-menu span {
	font-size: 0.875rem;
	color: var(--muted);
}

/* Help button and dialog */

.help {
	position: absolute;
	top: var(--help-top, max(16px, env(safe-area-inset-top, 0px)));
	right: var(--help-right, max(16px, env(safe-area-inset-right, 0px)));
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0;
	height: 36px;
	min-width: 36px;
	padding: 0 8px;
	overflow: hidden;
	font: inherit;
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--muted);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 99px;
	cursor: pointer;
	transition: gap 0.18s, padding 0.18s, color 0.18s;
}

.help svg {
	flex: none;
}

.help span {
	max-width: 0;
	opacity: 0;
	white-space: nowrap;
	transition: max-width 0.2s, opacity 0.2s;
}

.help:hover,
.help:focus-visible {
	gap: 8px;
	padding: 0 14px 0 10px;
	color: var(--ink);
}

.help:hover span,
.help:focus-visible span {
	max-width: 6em;
	opacity: 1;
}

dialog {
	width: min(520px, calc(100vw - 32px));
	max-height: calc(100vh - 48px);
	padding: 0;
	color: var(--ink);
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius-lg);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

dialog::backdrop {
	background: rgba(24, 24, 27, 0.5);
}

.dialog-body {
	display: flex;
	flex-direction: column;
	gap: 14px;
	max-height: calc(100vh - 50px);
	padding: 24px;
	overflow: auto;
}

.dialog-head {
	display: flex;
	align-items: center;
	gap: 12px;
}

.dialog-head h2 {
	flex: 1;
	margin: 0;
	font-size: 1.25rem;
}

.dialog-close {
	width: 36px;
	height: 36px;
	font: inherit;
	font-size: 1.4rem;
	line-height: 1;
	color: var(--muted);
	background: transparent;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	cursor: pointer;
}

.dialog-close:hover {
	color: var(--ink);
	background: var(--bg);
}

.dialog-body h3 {
	margin: 6px 0 0;
	font-size: 0.875rem;
	font-weight: 600;
	color: var(--ink);
}

.dialog-body p,
.dialog-body li {
	margin: 0;
	font-size: 0.95rem;
}

.dialog-body ol {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin: 0;
	padding-left: 20px;
}

.dialog-body small {
	font-family: var(--mono);
	font-size: 0.78rem;
	color: var(--muted);
}

/* Footer */

footer {
	display: flex;
	justify-content: center;
	margin-top: 28px;
}

footer a {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 0.85rem;
	color: var(--muted);
	text-decoration: none;
}

footer a:hover {
	color: var(--ink);
}

footer b {
	font-weight: 600;
	color: var(--ink);
}

@media (prefers-reduced-motion: reduce) {
	* {
		transition: none !important;
	}
}

/* Text for screen readers only. */

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}
