:root {
  --bg: #1e1e1e;
  --panel: #2a2a2c;
  --panel2: #333336;
  --line: #444;
  --text: #eee;
  --muted: #9a9a9e;
  --accent: #3b6ef5;
  --stage: #4a4a4d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
body { display: flex; flex-direction: column; }

/* Toolbar */
#toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: 0 0 auto; flex-wrap: wrap; }
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; user-select: none; }
.btn:hover { background: #3d3d40; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.big { padding: 10px 20px; font-size: 15px; background: var(--accent); border-color: var(--accent); }
.sep { width: 1px; height: 20px; background: var(--line); }
.label { font-variant-numeric: tabular-nums; min-width: 42px; text-align: center; color: var(--muted); }
.info { color: var(--muted); font-size: 12px; margin-left: auto; max-width: 40vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { background: var(--panel2); color: var(--text); border: none;
  border-right: 1px solid var(--line); padding: 4px 10px; cursor: pointer; font-size: 12px; }
.segmented button:last-child { border-right: none; }
.segmented select {
  background: var(--panel2); color: var(--text); border: none;
  border-right: 1px solid var(--line); padding: 0 6px; font: inherit;
  cursor: pointer; outline: none; -webkit-appearance: none; appearance: none;
}
.segmented select:hover { background: var(--panel); }
.segmented button.on { background: var(--accent); }
.segmented.small button { padding: 3px 8px; }

/* Find bar */
#findbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
#findbar input[type=text], #findbar input:not([type]) { background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; width: 200px; }
.chk { color: var(--muted); font-size: 12px; }

/* Main */
#main { flex: 1 1 auto; display: flex; min-height: 0; }
#stage { flex: 1 1 auto; overflow: auto; background: var(--stage); position: relative;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px; }
#empty { margin: auto; text-align: center; color: var(--muted); max-width: 460px; }
#empty h1 { color: var(--text); font-weight: 600; }
#empty .hint { font-size: 12px; margin-top: 24px; }

#pageWrap { position: relative; box-shadow: 0 4px 24px rgba(0,0,0,0.5); }
#page { display: block; background: #fff; }
#overlay { position: absolute; inset: 0; pointer-events: none; }

/* Paragraph boxes + object selection drawn as positioned divs */
.para-box { position: absolute; border: 1px dashed rgba(140,140,150,0.85); pointer-events: auto;
  cursor: text; }
.para-box:hover { border-color: var(--accent); border-style: dashed; }
.para-box.locked { border: 1px dotted rgba(200,120,120,0.4); cursor: not-allowed; }
.obj-box { position: absolute; border: 1.5px solid var(--accent); pointer-events: auto; cursor: move; }
.obj-handle { position: absolute; width: 10px; height: 10px; background: #fff; border: 1.5px solid var(--accent);
  border-radius: 50%; pointer-events: auto; z-index: 2; }
.sel-para { position: absolute; border: 1.5px solid var(--accent); pointer-events: auto; cursor: move; }

/* Text edit overlay. Transparent: the page render blanks the paragraph's
   original glyphs while editing, so the overlay text sits on the real page
   background — true WYSIWYG instead of a white patch. */
.editor { position: absolute; background: transparent; outline: 2px solid var(--accent);
  pointer-events: auto; overflow: hidden; color: #000; }
.editor [contenteditable] { outline: none; width: 100%; height: 100%; caret-color: #000; }

/* Grab strips along the editor's edges — drag to move the box while editing. */
.edit-move { position: absolute; pointer-events: auto; cursor: move; z-index: 1;
  background: transparent; }
.edit-move:hover { background: rgba(59, 110, 245, 0.18); }

/* Containers that mirror a (possibly rotated) box and hold its chrome. */
.edit-chrome, .sel-chrome { position: absolute; pointer-events: none; }
.edit-chrome > *, .sel-chrome > * { pointer-events: auto; }

/* Multi-selection outlines + marquee rubber band. */
.multi-box { position: absolute; border: 1.5px solid var(--accent);
  background: rgba(59, 110, 245, 0.06); pointer-events: auto; cursor: move; }
.marquee { position: absolute; border: 1px dashed var(--accent);
  background: rgba(59, 110, 245, 0.08); pointer-events: none; }

/* Rotate handle above a selected paragraph. */
.rot-handle { cursor: grab; }
.rot-stem { position: absolute; top: -14px; width: 1.5px; height: 14px;
  background: var(--accent); pointer-events: none; }

/* Inspector */
#inspector { flex: 0 0 250px; background: var(--panel); border-left: 1px solid var(--line);
  padding: 14px; overflow-y: auto; }
#inspector h2 { font-size: 13px; margin: 0 0 12px; }
#inspector .row { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
#inspector select { flex: 1; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px; }
.num { width: 56px; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px; text-align: right; }
.swatches { flex-wrap: wrap; }
.swatch { width: 22px; height: 22px; border-radius: 11px; border: 1px solid var(--line); cursor: pointer; }
#fColor { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.toggles button { width: 34px; height: 28px; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.toggles button.on { background: var(--accent); }
#inspector hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.field { display: flex; justify-content: space-between; align-items: center; color: var(--muted);
  font-size: 12px; margin-bottom: 8px; }
#inspector[disabled] { opacity: 0.5; pointer-events: none; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #000c; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 50; }

/* Loaded-file chip in the header; click shows details. */
.docname {
  margin-left: 10px; padding: 3px 10px; max-width: 320px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: transparent; border: 1px solid rgba(127,127,127,.4);
  border-radius: 999px; font: 12px/1.4 -apple-system, system-ui, sans-serif;
  color: inherit; opacity: .85; cursor: pointer;
}
.docname:hover { opacity: 1; }
