/* ─────────────────────────────────────────────────────────────────────────
   Design tokens
   Primary:    --color-primary-rgb (R G B) + --color-primary-light
   Dark theme: --bg-root (hex) — all background levels derive from this
   ───────────────────────────────────────────────────────────────────────── */
:root {
	/* Primary color */
	--color-primary-rgb: 255, 114, 71; /* #FF7247 */
	--color-primary: rgb(var(--color-primary-rgb));
	--color-primary-light: #ff9d79;
	--color-primary-a85: rgba(var(--color-primary-rgb), 0.85);
	--color-primary-a50: rgba(var(--color-primary-rgb), 0.5);
	--color-primary-a33: rgba(var(--color-primary-rgb), 0.33);
	--color-primary-a18: rgba(var(--color-primary-rgb), 0.18);
	--color-on-primary: #000; /* dark text on orange primary bg */

	/* Accent color — unified with primary */
	--color-accent-rgb: 255, 114, 71; /* #FF7247 */
	--color-accent: rgb(var(--color-accent-rgb));
	--color-accent-a33: rgba(var(--color-accent-rgb), 0.33);
	--color-accent-a18: rgba(var(--color-accent-rgb), 0.18);

	/* Danger color */
	--color-danger-rgb: 200, 68, 52;
	--color-danger: rgb(var(--color-danger-rgb));
	--color-danger-a25: rgba(var(--color-danger-rgb), 0.25);
	--color-danger-a20: rgba(var(--color-danger-rgb), 0.2);
	--color-danger-a15: rgba(var(--color-danger-rgb), 0.15);
	--color-danger-a10: rgba(var(--color-danger-rgb), 0.1);

	/* Text */
	--color-text: #efefef;

	/* Backgrounds — all derived from --bg-root via opacity steps */
	--bg-root: #292929;
	--bg-deep: color-mix(in srgb, white 1%, var(--bg-root)); /* ≈ #2b2b2b */
	--bg-base: color-mix(in srgb, white 2%, var(--bg-root)); /* ≈ #2d2d2d */
	--bg-surface: color-mix(in srgb, white 4%, var(--bg-root)); /* ≈ #303030 */
	--bg-panel: color-mix(in srgb, white 7%, var(--bg-root)); /* ≈ #383838 */
	--bg-input: color-mix(in srgb, white 10%, var(--bg-root)); /* ≈ #3e3e3e */

	/* Borders */
	--border-subtle: #363636;
	--border-default: #424242;
	--border-muted: #464646;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html {
	height: 100vh;
	overflow: hidden; /* Prevents 1px gap for fixed elements on iOS */
}

body {
	font-family:
		-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	background: var(--bg-base);
	color: var(--color-text);
	height: 100%;
	overflow: hidden;
	touch-action: manipulation;
}

#app {
	display: flex;
	flex-direction: column;
	height: 100dvh;
	width: 100%;
}

/* Preview area — fills full viewport */
#preview {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #000;
	overflow: hidden;
}

#canvas {
	/* サイズはJSで動的に設定（アスペクト比維持のため） */
}

/* Fullscreen UI */
#fullscreen-ui {
	display: none;
	position: absolute;
	inset: 0;
	pointer-events: none;
}

#preview.fullscreen #fullscreen-ui {
	display: block;
}

#fullscreen-bottom {
	position: absolute;
	bottom: 24px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 12px;
	pointer-events: auto;
}

#fullscreen-mode {
	display: none;
	padding: 10px 16px;
	background: rgba(255, 255, 255, 0.2);
	border: 1px solid rgba(255, 255, 255, 0.3);
	border-radius: 20px;
	color: var(--color-text);
	font-size: 12px;
	font-weight: 500;
	cursor: pointer;
}

#fullscreen-mode:active {
	background: rgba(255, 255, 255, 0.3);
}

/* Shutter button */
#fullscreen-shutter {
	width: 64px;
	height: 64px;
	padding: 0;
	background: transparent;
	border: 3px solid rgba(255, 255, 255, 0.8);
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

#fullscreen-shutter:active {
	transform: scale(0.95);
}

.shutter-icon {
	width: 48px;
	height: 48px;
	background: #ea4335;
	border-radius: 50%;
	transition:
		border-radius 0.15s,
		width 0.15s,
		height 0.15s;
}

#fullscreen-shutter.recording .shutter-icon {
	width: 24px;
	height: 24px;
	border-radius: 4px;
}

/* Fullscreen mode */
#preview.fullscreen {
	position: fixed;
	inset: 0;
	z-index: 1000;
}

/* Layer panel */
#layer-panel {
	/* background: var(--bg-deep); */
	padding: 12px 16px;
	padding-bottom: max(12px, env(safe-area-inset-bottom));
	display: flex;
	flex-direction: column;
	gap: 12px;
	width: 100%;
	position: fixed;
	bottom: 0;
	z-index: 100;
}

/* Layer header */
#layer-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	height: 24px;
}

