:root {
  --bg: #0f1115;
  --bg-2: #171a21;
  --bg-3: #1f232c;
  --panel: #161922;
  --line: #2a2f3a;
  --text: #e7eaf0;
  --muted: #8b93a4;
  --brand: #ffce3a;
  --brand-2: #ffb020;
  --accent: #5b8cff;
  --accent-2: #3f6fe0;
  --danger: #ff5c6c;
  --ok: #34d399;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .crown { font-size: 30px; filter: drop-shadow(0 2px 6px rgba(255,206,58,.4)); }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: .3px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.pill { background: var(--bg-3); color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: 13px; }

/* ---------- Layout ---------- */
.layout { flex: 1 1 auto; display: grid; grid-template-columns: 96px 1fr 320px; min-height: 0; }

/* ---------- Toolbar ---------- */
.toolbar { background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px; padding: 12px 8px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  border-radius: var(--radius); padding: 12px 4px; cursor: pointer; font-size: 11px; font-weight: 600;
  transition: all .12s ease; }
.tool span { font-size: 22px; }
.tool:hover { background: var(--bg-3); color: var(--text); }
.tool.active { background: linear-gradient(160deg, rgba(255,206,58,.18), rgba(255,176,32,.06));
  border-color: rgba(255,206,58,.4); color: var(--brand); }

/* ---------- Stage ---------- */
.stage-wrap { position: relative; display: flex; min-height: 0;
  background: repeating-conic-gradient(#13161c 0% 25%, #171b22 0% 50%) 50% / 28px 28px; }
.stage { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; overflow: hidden; }
#preview { max-width: 100%; max-height: 100%; box-shadow: var(--shadow); background:
  repeating-conic-gradient(#cfd3da 0% 25%, #eef1f6 0% 50%) 50% / 20px 20px; border-radius: 4px; }

.empty-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.empty-inner { text-align: center; color: var(--muted); }
.empty-crown { font-size: 64px; opacity: .5; }
.empty-state h2 { color: var(--text); margin: 8px 0; }
.empty-state.drag { background: rgba(91,140,255,.08); }
.muted { color: var(--muted); font-size: 12px; }

/* ---------- Crop overlay ---------- */
.crop-overlay { position: absolute; inset: 0; pointer-events: none; }
.crop-box { position: absolute; border: 2px solid var(--brand);
  box-shadow: 0 0 0 9999px rgba(0,0,0,.5); pointer-events: auto; cursor: move; }
.handle { position: absolute; width: 12px; height: 12px; background: var(--brand);
  border: 2px solid #1a1a1a; border-radius: 3px; }
.handle[data-h="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.handle[data-h="n"]  { left: 50%; top: -7px; transform: translateX(-50%); cursor: ns-resize; }
.handle[data-h="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.handle[data-h="e"]  { right: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.handle[data-h="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.handle[data-h="s"]  { left: 50%; bottom: -7px; transform: translateX(-50%); cursor: ns-resize; }
.handle[data-h="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.handle[data-h="w"]  { left: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

/* ---------- Text drag-handtag ---------- */
.text-handle { position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%; background: var(--brand); color: #1a1400; z-index: 6;
  display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: bold;
  cursor: move; border: 2px solid #1a1a1a; box-shadow: 0 2px 10px rgba(0,0,0,.6); pointer-events: auto;
  touch-action: none; }
.text-handle::after { content: ''; position: absolute; inset: -22px; }  /* större träffyta */

/* ---------- Panel ---------- */
.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; }
.panel h3 { margin: 0 0 4px; font-size: 16px; }
.panel .sub { color: var(--muted); font-size: 12px; margin: 0 0 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field .row { display: flex; align-items: center; gap: 8px; }
input[type="text"], input[type="number"], select {
  width: 100%; background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  padding: 9px 10px; border-radius: 8px; font-size: 14px; }
input[type="range"] { width: 100%; accent-color: var(--brand); }
input[type="color"] { width: 44px; height: 36px; padding: 2px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; }
.field .val { font-size: 12px; color: var(--text); min-width: 44px; text-align: right; }
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600; }
.chip.active { background: rgba(255,206,58,.16); border-color: var(--brand); color: var(--brand); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: #fff; }
.hint { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }

/* ---------- Buttons ---------- */
.btn { border: 1px solid var(--line); background: var(--bg-3); color: var(--text);
  padding: 10px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; transition: all .12s; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: linear-gradient(160deg, var(--brand), var(--brand-2)); color: #1a1400; border: none; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-accent { background: var(--accent); border: none; color: #fff; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Filmstrip ---------- */
.filmstrip-wrap { flex: 0 0 auto; background: var(--bg-2); border-top: 1px solid var(--line); padding: 8px 12px; }
.batch-status { font-size: 12px; color: var(--muted); margin-bottom: 6px; min-height: 16px; }
.filmstrip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; min-height: 76px; }
.thumb { position: relative; flex: 0 0 auto; width: 72px; height: 72px; border-radius: 8px; overflow: hidden;
  border: 2px solid transparent; cursor: pointer; background: var(--bg-3); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.active { border-color: var(--brand); }
.thumb .x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,.7); color: #fff; font-size: 12px; line-height: 18px; text-align: center; opacity: 0; transition: .1s; }
.thumb:hover .x { opacity: 1; }
.thumb .num { position: absolute; bottom: 2px; left: 3px; font-size: 10px; color: #fff; text-shadow: 0 1px 2px #000; }

/* ---------- Toast / progress ---------- */
.toast { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow); z-index: 50; font-size: 14px; }
.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .15s; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c313c; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
