:root {
  --bg: #0b0b10;
  --surface: #14141c;
  --surface-2: #1d1d28;
  --surface-3: #282836;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f5fa;
  --muted: #9b9bb2;
  --accent: #ff3d7f;
  --accent-2: #7c5cff;
  --gold: #ffd84d;
  --danger: #ff6b81;
  --grad: linear-gradient(120deg, #7c5cff 0%, #ff3d7f 52%, #ff9a3d 100%);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }

.icon { display: inline-flex; line-height: 0; }
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.boot img { animation: breathe 1.4s ease-in-out infinite; }

/* ---------- controlli ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface-2);
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: transform .12s ease, filter .12s ease, background .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); border: none; color: #fff; box-shadow: 0 8px 26px rgba(255, 61, 127, .32); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { height: 54px; padding: 0 24px; font-size: 16px; border-radius: 16px; }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .4; }

.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center;
  border-radius: 12px; border: none; background: transparent;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .3; background: transparent; }
.icon-btn.small { width: 32px; height: 32px; border-radius: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 13px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-weight: 500; font-size: 13px;
}
.chip:hover { border-color: var(--line-strong); }
.chip.on { background: var(--text); color: #111; border-color: transparent; }
.chips.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); }
.chips.grid .chip { flex-direction: column; border-radius: 14px; padding: 10px 4px; gap: 4px; font-size: 12px; }
.chip-icon { font-size: 20px; line-height: 1; height: 22px; }
.chips.filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips.filters .chip { flex-direction: column; background: none; border: none; padding: 0; gap: 6px; font-size: 12px; color: var(--muted); }
.chips.filters .chip.on { color: var(--text); background: none; }
.chips.filters .chip.on .filter-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.filter-thumb { width: 64px; height: 86px; border-radius: 10px; display: block; background: var(--surface-3); }
.filter-thumb.same { display: grid; place-items: center; color: var(--muted); }
.font-sample { font-size: 17px; line-height: 1; }
.ratio-shape { display: inline-block; border: 2px solid currentColor; border-radius: 3px; }

.slider { display: block; }
.slider-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.slider output { color: var(--text); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-ui { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 99px; background: var(--surface-3); position: relative; transition: background .15s; }
.toggle-ui::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked + .toggle-ui { background: var(--accent); }
.toggle input:checked + .toggle-ui::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle-ui { outline: 2px solid var(--accent); outline-offset: 2px; }

.text-input, select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 16px; font-weight: 500; resize: vertical;
}
.text-input.small { padding: 8px 10px; font-size: 14px; }
.text-input:focus, select:focus { outline: none; border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .25); padding: 0; }
.swatch.on { outline: 2px solid #fff; outline-offset: 3px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.center { align-items: center; text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row.center { justify-content: center; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.45; margin: 0; }
.optional { font-weight: 400; color: var(--muted); font-size: 12px; }
.sheet-body h3, .magic-panel h3, .export-panel h3 { font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---------- home ---------- */
.home { max-width: 1100px; margin: 0 auto; padding: calc(16px + var(--safe-t)) 20px calc(60px + var(--safe-b)); }
.home-top { display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 10px; font-size: 18px; letter-spacing: -.01em; }
.hero { padding: 48px 0 28px; position: relative; }
.hero::before {
  content: ''; position: absolute; inset: 0 -20% auto auto; width: 70%; height: 320px; z-index: -1;
  background: radial-gradient(closest-side, rgba(124, 92, 255, .28), transparent), radial-gradient(closest-side at 70% 60%, rgba(255, 61, 127, .22), transparent);
  filter: blur(30px);
}
.hero h1 { font-size: clamp(36px, 7.5vw, 68px); line-height: 1.02; font-weight: 800; letter-spacing: -.035em; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); font-size: 17px; max-width: 580px; line-height: 1.55; margin: 18px 0 0; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 28px 0 22px; }
.magic-btn { position: relative; animation: glow 3s ease-in-out infinite; }
.hero-points { list-style: none; display: flex; flex-wrap: wrap; gap: 10px 22px; padding: 0; margin: 0; color: var(--muted); font-size: 14px; }
.hero-points li { display: flex; align-items: center; gap: 7px; }
.hero-points .icon { color: var(--accent); }
.ios-hint { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 6px; }
.projects h2 { font-size: 18px; margin: 30px 0 14px; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.project-card { position: relative; background: var(--surface); border-radius: 16px; border: 1px solid var(--line); cursor: pointer; transition: transform .15s, border-color .15s; }
.project-card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.project-cover { aspect-ratio: 9 / 16; border-radius: 15px 15px 0 0; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }
.project-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.project-meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.project-meta b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-meta span { font-size: 12px; color: var(--muted); }
.project-menu { position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .5); backdrop-filter: blur(8px); }
.menu {
  position: absolute; top: 44px; right: 6px; z-index: 10; min-width: 170px; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 14px;
  display: flex; flex-direction: column; box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
}
.menu button { display: flex; gap: 10px; align-items: center; padding: 10px; background: none; border: none; border-radius: 9px; text-align: left; font-weight: 500; font-size: 14px; }
.menu button:hover { background: var(--surface-3); }
.menu .danger { color: var(--danger); }
.empty-note { color: var(--muted); grid-column: 1 / -1; }

/* ---------- editor ---------- */
.editor {
  position: fixed; inset: 0; display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "top" "stage" "transport" "timeline" "toolbar";
  background: var(--bg); user-select: none; -webkit-user-select: none;
}
.ed-top { grid-area: top; display: flex; align-items: center; gap: 2px; padding: calc(6px + var(--safe-t)) 8px 6px; }
.project-name { flex: 1 1 auto; min-width: 0; text-align: left; background: none; border: none; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 6px 8px; border-radius: 8px; }
.project-name:hover { background: var(--surface-2); }
.spacer { display: none; }
.export-btn { height: 36px; padding: 0 14px; margin-left: 6px; }

.stage { grid-area: stage; position: relative; min-height: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, #171723 0%, var(--bg) 70%); overflow: hidden; }
.stage-inner { position: relative; display: grid; place-items: center; }
canvas.preview { display: block; border-radius: 10px; background: #000; box-shadow: 0 20px 60px rgba(0, 0, 0, .55); touch-action: none; }
.text-frame { position: absolute; border: 1.5px dashed #fff; border-radius: 6px; pointer-events: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
.stage.snap-x::after { content: ''; position: absolute; left: 50%; top: 6px; bottom: 6px; width: 1px; background: #4de8c2; }
.magic-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 16px; background: rgba(11, 11, 16, .8); backdrop-filter: blur(8px); z-index: 3; max-width: calc(100% - 24px); }
.magic-hint .btn { height: 38px; font-size: 13px; white-space: normal; text-align: left; }
.stage-empty { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); }

.transport { grid-area: transport; position: relative; display: flex; align-items: center; justify-content: center; gap: 14px; height: 52px; }
.play-btn { width: 46px; height: 46px; border-radius: 50%; background: #fff; color: #111; display: grid; place-items: center; border: none; transition: transform .1s; }
.play-btn:active { transform: scale(.94); }
.time-label { position: absolute; right: 12px; font: 600 12px/1 ui-monospace, 'SF Mono', Menlo, monospace; color: var(--muted); font-variant-numeric: tabular-nums; }

.timeline { grid-area: timeline; position: relative; height: 196px; background: #0f0f15; border-top: 1px solid var(--line); }
.tl-scroll { position: absolute; inset: 0; overflow-x: auto; overflow-y: auto; scrollbar-width: none; overscroll-behavior: contain; }
.tl-scroll::-webkit-scrollbar { display: none; }
.tl-content { position: relative; min-height: 100%; padding: 2px 0 12px; }
.tl-playhead { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; pointer-events: none; z-index: 8; box-shadow: 0 0 10px rgba(255, 255, 255, .35); }
.tl-playhead::before { content: ''; position: absolute; top: 0; left: -5px; width: 12px; height: 8px; background: #fff; border-radius: 0 0 6px 6px; }
.tl-time { display: none; }
.tl-playhead.hidden { display: none; }
.tl-ruler { cursor: pointer; }
.tl-zoom { position: absolute; right: 6px; top: 4px; display: flex; gap: 2px; z-index: 9; background: rgba(15, 15, 21, .85); border-radius: 10px; }
.tl-ruler { position: relative; height: 18px; }
.tl-ruler .tick { position: absolute; top: 2px; font-size: 10px; color: var(--muted); transform: translateX(-50%); font-variant-numeric: tabular-nums; }
.tl-ruler .tick::after { content: ''; position: absolute; left: 50%; top: 13px; width: 1px; height: 4px; background: var(--line-strong); }
.tl-row { position: relative; margin: 6px 0; min-height: 24px; }
.tl-row.captions { height: 16px; min-height: 16px; }
.tl-row.audio { height: 30px; }
.tl-row.voice { height: 26px; }

.tl-clip { position: absolute; top: 0; height: 100%; border-radius: 8px; background: #22222c; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06); cursor: pointer; }
.tl-clip .tl-strip { display: block; height: 100%; border-radius: 8px; pointer-events: none; }
.tl-clip.selected { box-shadow: 0 0 0 2px #fff; z-index: 4; touch-action: none; }
.tl-clip.dragging { opacity: .85; z-index: 6; box-shadow: 0 0 0 2px var(--gold), 0 10px 30px rgba(0, 0, 0, .6); }
.tl-badges { position: absolute; left: 4px; top: 4px; display: flex; gap: 3px; pointer-events: none; }
.badge { display: inline-flex; align-items: center; gap: 2px; background: rgba(0, 0, 0, .65); border-radius: 5px; padding: 1px 4px; font-size: 10px; font-weight: 700; }
.tl-handle { position: absolute; top: -2px; bottom: -2px; width: 16px; background: #fff; cursor: ew-resize; touch-action: none; z-index: 2; }
.tl-handle::after { content: ''; position: absolute; left: 6px; top: 35%; bottom: 35%; width: 4px; border-radius: 2px; background: #111; }
.tl-handle.start { left: -15px; border-radius: 7px 0 0 7px; }
.tl-handle.end { right: -15px; border-radius: 0 7px 7px 0; }
.tl-item .tl-handle { top: -1px; bottom: -1px; width: 12px; }
.tl-item .tl-handle::after { left: 4px; width: 3px; }
.tl-item .tl-handle.start { left: -11px; }
.tl-item .tl-handle.end { right: -11px; }
.tl-trans {
  position: absolute; top: 19px; width: 20px; height: 20px; margin-left: -10px; border-radius: 6px; z-index: 5;
  display: grid; place-items: center; background: rgba(15, 15, 21, .85); color: #fff; border: 1.5px solid rgba(255, 255, 255, .7);
  font-size: 11px; font-weight: 700; padding: 0; box-shadow: 0 2px 8px rgba(0, 0, 0, .5); opacity: .8;
}
.tl-trans:hover { opacity: 1; }
.tl-trans.on { background: #fff; color: #111; border-color: #fff; opacity: 1; width: 24px; height: 24px; margin-left: -12px; top: 17px; }
.tl-add { position: absolute; top: 9px; width: 40px; height: 40px; border-radius: 10px; background: #fff; color: #111; border: none; display: grid; place-items: center; }
.tl-item {
  position: absolute; height: 24px; border-radius: 6px; font-size: 12px; font-weight: 600; padding: 0 8px;
  display: flex; align-items: center; gap: 4px; white-space: nowrap; cursor: pointer;
}
.tl-item > span { overflow: hidden; text-overflow: ellipsis; }
.tl-item.text { background: rgba(181, 123, 255, .22); border: 1px solid #b57bff; color: #eadcff; }
.tl-item.music { height: 30px; background: rgba(47, 211, 168, .16); border: 1px solid #2fd3a8; color: #bff5e6; padding: 0; overflow: hidden; }
.tl-item.voice { background: rgba(255, 154, 61, .18); border: 1px solid #ff9a3d; color: #ffd9b3; }
.tl-item.selected { box-shadow: 0 0 0 2px #fff; z-index: 4; touch-action: none; }
.tl-wave { position: absolute; left: 0; top: 2px; height: 26px; pointer-events: none; }
.tl-label { position: relative; display: flex; align-items: center; gap: 4px; padding: 0 8px; font-size: 11px; text-shadow: 0 1px 2px #000; }
.tl-placeholder {
  position: absolute; height: 24px; padding: 0 10px; border: 1px dashed var(--line-strong); border-radius: 6px;
  background: transparent; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px;
}
.tl-placeholder:hover { color: var(--text); border-color: var(--text); }
.tl-cap {
  position: absolute; height: 16px; background: rgba(255, 216, 77, .14); border-left: 2px solid var(--gold);
  font-size: 10px; color: #ffe9a0; overflow: hidden; white-space: nowrap; padding: 0 4px; line-height: 16px; cursor: pointer; border-radius: 2px;
}

.toolbar {
  grid-area: toolbar; display: flex; overflow-x: auto; gap: 2px; scrollbar-width: none;
  padding: 6px 6px calc(6px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line);
}
.toolbar::-webkit-scrollbar { display: none; }
.tool {
  flex: 0 0 auto; min-width: 66px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 6px; background: none; border: none; border-radius: 12px; font-size: 11px; font-weight: 500;
}
.tool:hover { background: var(--surface-2); }
.tool:disabled { opacity: .3; background: none; }
.tool.danger { color: var(--danger); }

.sheet-host { position: absolute; left: 0; right: 0; bottom: 0; z-index: 30; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: min(54vh, 560px);
  display: flex; flex-direction: column; background: var(--surface); border-radius: 22px 22px 0 0;
  box-shadow: 0 -24px 60px rgba(0, 0, 0, .55); padding-bottom: var(--safe-b);
  animation: sheet-up .22s cubic-bezier(.2, .9, .3, 1); user-select: text;
}
.sheet.closing { animation: sheet-down .18s ease-in forwards; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 6px 18px; }
.sheet-head h2 { font-size: 16px; }
.sheet-done { background: var(--text); color: #111; }
.sheet-done:hover { background: #fff; }
.sheet-body { overflow-y: auto; padding: 6px 18px 20px; overscroll-behavior: contain; }

.music-list { display: flex; flex-direction: column; gap: 4px; }
.music-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 6px; border-radius: 12px; cursor: pointer; }
.music-row:hover { background: var(--surface-2); }
.music-row.on { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--accent); }
.music-row .icon-btn { background: var(--surface-3); flex: 0 0 auto; }
.music-meta { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.music-meta b { font-size: 14px; }
.music-meta span { font-size: 12px; color: var(--muted); }
.music-use { font-size: 13px; color: var(--accent); font-weight: 700; }

.cap-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.cap-line { display: flex; gap: 8px; align-items: center; }
.cap-time { font: 600 11px ui-monospace, Menlo, monospace; color: var(--muted); background: none; border: none; width: 54px; flex: 0 0 auto; text-align: left; }
.cap-status { min-height: 2.6em; }

.rec-btn { width: 80px; height: 80px; border-radius: 50%; background: #ff3d5a; color: #fff; border: 5px solid rgba(255, 255, 255, .18); display: grid; place-items: center; }
.rec-btn.on { animation: pulse 1.1s ease-in-out infinite; }
.rec-status { margin: 0; font-weight: 500; }

/* video nascosti che alimentano l'anteprima: restano nel viewport per non essere messi in pausa dal browser */
.video-shelf { position: fixed; left: 0; top: 0; width: 2px; height: 2px; overflow: hidden; opacity: .01; pointer-events: none; z-index: -1; }
.video-shelf video { width: 2px; height: 2px; }

/* ---------- overlay: magia, esportazione, avanzamento ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(5, 5, 8, .74); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); display: grid; place-items: center; animation: fade .18s; }
.magic-panel, .export-panel {
  width: min(660px, 100%); max-height: min(92vh, 100%); overflow-y: auto; background: var(--surface);
  border-radius: 24px; padding: 0 22px; border: 1px solid var(--line); box-shadow: 0 40px 100px rgba(0, 0, 0, .6);
}
.magic-head { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: 40px 1fr 70px; align-items: center; padding: calc(12px + var(--safe-t)) 0 12px; background: var(--surface); }
.magic-head h2 { text-align: center; font-size: 17px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.magic-head h2 .icon { color: var(--accent); }
.magic-count { color: var(--muted); font-size: 12px; text-align: right; }
.magic-tiles { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.magic-tile { flex: 0 0 62px; height: 96px; border-radius: 10px; overflow: hidden; background: var(--surface-2); position: relative; display: grid; place-items: center; color: var(--muted); }
.magic-tile img, .magic-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-badge { position: absolute; bottom: 4px; right: 4px; background: rgba(0, 0, 0, .6); border-radius: 6px; padding: 2px; color: #fff; }
.magic-panel section h3 { margin: 22px 0 10px; }
.style-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.style-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 14px; border-radius: 16px;
  background: var(--surface-2); border: 2px solid transparent; text-align: left; transition: border-color .12s, transform .12s;
}
.style-card:hover { transform: translateY(-1px); }
.style-card.on { border-color: var(--accent); background: linear-gradient(160deg, rgba(255, 61, 127, .14), rgba(124, 92, 255, .1)), var(--surface-2); }
.style-emoji { font-size: 26px; margin-bottom: 4px; }
.style-card b { font-size: 15px; }
.style-card span { font-size: 12px; color: var(--muted); }
.music-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.music-chip { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; padding: 10px 14px; border-radius: 14px; background: var(--surface-2); border: 2px solid transparent; }
.music-chip.on { border-color: var(--accent); }
.music-chip b { font-size: 14px; }
.music-chip span { font-size: 12px; color: var(--muted); }
.magic-panel .hint { margin-top: 8px; }
.magic-cta { position: sticky; bottom: 0; padding: 18px 0 calc(18px + var(--safe-b)); background: linear-gradient(transparent, var(--surface) 28%); margin-top: 10px; }
.magic-cta .btn { width: 100%; }

.progress-card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 28px 24px; width: min(380px, 90vw); text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.progress-card h2 { font-size: 18px; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .9s linear infinite; }
.progress-track { width: 100%; height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--grad); border-radius: 99px; transition: width .25s; }
.progress-fill.indeterminate { width: 40% !important; animation: indeterminate 1.2s ease-in-out infinite; }
.progress-label { color: var(--muted); font-size: 14px; min-height: 1.3em; margin: 0; }

.export-body { padding: 4px 0 24px; }
.export-video { max-height: 52vh; max-width: 100%; border-radius: 14px; background: #000; }
.export-summary { color: var(--muted); font-size: 14px; margin: 0; }
.export-panel .btn.big { width: 100%; }
.export-panel .row .btn.big { width: auto; flex: 1; }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + var(--safe-b)); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { pointer-events: auto; background: #fff; color: #111; padding: 11px 16px; border-radius: 14px; font-weight: 600; font-size: 14px; box-shadow: 0 12px 30px rgba(0, 0, 0, .45); display: flex; gap: 14px; align-items: center; animation: sheet-up .2s; transition: opacity .3s, transform .3s; }
.toast.error { background: #ff4d6d; color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
.toast-action { background: none; border: none; font-weight: 800; color: var(--accent); padding: 0; }
.toast.error .toast-action { color: #fff; text-decoration: underline; }

dialog.confirm { background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-radius: 20px; padding: 22px; width: min(400px, 90vw); }
dialog.confirm p { margin: 0 0 12px; font-weight: 500; }
dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); }

/* telefono e tablet: con un pannello aperto l'anteprima si restringe e resta tutta visibile sopra il pannello */
@media (max-width: 999px) {
  .editor:has(.sheet-host > .sheet:not(.closing)) {
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top" "stage" "sheet";
  }
  .editor:has(.sheet-host > .sheet:not(.closing)) :is(.transport, .timeline, .toolbar) { display: none; }
  .editor:has(.sheet-host > .sheet:not(.closing)) .sheet-host { position: relative; grid-area: sheet; }
  .editor:has(.sheet-host > .sheet:not(.closing)) .sheet { position: relative; max-height: min(52vh, 520px); }
}

/* ---------- desktop: pannello laterale fisso ---------- */
@media (min-width: 1000px) {
  .editor {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: "top top" "stage side" "transport side" "timeline timeline" "toolbar toolbar";
  }
  .sheet-host { position: relative; grid-area: side; border-left: 1px solid var(--line); background: var(--surface); }
  .sheet-host:empty::before { content: 'Seleziona una clip o scegli uno strumento qui sotto.'; position: absolute; inset: 0; display: grid; place-items: center; padding: 40px; text-align: center; color: var(--muted); font-size: 14px; }
  .sheet { inset: 0; max-height: none; border-radius: 0; box-shadow: none; animation: fade .15s; }
  .sheet.closing { animation: none; }
  .toolbar { justify-content: center; }
  .timeline { height: 220px; }
  /* testina trascinabile: area di presa più larga della linea */
  .tl-playhead { pointer-events: auto; cursor: ew-resize; }
  .tl-playhead::after { content: ''; position: absolute; top: 0; bottom: 0; left: -7px; width: 16px; }
  .style-cards { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 560px) and (max-width: 999px) { .style-cards { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 640px) {
  .export-btn { padding: 0 12px; }
  .ed-top .icon-btn { width: 36px; }
  .transport { justify-content: flex-start; padding-left: calc(50% - 76px); }
  .magic-panel, .export-panel { height: 100%; max-height: 100%; border-radius: 0; border: none; }
  .overlay.magic, .overlay.export { place-items: stretch; }
  .hero { padding-top: 32px; }
  .hero-actions .btn { flex: 1 1 100%; }
}
@media (max-height: 700px) and (max-width: 999px) { .timeline { height: 160px; } }

@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
@keyframes sheet-down { to { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { transform: scale(1.08); opacity: .7; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(255, 61, 90, .2); } }
@keyframes glow { 50% { box-shadow: 0 8px 40px rgba(255, 61, 127, .55), 0 0 0 1px rgba(255, 255, 255, .1); } }
@keyframes indeterminate { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- AI ---------- */
.ai-action {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px; text-align: left;
  border-radius: 16px; border: 1px solid var(--line); background: var(--surface-2);
}
.ai-action:hover:not(:disabled) { border-color: var(--accent); }
.ai-action:disabled { opacity: .45; }
.ai-action .icon { color: var(--accent); flex: 0 0 auto; }
.ai-action span { display: flex; flex-direction: column; gap: 2px; }
.ai-action b { font-size: 15px; }
.ai-action small { color: var(--muted); font-size: 12px; }
.magic-options { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; padding: 14px; border-radius: 16px; background: var(--surface-2); }
.export-post { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 8px; }