.layer-header-label {
	font-size: 10px;
	font-weight: 600;
	color: #555;
	letter-spacing: 1.5px;
}

#layer-list {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

/* Layer strip (horizontal scroll) */
.layer-strip {
	display: flex;
	gap: 8px;
	overflow-x: auto;
	overflow-y: hidden;
	-webkit-overflow-scrolling: touch;
}

.layer-strip::-webkit-scrollbar {
	height: 4px;
}

.layer-strip::-webkit-scrollbar-track {
	background: transparent;
}

.layer-strip::-webkit-scrollbar-thumb {
	background: var(--border-default);
	border-radius: 2px;
}

/* Layer card */
.layer-card {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	gap: 10px;
	height: 40px;
	padding: 0 12px 0 10px;
	background: var(--bg-surface);
	border: 1px solid transparent;
	border-radius: 10px;
	cursor: pointer;
	user-select: none;
	-webkit-user-select: none;
	transition:
		transform 0.1s,
		opacity 0.1s,
		border-color 0.15s;
}

.layer-card.active {
	border-color: var(--color-primary-a33);
}

.layer-card.dragging {
	opacity: 0.5;
}

.layer-card.disabled {
	opacity: 0.4;
}

.layer-card.disabled .layer-card-icon {
	background: rgba(100, 100, 100, 0.15);
	border-color: #666;
}

.layer-card.drag-over {
	border: 2px dashed var(--color-primary);
	background: var(--color-primary-a18);
}

.layer-card-icon {
	width: 22px;
	height: 22px;
	background: var(--color-primary);
	border: none;
	border-radius: 5px;
	flex-shrink: 0;
}

.layer-card-info {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.layer-card-name {
	font-size: 12px;
	font-weight: 600;
	color: var(--color-text);
	white-space: nowrap;
}

.layer-card-meta {
	font-size: 10px;
	color: #888;
	white-space: nowrap;
}

/* Add layer card */
.layer-card-add {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	background: var(--bg-base);
	border: 1px solid var(--border-default);
	border-radius: 10px;
	cursor: pointer;
	transition:
		background 0.15s,
		border-color 0.15s;
}

.layer-card-add:active {
	background: var(--bg-surface);
	border-color: #444;
}

.layer-card-add-icon {
	font-size: 18px;
	color: #444;
}

/* Layer effects bar (horizontal scroll) */
.layer-effects {
	display: flex;
	gap: 6px;
	padding: 8px 0;
	overflow-x: auto;
	overflow-y: hidden;
	-webkit-overflow-scrolling: touch;
}

.layer-effects::-webkit-scrollbar {
	height: 4px;
}

.layer-effects::-webkit-scrollbar-track {
	background: var(--bg-surface);
}

.layer-effects::-webkit-scrollbar-thumb {
	background: #444;
	border-radius: 2px;
}

.effect-btn {
	flex-shrink: 0;
	padding: 6px 12px;
	background: var(--bg-surface);
	border: none;
	border-radius: 8px;
	color: var(--color-text);
	font-size: 11px;
	cursor: pointer;
	white-space: nowrap;
	user-select: none;
	-webkit-user-select: none;
}

.effect-btn:active {
	background: var(--color-primary);
	color: var(--color-on-primary);
}

.effect-btn-add {
	background: var(--bg-base);
	border: 1px solid var(--border-default);
	color: #444;
	padding: 6px 14px;
	font-size: 14px;
}

.effect-btn-add:active {
	background: var(--bg-surface);
	border-color: #444;
	color: #666;
}

/* Floating overlay buttons */
.floating-buttons {
	position: fixed;
	top: max(16px, env(safe-area-inset-top, 16px));
	display: flex;
	flex-direction: column;
	gap: 10px;
	z-index: 250;
}

.floating-left {
	left: 16px;
}

.floating-right {
	right: 16px;
}

.floating-buttons button {
	width: 48px;
	height: 48px;
	background: rgba(18, 18, 18, 0.72);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 50%;
	color: var(--color-text);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s;
	-webkit-tap-highlight-color: transparent;
}

.floating-buttons button:active {
	background: rgba(70, 70, 70, 0.85);
}

.floating-buttons button.active {
	background: var(--color-primary-a85);
	border-color: var(--color-primary-a50);
}

#btn-fps {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.02em;
}

.btn-camera-group {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 8px;
}

#btn-camera-switch {
	display: none;
}

#btn-camera-switch.visible {
	display: flex;
}

#fullscreen-fps {
	padding: 10px 16px;
	background: rgba(255, 255, 255, 0.2);
	border: 1px solid rgba(255, 255, 255, 0.3);
	border-radius: 20px;
	color: var(--color-text);
	font-size: 12px;
	font-weight: 500;
	cursor: pointer;
}

#fullscreen-fps:active {
	background: rgba(255, 255, 255, 0.3);
}

/* FPS warning button & popover (fullscreen video mode) */
#fps-warning-container {
	position: absolute;
	top: max(16px, env(safe-area-inset-top, 16px));
	right: max(16px, env(safe-area-inset-right, 16px));
	display: none;
	flex-direction: column;
	align-items: flex-end;
	gap: 8px;
	pointer-events: auto;
	z-index: 10;
}

