/* Components set display: flex and the like, which would otherwise beat the hidden
   attribute's display: none. */
[hidden] {
	display: none !important;
}

:root {
	--bg: #f4f4f2;
	--surface: #ffffff;
	--surface-2: #f0f0ee;
	--border: #d8d8d4;
	--text: #1d1d1b;
	--muted: #6b6b66;
	--accent: #2459d6;
	--accent-text: #ffffff;
	--danger: #c0362c;
	--select: #2f7bff;
	--guide: #e0457b;
	--shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 4px 16px rgb(0 0 0 / 0.08);
	--radius: 8px;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #18181a;
		--surface: #222225;
		--surface-2: #2b2b2f;
		--border: #3a3a3f;
		--text: #ececea;
		--muted: #a0a09a;
		--accent: #5b8cff;
		--accent-text: #0b0b0c;
		--danger: #ff6b5e;
		--shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.3);
		color-scheme: dark;
	}
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font:
		14px/1.4 system-ui,
		-apple-system,
		"Segoe UI",
		sans-serif;
}

h1 {
	font-size: 16px;
	margin: 0;
	font-weight: 650;
}
h2 {
	font-size: 13px;
	margin: 0;
	font-weight: 600;
}

button,
select,
input,
textarea {
	font: inherit;
	color: inherit;
}

button {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 5px 11px;
	cursor: pointer;
}
button:hover:not(:disabled) {
	background: var(--surface-2);
}
button:disabled {
	opacity: 0.5;
	cursor: default;
}
button.primary {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
	font-weight: 600;
	padding: 6px 20px;
}
button.primary:hover:not(:disabled) {
	background: var(--accent);
	filter: brightness(1.08);
}
button.danger {
	color: var(--danger);
}

select,
input[type="number"],
input[type="text"],
textarea {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 4px 7px;
	min-width: 0;
}
textarea {
	width: 100%;
	resize: vertical;
}
input[type="number"] {
	width: 5.5em;
}
:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
}

.topbar {
	display: flex;
	align-items: center;
	gap: 16px;
	padding: 10px 16px;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	flex-wrap: wrap;
}
.spacer {
	flex: 1;
}
.filebar {
	display: flex;
	gap: 6px;
}

.segmented {
	display: inline-flex;
	border: 1px solid var(--border);
	border-radius: 7px;
	overflow: hidden;
}
.segmented button {
	border: 0;
	border-radius: 0;
	padding: 5px 14px;
}
.segmented button + button {
	border-left: 1px solid var(--border);
}
.segmented button[aria-selected="true"],
.segmented button[aria-pressed="true"] {
	background: var(--accent);
	color: var(--accent-text);
}
.segmented.small button {
	padding: 3px 10px;
}

.banner {
	background: #fff4d6;
	color: #5a4200;
	border-bottom: 1px solid #ecd48f;
	padding: 8px 16px;
}
@media (prefers-color-scheme: dark) {
	.banner {
		background: #3a2f10;
		color: #f3dc9a;
		border-color: #5d4c1a;
	}
}

.layout {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 340px;
	gap: 16px;
	padding: 16px;
	max-width: 1280px;
	margin: 0 auto;
}
@media (max-width: 820px) {
	.layout {
		grid-template-columns: minmax(0, 1fr);
	}
}

.workspace {
	display: flex;
	flex-direction: column;
	gap: 12px;
	min-width: 0;
}

.labelbar,
.printbar {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}
.labelbar label,
.printbar label {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}
.custom-size input[type="number"] {
	width: 4.5em;
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}
.hint {
	color: var(--muted);
	font-size: 12.5px;
}

.stage {
	background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--bg) 0 50%) 0 0 / 16px 16px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	min-height: 220px;
	/* Flex with auto margins, not grid centring: a zoomed-in label wider than the stage must
	   scroll to both edges, and centring would push its left side out of reach. */
	display: flex;
	padding: 32px 16px;
	overflow: auto;
}
.stage > .paper-wrap {
	margin: auto;
	flex: none;
}
/* Rulers sit above and left of the label, and stick to the stage's edges while a zoomed
   label scrolls under them. The 20px matches SIZE in ruler.js. */
