:root {
	--bg: #0d0f17;
	--bg2: #131624;
	--card: #171b2c;
	--card2: #1d2236;
	--line: #262c45;
	--text: #e7e9f3;
	--muted: #8b91ad;
	--accent: #7c5cff;
	--accent2: #22d3ee;
	--danger: #ff5c7a;
	--ok: #34d399;
	--radius: 14px;
	color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
	background:
		radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, .16), transparent 60%),
		radial-gradient(900px 500px at 110% 10%, rgba(34, 211, 238, .10), transparent 60%),
		var(--bg);
	color: var(--text);
	font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}
body.noscroll { overflow: hidden; }
a { color: var(--accent2); }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
	display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
	padding: 22px clamp(16px, 4vw, 40px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }
.logo {
	width: 44px; height: 44px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
	transform: rotate(-8deg); flex: none;
}
.logo span { border-radius: 5px; background: var(--accent); }
.logo span:nth-child(2), .logo span:nth-child(3) { background: var(--accent2); }

/* ---------- layout ---------- */
.layout {
	flex: 1;
	display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: start;
	padding: 0 clamp(16px, 4vw, 40px) 30px;
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.panel {
	position: sticky; top: 16px;
	background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
	padding: 18px;
}
@media (max-width: 860px) { .panel { position: static; } }
.panel h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.panel small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.field { padding: 12px 0; border-top: 1px solid var(--line); }
.field > label, .field-head label { font-weight: 600; font-size: 14px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field-head output { color: var(--accent2); font-variant-numeric: tabular-nums; font-size: 13px; }
.field.variant { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 14px; }
.field.variant b { color: var(--accent2); font-weight: 600; }

.switch-row {
	display: flex; align-items: center; justify-content: space-between; gap: 12px;
	padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.panel > .switch-row:first-of-type { border-top: 0; padding-top: 0; }
.switch-row strong { font-size: 14px; }
.switch-row small { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; word-break: break-all; }

.switch {
	appearance: none; -webkit-appearance: none; flex: none;
	width: 42px; height: 24px; border-radius: 999px; margin: 0;
	background: var(--line); position: relative; cursor: pointer; transition: background .2s;
}
.switch::after {
	content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
	background: #fff; transition: transform .2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.switch:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

input[type=range] { width: 100%; accent-color: var(--accent); margin: 8px 0 2px; }
select {
	width: 100%; margin-top: 6px; padding: 8px 10px; border-radius: 9px;
	background: var(--card); color: var(--text); border: 1px solid var(--line); font: inherit;
}


/* ---------- buttons ---------- */
.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px;
	padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
	font: inherit; font-weight: 600; cursor: pointer; color: var(--text);
	transition: background .15s, border-color .15s, opacity .15s, transform .05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b3ff0); }
.btn.primary:hover:not(:disabled) { background: linear-gradient(135deg, #8d71ff, var(--accent)); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: var(--muted); background: rgba(255, 255, 255, .03); }
.btn.danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

/* ---------- drop zone ---------- */
.drop {
	border: 2px dashed #3a4166; border-radius: var(--radius);
	background: rgba(23, 27, 44, .6);
	padding: 56px 20px; text-align: center; cursor: pointer;
	transition: border-color .2s, background .2s, padding .25s;
}
.drop:hover, .drop:focus-visible, body.dragging .drop {
	border-color: var(--accent); background: rgba(124, 92, 255, .08); outline: none;
}
body.dragging .drop { box-shadow: 0 0 0 6px rgba(124, 92, 255, .15); }
.drop-icon svg { width: 58px; height: 58px; fill: none; stroke: var(--accent2); stroke-width: 2.5; }
.drop-icon svg rect:nth-child(1), .drop-icon svg rect:nth-child(4) { stroke: var(--accent); }
.drop-title { margin: 10px 0 4px; font-size: 20px; font-weight: 700; }
.drop-sub { margin: 0; color: var(--muted); font-size: 14px; }
.drop.compact { padding: 18px 20px; display: flex; align-items: center; justify-content: center; gap: 14px; text-align: left; }
.drop.compact .drop-icon svg { width: 34px; height: 34px; }
.drop.compact .drop-title { margin: 0; font-size: 16px; }

/* ---------- toolbar ---------- */
.toolbar {
	display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
	margin: 18px 0 8px;
}
.stats { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin-bottom: 10px; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }

/* ---------- grid of cards ---------- */
.grid {
	list-style: none; margin: 14px 0 0; padding: 0;
	display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px;
}
.card {
	background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
	overflow: hidden; display: flex; flex-direction: column;
	animation: pop .25s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
.card[data-status=error] { border-color: rgba(255, 92, 122, .5); }

.thumb {
	position: relative; display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 0;
	background: #0a0c13 repeating-conic-gradient(#141827 0 25%, #0f121d 0 50%) 0 0 / 20px 20px;
	cursor: zoom-in; overflow: hidden;
}
.card:not([data-status=done]) .thumb { cursor: default; }
.thumb .tiles, .thumb .before {
	position: absolute; inset: 0;
	background-repeat: repeat; background-size: 50% 50%; background-position: 0 0;
	image-rendering: auto;
}
.thumb .before { opacity: 0; transition: opacity .12s; }
.card:not([data-status=done]) .thumb .before { opacity: .35; filter: grayscale(.6); }
.card.show-before .thumb .before { opacity: 1; filter: none; }
.thumb .badge {
	position: absolute; top: 8px; left: 8px;
	padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700;
	background: rgba(0, 0, 0, .55); color: #fff; backdrop-filter: blur(4px);
}
.card.show-before .badge::after { content: " · " attr(data-orig); }
.thumb:hover .badge { background: var(--accent); }
.spin {
	position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
	border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--accent2); border-radius: 50%;
	animation: spin .8s linear infinite; display: none;
}
.card[data-status=working] .spin, .card[data-status=queued] .spin { display: block; }
.card[data-status=queued] .spin { animation-duration: 2s; border-top-color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }
.thumb .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0, 0, 0, .4); display: none; }
.card[data-status=working] .bar { display: block; }
.thumb .bar i { display: block; height: 100%; width: 0; background: var(--accent2); }

.meta { padding: 10px 12px 4px; min-width: 0; }
.meta .name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.meta .sub { color: var(--muted); font-size: 12px; min-height: 18px; }
.card[data-status=error] .sub { color: var(--danger); }
.row { display: flex; gap: 6px; padding: 8px 12px 12px; }
.row .btn.primary { flex: 1; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: #05060a; }
.modal-bar {
	display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
	padding: 10px 16px; background: rgba(13, 15, 23, .92); border-bottom: 1px solid var(--line);
	font-size: 14px;
}
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.zoom { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.zoom input { width: 140px; margin: 0; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.chk input { accent-color: var(--accent); }
.modal-name { margin-left: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.close {
	width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
	background: transparent; color: var(--text); font-size: 16px; cursor: pointer;
}
.close:hover { border-color: var(--danger); color: var(--danger); }
.modal-tiles { flex: 1; background-repeat: repeat; background-position: 0 0; position: relative; }
.modal-tiles.grid-on::after {
	content: ""; position: absolute; inset: 0; pointer-events: none;
	background:
		linear-gradient(to right, rgba(255, 60, 120, .85) 1px, transparent 1px) 0 0 / var(--tw) var(--th),
		linear-gradient(to bottom, rgba(255, 60, 120, .85) 1px, transparent 1px) 0 0 / var(--tw) var(--th);
}

/* ---------- misc ---------- */
.toast {
	position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
	background: var(--card2); border: 1px solid var(--line); color: var(--text);
	padding: 10px 18px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
	transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 32px);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- live preview ---------- */
.live {
	margin: 14px 0 4px; border: 1px solid var(--line); border-radius: var(--radius);
	background: var(--bg2); overflow: hidden;
}
.live-bar {
	display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
	padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.live-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.live-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(52, 211, 153, .6); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }
.live-name {
	flex: 1; min-width: 80px; color: var(--muted); font-size: 12.5px;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.live-bar .zoom input { width: 120px; }
.live-view {
	position: relative; height: clamp(260px, 52vh, 620px);
	resize: vertical; overflow: hidden; min-height: 180px;
	background: #0a0c13 repeating-conic-gradient(#141827 0 25%, #0f121d 0 50%) 0 0 / 20px 20px;
}
.live-view canvas { display: block; width: 100%; height: 100%; }
.live-state {
	position: absolute; right: 10px; bottom: 10px;
	padding: 3px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
	background: rgba(0, 0, 0, .6); color: #cfd3ea; backdrop-filter: blur(4px); pointer-events: none;
}
.live-state.working { color: var(--accent2); }
.live-state:empty { display: none; }

.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(124, 92, 255, .35); }
.thumb { cursor: pointer; }
.card:not([data-status=done]) .thumb { cursor: pointer; }

/* ---------- language picker ---------- */
.lang {
	display: inline-flex; align-items: center; gap: 8px;
	padding: 4px 6px 4px 12px; border-radius: 999px;
	background: var(--bg2); border: 1px solid var(--line); color: var(--muted);
}
.lang:focus-within { border-color: var(--accent); }
.lang svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; flex: none; }
.lang select { width: auto; margin: 0; padding: 4px 6px; border: 0; background: transparent; color: var(--text); font-weight: 600; cursor: pointer; }
.lang select:focus { outline: none; }
.lang option { background: var(--card); color: var(--text); }
.drop > div:last-child { min-width: 0; }

/* ---------- direction ---------- */
.field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.seg-full { display: flex; width: 100%; }
.seg-full button { flex: 1; padding: 6px 4px; font-size: 13px; white-space: nowrap; }
.card[data-axis=x] .thumb .tiles, .card[data-axis=x] .thumb .before { background-repeat: repeat-x; background-position: 0 50%; }
.card[data-axis=y] .thumb .tiles, .card[data-axis=y] .thumb .before { background-repeat: repeat-y; background-position: 50% 0; }
.modal-tiles[data-axis=x] { background-repeat: repeat-x; background-position: 0 50%; }
.modal-tiles[data-axis=y] { background-repeat: repeat-y; background-position: 50% 0; }
.modal-tiles[data-axis=x].grid-on::after, .modal-tiles[data-axis=y].grid-on::after { display: none; }