#fps-warning-container.visible {
	display: flex;
}

#fps-warning-btn {
	width: 36px;
	height: 36px;
	padding: 0;
	background: rgba(255, 180, 0, 0.25);
	border: 1px solid rgba(255, 180, 0, 0.6);
	border-radius: 50%;
	color: #ffb400;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s;
}

#fps-warning-btn:active {
	background: rgba(255, 180, 0, 0.4);
}

#fps-warning-popover {
	display: none;
	max-width: 240px;
	background: rgba(30, 30, 30, 0.92);
	border: 1px solid rgba(255, 255, 255, 0.15);
	border-radius: 10px;
	padding: 10px 12px;
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
}

#fps-warning-popover.open {
	display: block;
	animation: popover-in 0.15s ease;
}

#fps-warning-popover p {
	margin: 0;
	font-size: 12px;
	line-height: 1.5;
	color: rgba(255, 255, 255, 0.85);
}

@keyframes popover-in {
	from {
		opacity: 0;
		transform: translateY(-4px) scale(0.97);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* Effect panel (modal) */
#effect-panel {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: flex-end;
	z-index: 300;
	pointer-events: none;
}

#effect-panel.open {
	pointer-events: auto;
}

#effect-panel .panel-content {
	position: relative;
	z-index: 1;
	width: 100%;
	height: calc(41vh + env(safe-area-inset-bottom, 0px));
	background: var(--bg-deep);
	border-radius: 16px 16px 0 0;
	padding: 16px;
	padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	overflow-y: hidden;
	display: flex;
	flex-direction: column;
	transform: translateY(100%);
	transition: transform 0.25s ease;
}

#effect-panel.open .panel-content {
	transform: translateY(0);
}

#effect-panel .panel-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 12px;
}

#effect-panel .panel-title {
	font-size: 16px;
	font-weight: 600;
}

#effect-panel .panel-close {
	background: none;
	border: none;
	color: #888;
	font-size: 24px;
	cursor: pointer;
}

#effect-panel .effect-tabs {
	display: flex;
	gap: 6px;
	overflow-x: auto;
	padding-bottom: 10px;
	margin-bottom: 12px;
	scrollbar-width: none;
}

#effect-panel .effect-tabs::-webkit-scrollbar {
	display: none;
}

#effect-panel .effect-tab {
	flex-shrink: 0;
	padding: 6px 14px;
	background: var(--border-default);
	border: none;
	border-radius: 20px;
	color: #aaa;
	font-size: 12px;
	cursor: pointer;
	white-space: nowrap;
}

#effect-panel .effect-tab.active {
	background: var(--color-primary);
	color: var(--color-text);
}

#effect-panel .effect-list {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 8px;
	align-content: start;
}

#effect-panel .effect-item {
	padding: 18px 8px;
	background: var(--border-default);
	border: none;
	border-radius: 8px;
	color: var(--color-text);
	font-size: 13px;
	cursor: pointer;
}

#effect-panel .effect-item:active {
	background: var(--color-primary);
}

/* Param panel (modal) */
#param-panel {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: flex-end;
	z-index: 301;
	pointer-events: none;
}

#param-panel.open {
	pointer-events: auto;
}

#param-panel .panel-content {
	position: relative;
	z-index: 1;
	width: 100%;
	max-height: calc(60vh + env(safe-area-inset-bottom, 0px));
	background: var(--bg-deep);
	border-radius: 16px 16px 0 0;
	box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.28);
	padding: 16px;
	padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	overflow-y: auto;
	transform: translateY(calc(100% + 24px));
	transition: transform 0.25s ease;
	user-select: none;
	-webkit-user-select: none;
}

#param-panel.open .panel-content {
	transform: translateY(0);
}

#param-panel .panel-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 16px;
}

#param-panel .panel-title {
	font-size: 16px;
	font-weight: 600;
}

#param-panel .panel-close {
	background: none;
	border: none;
	color: #888;
	font-size: 24px;
	cursor: pointer;
}

.param-list {
	display: flex;
	flex-direction: column;
	gap: 14px;
	margin-bottom: 12px;
}

.param-row {
	display: flex;
	align-items: center;
	gap: 12px;
}

.param-row-slider {
	align-items: stretch;
}

.param-label {
	font-size: 12px;
	color: #aaa;
}

/* Integrated slider: label + value + track in one bar */
.param-slider-track {
	position: relative;
	height: 26px;
	width: 100%;
	background: var(--bg-input);
	border-radius: 4px;
	cursor: pointer;
	touch-action: none;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 2px 16px;
}

.param-slider-fill {
	position: absolute;
	left: 0;
	top: 0;
	height: 100%;
	background: var(--color-primary-a18);
	pointer-events: none;
}

