/* http://meyerweb.com/eric/tools/css/reset/
   v2.0 | 20110126
   License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}

/* =====================================================================
   DESIGN TOKENS
   ===================================================================== */
:root {
	/* Colors */
	--color-bg:         #0d1b2a;
	--color-surface:    #1a2e42;
	--color-surface-2:  #243d55;
	--color-border:     #2e5170;
	--color-accent:     #38a3d4;
	--color-accent-dim: #1d6e99;
	--color-text:       #e8edf2;
	--color-text-muted: #8ba7be;
	--color-link:       #7dd3f7;
	--color-canvas-bg:  #f5f5f5;

	/* Spacing */
	--space-1: 4px;
	--space-2: 8px;
	--space-3: 12px;
	--space-4: 16px;
	--space-5: 24px;
	--space-6: 32px;

	/* Radii */
	--radius-sm: 4px;
	--radius-md: 8px;
	--radius-lg: 12px;

	/* Typography */
	--font-sans: 'Inter', system-ui, -apple-system, sans-serif;
	--font-mono: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
}

/* =====================================================================
   GLOBAL BASE
   ===================================================================== */
*, *::before, *::after {
	box-sizing: border-box;
}

html, body {
	height: 100%;
}

body {
	background: var(--color-bg);
	color: var(--color-text);
	font-family: var(--font-sans);
	font-size: 1rem;
	line-height: 1.5;
}

/* =====================================================================
   APP SHELL
   ===================================================================== */
#app {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
}

/* =====================================================================
   HEADER
   ===================================================================== */
#app-header {
	background: var(--color-surface);
	border-bottom: 1px solid var(--color-border);
	padding: var(--space-3) var(--space-5);
}

#app-header h1 {
	font-size: 1.375rem;
	font-weight: 600;
	color: var(--color-text);
	line-height: 1.2;
}

#app-header .tagline {
	font-size: 0.75rem;
	color: var(--color-text-muted);
	margin-top: var(--space-1);
}

/* =====================================================================
   CONTROLS BAR
   ===================================================================== */
#controls-wrapper {
	width: 100%;
}

#controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-3);
	background: var(--color-surface);
	color: var(--color-text);
	border-bottom: 1px solid var(--color-border);
	padding: var(--space-3) var(--space-4);
}

.control-group {
	display: flex;
	align-items: center;
	gap: var(--space-2);
}

/* =====================================================================
   BUTTONS
   ===================================================================== */
button,
.btn {
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
	padding: var(--space-2) var(--space-4);
	background: var(--color-accent);
	color: #fff;
	border: none;
	border-radius: var(--radius-sm);
	font-family: var(--font-sans);
	font-size: 0.875rem;
	font-weight: 500;
	line-height: 1;
	cursor: pointer;
	text-decoration: none;
	transition: background 150ms ease, box-shadow 150ms ease;
	white-space: nowrap;
}

button:hover,
.btn:hover {
	background: var(--color-accent-dim);
}

button:active,
.btn:active {
	transform: translateY(1px);
}

button:focus-visible,
.btn:focus-visible {
	outline: 2px solid var(--color-accent);
	outline-offset: 2px;
}

/* Ghost variant for secondary actions (Toggle Log) */
#toggleLog {
	background: transparent;
	color: var(--color-text-muted);
	border: 1px solid var(--color-border);
}

#toggleLog:hover {
	background: var(--color-surface-2);
	color: var(--color-text);
	border-color: var(--color-accent);
}

/* =====================================================================
   CHECKBOX LABEL
   ===================================================================== */
.checkbox-label {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	font-size: 0.875rem;
	color: var(--color-text-muted);
	cursor: pointer;
	user-select: none;
}

.checkbox-label input[type="checkbox"] {
	width: 15px;
	height: 15px;
	accent-color: var(--color-accent);
	cursor: pointer;
}

.checkbox-label:hover {
	color: var(--color-text);
}

/* =====================================================================
   FILE INPUT — visually hidden, activated via styled label
   ===================================================================== */
#file {
	opacity: 0;
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

label.file-btn {
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
	padding: var(--space-2) var(--space-4);
	background: var(--color-accent);
	color: #fff;
	border-radius: var(--radius-sm);
	font-family: var(--font-sans);
	font-size: 0.875rem;
	font-weight: 500;
	line-height: 1;
	cursor: pointer;
	transition: background 150ms ease;
	white-space: nowrap;
}

label.file-btn:hover {
	background: var(--color-accent-dim);
}

label.file-btn:focus-within {
	outline: 2px solid var(--color-accent);
	outline-offset: 2px;
}

