html, body {
  height: 100%;
  margin: 0;
  font-family: 'Roboto', Arial, sans-serif;
  overflow: hidden;
}

body.body-scrollable {
  overflow-y: auto;
}


/* ========= Responsive Stage ========= */
/* Logical design size (the coordinates you store) */
:root {
  --base-w: 1440;    /* design width in px */
  --base-h: 900;     /* design height in px */
  --scale: 1;        /* updated by JS */
}

.stage-outer {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;

  display: flex;
  justify-content: center;
  align-items: flex-start;
  
}

.stage-shell{
  position: relative;
  width: calc(var(--scale, 1) * 1440px);
  height: calc(var(--scale, 1) * 900px);
}


body.body-scrollable .stage-outer {
  overflow-y: auto;
}

.stage {
  position: relative;
  width: calc(var(--base-w) * 1px);
  height: calc(var(--base-h) * 1px);
  transform-origin: top left;
  transform: scale(var(--scale));
}

/* All existing absolutely-positioned shapes work as-is */
.stage .rectangle,
.stage .textbox,
.stage .line-shape,
.stage .image-shape {
  position: absolute;
  box-sizing: border-box;
}

/* Selection overlay (marquee etc.) will be placed inside .stage now */
#selectionOverlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* SVG line crispness even when the stage is scaled */
.line-svg line,
.line-svg polyline,
.line-svg path {
  vector-effect: non-scaling-stroke;
}

/* ========== Base layout ========== */


.main-container { text-align: center; }

.image-container img {
  max-width: 100%;
  height: auto;
  margin-top: 20px;
}

.button-container {
  margin-top: 20px;
  text-align: center;
}

/* ========== Floating UI (FAB + Panel) ========== */
.fab{
  position: fixed;
  right: 24px;
  top: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: #fff;
  color: #5f6368;
  box-shadow: 0 6px 16px rgba(0,0,0,.18);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 1000;
  transition: box-shadow .2s, transform .05s;
}
.fab:hover{ box-shadow: 0 8px 20px rgba(0,0,0,.20); }
.fab:active{ transform: scale(.98); }
.fab .material-symbols-outlined{ font-size: 24px; line-height: 1; }
.fab[hidden]{ display: none; }
.edit-toggle{
  background: #ffffff;
  color: #0c0707;
}

.tool-panel{
  position: fixed;
  right: 16px;
  top: 88px;
  width: 64px;
  max-height: 70vh;
  padding: 12px 8px 8px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(0,0,0,.18);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  transform: translateX(-120%);
  opacity: 0;
  pointer-events: none;
  transition: transform .2s ease, opacity .2s ease;
}
.tool-panel.open{
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.tool{
  width: 44px; height: 44px;
  border-radius: 12px; border: 0;
  background: #f7f7f7; color: #333; cursor: pointer;
  font-size: 22px;
  display: grid; place-items: center;
  transition: background-color .2s, transform .05s;
  place-self: center;
}
.tool .material-symbols-outlined { font-size: 22px; }
.tool:hover{ background: #efefef; }
.tool:active{ transform: scale(.98); }

/* ========== Shapes: shared ========== */
.rectangle, .textbox, .line-shape, .image-shape { box-sizing: border-box; }
.resize-handle{ opacity: 0; transition: opacity .12s; }
.rectangle.selected .resize-handle,
.textbox.selected .resize-handle,
.image-shape.selected .resize-handle{ opacity: 1; }

/* ========== Rectangle ========== */
.rectangle {
  width: 100px;
  height: 50px;
  background-color: rgb(116, 162, 223);
  position: absolute;
  user-select: none;
  cursor: grab;
  outline: 0;
}
.rectangle:active { cursor: grabbing; }
.rectangle.selected {
  outline: 2px solid rgba(21,137,255,0.85);
  outline-offset: 0;
  
}
.rectangle.anchor-preview:not(.selected) {
  outline: 2px dashed rgba(37,99,235,0.6);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.12);
}

.image-shape {
  width: 240px;
  height: 160px;
  position: absolute;
  background: #fff;
  border: 1px solid rgba(23,37,84,0.25);
  box-shadow: 0 8px 16px rgba(15,23,42,0.18);
  overflow: hidden;
  user-select: none;
  cursor: move;
}
.image-shape img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-shape.selected {
  outline: 2px solid rgba(21,137,255,0.85);
  outline-offset: 0;
}
.image-shape.anchor-preview:not(.selected) {
  outline: 2px dashed rgba(37,99,235,0.6);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.12);
}