.paper-wrap.with-ruler {
	display: grid;
	grid-template-areas: ". top" "left paper";
	grid-template-columns: 20px auto;
	grid-template-rows: 20px auto;
	gap: 4px;
}
.ruler {
	display: block;
	position: sticky;
	z-index: 4;
	border-radius: 3px;
	box-shadow: 0 0 0 1px var(--border);
}
.ruler.top {
	grid-area: top;
	top: 0;
}
.ruler.left {
	grid-area: left;
	left: 0;
}
.paper-wrap.with-ruler > .paper {
	grid-area: paper;
}
.ruler-toggle {
	margin-left: auto;
	padding: 2px 8px;
}
.ruler-toggle[aria-pressed="true"] {
	background: var(--accent);
	border-color: var(--accent);
	color: #fff;
}
.zoom {
	display: inline-flex;
	gap: 2px;
}
.zoom button {
	min-width: 2.2em;
	padding: 2px 6px;
}
.paper {
	position: relative;
	box-shadow: var(--shadow);
	background: #fff;
	/* Die-cut labels have rounded corners; it helps judge how close to the edge things are. */
	border-radius: calc(var(--dot) * 8);
	overflow: hidden;
}
/* A continuous roll is cut straight across, so no die-cut corners. */
.paper.continuous {
	border-radius: 0;
}
.paper canvas {
	display: block;
	image-rendering: pixelated;
}
.stage-hint {
	margin: -4px 0 0;
}

.overlay {
	position: absolute;
	inset: 0;
	touch-action: none;
}
/* Guides extend past the label edge; let them show. */
.paper:has(.snapline) {
	overflow: visible;
}
.guide {
	position: absolute;
	border: 1px dashed var(--guide);
	opacity: 0.55;
	pointer-events: none;
}
.emoji-search {
	width: 100%;
	box-sizing: border-box;
	margin-bottom: 8px;
}
.batch {
	font-size: 13px;
	color: var(--muted);
}
.batch[open] {
	display: flex;
	flex-direction: column;
	gap: 6px;
}
.batch summary {
	cursor: pointer;
}
.batch textarea {
	width: 100%;
	box-sizing: border-box;
	font: inherit;
	color: var(--text);
}
.batch p {
	margin: 0;
}
.marquee {
	position: absolute;
	z-index: 2;
	border: 1px solid var(--select);
	background: rgb(47 123 255 / 0.1);
	pointer-events: none;
}
/* The inline editor: the canvas below is the text you read; see the comment in stage.js. */
.inline-editor {
	position: absolute;
	z-index: 3;
	outline: 2px solid var(--select);
	cursor: text;
	touch-action: none;
}
.inline-local {
	position: absolute;
	left: 0;
	top: 0;
	transform-origin: 0 0;
}
.inline-caret {
	position: absolute;
	width: 2px;
	margin-left: -1px;
	background: #000;
	pointer-events: none;
}
.inline-editor.invert .inline-caret {
	background: #fff;
}
.inline-caret.blink {
	animation: caret-blink 1.06s steps(1) infinite;
}
@keyframes caret-blink {
	50% {
		opacity: 0;
	}
}
.inline-selection > div {
	position: absolute;
	background: rgb(47 123 255 / 0.3);
	pointer-events: none;
}
/* Takes the typing but shows nothing; it sits at the caret for input methods' windows. */
.inline-edit {
	position: absolute;
	width: 1px;
	margin: 0;
	padding: 0;
	border: 0;
	resize: none;
	overflow: hidden;
	white-space: pre;
	color: transparent;
	caret-color: transparent;
	background: transparent;
	outline: none;
	pointer-events: none;
}
.inline-edit::selection {
	background: transparent;
}
@media (prefers-reduced-motion: reduce) {
	.inline-caret.blink {
		animation: none;
	}
}
.layer {
	position: absolute;
	inset: 0;
	pointer-events: none;
}
.layer.boxes > .box {
	pointer-events: auto;
}
.snapline {
	position: absolute;
	pointer-events: none;
	background: var(--guide);
	z-index: 2;
}
.snapline.x {
	top: -12px;
	bottom: -12px;
	width: 1px;
	margin-left: -0.5px;
}
.snapline.y {
	left: -12px;
	right: -12px;
	height: 1px;
	margin-top: -0.5px;
}
.box {
	position: absolute;
	outline: 1px dashed rgb(47 123 255 / 0.35);
	cursor: move;
}
.box:hover {
	outline: 1px solid rgb(47 123 255 / 0.7);
}
.box.warn {
	outline: 2px dashed var(--danger);
}
.box.selected {
	outline: 2px solid var(--select);
}
.handle {
	position: absolute;
	width: 10px;
	height: 10px;
	background: #fff;
	border: 2px solid var(--select);
	border-radius: 2px;
	margin: -5px 0 0 -5px;
}
.handle[data-dir="nw"] {
	left: 0;
	top: 0;
	cursor: nwse-resize;
}
.handle[data-dir="ne"] {
	left: 100%;
	top: 0;
	cursor: nesw-resize;
}
.handle[data-dir="sw"] {
	left: 0;
	top: 100%;
	cursor: nesw-resize;
}
.handle[data-dir="se"] {
	left: 100%;
	top: 100%;
	cursor: nwse-resize;
}
.handle[data-dir="e"] {
	left: 100%;
	top: 50%;
	cursor: ew-resize;
}
.handle[data-dir="w"] {
	left: 0;
	top: 50%;
	cursor: ew-resize;
}
.handle[data-dir="n"] {
	left: 50%;
	top: 0;
	cursor: ns-resize;
}
.handle[data-dir="s"] {
	left: 50%;
	top: 100%;
	cursor: ns-resize;
}

