/* ---- sizing tokens ---- */
:root{
  /* set these; your JS also overrides --stage-w/--stage-h at runtime */
  --stage-w: 1200px;          /* or 600px */
  --stage-h: 600px;           /* or 300px */
  --sidebar-w: 80px;
  --panel-w: 200px;
  --stickerbar-h: 100px;
  --stage-bg: #fff;
  
    /* frame size derived from parts */
  --frame-w: calc(var(--sidebar-w) + var(--panel-w) + var(--stage-w));
  --frame-h: calc(var(--stage-h) + var(--stickerbar-h));

  /* current visual scale, set by JS */
  --ui-scale: 1;
}

html, body { 
	margin:0; 
	height:100%; }
body { 
	font-family: sans-serif; 
	background:#fff; }

/* viewport shell that centers the frame */
#root{
  display:flex;
  justify-content:flex-start;   /* was “top left” — invalid */
  align-items:flex-start;       /* was “top left” — invalid */
  height:100vh;
  width:100vw;
  overflow:auto;
  background:#fff;
}
}

/* the grid “frame” (your #app) has fixed logical size, then is scaled */
#app{

}

/* main app row: sidebar | panel | stage */
/* Frame: 3 columns (sidebar | panel | stage), 2 rows (stage | sticker bar) */
#app{ 
  width: var(--frame-w);
  height: var(--frame-h);
  transform: scale(var(--ui-scale));
  transform-origin: top left;
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--panel-w) var(--stage-w);
  grid-template-rows: var(--stage-h) var(--stickerbar-h);
  gap: 0;
  /* allow page scrolling if viewport smaller than full frame */
  min-width: calc(var(--sidebar-w) + var(--panel-w) + var(--stage-w));
  min-height: calc(var(--stage-h) + var(--stickerbar-h));
  
}


/* Sidebar occupies left column, only the stage row (not the sticker bar row) */
#sidebar{
  grid-column: 1;
  grid-row: 1 / -1;          /* or 1 / span 2 */
  width: var(--sidebar-w);
  height: auto;              /* let grid set the full height */
  background: #222;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 8px;
  box-sizing: border-box;
  overflow: hidden; /* fixed width, no reflow */
}
.category{
  padding: 10px;
  background: #333;
  cursor: pointer;
  text-align: center;
  user-select: none;
  border: none;
  color: #fff;
}

/* Export buttons */
.export-btn {
    margin-top: 10px;
    padding: 8px;
    border: none;
    background: #555;
    color: #fff;
    cursor: pointer;
}