.param-slider-knob {
	position: absolute;
	top: 0;
	bottom: 0;
	width: 4px;
	background: rgb(240, 240, 240);
	transform: translateX(-50%);
	pointer-events: none;
}

.param-slider-track.active .param-slider-knob {
	background: rgb(240, 240, 240);
}

.param-slider-track .param-label {
	position: relative;
	z-index: 1;
	font-size: 13px;
	color: #bbb;
	pointer-events: none;
	user-select: none;
}

.param-value {
	position: relative;
	z-index: 1;
	font-size: 13px;
	font-weight: 500;
	color: var(--color-text);
	font-family: monospace;
	pointer-events: none;
	user-select: none;
}

/* Toggle track — same bar style as slider, tap to switch on/off */
.param-toggle-track {
	position: relative;
	height: 26px;
	width: 100%;
	background: var(--bg-input);
	border-radius: 4px;
	cursor: pointer;
	touch-action: none;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 2px 16px;
}

.param-toggle-track .param-slider-fill {
	background: var(--color-primary-a18);
	transition: width 0.15s ease;
}

.param-toggle-track .param-label {
	position: relative;
	z-index: 1;
	font-size: 13px;
	color: #bbb;
	pointer-events: none;
	user-select: none;
}

.param-toggle-track .param-value {
	color: #555;
}

.param-toggle-track.on .param-value {
	color: var(--color-primary);
}

.param-button {
	padding: 8px 16px;
	background: #444;
	border: none;
	border-radius: 4px;
	color: var(--color-text);
	font-size: 12px;
	cursor: pointer;
	transition: background 0.2s;
}

.param-button:hover {
	background: #555;
}

.param-button:active {
	background: #666;
}

.param-select {
	flex: 1;
	padding: 6px 8px;
	background: var(--border-default);
	border: 1px solid #555;
	border-radius: 4px;
	color: var(--color-text);
	font-size: 13px;
	cursor: pointer;
}

.param-select:focus {
	outline: none;
	border-color: var(--color-primary);
}

/* Vec2 Pad */
.param-row-pad {
	flex-direction: column;
	align-items: stretch;
	gap: 8px;
}

.param-row-pad .param-label {
	width: auto;
}

.param-pad {
	position: relative;
	width: 100%;
	aspect-ratio: 2 / 1;
	max-height: 120px;
	background: var(--border-default);
	border-radius: 8px;
	touch-action: none;
	cursor: crosshair;
	overflow: hidden;
}

.param-pad-crosshair-h,
.param-pad-crosshair-v {
	position: absolute;
	background: rgba(255, 255, 255, 0.1);
	pointer-events: none;
}

.param-pad-crosshair-h {
	left: 0;
	right: 0;
	top: 50%;
	height: 1px;
	transform: translateY(-50%);
}

.param-pad-crosshair-v {
	top: 0;
	bottom: 0;
	left: 50%;
	width: 1px;
	transform: translateX(-50%);
}

.param-pad-thumb {
	position: absolute;
	width: 24px;
	height: 24px;
	background: var(--color-primary);
	border: 2px solid #fff;
	border-radius: 50%;
	transform: translate(-50%, -50%);
	pointer-events: none;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
	transition:
		transform 0.1s,
		box-shadow 0.1s;
}

.param-pad.active .param-pad-thumb {
	transform: translate(-50%, -50%) scale(1.2);
	box-shadow: 0 0 0 4px var(--color-primary-a33);
}

.param-pad-values {
	display: flex;
	justify-content: space-between;
	font-size: 11px;
	color: #888;
	font-family: monospace;
}

/* Color picker */
.param-row-color {
	flex-direction: column;
	align-items: stretch;
	gap: 8px;
}

.param-row-color .param-label {
	width: auto;
}

.color-picker {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.color-preview {
	width: 100%;
	height: 32px;
	background: hsl(0, 50%, 50%);
	border-radius: 6px;
	border: 1px solid rgba(255, 255, 255, 0.1);
}

.color-hue-track {
	position: relative;
	width: 100%;
	height: 24px;
	background: linear-gradient(
		to right,
		hsl(0, 100%, 50%),
		hsl(60, 100%, 50%),
		hsl(120, 100%, 50%),
		hsl(180, 100%, 50%),
		hsl(240, 100%, 50%),
		hsl(300, 100%, 50%),
		hsl(360, 100%, 50%)
	);
	border-radius: 12px;
	cursor: pointer;
	touch-action: none;
}

.color-hue-thumb {
	position: absolute;
	top: 50%;
	width: 22px;
	height: 22px;
	background: #fff;
	border: 2px solid var(--border-default);
	border-radius: 50%;
	transform: translate(-50%, -50%);
	pointer-events: none;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
	transition:
		transform 0.1s,
		box-shadow 0.1s;
}

.color-hue-track.active .color-hue-thumb {
	transform: translate(-50%, -50%) scale(1.2);
	box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.3);
}