.printbar {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 10px 12px;
}
.printbar input[type="number"] {
	width: 4em;
}
.status {
	font-size: 12.5px;
	color: var(--muted);
}
.status.ok::before {
	content: "● ";
	color: #2a9d4b;
}
.status.problem {
	color: var(--danger);
	font-weight: 600;
}
.status.problem::before {
	content: "● ";
}
progress {
	width: 120px;
}

.advanced {
	font-size: 13px;
	color: var(--muted);
}
/* On a wrapper: Chromium lays out a <details> element's contents itself, ignoring flex. */
.advanced-body {
	display: flex;
	flex-direction: column;
	gap: 8px;
	align-items: flex-start;
	padding: 8px 0 0 14px;
}
.advanced-body label {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 6px;
}
.advanced-body > .hint {
	margin: 0;
}
.advanced summary {
	cursor: pointer;
}
.advanced input[type="number"] {
	width: 4.5em;
}

.virtual {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 12px;
}
.virtual-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.tape {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin-top: 8px;
}
.printed {
	display: flex;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
}
.printed canvas {
	image-rendering: pixelated;
	background: #fff;
	border-radius: 4px;
	box-shadow: var(--shadow);
	max-width: 100%;
}

.panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 14px;
	align-self: start;
	display: flex;
	flex-direction: column;
	gap: 12px;
	position: sticky;
	top: 16px;
}
.props {
	display: flex;
	flex-direction: column;
	gap: 12px;
}
#designPanel {
	display: flex;
	flex-direction: column;
	gap: 12px;
}
.field {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 12.5px;
	color: var(--muted);
}
.field-head {
	display: flex;
	align-items: center;
	gap: 6px;
}
.field-head > label {
	margin-right: auto;
}
.insert-field {
	font-size: 12px;
	padding: 2px 4px;
	max-width: 9em;
}
.insert-emoji {
	padding: 2px 8px;
	font-size: 12px;
}
.field > select,
.field > textarea {
	color: var(--text);
	font-size: 14px;
}
.row {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	color: var(--text);
}
.row.two {
	align-items: end;
}
.row.two .field {
	flex: 1;
}
.check {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	font-size: 13px;
	color: var(--text);
}
.italic-check {
	padding-bottom: 6px;
}
.unit {
	color: var(--muted);
}
.toolbar {
	display: flex;
	gap: 6px;
	align-items: center;
	flex-wrap: wrap;
}
.toolbar-group {
	display: inline-flex;
	gap: 6px;
}
.section {
	color: var(--muted);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
.section-label {
	font-size: 12.5px;
	color: var(--muted);
}
.layers {
	list-style: none;
	margin: 0;
	padding: 0;
	border: 1px solid var(--border);
	border-radius: 6px;
	max-height: 180px;
	overflow: auto;
}
.layers li {
	padding: 5px 9px;
	cursor: pointer;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	border-bottom: 1px solid var(--border);
}
.layers li:last-child {
	border-bottom: 0;
}
.layers li:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: -2px;
}
.layers li[aria-selected="true"] {
	background: var(--accent);
	color: var(--accent-text);
}
.layers li .kind {
	opacity: 0.6;
	margin-right: 6px;
	font-size: 12px;
}
.layers:empty::after {
	content: "Nothing on the label yet.";
	display: block;
	padding: 8px;
	color: var(--muted);
}
input[type="range"] {
	width: 100%;
	accent-color: var(--accent);
}
.grid4 {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 6px;
}
.grid4 label {
	display: flex;
	flex-direction: column;
	font-size: 12px;
	color: var(--muted);
}
.grid4 input {
	width: 100%;
}
.keys {
	margin: 0;
}
.warning {
	margin: 0;
	padding: 8px 10px;
	border-radius: 6px;
	background: color-mix(in srgb, var(--danger) 12%, transparent);
	color: var(--danger);
	font-size: 13px;
}
kbd {
	font:
		11px ui-monospace,
		monospace;
	border: 1px solid var(--border);
	border-bottom-width: 2px;
	border-radius: 4px;
	padding: 0 4px;
}

