/* ============================================================
   Media Editor — standalone module
   Self-contained stylesheet: theme tokens + shared components are
   copied here from the system's css/theme.css, and the .mm-* editor
   styles from css/maker.css, so this folder can be uploaded and
   served on its own. Nothing outside media-editor/ is required.

   Theme is driven from <html data-theme="light|dark" data-accent="…">
   exactly like the rest of the system.
   ============================================================ */

/* ---------- tokens (from css/theme.css) ---------- */
:root{
  --bg:#eef1f7;
  --bg-2:#e6ebf4;
  --panel:#ffffff;
  --panel-2:#f5f7fc;
  --panel-3:#eef2f9;
  --line:#e3e8f1;
  --line-2:#d3dbe8;
  --text:#161c28;
  --muted:#5b6577;
  --muted-2:#8a94a6;
  --shadow:0 22px 50px -26px rgba(20,30,60,.28);

  --radius:16px;
  --font:'Inter',system-ui,-apple-system,Segoe UI,Roboto,sans-serif;
  --display:'Plus Jakarta Sans',var(--font);
  --mono:'JetBrains Mono',ui-monospace,monospace;
}
[data-theme="dark"]{
  --bg:#090d17;
  --bg-2:#0d1220;
  --panel:#111827;
  --panel-2:#151d30;
  --panel-3:#1a2338;
  --line:#212c46;
  --line-2:#2a3752;
  --text:#e9eef8;
  --muted:#8b98b8;
  --muted-2:#5d6a89;
  --shadow:0 22px 60px -24px rgba(0,0,0,.75);
}
:root,[data-accent="cyan"]{--accent:#06b6d4;--accent-2:#3b82f6;--accent-ink:#fff;--accent-soft:rgba(6,182,212,.15)}
[data-accent="magenta"]{--accent:#ec4899;--accent-2:#8b5cf6;--accent-ink:#fff;--accent-soft:rgba(236,72,153,.15)}
[data-accent="yellow"]{--accent:#f5b301;--accent-2:#fb923c;--accent-ink:#241c00;--accent-soft:rgba(245,179,1,.18)}
[data-accent="key"]{--accent:#64748b;--accent-2:#334155;--accent-ink:#fff;--accent-soft:rgba(100,116,139,.18)}

*{box-sizing:border-box;margin:0;padding:0}
/* A plain `display` on a class outranks the UA's [hidden] rule, so several
   components below (.mm-drop, .mm-tabs, …) would stay on screen after the JS
   sets el.hidden = true. Settle it once, here. */
[hidden]{display:none!important}
html,body{height:100%}
body{
  font-family:var(--font);color:var(--text);
  background:
    radial-gradient(1100px 640px at 82% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 600px at 6% 112%, rgba(255,255,255,.03), transparent 55%),
    var(--bg);
  -webkit-font-smoothing:antialiased;
}
a{color:inherit;text-decoration:none}
::selection{background:var(--accent);color:var(--accent-ink)}
*::-webkit-scrollbar{width:10px;height:10px}
*::-webkit-scrollbar-thumb{background:var(--line-2);border-radius:20px;border:2px solid transparent;background-clip:padding-box}
*::-webkit-scrollbar-thumb:hover{background:var(--muted-2)}

/* ---------- buttons (from css/theme.css) ---------- */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;font-family:var(--font);font-size:13.5px;font-weight:600;padding:11px 16px;border-radius:12px;border:1px solid var(--line-2);background:var(--panel-2);color:var(--text);cursor:pointer;transition:.15s;white-space:nowrap}
.btn:hover:not(:disabled){border-color:var(--muted-2);transform:translateY(-1px)}
.btn:disabled{opacity:.45;cursor:default}
.btn svg{width:16px;height:16px}
.btn-icon{padding:11px;width:42px;height:42px}
.btn-icon svg{width:17px;height:17px}
.btn-primary{border-color:transparent;color:var(--accent-ink);background:linear-gradient(135deg,var(--accent),var(--accent-2));box-shadow:0 3px 8px -5px var(--accent)}
.btn-primary:hover:not(:disabled){filter:brightness(1.05)}

/* ============================================================
   Page shell — mirrors the system's .editor-head / panel look
   ============================================================ */
.me-shell{
  width:min(1180px,100%);margin:0 auto;padding:26px 22px 40px;
  display:flex;flex-direction:column;gap:16px;min-height:100%;
}
.me-head{
  display:flex;align-items:center;gap:13px;
  padding:16px 18px;border-radius:var(--radius);
  background:var(--panel);border:1px solid var(--line);box-shadow:var(--shadow);
}
.me-ic{
  width:44px;height:44px;flex:none;border-radius:12px;display:grid;place-items:center;
  color:var(--accent-ink);background:linear-gradient(135deg,var(--accent),var(--accent-2));
}
.me-ic svg{width:22px;height:22px}
.me-tx h1{font-family:var(--display);font-size:17px;font-weight:800;line-height:1.2}
.me-tx p{font-size:12px;color:var(--muted-2);margin-top:2px}
.me-actions{margin-left:auto;display:flex;align-items:center;gap:10px}
/* Narrow screens: let the accent/theme controls drop to their own row instead
   of squeezing the title into a five-line column. */
@media (max-width:620px){
  .me-head{flex-wrap:wrap;row-gap:12px}
  .me-tx{flex:1 1 140px;min-width:0}
  .me-actions{flex:0 0 auto}
}
.me-accents{display:flex;gap:6px;padding:6px;border-radius:999px;background:var(--panel-2);border:1px solid var(--line)}
.me-acc{width:20px;height:20px;padding:0;border:2px solid transparent;border-radius:50%;cursor:pointer;transition:.15s}
.me-acc:hover{transform:scale(1.12)}
.me-acc[aria-pressed="true"]{border-color:var(--text)}
.me-theme .moon{display:none}
[data-theme="dark"] .me-theme .sun{display:none}
[data-theme="dark"] .me-theme .moon{display:block}

.me-card{
  border-radius:var(--radius);background:var(--panel);border:1px solid var(--line);
  box-shadow:var(--shadow);overflow:hidden;
}
/* preview column | tools column */
.me-grid{display:grid;grid-template-columns:minmax(0,400px) minmax(0,1fr);gap:18px;padding:16px}
/* min-width:0 or a grid item is sized by its content and overflows the column
   on narrow screens instead of letting its children wrap. */
.me-col{min-width:0}
.me-col h4{
  font-size:10.5px;font-weight:700;letter-spacing:.12em;text-transform:uppercase;
  color:var(--muted-2);margin-bottom:10px;
}
.me-col-tools{min-width:0}
@media (max-width:860px){.me-grid{grid-template-columns:1fr}}

.me-foot{display:flex;align-items:center;gap:9px;padding:14px 18px;border-top:1px solid var(--line);flex-wrap:wrap}
.me-foot .me-spacer{margin-left:auto}
.me-hint{font-size:11.5px;color:var(--muted-2);padding:0 4px}

/* What you can do directly on the preview. Centred under it, and quiet enough
   that it reads as a caption rather than a control. */
.me-drag-hint{
  display:flex;align-items:center;justify-content:center;flex-wrap:wrap;
  gap:9px;margin:12px auto 0;padding:7px 12px;
  width:max-content;max-width:100%;
  border-radius:999px;background:var(--panel-2);border:1px solid var(--line);
  font-size:11px;color:var(--muted-2);
}
.me-drag-hint[hidden]{display:none}
.me-drag-hint span{display:inline-flex;align-items:center;gap:5px;white-space:nowrap}
.me-drag-hint svg{width:13px;height:13px;color:var(--accent);flex:none}
.me-drag-hint i{width:1px;height:11px;background:var(--line-2);flex:none}
@media (max-width:520px){
  /* max-content keeps every item on one line, so the pill has to give that up
     before flex-wrap can do anything. */
  .me-drag-hint{width:auto;border-radius:14px;gap:6px 10px;justify-content:center}
  .me-drag-hint i{display:none}
}
.me-note{font-size:11.5px;color:var(--muted-2);text-align:center;line-height:1.8}
/* Visit count. Sits with the note rather than in its own band — it is a
   footnote, not a feature. Hidden entirely unless count.php answers. */
.me-visits{display:inline-flex;align-items:center;gap:6px;white-space:nowrap}
.me-visits[hidden]{display:none}
.me-visits i{width:1px;height:11px;background:var(--line-2);margin:0 3px}
.me-visits svg{width:13px;height:13px;color:var(--accent)}
.me-visits b{font-weight:700;color:var(--muted);font-variant-numeric:tabular-nums}
/* a brief pulse when the number goes up, so a live change is noticeable */
.me-visits b.bump{animation:meBump .5s ease}
@keyframes meBump{0%{color:var(--accent);transform:translateY(-1px)}100%{color:var(--muted);transform:none}}

/* ============================================================
   Editor controls — lifted verbatim from css/maker.css so the
   look matches the in-app Photo & Signature modal exactly.
   ============================================================ */
.mm-tabs{display:flex;gap:6px;padding:18px 18px 0}
.mm-tab{flex:1;display:flex;align-items:center;justify-content:center;gap:7px;font-family:var(--font);font-size:12.5px;font-weight:600;color:var(--muted);padding:9px;border:1px solid var(--line);border-radius:10px;background:var(--panel-2);cursor:pointer;transition:.15s}
.mm-tab:hover{color:var(--text);border-color:var(--line-2)}
.mm-tab.active{color:var(--accent-ink);background:linear-gradient(135deg,var(--accent),var(--accent-2));border-color:transparent}
.mm-body[hidden]{display:none}

.mm-stage{display:flex;justify-content:center}
.mm-drop{display:block;width:100%;cursor:pointer}
.mm-drop-inner{border:1.5px dashed var(--line-2);border-radius:14px;padding:46px 16px;text-align:center;color:var(--muted);background:var(--panel-2);transition:.16s}
.mm-drop:hover .mm-drop-inner,.mm-drop.drag .mm-drop-inner{border-color:var(--accent);color:var(--text);background:var(--accent-soft)}
.mm-drop-inner svg{color:var(--accent);margin-bottom:8px}
.mm-drop-inner span{display:block;font-size:13px}
.mm-drop-inner small{font-size:11px;color:var(--muted-2)}
/* Transparent output (a cut-out photo, or ink with the paper removed) is
   unreadable on a flat dark panel, so the preview sits on a checkerboard —
   the usual "this part is see-through" cue. Opaque results cover it entirely. */
.mm-canvas-wrap{
  position:relative;width:100%;max-width:340px;aspect-ratio:1;
  border-radius:14px;overflow:hidden;border:1px solid var(--line);
  background-color:#fff;
  background-image:
    linear-gradient(45deg,#dfe4ec 25%,transparent 25%,transparent 75%,#dfe4ec 75%),
    linear-gradient(45deg,#dfe4ec 25%,transparent 25%,transparent 75%,#dfe4ec 75%);
  background-size:18px 18px;
  background-position:0 0,9px 9px;
}
.mm-canvas-wrap.sig{max-width:400px;aspect-ratio:2/1}
/* the photo preview is directly draggable */
#photoPreview{cursor:grab;touch-action:none}
#photoPreview.dragging{cursor:grabbing}
#photoPreview canvas{user-select:none;-webkit-user-drag:none}
.mm-canvas-wrap canvas{width:100%;height:100%;object-fit:contain;display:block}
.mm-busy{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;background:rgba(255,255,255,.72);backdrop-filter:blur(1px);font-size:11.5px;font-weight:600;color:var(--muted);border-radius:14px}
.mm-busy[hidden]{display:none}
.mm-spin{width:22px;height:22px;border-radius:50%;border:2.5px solid var(--line-2);border-top-color:var(--accent);animation:mmSpin .7s linear infinite}
@keyframes mmSpin{to{transform:rotate(360deg)}}

.mm-tools{display:flex;flex-direction:column;gap:8px}
.mm-tools[hidden]{display:none}
.mm-tool{border:1px solid var(--line);border-radius:12px;padding:9px 11px;background:var(--panel-2)}
.mm-tool[hidden]{display:none}
.mm-tool-head{display:flex;align-items:center;gap:8px;font-size:12.5px;font-weight:700;margin-bottom:7px}
.mm-tool-head small{font-weight:500;color:var(--muted-2);font-size:10.5px;margin-left:auto}
/* Which cut-out engine actually ran. Edge quality is mostly decided here, so
   it is worth being able to see it rather than infer it from the result. */
.mm-engine{
  margin-left:auto;font-style:normal;font-weight:600;font-size:9.5px;
  letter-spacing:.06em;text-transform:uppercase;
  padding:3px 7px;border-radius:999px;
  background:var(--accent-soft);color:var(--accent);
}
.mm-engine[hidden]{display:none}
.mm-engine.basic{background:rgba(229,72,77,.15);color:#e5484d}
.mm-tool-head.mm-collapsible{cursor:pointer;user-select:none}
.mm-tool-chev{width:14px;height:14px;color:var(--muted-2);transition:transform .2s ease;flex:none}
.mm-tool.collapsed .mm-tool-chev{transform:rotate(-90deg)}
.mm-tool.collapsed .mm-tool-head{margin-bottom:0}
.mm-tool.collapsed .mm-tool-body{display:none}
.mm-range{display:flex;align-items:center;gap:10px;margin-top:6px}
.mm-range label{font-size:11.5px;color:var(--muted);width:64px;flex:none;display:flex;align-items:center;gap:5px}
/* the colour the spill key is currently matching */
.mm-dot{width:10px;height:10px;border-radius:50%;border:1px solid var(--line-2);flex:none}
.mm-dot[hidden]{display:none}
.mm-range input[type=range]{flex:1;accent-color:var(--accent);min-width:0}
.mm-range output{font-size:11px;font-family:var(--mono);color:var(--muted-2);width:38px;text-align:right}
.mm-range.off{opacity:.4;pointer-events:none}

.mm-switch{position:relative;display:inline-block;width:38px;height:22px;margin-left:auto;flex:none}
.mm-switch input{opacity:0;width:0;height:0}
.mm-switch span{position:absolute;inset:0;background:var(--line-2);border-radius:22px;transition:.18s;cursor:pointer}
.mm-switch span:before{content:"";position:absolute;width:16px;height:16px;left:3px;top:3px;background:#fff;border-radius:50%;transition:.18s}
.mm-switch input:checked+span{background:var(--accent)}
.mm-switch input:checked+span:before{transform:translateX(16px)}

/* Adjust panel — histogram readout + the small Auto / Reset row under it. */
.mm-hist{
  width:100%;height:42px;display:block;margin:2px 0 4px;
  border-radius:8px;border:1px solid var(--line);background:var(--panel);
}
.mm-btnrow{display:flex;gap:7px;margin-top:11px}
.mm-mini{
  flex:1;padding:7px 10px;border-radius:9px;cursor:pointer;
  font:600 11.5px var(--font);color:var(--text);
  background:var(--panel);border:1px solid var(--line-2);transition:.15s;
}
.mm-mini:hover{border-color:var(--accent);color:var(--accent)}

.mm-swatches{display:flex;gap:8px;margin-top:11px}
.mm-sw{width:26px;height:26px;border-radius:8px;cursor:pointer;border:2px solid var(--line-2);transition:.15s}
.mm-sw:hover{transform:scale(1.08)}
.mm-sw.active{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent-soft)}
.mm-sw.none{display:grid;place-items:center;font-size:14px;color:var(--muted);background:var(--panel)}

.mm-overlays{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}
.mm-ov{position:relative;aspect-ratio:1;border-radius:10px;border:1.5px solid var(--line);background:#eef1f5;cursor:pointer;overflow:hidden;transition:.15s;display:grid;place-items:center}
.mm-ov:hover{border-color:var(--line-2)}
.mm-ov.active{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}
.mm-ov img{width:100%;height:100%;object-fit:contain}
.mm-ov.none{font-size:10.5px;font-weight:700;color:var(--muted)}
.mm-ov.upload{border-style:dashed;color:var(--accent);font-size:10.5px;font-weight:700;flex-direction:column;gap:2px}
.mm-ov.upload svg{width:18px;height:18px}
.mm-ov-adj{margin-top:11px;padding-top:11px;border-top:1px dashed var(--line)}
.mm-ov-adj[hidden]{display:none}

#meRemove{color:#e5484d}