.color-sl-pad {
	position: relative;
	width: 100%;
	aspect-ratio: 2 / 1;
	max-height: 120px;
	border-radius: 8px;
	cursor: crosshair;
	touch-action: none;
	background:
		linear-gradient(to top, #000, transparent),
		linear-gradient(to right, #fff, hsl(var(--hue, 0deg), 100%, 50%));
}

.color-sl-thumb {
	position: absolute;
	width: 22px;
	height: 22px;
	background: #fff;
	border: 2px solid var(--border-default);
	border-radius: 50%;
	transform: translate(-50%, -50%);
	pointer-events: none;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
	transition:
		transform 0.1s,
		box-shadow 0.1s;
}

.color-sl-pad.active .color-sl-thumb {
	transform: translate(-50%, -50%) scale(1.2);
	box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.3);
}

/* Preset panel (modal) */
#preset-panel {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.8);
	display: none;
	align-items: flex-end;
	z-index: 302;
}

#preset-panel.open {
	display: flex;
}

#preset-panel .panel-content {
	width: 100%;
	max-height: calc(70vh + env(safe-area-inset-bottom, 0px));
	background: var(--bg-panel);
	border-radius: 16px 16px 0 0;
	padding: 16px;
	padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	overflow-y: auto;
}

#preset-panel .panel-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 12px;
}

#preset-panel .panel-title {
	font-size: 16px;
	font-weight: 600;
}

#preset-panel .panel-close {
	background: none;
	border: none;
	color: #888;
	font-size: 24px;
	cursor: pointer;
}

.preset-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.preset-empty {
	text-align: center;
	color: #666;
	padding: 24px;
}

.preset-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px;
	background: var(--border-default);
	border-radius: 8px;
}

.preset-info {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.preset-name {
	font-size: 14px;
	color: var(--color-text);
}

.preset-date {
	font-size: 11px;
	color: #666;
}

.preset-actions {
	display: flex;
	gap: 8px;
}

.preset-load {
	padding: 6px 12px;
	background: var(--color-primary);
	border: none;
	border-radius: 4px;
	color: var(--color-text);
	font-size: 12px;
	cursor: pointer;
}

.preset-load:active {
	background: var(--color-primary);
}

.preset-delete {
	padding: 6px 10px;
	background: #555;
	border: none;
	border-radius: 4px;
	color: #aaa;
	font-size: 12px;
	cursor: pointer;
}

.preset-delete:active {
	background: #c44;
	color: var(--color-text);
}

/* Settings modal */
#settings-modal {
	position: fixed;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 302;
}

#settings-modal.open {
	display: flex;
}

.settings-overlay {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.8);
}

.settings-content {
	position: relative;
	width: min(420px, 90vw);
	max-height: 80vh;
	background: var(--bg-panel);
	border-radius: 16px;
	padding: 24px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 0;
}

.settings-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 20px;
}

.settings-title {
	font-size: 17px;
	font-weight: 600;
	color: var(--color-text);
}

.settings-close {
	background: none;
	border: none;
	color: #888;
	font-size: 24px;
	cursor: pointer;
	line-height: 1;
	padding: 0 2px;
}

.settings-close:hover {
	color: var(--color-text);
}

.settings-section {
	border-top: 1px solid var(--border-default);
	padding-top: 16px;
	margin-top: 4px;
	margin-bottom: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.settings-section-title {
	font-size: 10px;
	font-weight: 600;
	letter-spacing: 0.08em;
	color: #666;
	text-transform: uppercase;
}

.settings-save-row {
	display: flex;
	gap: 8px;
}

.settings-donate {
	display: flex;
	justify-content: center;
	padding-top: 16px;
}

.donate-bmc-img {
	height: 48px !important;
	width: auto !important;
	border-radius: 8px;
}

.settings-version {
	font-size: 13px;
	color: #666;
	text-align: center;
	padding-top: 12px;
	padding-bottom: 4px;
}

.settings-version a {
	color: #888;
	text-decoration: none;
	transition: color 0.15s;
}

.settings-version a:hover {
	color: #fff;
}

.preset-name-input {
	flex: 1;
	background: var(--bg-base);
	border: 1px solid #444;
	border-radius: 8px;
	color: var(--color-text);
	font-size: 14px;
	padding: 8px 12px;
	outline: none;
}

.preset-name-input:focus {
	border-color: var(--color-primary);
}

.btn-preset-save {
	padding: 8px 16px;
	background: var(--color-primary);
	border: none;
	border-radius: 8px;
	color: var(--color-text);
	font-size: 14px;
	font-weight: 500;
	cursor: pointer;
	white-space: nowrap;
}

.btn-preset-save:active {
	background: var(--color-primary);
}

.btn-manage {
	width: 100%;
	padding: 10px 16px;
	background: var(--border-default);
	border: none;
	border-radius: 8px;
	color: #ccc;
	font-size: 14px;
	cursor: pointer;
	text-align: left;
}

.btn-manage:hover {
	background: var(--border-muted);
	color: var(--color-text);
}

.btn-manage:active {
	background: #444;
}

/* Opacity overlay */
#opacity-overlay {
	position: fixed;
	inset: 0;
	background: transparent;
	display: none;
	align-items: flex-end;
	z-index: 303;
	pointer-events: none;
}

