/* ============================================================================
   Colorful - foglio di stile unico
   Tema chiaro/scuro con variabili, layout a tutta pagina, zero dipendenze.
   ========================================================================== */

:root {
	--bg: #0b0d12;
	--surface: #141821;
	--surface-2: #1b2130;
	--line: #262e3d;
	--text: #eef1f6;
	--muted: #98a2b6;
	--accent: #3b82f6;
	--accent-ink: #ffffff;
	--danger: #ef4444;
	--radius: 14px;
	--shadow: 0 18px 45px rgba(0, 0, 0, .45);
	--topbar-h: 58px;
	--dock-h: 56px;
	--sans: ui-sans-serif, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
	--mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
	color-scheme: dark;
}

[data-theme="light"] {
	--bg: #f3f4f7;
	--surface: #ffffff;
	--surface-2: #f0f2f6;
	--line: #dfe3ea;
	--text: #14161c;
	--muted: #626b7b;
	--shadow: 0 18px 45px rgba(15, 23, 42, .14);
	color-scheme: light;
}

* { box-sizing: border-box; }

/* Un'author rule con display: batte lo stile utente di [hidden]: qui vince hidden. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
	margin: 0;
	font-family: var(--sans);
	font-size: 14px;
	color: var(--text);
	background: var(--bg);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	-webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
h2, h3 { margin: 0; font-size: 14px; }
.muted { color: var(--muted); }
.icon { display: block; }

/* ------------------------------------------------------------- barra alta */