/* ========== Resize handles (for both shapes) ========== */
.resize-handle {
  width: 5px;
  height: 5px;
  background-color: rgb(249, 249, 255);
  border-radius: 50%;
  position: absolute;
  transform: translate(-50%,-50%);
}

.resize-handle-top       { top: 0; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle-bottom    { bottom: 0; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle-left      { left: 0; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.resize-handle-right     { right: 0; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.resize-handle-top-left     { top: 0; left: 0; cursor: nwse-resize; }
.resize-handle-top-right    { top: 0; right: 0; cursor: nesw-resize; }
.resize-handle-bottom-left  { bottom: 0; left: 0; cursor: nesw-resize; }
.resize-handle-bottom-right { bottom: 0; right: 0; cursor: nwse-resize; }

/* ========== Line ========== */
.line-shape {
  position: absolute;
  pointer-events: auto;
  user-select: none;
  cursor: grab;
  touch-action: none;
  --line-color: #2563eb;
  --line-thickness: 4;

  filter: var(--user-shadow,none);
}
.line-shape.dragging { cursor: grabbing; }

body:not(.edit-mode-enabled) .rectangle,
body:not(.edit-mode-enabled) .textbox,
body:not(.edit-mode-enabled) .line-shape,
body:not(.edit-mode-enabled) .image-shape {
  cursor: default;
}

.line-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.line-segment {
  stroke: var(--line-color);
  stroke-width: var(--line-thickness, 4);
  stroke-linecap: round;
  pointer-events: auto;
}
.line-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(37,99,235,0.85);
  background: #ffffff;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px rgba(37,99,235,0.18);
  cursor: move;
  opacity: 0;
  pointer-events: auto;
  transition: opacity .12s ease;
}
.line-handle:active { cursor: grabbing; }
.line-shape.selected .line-handle { opacity: 1; }

/* ========== Textbox ========== */
/* Container (NOT contenteditable) */
.textbox {
  position: absolute;
  min-width: 8px;
  min-height: 16px;
  background: transparent;
  display: inline-block;
  overflow: visible;
  z-index: auto;                   /* keep handles usable */
  cursor: move;
}
.textbox.selected {
  outline: 2px solid rgba(21,137,255,0.85);
  outline-offset: 0;
}
.textbox.anchor-preview:not(.selected) {
  outline: 2px dashed rgba(37,99,235,0.6);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.12);
}

/* Editable inner area */
.textbox-content {
  writing-mode: horizontal-tb !important;  /* force horizontal typing */
  text-orientation: mixed !important;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: break-word;
  font: 16px/1.2 'Roboto', Arial, sans-serif;
  text-align:left;
  color: #111;
  padding: 1px 4px;
  outline: none;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  cursor: text;
}
.textbox-content * {
  margin: 0;
}

/* Placeholder when empty */
.textbox-content:empty::before {
  content: attr(data-placeholder);
  color: #888;
  pointer-events: none;
}

/* Keep handles above content for hit testing */
.rectangle .resize-handle,
.textbox .resize-handle,
.image-shape .resize-handle { z-index: 2; }
.textbox .textbox-content { position: relative; z-index: 1; }

/* Cursor rule: when NOT editing, you can drag the box */
.textbox .textbox-content[contenteditable="true"] { cursor: text; }
.textbox .textbox-content[contenteditable="false"] { cursor: move; }

.rectangle .resize-handle,
.textbox .resize-handle,
.image-shape .resize-handle {
  width: 7px;
  height: 7px;
  background: #ffffff;
  border-radius: 50%;
  border: 1px solid rgba(37,99,235,0.85);
  box-shadow: 0 0 0 1px rgba(37,99,235,0.12);
}
.rectangle .resize-handle-top,
.textbox .resize-handle-top,
.image-shape .resize-handle-top { transform: translate(-50%, -50%); }
.rectangle .resize-handle-bottom,
.textbox .resize-handle-bottom,
.image-shape .resize-handle-bottom { transform: translate(-50%, 50%); }
.rectangle .resize-handle-left,
.textbox .resize-handle-left,
.image-shape .resize-handle-left { transform: translate(-50%, -50%); }
.rectangle .resize-handle-right,
.textbox .resize-handle-right,
.image-shape .resize-handle-right { transform: translate(50%, -50%); }
.rectangle .resize-handle-top-left,
.textbox .resize-handle-top-left,
.image-shape .resize-handle-top-left { transform: translate(-50%, -50%); }
.rectangle .resize-handle-top-right,
.textbox .resize-handle-top-right,
.image-shape .resize-handle-top-right { transform: translate(50%, -50%); }
.rectangle .resize-handle-bottom-left,
.textbox .resize-handle-bottom-left,
.image-shape .resize-handle-bottom-left { transform: translate(-50%, 50%); }
.rectangle .resize-handle-bottom-right,
.textbox .resize-handle-bottom-right,
.image-shape .resize-handle-bottom-right { transform: translate(50%, 50%); }
.textbox.compact-textbox .resize-handle { display: none; }
.textbox.compact-textbox .resize-handle-top-left,
.textbox.compact-textbox .resize-handle-right { display: block; }

.tool-panel .tool { font-size: 18px; font-weight: 600; }

.shape-inspector {
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%) translateY(-12px);
  display: inline-flex;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 999px;
  background: #f8fafc;
  box-shadow: 0 20px 40px rgba(15,23,42,0.18);
  align-items: center;
  opacity: 0;
  pointer-events: none;
  z-index: 1300;
  transition: opacity .18s ease, transform .18s ease;
  font-size: 13px;
}
.shape-inspector.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.inspector-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 18px;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(148,163,184,0.25);
}
.inspector-chip input[type="color"] {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
}
.inspector-chip input[type="number"],
.inspector-chip select {
  height: 28px;
  border: 1px solid rgba(148,163,184,0.35);
  border-radius: 12px;
  padding: 0 8px;
  background: #fff;
}
.inspector-chip input[type="range"] {
  width: 120px;
}
.chip-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #475569;
}
.download-btn {
  border: none;
  cursor: pointer;
  font-weight: 600;
  color: #2563eb;
}

