:root {
	--bg: #f6f2ea;
	--panel: #fffdf8;
	--text: #2b2117;
	--muted: #7a6d5d;
	--line: #e3d9c7;
	--accent: #b5562b;
	--accent-text: #fff;
	--tile: #f1e3c4;
	--tile-edge: #c8ad80;
	--viewer: radial-gradient(circle at 50% 35%, #fffaf0, #e9dfcd);
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #1b1814;
		--panel: #24201b;
		--text: #f1e8da;
		--muted: #a99b88;
		--line: #3a332a;
		--accent: #e07a45;
		--accent-text: #1b1814;
		--tile: #e9d7b0;
		--tile-edge: #a8875a;
		--viewer: radial-gradient(circle at 50% 35%, #3a3229, #1f1b16);
		color-scheme: dark;
	}
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font:
		15px/1.45 system-ui,
		-apple-system,
		'Segoe UI',
		Roboto,
		sans-serif;
}

[hidden] {
	display: none !important;
}

.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 12px 20px;
	border-bottom: 1px solid var(--line);
}

.topbar h1 {
	margin: 0;
	font-size: 1.15rem;
	display: flex;
	align-items: center;
	gap: 10px;
}

.logo {
	display: inline-grid;
	place-items: center;
	width: 34px;
	height: 34px;
	border-radius: 6px;
	background: var(--tile);
	border: 2px solid var(--tile-edge);
	color: #2b2117;
	font-weight: 800;
	font-size: 20px;
	position: relative;
	line-height: 1;
}

.logo sub {
	position: absolute;
	right: 3px;
	bottom: 3px;
	font-size: 9px;
}

.topbar-right {
	display: flex;
	align-items: center;
	gap: 16px;
}

.topbar-right select {
	width: auto;
	padding: 3px 6px;
}

.gh {
	color: var(--muted);
	text-decoration: none;
}

.gh:hover {
	color: var(--accent);
}

.layout {
	display: grid;
	grid-template-columns: 340px minmax(0, 1fr);
	gap: 20px;
	padding: 20px;
	max-width: 1500px;
	margin: 0 auto;
}

.panel {
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 8px 16px 16px;
	align-self: start;
	position: sticky;
	top: 20px;
	max-height: calc(100vh - 40px);
	overflow: auto;
}

fieldset {
	border: 0;
	border-bottom: 1px solid var(--line);
	margin: 0;
	padding: 12px 0;
}

details.group {
	border-bottom: 1px solid var(--line);
	padding: 4px 0;
}

details.group summary {
	cursor: pointer;
	font-weight: 700;
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--muted);
	padding: 10px 0;
	list-style-position: inside;
}

details.group summary:hover {
	color: var(--accent);
}

details.group[open] {
	padding-bottom: 12px;
}

legend {
	font-weight: 700;
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--muted);
	padding: 0;
	margin-bottom: 6px;
	float: left;
	width: 100%;
}

.field {
	display: grid;
	grid-template-columns: 1fr 130px;
	align-items: center;
	gap: 4px 10px;
	margin: 6px 0;
	clear: both;
}

.field small {
	grid-column: 1 / -1;
	color: var(--muted);
	font-size: 0.8rem;
}

.field-textarea,
.field-file {
	grid-template-columns: 1fr;
}

.field-checkbox {
	grid-template-columns: auto 1fr;
	cursor: pointer;
}

.field-select {
	grid-template-columns: 1fr;
}

input,
select,
textarea {
	font: inherit;
	color: inherit;
	background: var(--bg);
	border: 1px solid var(--line);
	border-radius: 6px;
	padding: 5px 8px;
	width: 100%;
	min-width: 0;
}

textarea {
	font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
	font-size: 13px;
	resize: vertical;
}

input[type='checkbox'] {
	width: 18px;
	height: 18px;
	accent-color: var(--accent);
}

input[type='color'] {
	padding: 2px;
	height: 32px;
}

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

.with-unit {
	display: flex;
	align-items: center;
	gap: 6px;
}

.unit {
	color: var(--muted);
	font-size: 0.85rem;
	width: 26px;
}

.stage {
	min-width: 0;
}

.viewer-wrap {
	position: relative;
	border-radius: 12px;
	overflow: hidden;
	background: var(--viewer);
	border: 1px solid var(--line);
}

#viewer {
	height: min(62vh, 620px);
	min-height: 320px;
}

