/**
 * DIY Daily — Circuit Simulator styles
 * Dark chrome panels (#232D36) with a cream canvas area and burnt-orange
 * accents, per SPEC design tokens. Mobile-first responsive: the palette
 * collapses into a bottom sheet below 1024px.
 */

.dd-sim-page {
	background: #1b232b;
}

.dd-sim-app {
	--sim-panel: #232d36;
	--sim-panel-2: #2b3742;
	--sim-line: #3a4753;
	--sim-text: #e8e2d8;
	--sim-muted: #9aa7b2;
	--sim-accent: #d9661f;
	--sim-accent-hover: #f07a2e;
	--sim-cream: #faf7f2;
	--sim-danger: #c0392b;

	display: flex;
	flex-direction: column;
	height: 100vh;
	max-height: 100vh;
	overflow: hidden;
	font-family: 'Inter', system-ui, -apple-system, sans-serif;
	color: var(--sim-text);
	background: var(--sim-panel);
}

/* ================= Toolbar ================= */

.sim-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 14px;
	padding: 8px 12px;
	background: var(--sim-panel);
	border-bottom: 1px solid var(--sim-line);
	z-index: 30;
}

.sim-toolbar-group {
	display: flex;
	align-items: center;
	gap: 6px;
	padding-right: 12px;
	border-right: 1px solid var(--sim-line);
}

.sim-toolbar-group:last-child {
	border-right: 0;
	padding-right: 0;
}

.sim-toolbar-label {
	font-size: 12px;
	color: var(--sim-muted);
}

.sim-btn {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 6px 10px;
	font: inherit;
	font-size: 12.5px;
	font-weight: 500;
	color: var(--sim-text);
	background: var(--sim-panel-2);
	border: 1px solid var(--sim-line);
	border-radius: 8px;
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.15s ease, border-color 0.15s ease;
}

.sim-btn:hover {
	background: #33414e;
	border-color: #4a5a68;
}

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

.sim-btn:disabled {
	opacity: 0.45;
	cursor: default;
}

.sim-btn[aria-pressed="true"] {
	border-color: var(--sim-accent);
	box-shadow: inset 0 0 0 1px var(--sim-accent);
}

.sim-btn-danger:hover {
	background: #4a2c28;
	border-color: var(--sim-danger);
}

.sim-btn-run {
	background: var(--sim-accent);
	border-color: var(--sim-accent);
	color: #fff;
	font-weight: 600;
}

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

.sim-btn-run.is-running {
	background: var(--sim-danger);
	border-color: var(--sim-danger);
}

.sim-run-dot {
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: #d8d2c8;
	box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
}

.sim-btn-run.is-running .sim-run-dot {
	background: #7bf0a0;
	animation: sim-pulse 1.1s ease-in-out infinite;
}

@keyframes sim-pulse {
	0%, 100% { box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25); }
	50%      { box-shadow: 0 0 8px 3px rgba(123, 240, 160, 0.55); }
}

.sim-select {
	padding: 6px 8px;
	font: inherit;
	font-size: 12.5px;
	color: var(--sim-text);
	background: var(--sim-panel-2);
	border: 1px solid var(--sim-line);
	border-radius: 8px;
	max-width: 190px;
}

/* ================= Main layout ================= */

.sim-main {
	display: flex;
	flex: 1 1 auto;
	min-height: 0;
	position: relative;
}

/* ---- Left palette ---- */

.sim-palette-handle {
	display: none; /* only visible on mobile */
}

.sim-palette {
	width: 208px;
	flex: 0 0 auto;
	overflow-y: auto;
	background: var(--sim-panel);
	border-right: 1px solid var(--sim-line);
	padding: 10px;
	z-index: 20;
}

.sim-palette-group {
	margin-bottom: 10px;
	border: 1px solid var(--sim-line);
	border-radius: 10px;
	overflow: hidden;
	background: var(--sim-panel-2);
}