/* Panel sits between sidebar and stage, same height as stage; scrolls internally */
#panel{
  grid-column: 2;
  grid-row: 1 / -1;          /* or 1 / span 2 */
  width: var(--panel-w);
  height: auto;
  background: #f0f0f0;
  border-right: 1px solid #ccc;
  overflow-y: auto;        /* content scrolls; width never changes */
  box-sizing: border-box;
}
.panel-section{ padding: 10px; }
.hidden{ display: none; }
.lbl{ display:block; margin:8px 0 4px; font-size:12px; color:#333; }
.num{ width:80px; }
.btn-row{ margin-top:12px; display:flex; gap:8px; }
.progress{ margin-top:8px; font-size:12px; color:#333; }
.export-btn{ padding:8px 10px; border:0; background:#555; color:#fff; cursor:pointer; }
.export-btn[disabled]{ opacity:.5; cursor:not-allowed; }


/* BACKGROUND OPTIONS */
.bg-option {
    width: 100%;
    height: 80px;
    background-size: cover;
    background-position: center;
    margin-bottom: 10px;
    cursor: pointer;
    border: 1px solid #ccc;
}

/* Stage: fixed box; never flexes, never covered */
#stage{
  grid-column: 3;
  grid-row: 1;
  width: var(--stage-w);
  height: var(--stage-h);
  background-color: var(--stage-bg);
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

/* Sticker bar: only under the stage (column 3, row 2) */
#sticker-bar{
  grid-column: 3;
  grid-row: 2;
  height: var(--stickerbar-h);
  background: #ddd;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  overflow-x: auto;
  box-sizing: border-box;
}

/* Sticker thumbnails */
.sticker-src{
z-index: 100;
  height: 60px;
  cursor: grab;
  user-drag: none;
  -webkit-user-drag: none;
}


/* STICKER WRAPPER */
.sticker-wrapper {
  position: absolute;
  touch-action: none;
  transform-origin: rop left;
}

/* Sticker image */
.sticker-wrapper img{
  display:block;
  user-select:none;
  pointer-events:auto;
  position:relative;
  z-index:1;
  cursor: move; /* 4-way move icon */
}

/* --- DEFAULT: HIDE HANDLES --- */
.scale-handle,
.rot-handle { display: none; }

/* SHOW HANDLES ONLY WHEN SELECTED */
.sticker-wrapper.selected .scale-handle { display: block; }
.sticker-wrapper.selected .rot-handle   { display: block; }

/* Selection outline */
.sticker-wrapper.selected {
  outline: 2px dashed #000;
  outline-offset: 4px;
}

/* SCALE HANDLE (with larger invisible hit area + glyph) */
.scale-handle{
  position:absolute;
  width:18px; height:18px;
  bottom:-12px; right:-12px;   /* keep your current corner */
  background:#fff;
  border:2px solid #000;
  border-radius:3px;
  z-index:2;
  pointer-events:auto;
}
.scale-handle::before{
  content:"";
  position:absolute;
  inset:-5px;                  /* enlarge hover target */
  cursor: se-resize;           /* native diagonal arrows */
}
.scale-handle::after{
  content:"⤡";                 /* diagonal glyph */
  position:absolute;
  left:50%; top:50%;
  transform:translate(-50%,-50%);
  font-size:12px;
  line-height:1;
  color:#000;
  text-shadow:0 1px 0 #fff;
  pointer-events:none;
  opacity:.5;
}
.scale-handle:hover::after,
.scale-handle.dragging::after{ opacity:1; }

/* ROTATE HANDLE (with larger invisible hit area + glyph) */
.rot-handle{
  position:absolute;
  width:18px; height:18px;
  top:-24px; left:50%;
  transform:translateX(-50%);
  background:#fff;
  border:2px solid #000;
  border-radius:50%;
  z-index:2;
  pointer-events:auto;
  cursor: grab;
}
.rot-handle::before{
  content:"";
  position:absolute;
  inset:-14px;                 /* enlarge hover target */
  cursor: grab;
}
.rot-handle::after{
  content:"↻";
  position:absolute;
  left:50%; top:50%;
  transform:translate(-50%,-50%);
  font-size:12px;
  line-height:1;
  color:#000;
  text-shadow:0 1px 0 #fff;
  pointer-events:none;
  opacity:.5;
}
.rot-handle:hover::after,
.rot-handle.dragging::after{ opacity:1; }

/* Drag/scale/rotate feedback (you already wire these classes in JS) */
.sticker-wrapper.dragging img { cursor: grabbing; }
.scale-handle.dragging        { cursor: se-resize !important; }
.rot-handle.dragging          { cursor: grabbing !important; }
body.scaling,  body.scaling  * { cursor: se-resize !important; }
body.rotating, body.rotating * { cursor: grabbing  !important; }




#sticker-bar {
  position: relative;            /* new */
  padding-right: 44px;           /* prevents stickers under the button */
}

/* Fullscreen button (bottom-right of viewport, not scaled) */
.fs-btn-inbar{
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: #222;
  color: #fff;
  opacity: .85;
  cursor: pointer;
}
.fs-btn-inbar:hover{ opacity: 1; }


/* Future non-sticker layers that must sit above stickers */
.headline-layer,
.cta-layer,
.hero-layer {
  position: absolute;
  z-index: 2000;   /* safely above the sticker bubble (100..999) */
  pointer-events: auto;
}

/* Fullscreen ON (class-based, works everywhere) */
#root.fs-on{
  background:#000;             /* black bars */
  justify-content:center;      /* center horizontally */
  align-items:center;          /* center vertically */
  overflow:hidden;             /* no scrollbars in fullscreen */
}
#root.fs-on #app{
  transform-origin:center center; /* scale from center while FS */
}
