:root {
	--bg: #f6f5f2;
	--panel: #ffffff;
	--ink: #1d1d1f;
	--muted: #6b6b70;
	--grid: #c9c7c1;
	--border: #1d1d1f;
	--cell: #ffffff;
	--clue-bg: #ecebe6;
	--sel: #ffe9a8;
	--max-fill: #e4ecf7;
	--line: #d9480f;
	--line-maybe: #e7a37f;
	--solved: #1c5fd6;
	--error: #c92a2a;
	--accent: #1c5fd6;
	--accent-ink: #ffffff;
	color-scheme: light;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #17171a;
		--panel: #222226;
		--ink: #ececef;
		--muted: #9a9aa2;
		--grid: #45454c;
		--border: #d8d8de;
		--cell: #1d1d21;
		--clue-bg: #2a2a2f;
		--sel: #5a4a14;
		--max-fill: #23324a;
		--line: #ff7a3d;
		--line-maybe: #8a5236;
		--solved: #7fb0ff;
		--error: #ff6b6b;
		--accent: #4d8dff;
		--accent-ink: #0b0b0d;
		color-scheme: dark;
	}
}
:root[data-theme="dark"] {
	--bg: #17171a; --panel: #222226; --ink: #ececef; --muted: #9a9aa2; --grid: #45454c;
	--border: #d8d8de; --cell: #1d1d21; --clue-bg: #2a2a2f; --sel: #5a4a14; --max-fill: #23324a;
	--line: #ff7a3d; --line-maybe: #8a5236; --solved: #7fb0ff; --error: #ff6b6b;
	--accent: #4d8dff; --accent-ink: #0b0b0d; color-scheme: dark;
}

* { box-sizing: border-box; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--ink);
	font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
main {
	display: flex;
	gap: 24px;
	padding: 24px 16px;
	align-items: flex-start;
	justify-content: center;
	flex-wrap: wrap;
}
.board-wrap { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
@media (min-width: 900px) { .board-wrap { width: auto; flex: 0 1 640px; } }
/* The SVG scales down to the screen width; its viewBox keeps the aspect ratio. */
#board { display: block; outline: none; user-select: none; max-width: 100%; height: auto; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
kbd, code { font-family: ui-monospace, monospace; font-size: 12px; background: var(--clue-bg); padding: 0 4px; border-radius: 3px; }

.panel {
	background: var(--panel);
	border-radius: 10px;
	padding: 16px;
	width: 340px;
	max-width: 100%;
	box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
	display: flex;
	flex-direction: column;
	gap: 12px;
}
h1 { font-size: 18px; margin: 0; }
.dims { display: flex; gap: 8px; }
.dims label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); flex: 1; }
input[type="number"] { width: 100%; padding: 4px 6px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--grid); border-radius: 5px; }
.buttons { display: flex; flex-wrap: wrap; gap: 6px; }
button {
	font: inherit; padding: 5px 10px; border-radius: 6px; cursor: pointer; touch-action: manipulation;
	border: 1px solid var(--grid); background: var(--bg); color: var(--ink);
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.status { font-weight: 600; }
.status.error { color: var(--error); white-space: pre-wrap; font-weight: 400; font-family: ui-monospace, monospace; font-size: 12px; }
.stats { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }
details summary { cursor: pointer; color: var(--muted); }
textarea {
	width: 100%; margin-top: 6px; font: 11px/1.4 ui-monospace, monospace;
	color: var(--ink); background: var(--bg); border: 1px solid var(--grid); border-radius: 5px; padding: 6px;
}
.rules { padding-left: 18px; margin: 6px 0 0; color: var(--muted); font-size: 13px; }

/* Board */
.cell { fill: var(--cell); stroke: var(--grid); stroke-width: 1; cursor: pointer; }
.cell.max { fill: var(--max-fill); }
.cell.sel { fill: var(--sel); }
/* Clue areas are always faintly visible so touch users can find them. */
.clue-bg { fill: var(--clue-bg); fill-opacity: 0.6; cursor: pointer; }
.clue-bg:hover { fill-opacity: 1; }
.clue-bg.sel { fill: var(--sel); fill-opacity: 1; }
.clue { fill: var(--ink); font-size: 15px; font-weight: 600; pointer-events: none; }
.clue.bad { fill: var(--error); }
.caret { fill: var(--muted); }
.region { stroke: var(--border); stroke-width: 3; stroke-linecap: square; pointer-events: none; }
.outer { fill: none; stroke: var(--border); stroke-width: 3; pointer-events: none; }
.net { stroke: var(--line); stroke-width: 6; stroke-linecap: round; pointer-events: none; }
.net.maybe { stroke: var(--line-maybe); stroke-width: 3; stroke-dasharray: 4 5; }
.num { font-size: 22px; text-anchor: middle; dominant-baseline: central; pointer-events: none; fill: var(--solved); }
.num.given { fill: var(--ink); font-weight: 700; }
.pm { font-size: 10px; text-anchor: middle; dominant-baseline: central; pointer-events: none; fill: var(--muted); }

@media (max-width: 720px) {
	main { padding: 12px 16px 24px; gap: 16px; }
	.panel { width: 100%; }
}
.num, .pm { paint-order: stroke; stroke: var(--cell); stroke-width: 4px; stroke-linejoin: round; }

.many { align-items: center; }
.many input { width: 80px; }
.solnav { align-items: center; }
.solnav[hidden] { display: none; }
#sol-label { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
button.on { background: var(--sel); }

.args { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
.args input { font: 12px ui-monospace, monospace; padding: 4px 6px; color: var(--ink); background: var(--bg); border: 1px solid var(--grid); border-radius: 5px; }

.advanced { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.solnav button { min-width: 44px; }

/* On-screen keypad, shown while a cell or clue is selected. */
.keypad[hidden] { display: none; }
.keypad { background: var(--panel); border-radius: 10px; padding: 10px; box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }
.keypad-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
#keypad-label { font-weight: 600; overflow-wrap: anywhere; }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.keys button { min-height: 44px; font-size: 18px; }
.keys button[data-key=" "], .keys button[data-key="Delete"], .keys button[data-key="Enter"] { font-size: 14px; }
.keypad .done { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Bigger tap targets on touch screens; 16px inputs stop iOS zooming on focus. */
@media (pointer: coarse) {
	button { min-height: 40px; padding: 6px 12px; }
	input[type="number"], .args input, textarea { font-size: 16px; }
	.dims input { min-height: 40px; }
}
@media (pointer: fine) {
	.keypad { display: none; }
}