.sim-palette-heading {
	margin: 0;
	padding: 8px 10px;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--sim-muted);
	cursor: pointer;
	user-select: none;
}

.sim-palette-heading::after {
	content: "\25BE"; /* down chevron */
	float: right;
	transition: transform 0.15s ease;
}

.sim-palette-group.is-collapsed .sim-palette-heading::after {
	transform: rotate(-90deg);
}

.sim-palette-group.is-collapsed .sim-palette-items {
	display: none;
}

.sim-palette-items {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 4px 6px 8px;
}

.sim-pal-item {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 7px 8px;
	font: inherit;
	font-size: 12.5px;
	color: var(--sim-text);
	background: #1f2830;
	border: 1px solid var(--sim-line);
	border-radius: 8px;
	cursor: grab;
	text-align: left;
	touch-action: none;
	transition: border-color 0.15s ease, background 0.15s ease;
}

.sim-pal-item:hover,
.sim-pal-item.is-armed {
	border-color: var(--sim-accent);
	background: #26303a;
}

.sim-pal-item.is-armed {
	box-shadow: 0 0 0 1px var(--sim-accent);
}

/* Palette mini icons (pure CSS hints of the part shape) */
.sim-pal-icon {
	position: relative;
	width: 26px;
	height: 16px;
	flex: 0 0 auto;
	border-radius: 3px;
	background: #39454f;
}