.shape-context[hidden] { display: none; }
.shape-context {
  position: fixed;
  min-width: 180px;
  padding: 6px;
  display: grid;
  gap: 4px;
  background: #1f2937;
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 16px 32px rgba(0,0,0,0.35);
  z-index: 1500;
}
.shape-context button {
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.shape-context button:hover {
  background: rgba(255,255,255,0.08);
}

.shape-context header {
  padding: 6px 10px 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: rgba(255,255,255,0.6);
}

.has-link,
.has-link .textbox-content {
  cursor: pointer;
}
.has-link:hover,
.has-link .textbox-content:hover {
  color: #2563eb;
  filter: brightness(1.05);
}

/* Make linked shapes behave like clickable buttons */
.rectangle.has-link,
.textbox.has-link,
.image-shape.has-link {
  cursor: pointer;
}

/* Text inside linked textboxes should also show pointer */
.textbox.has-link .textbox-content {
  cursor: pointer;
}

/* Override resize / line handles inside linked shapes */
.has-link .resize-handle,
.has-link .line-handle {
  cursor: pointer;
}


.selection-box {
  position: absolute;
  border: 1px dashed #2563eb;
  background: rgba(37,99,235,0.12);
  pointer-events: none;
  z-index: 1400; /* above shapes in the stage */
}

/* DO NOT set position: fixed here; the absolute version above is the one we want */


.rounded-ready {
  background: #8fa8df;
  border-radius: 24px;
  border: 1px solid rgba(23,37,84,0.25);
  box-shadow: 0 8px 16px rgba(15,23,42,0.26);
}


.font-size {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.font-size button {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 1px solid rgba(148,163,184,.35);
  background: #fff;
  cursor: pointer;
}

#fillAlpha { width: 80px; }