.topbar {
	height: var(--topbar-h);
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 0 14px;
	background: var(--surface);
	border-bottom: 1px solid var(--line);
	z-index: 20;
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .2px; }
.brand-name { font-size: 15px; }
.brand-dots { display: grid; grid-template-columns: 9px 9px; gap: 2px; }
.brand-dots i { width: 9px; height: 9px; border-radius: 3px; display: block; }
.brand-dots i:nth-child(1) { background: #3b82f6; }
.brand-dots i:nth-child(2) { background: #f59e0b; }
.brand-dots i:nth-child(3) { background: #38bdf8; }
.brand-dots i:nth-child(4) { background: #ef4444; }

.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 11px; }
.tab {
	border: 0; background: transparent; color: var(--muted);
	padding: 6px 16px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.divider { width: 1px; height: 24px; background: var(--line); }

.primary-btn {
	display: inline-flex; align-items: center; gap: 8px;
	border: 0; border-radius: 10px; cursor: pointer; font-weight: 650;
	padding: 9px 16px; background: var(--accent); color: var(--accent-ink);
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.primary-btn:disabled { opacity: .45; cursor: default; }
.key-hint {
	font-size: 10.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
	background: rgba(255, 255, 255, .22); padding: 2px 6px; border-radius: 5px;
}

.icon-btn {
	display: inline-flex; align-items: center; justify-content: center;
	width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
	background: transparent; border: 1px solid transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.small { width: 28px; height: 28px; border-radius: 8px; }

.ghost-btn {
	border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
	padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 550;
}
.ghost-btn:hover { border-color: var(--muted); }
.ghost-btn:disabled { opacity: .4; cursor: default; }
.ghost-btn.danger { color: var(--danger); }
.ghost-btn.wide { flex: 1; }

.select-wrap select, .field select, .text-input, .num, .hex-field input {
	background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
	border-radius: 9px; padding: 8px 10px; outline: none;
}
select:focus, input:focus { border-color: var(--accent); }

main { flex: 1 1 auto; min-height: 0; display: flex; }
.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

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

.strip { flex: 1 1 auto; min-height: 0; display: flex; }

.swatch {
	position: relative; flex: 1 1 0; min-width: 0;
	background: var(--c); color: var(--fg);
	display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
	padding: 0 6px 9vh; cursor: grab; user-select: none;
	transition: flex-grow .25s ease;
}
.swatch.dragging { opacity: .55; }
.swatch.drop-target { outline: 3px dashed var(--fg); outline-offset: -12px; }

.sw-tools {
	position: absolute; top: 0; left: 0; right: 0;
	display: flex; justify-content: center; flex-wrap: wrap; gap: 2px; padding-top: 16px;
	opacity: 0; transition: opacity .16s ease;
}
.swatch:hover .sw-tools, .swatch:focus-within .sw-tools { opacity: 1; }
.sw-btn {
	width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
	border: 0; border-radius: 8px; background: transparent; color: var(--fg);
	opacity: .72; cursor: pointer;
}
.sw-btn:hover { opacity: 1; background: rgba(127, 127, 127, .22); }
.sw-btn:disabled { opacity: .2; cursor: default; background: transparent; }
.swatch.is-locked .sw-tools { opacity: 1; }
.swatch.is-locked [data-act="lock"] { opacity: 1; background: rgba(127, 127, 127, .22); }

.sw-body { text-align: center; width: 100%; }
.sw-hex {
	font-family: var(--mono); font-size: clamp(15px, 1.7vw, 27px); font-weight: 700;
	letter-spacing: .06em; background: transparent; border: 0; color: inherit; cursor: copy;
	padding: 4px 6px; border-radius: 8px; max-width: 100%;
}
.sw-hex:hover { background: rgba(127, 127, 127, .18); }
.sw-name {
	font-size: clamp(10px, .82vw, 13px); font-weight: 600; opacity: .8;
	margin-top: 2px; line-height: 1.25; word-break: break-word;
}
.sw-meta { font-size: 10.5px; opacity: .62; margin-top: 10px; font-family: var(--mono); line-height: 1.5; }
.sw-meta .badge {
	display: inline-block; margin-top: 3px; padding: 1px 6px; border-radius: 20px;
	border: 1px solid currentColor; font-size: 9.5px; letter-spacing: .04em;
}

.sw-panel {
	position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 8;
	width: 250px; max-width: calc(100vw - 24px);
	background: var(--surface); color: var(--text); border: 1px solid var(--line);
	border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
	cursor: default;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }

.field-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.color-input {
	width: 44px; height: 36px; padding: 2px; border-radius: 9px;
	border: 1px solid var(--line); background: var(--surface-2); cursor: pointer;
}
.hex-field { display: flex; align-items: center; flex: 1; min-width: 0; }
.hex-field span {
	padding: 8px 6px 8px 10px; border: 1px solid var(--line); border-right: 0;
	border-radius: 9px 0 0 9px; background: var(--surface-2); color: var(--muted);
}
.hex-field input {
	flex: 1; min-width: 0; border-radius: 0 9px 9px 0; font-family: var(--mono); text-transform: uppercase;
}

.slider-row { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.slider-label { width: 84px; flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.slider-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.slider-row output { width: 44px; text-align: right; font-family: var(--mono); font-size: 12px; color: var(--muted); }

.panel-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.panel-actions .ghost-btn { flex: 1; text-align: center; padding: 6px 8px; font-size: 12.5px; }

.sw-shades {
	position: absolute; inset: auto 0 0; z-index: 7; display: flex; flex-direction: column;
	background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow);
}
.shade {
	border: 0; background: var(--s); color: var(--sf); cursor: pointer;
	padding: 7px 4px; font-family: var(--mono); font-size: 10.5px; font-weight: 600;
	text-align: center; opacity: .95;
}
.shade:hover { opacity: 1; outline: 2px solid var(--sf); outline-offset: -4px; }

/* ------------------------------------------------------------------- dock */

.dock {
	flex: 0 0 auto; min-height: var(--dock-h);
	display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
	padding: 8px 14px; background: var(--surface); border-top: 1px solid var(--line);
}
.dock-group { display: flex; align-items: center; gap: 6px; }
.counter { font-size: 13px; color: var(--muted); min-width: 68px; text-align: center; }
.counter strong { color: var(--text); font-size: 15px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); }

/* -------------------------------------------------------------- gradiente */

.grad-layout {
	flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px;
	gap: 18px; padding: 18px; overflow: hidden;
}
/* Le due colonne scorrono in modo indipendente: l'anteprima resta a vista. */
.grad-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; overflow: auto; }

.grad-preview {
	flex: 1 1 auto; min-height: 240px; border-radius: 18px; border: 1px solid var(--line);
	box-shadow: var(--shadow);
}

.grad-track { position: relative; height: 64px; padding: 0 26px; touch-action: none; }
.track-bar {
	position: absolute; inset: 0 26px 26px; border-radius: 10px; border: 1px solid var(--line);
	background-image:
		linear-gradient(45deg, rgba(127, 127, 127, .18) 25%, transparent 25%, transparent 75%, rgba(127, 127, 127, .18) 75%),
		linear-gradient(45deg, rgba(127, 127, 127, .18) 25%, transparent 25%, transparent 75%, rgba(127, 127, 127, .18) 75%);
	background-size: 14px 14px;
}
.track-stops { position: absolute; inset: 0 26px; }

.gstop {
	position: absolute; top: -6px; transform: translateX(-50%);
	display: flex; flex-direction: column; align-items: center; gap: 3px;
	background: transparent; border: 0; padding: 0; cursor: grab; touch-action: none;
}
.gstop-dot {
	width: 20px; height: 20px; border-radius: 7px; background: var(--c);
	border: 2px solid var(--surface); box-shadow: 0 0 0 1.5px var(--line), 0 3px 8px rgba(0, 0, 0, .35);
}
.gstop-hex {
	font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: .02em;
	background: var(--surface); padding: 1px 4px; border-radius: 5px; border: 1px solid var(--line);
}
.gstop.selected .gstop-dot { box-shadow: 0 0 0 2.5px var(--accent), 0 3px 10px rgba(0, 0, 0, .4); }
.gstop.selected .gstop-hex { color: var(--text); border-color: var(--accent); }

.gmid {
	position: absolute; top: 14px; transform: translateX(-50%) rotate(45deg);
	width: 11px; height: 11px; padding: 0; cursor: ew-resize; touch-action: none;
	background: var(--surface); border: 1.5px solid var(--muted); border-radius: 2px;
}
.gmid:hover, .gmid.moved { border-color: var(--accent); background: var(--accent); }

.hint { margin: -4px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }

.code-row {
	display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
	background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.code-row code {
	flex: 1; min-width: 200px; font-family: var(--mono); font-size: 11.5px; color: var(--muted);
	max-height: 60px; overflow: auto; word-break: break-all;
}
.code-actions { display: flex; gap: 6px; }

.grad-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; overflow: auto; padding-right: 2px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel h3 {
	margin: 0 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
	display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
}
.panel h3 .muted { text-transform: none; letter-spacing: 0; font-size: 11.5px; font-weight: 500; }

.field { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.field > span { width: 84px; flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.field select, .field .text-input { flex: 1; min-width: 0; }
.field.compact > span { width: auto; }
.field-inline { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.num { width: 74px; font-family: var(--mono); }

.mix-strip { display: flex; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); margin-top: 4px; }
.mix-chip {
	flex: 1; min-width: 0; border: 0; cursor: copy; background: var(--c); color: var(--fg);
	height: 54px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 5px;
}
.mix-chip span {
	font-family: var(--mono); font-size: 8.5px; opacity: 0; transition: opacity .15s;
	writing-mode: vertical-rl; transform: rotate(180deg); height: 44px;
}
.mix-strip:hover .mix-chip span { opacity: .85; }

/* ----------------------------------------------------------------- modali */

.modal {
	border: 1px solid var(--line); border-radius: 18px; padding: 0; color: var(--text);
	background: var(--surface); box-shadow: var(--shadow); width: min(560px, calc(100vw - 32px));
	max-height: calc(100vh - 60px);
}
.modal.wide { width: min(1040px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(3, 6, 12, .62); backdrop-filter: blur(2px); }

.modal-head {
	display: flex; align-items: center; justify-content: space-between; gap: 12px;
	padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 11px; }
.modal-body { padding: 16px; overflow: auto; max-height: calc(100vh - 150px); }

.opts {
	display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 14px;
	padding-bottom: 14px; border-bottom: 1px solid var(--line);
}
.opts .field { margin-bottom: 0; }
.opts .field > span { width: auto; }
.opts .field select, .opts .field .text-input { flex: 0 0 auto; width: auto; min-width: 130px; }

.code-output {
	margin: 0; padding: 14px; border-radius: 12px; background: var(--surface-2);
	border: 1px solid var(--line); font-family: var(--mono); font-size: 12px; line-height: 1.6;
	max-height: 44vh; overflow: auto; white-space: pre; color: var(--text);
}
.png-preview {
	border-radius: 12px; overflow: auto; border: 1px solid var(--line); background: var(--surface-2);
	padding: 10px; max-height: 52vh; display: flex; justify-content: center;
}
.png-preview canvas { width: 100%; height: auto; border-radius: 6px; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-actions .muted { margin-right: auto; font-family: var(--mono); font-size: 12px; }

.lib-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.lib-item { display: flex; align-items: center; gap: 10px; }
.lib-preview {
	display: flex; flex: 1; height: 42px; border-radius: 10px; overflow: hidden;
	border: 1px solid var(--line); cursor: pointer; padding: 0; background: none;
}
.lib-preview span { flex: 1; }
.lib-preview:hover { border-color: var(--accent); }
.lib-meta { display: flex; flex-direction: column; width: 150px; font-size: 12.5px; }
.lib-meta .muted { font-size: 11px; }

.shortcuts { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.shortcuts li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); }
kbd {
	font-family: var(--mono); font-size: 11px; color: var(--text);
	background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px;
	border-radius: 6px; padding: 2px 7px;
}

/* --------------------------------------------------------------- notifica */

.toast {
	position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 18px);
	display: flex; align-items: center; gap: 8px;
	background: var(--surface); color: var(--text); border: 1px solid var(--line);
	border-radius: 999px; padding: 10px 18px; box-shadow: var(--shadow);
	opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 90;
	font-weight: 600; font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { color: var(--danger); }

/* ------------------------------------------------------------ adattamento */

@media (max-width: 1080px) {
	.grad-layout { grid-template-columns: 1fr; overflow: auto; }
	.grad-main, .grad-side { overflow: visible; }
	.grad-preview { min-height: 220px; }
}

@media (max-width: 860px) {
	.topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 10px; }
	.topbar-actions { width: 100%; margin-left: 0; flex-wrap: wrap; }
	.strip { flex-direction: column; }
	.swatch { padding: 0 6px; justify-content: center; min-height: 84px; }
	.swatch .sw-tools { top: 50%; right: 10px; left: auto; transform: translateY(-50%); padding-top: 0; width: auto; }
	.sw-meta { display: none; }
	.sw-panel { bottom: auto; top: 50%; transform: translate(-50%, -50%); }
	.sw-shades { inset: 0; flex-direction: row; }
	.shade { flex: 1; min-width: 0; font-size: 9px; padding: 6px 2px; }
	.dock { gap: 8px; }
	.dock .divider { display: none; }
}

@media (prefers-reduced-motion: reduce) {
	* { transition: none !important; }
}