#viewer canvas {
	display: block;
	width: 100%;
	height: 100%;
	touch-action: none;
}

.viewer-tools {
	position: absolute;
	top: 12px;
	left: 12px;
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}

.viewer-tools select {
	width: auto;
	background: var(--panel);
}

.seg {
	display: inline-flex;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 2px;
}

.seg button {
	font: inherit;
	border: 0;
	background: none;
	color: var(--muted);
	padding: 4px 12px;
	border-radius: 6px;
	cursor: pointer;
}

.seg button.active {
	background: var(--accent);
	color: var(--accent-text);
}

.tool-btn {
	font: inherit;
	background: var(--panel);
	color: var(--muted);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 4px 12px;
	cursor: pointer;
}

.tool-btn[aria-pressed='true'] {
	color: var(--accent);
	border-color: var(--accent);
}

.view-note {
	align-self: center;
	font-size: 0.85rem;
	color: var(--muted);
}

.view-note:empty {
	display: none;
}

.status {
	min-height: 1.5em;
	margin-top: 8px;
	font-size: 0.9rem;
	color: var(--muted);
}

.status.error {
	color: #c0392b;
	font-weight: 600;
}

.tiles-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin: 6px 0 8px;
}

.tiles-head h2 {
	font-size: 1rem;
	margin: 0;
}

#summary {
	color: var(--muted);
	font-size: 0.9rem;
}

.tile-list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
	gap: 8px;
}

.chip {
	position: relative;
	aspect-ratio: 1;
	border-radius: 6px;
	border: 2px solid var(--tile-edge);
	background: var(--tile);
	color: #2b2117;
	cursor: pointer;
	padding: 0;
	font: inherit;
}

.chip:hover {
	transform: translateY(-1px);
}

.chip.active {
	outline: 3px solid var(--accent);
	outline-offset: 1px;
}

.chip .l {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	font-weight: 800;
	font-size: 22px;
	/* stejně jako na kameni: vodorovně uprostřed, o 3 % výš */
	padding-bottom: 6%;
}

.chip .v {
	position: absolute;
	right: 4px;
	bottom: 2px;
	font-size: 10px;
	font-weight: 700;
}

.chip .c {
	position: absolute;
	left: 4px;
	bottom: 2px;
	font-size: 9px;
	color: #7a6d5d;
}

.tile-list.selecting {
	grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
}

.cell {
	display: grid;
	gap: 4px;
}

.stepper {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: center;
	border: 1px solid var(--line);
	border-radius: 6px;
	background: var(--panel);
	font-size: 0.85rem;
	text-align: center;
	color: var(--muted);
}

.stepper.on {
	border-color: var(--accent);
	color: var(--text);
	font-weight: 700;
}

.stepper button {
	font: inherit;
	border: 0;
	background: none;
	color: inherit;
	padding: 2px 0;
	cursor: pointer;
}

.stepper button:disabled {
	opacity: 0.3;
	cursor: default;
}

.selection-tools {
	display: flex;
	gap: 12px;
	margin-right: auto;
}

.btn.link.small {
	padding: 0;
	font-size: 0.85rem;
}

.actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 18px;
}

.btn {
	font: inherit;
	font-weight: 600;
	padding: 10px 16px;
	border-radius: 8px;
	border: 1px solid var(--line);
	background: var(--panel);
	color: var(--text);
	cursor: pointer;
}

.btn:hover {
	border-color: var(--accent);
}

.btn.primary {
	background: var(--accent);
	border-color: var(--accent);
	color: var(--accent-text);
}

.btn:disabled {
	opacity: 0.6;
	cursor: progress;
}

.btn.link {
	border: 0;
	background: none;
	color: var(--muted);
	font-weight: 400;
	padding: 12px 0 0;
	text-decoration: underline;
}

.tips-title {
	font-size: 1rem;
	margin: 24px 0 8px;
}

.tips {
	color: var(--muted);
	font-size: 0.9rem;
	max-width: 75ch;
	margin: 0;
	padding-left: 20px;
}

.tips li {
	margin: 4px 0;
}

.tips li.warn {
	color: var(--accent);
	font-weight: 600;
}

@media (max-width: 860px) {
	.layout {
		grid-template-columns: 1fr;
		padding: 12px 16px;
	}

	.panel {
		position: static;
		max-height: none;
		order: 2;
	}

	#viewer {
		height: 55vh;
	}
}