.sim-pal-icon-battery { background: linear-gradient(90deg, #d9661f 0 30%, #39454f 30%); }
.sim-pal-icon-switch  { background: linear-gradient(115deg, #39454f 55%, #d9661f 55% 65%, #39454f 65%); }
.sim-pal-icon-resistor {
	background: repeating-linear-gradient(90deg, #c9a26b 0 5px, #8a6b3f 5px 7px);
}
.sim-pal-icon-pot     { background: radial-gradient(circle at 50% 50%, #d9661f 0 5px, #39454f 6px); }
.sim-pal-icon-cap     { background: linear-gradient(90deg, #39454f 40%, #e8e2d8 40% 45%, #39454f 45% 55%, #e8e2d8 55% 60%, #39454f 60%); }
.sim-pal-icon-led     { background: #39454f; }
.sim-pal-icon-led::after {
	content: "";
	position: absolute;
	left: 8px;
	top: 3px;
	width: 10px;
	height: 10px;
	border-radius: 50%;
}
.sim-pal-led-red::after    { background: #e23b2e; }
.sim-pal-led-green::after  { background: #35c15a; }
.sim-pal-led-blue::after   { background: #3b82f6; }
.sim-pal-led-yellow::after { background: #f2c420; }
.sim-pal-icon-buzzer { background: radial-gradient(circle at 50% 50%, #1b232b 0 3px, #d9a441 4px 6px, #39454f 7px); }
.sim-pal-icon-uno    { background: #0e7c8f; }
.sim-pal-icon-esp32  { background: #15181c; border: 1px solid #4a5a68; }
.sim-pal-icon-555    { background: linear-gradient(#15181c 45%, #e8e2d8 45% 55%, #15181c 55%); }

/* ---- Canvas ---- */

.sim-canvas-wrap {
	flex: 1 1 auto;
	position: relative;
	min-width: 0;
	background: var(--sim-cream);
}

#sim-canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	display: block;
	touch-action: none; /* we handle all gestures ourselves */
	cursor: crosshair;
	background: var(--sim-cream);
}

#sim-canvas.is-panning { cursor: grabbing; }
#sim-canvas.is-placing { cursor: copy; }
#sim-canvas.is-wiring  { cursor: cell; }

/* ---- Right side panel ---- */

.sim-side {
	width: 300px;
	flex: 0 0 auto;
	display: flex;
	flex-direction: column;
	background: var(--sim-panel);
	border-left: 1px solid var(--sim-line);
	overflow-y: auto;
	z-index: 20;
}

.sim-side-heading {
	margin: 0;
	padding: 10px 12px 6px;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--sim-muted);
}

.sim-props {
	flex: 0 0 auto;
	border-bottom: 1px solid var(--sim-line);
	padding-bottom: 10px;
}

.sim-props-body {
	padding: 0 12px;
	font-size: 13px;
}

.sim-props-empty {
	color: var(--sim-muted);
	font-size: 12.5px;
}

.sim-prop-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin: 8px 0;
}

.sim-prop-row label {
	color: var(--sim-muted);
	font-size: 12px;
	flex: 0 0 auto;
}

.sim-prop-row input[type="number"],
.sim-prop-row input[type="text"],
.sim-prop-row select {
	width: 130px;
	padding: 5px 7px;
	font: inherit;
	font-size: 12.5px;
	color: var(--sim-text);
	background: #1f2830;
	border: 1px solid var(--sim-line);
	border-radius: 6px;
}

.sim-prop-row input[type="range"] {
	width: 130px;
	accent-color: var(--sim-accent);
}

.sim-prop-row input[type="checkbox"] {
	accent-color: var(--sim-accent);
	width: 16px;
	height: 16px;
}

.sim-props-title {
	margin: 4px 0 2px;
	font-size: 13.5px;
	font-weight: 600;
	color: var(--sim-text);
}

.sim-props-sub {
	margin: 0 0 6px;
	font-size: 11.5px;
	color: var(--sim-muted);
}

.sim-props-actions {
	margin-top: 10px;
	display: flex;
	gap: 6px;
}

/* ---- Code panel ---- */

.sim-code-wrap {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	min-height: 180px;
}

.sim-code-wrap.is-hidden {
	display: none;
}

.sim-code-editor {
	position: relative;
	flex: 1 1 auto;
	margin: 0 10px 10px;
	min-height: 160px;
	border: 1px solid var(--sim-line);
	border-radius: 10px;
	overflow: hidden;
	background: #1e2a33; /* --dd-code-bg */
}

.sim-code-highlight,
.sim-code-text {
	margin: 0;
	padding: 10px 12px;
	font-family: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
	font-size: 12.5px;
	line-height: 1.55;
	tab-size: 4;
	white-space: pre;
	overflow: auto;
}

.sim-code-highlight {
	position: absolute;
	inset: 0;
	pointer-events: none;
	color: #d7dde3;
}

.sim-code-text {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	background: transparent;
	color: transparent;
	caret-color: #f2c420;
	border: 0;
	resize: none;
	outline: none;
}

.sim-code-text::selection {
	background: rgba(217, 102, 31, 0.35);
}

/* Syntax highlight token colors */
.sim-tok-kw   { color: #f08c4a; font-weight: 600; }  /* keywords */
.sim-tok-type { color: #6fc3b8; }                    /* types */
.sim-tok-fn   { color: #f2c420; }                    /* function calls */
.sim-tok-num  { color: #d98cb3; }                    /* numbers / constants */
.sim-tok-str  { color: #9ece6a; }                    /* strings */
.sim-tok-com  { color: #6b7a88; font-style: italic; }/* comments */
.sim-tok-pre  { color: #b392f0; }                    /* preprocessor */

/* ================= Status bar ================= */

.sim-statusbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 7px 12px;
	font-size: 12.5px;
	background: var(--sim-panel);
	border-top: 1px solid var(--sim-line);
	z-index: 30;
}

.sim-status-msg {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sim-status-msg.is-ok      { color: #7bf0a0; }
.sim-status-msg.is-warn    { color: #f2c420; }
.sim-status-msg.is-error   { color: #ff7a66; }

.sim-status-info {
	flex: 0 0 auto;
	color: var(--sim-muted);
	font-variant-numeric: tabular-nums;
}

/* ================= Modals ================= */

.sim-modal {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	background: rgba(12, 17, 21, 0.65);
	z-index: 100;
}

.sim-modal[hidden] {
	display: none;
}

.sim-modal-card {
	width: 100%;
	max-width: 420px;
	max-height: 85vh;
	overflow-y: auto;
	background: var(--sim-panel-2);
	border: 1px solid var(--sim-line);
	border-radius: 12px;
	padding: 18px 20px;
	box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

.sim-modal-card-wide {
	max-width: 560px;
}

.sim-modal-title {
	margin: 0 0 8px;
	font-family: 'Space Grotesk', 'Inter', sans-serif;
	font-size: 18px;
	color: var(--sim-text);
}

.sim-modal-text {
	margin: 6px 0;
	font-size: 13px;
	color: var(--sim-muted);
}

.sim-modal-row {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 12px 0;
	font-size: 13px;
}

.sim-modal-row input {
	flex: 1 1 auto;
	padding: 7px 9px;
	font: inherit;
	color: var(--sim-text);
	background: #1f2830;
	border: 1px solid var(--sim-line);
	border-radius: 8px;
}

.sim-modal-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-top: 14px;
}

.sim-colors-canvas {
	display: block;
	width: 100%;
	max-width: 320px;
	height: 80px;
	margin: 8px auto;
	background: var(--sim-cream);
	border-radius: 8px;
}

.sim-colors-result {
	font-weight: 600;
	color: var(--sim-text);
}

.sim-slots-list {
	list-style: none;
	margin: 10px 0 0;
	padding: 0;
	max-height: 300px;
	overflow-y: auto;
}

.sim-slots-list li {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 10px;
	border: 1px solid var(--sim-line);
	border-radius: 8px;
	margin-bottom: 6px;
	font-size: 13px;
}

.sim-slots-list .sim-slot-name {
	flex: 1 1 auto;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sim-slots-list .sim-slot-empty {
	border: 0;
	color: var(--sim-muted);
	justify-content: center;
}

.sim-help-list {
	margin: 8px 0 0;
	padding-left: 20px;
	font-size: 13.5px;
	line-height: 1.6;
	color: var(--sim-text);
}

.sim-help-list li {
	margin-bottom: 6px;
}

/* ================= Responsive ================= */

@media (max-width: 1280px) {
	.sim-side { width: 260px; }
	.sim-palette { width: 184px; }
}

/* Below 1024px: side panel slides over canvas, palette becomes bottom sheet */
@media (max-width: 1023px) {
	.sim-side {
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		width: min(320px, 86vw);
		box-shadow: -12px 0 30px rgba(0, 0, 0, 0.35);
		transform: translateX(0);
		transition: transform 0.2s ease;
	}

	.sim-side.is-hidden {
		transform: translateX(105%);
	}

	/* Palette bottom sheet */
	.sim-palette {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		top: auto;
		width: auto;
		max-height: 46%;
		border-right: 0;
		border-top: 1px solid var(--sim-line);
		border-radius: 14px 14px 0 0;
		box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.35);
		transform: translateY(0);
		transition: transform 0.2s ease;
		padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0));
	}

	.sim-palette.is-hidden {
		transform: translateY(105%);
	}

	.sim-palette-items {
		flex-direction: row;
		flex-wrap: wrap;
	}

	.sim-pal-item {
		flex: 0 0 auto;
	}

	.sim-palette-handle {
		display: block;
		position: absolute;
		left: 12px;
		bottom: 12px;
		z-index: 26;
		padding: 9px 14px;
		font: inherit;
		font-size: 13px;
		font-weight: 600;
		color: #fff;
		background: var(--sim-accent);
		border: 0;
		border-radius: 999px;
		box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
		cursor: pointer;
	}
}

@media (max-width: 640px) {
	.sim-toolbar {
		gap: 6px 8px;
		padding: 6px 8px;
	}

	.sim-toolbar-group {
		border-right: 0;
		padding-right: 0;
	}

	.sim-btn {
		padding: 6px 8px;
		font-size: 12px;
	}

	.sim-select {
		max-width: 140px;
	}

	.sim-status-info {
		display: none;
	}
}