/* =====================================================================
   SCALE GROUP
   ===================================================================== */
.scale-group {
	display: flex;
	align-items: center;
	gap: var(--space-2);
}

.scale-label {
	font-size: 0.75rem;
	color: var(--color-text-muted);
	white-space: nowrap;
}

/* Range track */
#scale {
	-webkit-appearance: none;
	appearance: none;
	width: 130px;
	height: 4px;
	background: var(--color-surface-2);
	border-radius: 2px;
	cursor: pointer;
	outline: none;
	border: 1px solid var(--color-border);
}

#scale:focus-visible {
	outline: 2px solid var(--color-accent);
	outline-offset: 3px;
}

#scale::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: var(--color-accent);
	cursor: grab;
	transition: background 150ms ease, transform 150ms ease;
}

#scale::-webkit-slider-thumb:active {
	cursor: grabbing;
	transform: scale(1.15);
}

#scale::-moz-range-thumb {
	width: 14px;
	height: 14px;
	border: none;
	border-radius: 50%;
	background: var(--color-accent);
	cursor: grab;
	transition: background 150ms ease;
}

#scale::-moz-range-track {
	background: var(--color-surface-2);
	height: 4px;
	border-radius: 2px;
}

/* Scale value text input */
#sel_scale {
	width: 56px;
	padding: var(--space-1) var(--space-2);
	background: var(--color-surface-2);
	color: var(--color-text);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	font-family: var(--font-mono);
	font-size: 0.8125rem;
	text-align: right;
	transition: border-color 150ms ease;
}

#sel_scale:focus {
	outline: none;
	border-color: var(--color-accent);
}

/* =====================================================================
   LOG PANEL
   NOTE: #logwrapper display is toggled by JS inline style — do NOT set
   display here, as JS inline styles take precedence over stylesheet rules
   and would interfere with the toggle logic.
   ===================================================================== */
#logwrapper {
	width: 100%;
	background: var(--color-surface);
	border-bottom: 1px solid var(--color-border);
	padding: var(--space-2) var(--space-4);
}

#log {
	width: 100%;
	height: 120px;
	max-height: 200px;
	resize: vertical;
	background: var(--color-surface-2);
	color: var(--color-text);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-sm);
	padding: var(--space-2);
	font-family: var(--font-mono);
	font-size: 0.75rem;
	line-height: 1.5;
	box-sizing: border-box;
}

#log:focus {
	outline: none;
	border-color: var(--color-accent);
}

/* =====================================================================
   MAIN CONTENT AREA
   ===================================================================== */
#app-main {
	display: flex;
	flex-direction: column;
	flex: 1;
}

/* =====================================================================
   CANVAS CONTAINER
   ===================================================================== */
#canvas-container {
	flex: 1;
	overflow: auto;
	background: var(--color-canvas-bg);
	padding: var(--space-4);
	display: flex;
	justify-content: flex-start;
	align-items: flex-start;
}

/* CRITICAL: never set width or height on #canvas — JS controls these
   dynamically. Only cosmetic properties are safe here. */
#canvas {
	display: block;
	box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
	border-radius: var(--radius-sm);
	max-width: none;
	cursor: crosshair;
}

/* =====================================================================
   FOOTER
   ===================================================================== */
#app-footer {
	background: var(--color-surface);
	border-top: 1px solid var(--color-border);
	padding: var(--space-3) var(--space-5);
	font-size: 0.75rem;
	color: var(--color-text-muted);
	line-height: 1.5;
}

#app-footer a {
	color: var(--color-link);
	text-decoration: underline;
	text-underline-offset: 2px;
}

#app-footer a:hover {
	color: var(--color-text);
}

/* =====================================================================
   RESPONSIVE — TABLET (< 768px)
   ===================================================================== */
@media (max-width: 767px) {
	#controls {
		flex-direction: column;
		align-items: stretch;
		gap: var(--space-2);
	}

	.control-group {
		flex-wrap: wrap;
	}

	.scale-group {
		width: 100%;
	}

	#scale {
		flex: 1;
	}

	#canvas-container {
		padding: var(--space-2);
	}
}

/* =====================================================================
   RESPONSIVE — MOBILE (< 480px)
   ===================================================================== */
@media (max-width: 479px) {
	#app-header h1 {
		font-size: 1.125rem;
	}

	#app-header {
		padding: var(--space-2) var(--space-3);
	}

	#controls {
		padding: var(--space-2) var(--space-3);
	}

	#sel_scale {
		width: 48px;
	}
}

/* =====================================================================
   MOTION — respect user preference
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after {
		transition-duration: 0ms !important;
		animation-duration: 0ms !important;
	}
}