#opacity-overlay.open {
	display: flex;
	pointer-events: auto;
}

.opacity-overlay-content {
	width: 100%;
	background: var(--bg-panel);
	border-radius: 16px 16px 0 0;
	padding: 20px 16px 32px;
}

.opacity-overlay-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 16px;
}

.opacity-overlay-title {
	font-size: 14px;
	color: #888;
}

.opacity-overlay-value {
	font-size: 16px;
	font-weight: 600;
	color: var(--color-text);
	min-width: 50px;
	text-align: right;
}

.opacity-overlay-slider {
	width: 100%;
	height: 8px;
	-webkit-appearance: none;
	appearance: none;
	background: #444;
	border-radius: 4px;
	outline: none;
}

.opacity-overlay-slider::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 28px;
	height: 28px;
	background: var(--color-primary);
	border-radius: 50%;
	cursor: pointer;
}

/* Layer Detail Sheet */
#layer-detail-sheet {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: flex-end;
	z-index: 200;
	pointer-events: none;
}

#layer-detail-sheet.open {
	pointer-events: auto;
}

.sheet-backdrop {
	position: absolute;
	inset: 0;
}

.sheet-content {
	position: relative;
	z-index: 1;
	width: 100%;
	max-height: calc(30vh + max(7vh, env(safe-area-inset-bottom)));
	background: var(--bg-deep);
	border-radius: 24px 24px 0 0;
	display: flex;
	flex-direction: column;
	transform: translateY(100%);
	transition: transform 0.25s ease;
	overflow: clip;
}

#layer-detail-sheet.open .sheet-content {
	transform: translateY(0);
}

.sheet-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	height: 60px;
	padding: 0 20px;
}

.sheet-header-left {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
}

.sheet-layer-name {
	font-size: 19px;
	font-weight: 700;
	color: var(--color-text);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.sheet-toggle {
	position: relative;
	width: 44px;
	height: 26px;
	background: var(--border-muted);
	border: none;
	border-radius: 13px;
	cursor: pointer;
	transition: background 0.2s;
}

.sheet-toggle.active {
	background: var(--color-primary);
}

.sheet-toggle-knob {
	position: absolute;
	top: 3px;
	left: 3px;
	width: 20px;
	height: 20px;
	background: #fff;
	border-radius: 50%;
	transition: left 0.2s;
}

.sheet-toggle.active .sheet-toggle-knob {
	left: 21px;
}

.sheet-delete {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	background: rgb(65, 65, 65);
	border: 1px solid var(--color-danger);
	border-radius: 8px;
	color: rgb(220, 72, 72);
	font-size: 14px;
	cursor: pointer;
	transition: background 0.15s;
}

.sheet-delete:active {
	background: rgb(75, 55, 52);
}

/* Blend + Opacity 70/30 row */
.sheet-controls-row {
	display: flex;
	gap: 8px;
	align-items: center;
	height: 48px;
	padding: 0 20px;
}

.sheet-blend-value {
	flex: 7;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 32px;
	padding: 0 12px;
	background: var(--bg-surface);
	border: none;
	border-radius: 8px;
	cursor: pointer;
}

.sheet-opacity-btn {
	flex: 3;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 32px;
	padding: 0 10px;
	background: var(--bg-base);
	border: 1px solid var(--border-default);
	border-radius: 8px;
	cursor: pointer;
	transition:
		background 0.15s,
		border-color 0.15s;
}

.sheet-opacity-btn:active {
	background: var(--bg-surface);
	border-color: #444;
}

.sheet-opacity-btn-label {
	font-size: 12px;
	color: #888;
}

.sheet-opacity-btn-value {
	font-size: 13px;
	font-weight: 500;
	color: var(--color-text);
	font-family: monospace;
}

.sheet-blend-text {
	font-size: 13px;
	font-weight: 500;
	color: var(--color-text);
}

.sheet-blend-chevron {
	font-size: 10px;
	color: #666;
}

.sheet-opacity-slider {
	position: relative;
	height: 26px;
	background: var(--bg-input);
	border-radius: 4px;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 2px 16px;
	cursor: pointer;
	touch-action: none;
}

.sheet-opacity-fill {
	position: absolute;
	left: 0;
	top: 0;
	height: 100%;
	background: var(--color-primary-a18);
	pointer-events: none;
}

.sheet-opacity-knob {
	position: absolute;
	top: 0;
	bottom: 0;
	width: 4px;
	background: rgb(240, 240, 240);
	transform: translateX(-50%);
	pointer-events: none;
}

.sheet-opacity-slider:active .sheet-opacity-knob {
	background: rgb(240, 240, 240);
}

.sheet-opacity-label {
	position: relative;
	z-index: 1;
	font-size: 13px;
	color: #bbb;
	pointer-events: none;
	user-select: none;
}

.sheet-opacity-value {
	position: relative;
	z-index: 1;
	font-size: 13px;
	font-weight: 500;
	color: var(--color-text);
	font-family: monospace;
	pointer-events: none;
	user-select: none;
}

/* Opacity sub-panel — slides up from bottom */
#opacity-panel {
	position: fixed;
	inset: 0;
	z-index: 210;
	display: flex;
	align-items: flex-end;
	pointer-events: none;
}