dialog {
	border: 1px solid var(--border);
	border-radius: 12px;
	background: var(--surface);
	color: var(--text);
	padding: 16px;
	max-width: min(460px, calc(100vw - 32px));
	box-shadow: var(--shadow);
}
dialog::backdrop {
	background: rgb(0 0 0 / 0.35);
}
dialog form {
	display: flex;
	flex-direction: column;
	gap: 12px;
}
.emoji-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
	gap: 4px;
	max-height: 300px;
	overflow: auto;
}
.emoji-grid button {
	font-size: 22px;
	padding: 4px;
	line-height: 1.2;
}
.dialog-actions {
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	gap: 8px;
}
#printedDialog h2,
#printedDialog p {
	margin: 0;
}

.toast {
	position: fixed;
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
	background: var(--text);
	color: var(--bg);
	padding: 9px 16px;
	border-radius: 8px;
	box-shadow: var(--shadow);
	max-width: calc(100vw - 32px);
	z-index: 10;
}
.toast.error {
	background: var(--danger);
	color: #fff;
}

.history-dialog {
	width: min(720px, calc(100vw - 32px));
	max-width: none;
}
.history-dialog[open] {
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-height: calc(100vh - 64px);
}
.history-head,
.history-tools {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
}
.history-head form {
	display: contents;
}
.history-tools input[type="search"] {
	flex: 1;
	min-width: 140px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 4px 8px;
}
.history-list {
	list-style: none;
	margin: 0;
	padding: 0;
	overflow: auto;
	display: flex;
	flex-direction: column;
	gap: 6px;
}
.history-list li {
	display: grid;
	grid-template-columns: 132px minmax(0, 1fr) auto;
	align-items: center;
	gap: 12px;
	padding: 8px;
	border: 1px solid var(--border);
	border-radius: 8px;
}
.thumb-btn {
	padding: 4px;
	background: #fff;
	line-height: 0;
}
.thumb {
	width: 120px;
	height: auto;
	image-rendering: pixelated;
}
.entry-meta {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}
.entry-meta strong {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.entry-actions {
	display: flex;
	gap: 6px;
}
.tag {
	margin-left: 6px;
	padding: 0 6px;
	border-radius: 4px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	font-size: 11px;
}
@media (max-width: 560px) {
	.history-list li {
		grid-template-columns: 1fr;
	}
	.thumb {
		width: 100%;
	}
}
.props > p.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}
.hint {
	margin: 0;
}

.site-footer {
	padding: 12px 16px 20px;
	color: var(--muted);
	font-size: 12px;
	text-align: center;
}
.site-footer p {
	margin: 4px 0;
}
/* An action that sits in running text, like the links around it. */
button.link {
	padding: 0;
	border: 0;
	background: none;
	color: LinkText;
	font: inherit;
	text-decoration: underline;
	cursor: pointer;
}