#opacity-panel.open {
	pointer-events: auto;
}

.opacity-panel-backdrop {
	position: absolute;
	inset: 0;
	background: transparent;
}

.opacity-panel-content {
	position: relative;
	z-index: 1;
	width: 100%;
	background: var(--bg-deep);
	border-radius: 16px 16px 0 0;
	box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.28);
	padding: 20px;
	padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
	transform: translateY(calc(100% + 24px));
	transition: transform 0.25s ease;
}

#opacity-panel.open .opacity-panel-content {
	transform: translateY(0);
}

#opacity-panel .panel-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 12px;
}

#opacity-panel .panel-title {
	font-size: 16px;
	font-weight: 600;
}

#opacity-panel .panel-close {
	background: none;
	border: none;
	color: #888;
	font-size: 24px;
	cursor: pointer;
}

.sheet-divider {
	height: 1px;
	background: var(--bg-surface);
}

.sheet-effects-label {
	height: 36px;
	padding: 0 20px;
	display: flex;
	align-items: center;
	font-size: 10px;
	font-weight: 600;
	color: #555;
	letter-spacing: 1.2px;
}

/* Effects horizontal strip */
.sheet-effects-list {
	display: flex;
	flex-wrap: nowrap;
	gap: 8px;
	padding: 8px 20px calc(16px + env(safe-area-inset-bottom, 0px));
	overflow-x: auto;
	overflow-y: hidden;
	-webkit-overflow-scrolling: touch;
	touch-action: pan-x;
}

.sheet-effects-list::-webkit-scrollbar {
	height: 4px;
}

.sheet-effects-list::-webkit-scrollbar-track {
	background: transparent;
}

.sheet-effects-list::-webkit-scrollbar-thumb {
	background: var(--border-default);
	border-radius: 2px;
}

/* Effect card (horizontal) */
.sheet-effect-card {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	gap: 6px;
	height: 40px;
	padding: 0 6px 0 0;
	background: var(--bg-surface);
	border: 1px solid var(--border-default);
	border-radius: 10px;
}

.sheet-effect-card-name {
	display: flex;
	align-items: center;
	height: 100%;
	padding: 0 12px;
	background: transparent;
	border: none;
	font-size: 13px;
	font-weight: 600;
	color: var(--color-text);
	cursor: pointer;
	white-space: nowrap;
}

.sheet-effect-card-name:active {
	color: var(--color-primary);
}

.sheet-effect-card-delete {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	background: rgb(60, 60, 60);
	border: 1px solid rgba(var(--color-danger-rgb), 0.5);
	border-radius: 7px;
	color: rgb(220, 72, 72);
	font-size: 11px;
	cursor: pointer;
	transition: background 0.15s;
}

.sheet-effect-card-delete:active {
	background: rgb(75, 55, 52);
}

/* Add effect card (always on the left) */
.sheet-effect-card-add {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	background: var(--bg-base);
	border: 1px solid var(--border-default);
	border-radius: 10px;
	cursor: pointer;
	transition:
		background 0.15s,
		border-color 0.15s;
}

.sheet-effect-card-add:active {
	background: var(--bg-surface);
	border-color: #444;
}

.sheet-effect-card-add-icon {
	font-size: 18px;
	color: #444;
}

/* Loading screen */
#loading-screen {
	position: fixed;
	inset: 0;
	background: var(--bg-base);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 9999;
	transition: opacity 0.4s ease;
}

#loading-screen.fade-out {
	opacity: 0;
	pointer-events: none;
}

.loading-content {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 32px;
}

.loading-logo {
	font-size: 28px;
	font-weight: 700;
	letter-spacing: 0.05em;
	color: var(--color-text);
}

.loading-spinner {
	width: 36px;
	height: 36px;
}

.spinner-ring {
	width: 100%;
	height: 100%;
	border: 2px solid var(--border-default);
	border-top-color: var(--color-text);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* PWA update toast */
#pwa-update-toast {
	position: fixed;
	bottom: calc(24px + env(safe-area-inset-bottom, 0px));
	left: 50%;
	transform: translateX(-50%) translateY(100%);
	display: flex;
	align-items: center;
	gap: 10px;
	background: var(--bg-input);
	color: var(--color-text);
	padding: 12px 16px;
	border-radius: 12px;
	border: 1px solid #444;
	font-size: 14px;
	white-space: nowrap;
	z-index: 9999;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition:
		transform 0.3s ease,
		opacity 0.3s ease,
		visibility 0s linear 0.3s;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
#pwa-update-toast.visible {
	transform: translateX(-50%) translateY(0);
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition:
		transform 0.3s ease,
		opacity 0.3s ease,
		visibility 0s linear 0s;
}
#pwa-update-btn {
	background: var(--color-primary);
	color: var(--color-text);
	border: none;
	border-radius: 8px;
	padding: 6px 14px;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
}
#pwa-dismiss-btn {
	background: transparent;
	color: #999;
	border: none;
	padding: 6px 8px;
	font-size: 13px;
	cursor: pointer;
}

/* Video export progress modal */
#export-progress-modal {
	position: fixed;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, 0.7);
	z-index: 10000;
}
#export-progress-modal.visible {
	display: flex;
}
.export-progress-content {
	background: var(--bg-base);
	border: 1px solid #444;
	border-radius: 12px;
	padding: 24px 28px;
	min-width: 280px;
	max-width: 90vw;
	color: var(--color-text);
	text-align: center;
	box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
.export-progress-title {
	font-size: 16px;
	font-weight: 600;
	margin-bottom: 6px;
}
.export-progress-phase {
	font-size: 12px;
	color: #999;
	margin-bottom: 14px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}
.export-progress-bar {
	height: 6px;
	background: var(--border-default);
	border-radius: 3px;
	overflow: hidden;
	margin-bottom: 10px;
}
.export-progress-fill {
	height: 100%;
	width: 0%;
	background: var(--color-primary);
	transition: width 0.15s ease;
}
.export-progress-status {
	font-size: 13px;
	color: #ccc;
	margin-bottom: 16px;
	font-variant-numeric: tabular-nums;
}
#export-progress-cancel {
	background: #444;
	color: var(--color-text);
	border: none;
	border-radius: 8px;
	padding: 8px 18px;
	font-size: 14px;
	cursor: pointer;
}
#export-progress-cancel:hover {
	background: #555;
}

/* Onboarding modal */
#onboarding-modal {
	position: fixed;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 20000;
}

#onboarding-modal.visible {
	display: flex;
}

.onboarding-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.75);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
}

.onboarding-content {
	position: relative;
	width: min(400px, 92vw);
	max-height: 88dvh;
	background: var(--bg-base);
	border: 1px solid var(--border-subtle);
	border-radius: 20px;
	padding: 28px 24px 20px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 20px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

.onboarding-header {
	text-align: center;
}

.onboarding-logo {
	font-size: 24px;
	font-weight: 700;
	letter-spacing: -0.5px;
	color: var(--color-text);
	margin-bottom: 4px;
}

.onboarding-tagline {
	font-size: 13px;
	color: #666;
	line-height: 1.4;
}

.onboarding-steps {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.onboarding-step {
	display: flex;
	align-items: center;
	gap: 14px;
}

.onboarding-step-icon {
	flex-shrink: 0;
	width: 38px;
	height: 38px;
	background: var(--bg-panel);
	border: 1px solid var(--border-default);
	border-radius: 11px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #bbb;
}

.onboarding-step-icon--plus {
	font-size: 24px;
	font-weight: 300;
	line-height: 1;
	color: #bbb;
}

.onboarding-step-icon--fps {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.02em;
	color: #bbb;
}

.onboarding-step-text {
	flex: 1;
	font-size: 13px;
	color: #999;
	line-height: 1.45;
}

.onboarding-step-text strong {
	display: block;
	color: var(--color-text);
	font-size: 14px;
	font-weight: 600;
	margin-bottom: 1px;
}

/* Fullscreen step has no icon — indent text to align with others */
.onboarding-step--no-icon .onboarding-step-text {
	padding-left: calc(38px + 14px);
}

.onboarding-divider {
	height: 1px;
	background: var(--bg-input);
	margin: 0;
}

.onboarding-footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.onboarding-checkbox-label {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
	color: #888;
	cursor: pointer;
	user-select: none;
}

.onboarding-checkbox-label input[type="checkbox"] {
	display: none;
}

.onboarding-checkbox-custom {
	width: 18px;
	height: 18px;
	border: 1.5px solid #555;
	border-radius: 5px;
	flex-shrink: 0;
	position: relative;
	transition:
		background 0.15s,
		border-color 0.15s;
}

.onboarding-checkbox-label
	input[type="checkbox"]:checked
	+ .onboarding-checkbox-custom {
	background: var(--color-primary);
	border-color: var(--color-primary);
}

.onboarding-checkbox-label
	input[type="checkbox"]:checked
	+ .onboarding-checkbox-custom::after {
	content: "";
	position: absolute;
	left: 4px;
	top: 1px;
	width: 5px;
	height: 9px;
	border: 2px solid #fff;
	border-top: none;
	border-left: none;
	transform: rotate(45deg);
}

#onboarding-close {
	padding: 7px 16px;
	background: var(--color-primary);
	border: none;
	border-radius: 8px;
	color: var(--color-text);
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
	flex-shrink: 0;
	transition: background 0.15s;
}

#onboarding-close:hover {
	background: var(--color-primary-light);
}

#onboarding-close:active {
	background: var(--color-primary);
}
