:root {
  --bg:#0e111a; --panel:#151a26; --ink:#e9edf5; --muted:#a8b3c7; --accent:#7aa2ff;
  --border:#263045; --warn:#ff6b6b; --sel:#00e0c6; --rect:#ffd34d;

  /* Alternating page backgrounds */
  /* darker odd */
  --page-dark-bg:   #0c1122;
  --page-dark-bord: #1e2a46;

  /* brighter even */
  --page-light-bg:  #22335f;   /* noticeably lighter */
  --page-light-bord:#4b66a8;
}

* { box-sizing: border-box; }

body {
  margin:0;
  background:var(--bg);
  color:var(--ink);
  font-family: system-ui,-apple-system,Segoe UI,Roboto,Inter,Arial,sans-serif;
}

/* ===== Fixed header (title + actions) ===== */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;

  display:flex;
  justify-content:space-between;
  align-items:center;

  padding:16px;
  background:#0b0f18;
  border-bottom:1px solid var(--border);
}

h1 {
  margin:0;
  font-size:18px;
  line-height:1.2;
}

.header-buttons {
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

/* Push content below fixed header + full width layout */
main {
  width: 100%;
  margin: 0;
  padding:90px 20px 40px;   /* top ≈ header height */
  box-sizing: border-box;
}

/* ===== Cards / layout ===== */
.card {
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:12px;
  padding:14px;
  margin:14px 0;
  box-shadow:0 8px 24px rgba(0,0,0,.25);
  width: 100%;
  max-width: none;
}

.row { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.grow { flex:1 1 auto; }
label { font-size:13px; color:var(--muted); }

/* ===== Inputs / buttons ===== */
input[type="file"], select, input[type="number"], input[type="range"], input[type="text"] {
  background:#0e1424;
  border:1px solid var(--border);
  color:#e9edf5;
  border-radius:10px;
  padding:8px 10px;
}

input[type="checkbox"] { transform: translateY(1px); }
label.btn { display:inline-block; }

.btn {
  appearance:none;
  border:1px solid var(--border);
  background:#0f1830;
  color:#e9edf5;
  padding:9px 12px;
  border-radius:10px;
  cursor:pointer;
  font-weight:600;
}
.btn:hover { background:#0d1427; border-color:#3340a0; }
.btn[disabled] { opacity:.5; cursor:not-allowed; }
.btn.accent { background:#15265f; border-color:#3a56c4; }
.btn.danger { background:#3a1620; border-color:#7a2a3a; }

.small { font-size:12px; color:#a8b3c7; }
.pill {
  display:inline-block;
  padding:2px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  background:#0e1424;
  color:#cfe7ff;
  font-size:12px;
}

/* ===== Page preview & drawing ===== */
.page {
  background: var(--page-dark-bg);
  border: 1px solid var(--page-dark-bord);
  border-radius:12px;
  padding:12px;
  margin:12px 0;
  overflow:hidden;          /* no inner scrollbars */
}

/* Alternate light tone for even pages */
#pages > .page:nth-child(even) {
  background: var(--page-light-bg);
  border-color: var(--page-light-bord);
}

.page h3 {
  margin:0 0 8px 0;
  font-size:14px;
  color:#cdd8ff;
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
}

.wrap {
  position:relative;
  display:inline-block;
  max-width:100%;
  line-height:0;            /* remove inline gap */
}

/* Key: shrink wide pages; never upscale */
img.page-img {
  display:block;
  image-rendering:auto;
  max-width:100%;
  height:auto;
}

/* Layering: overlay above rects for drawing; JS peeks under for handle hits */
.overlay { position:absolute; inset:0; z-index: 20; cursor: crosshair; }
.rect    { position:absolute; border:2px solid var(--rect); background:rgba(255,211,77,0.08); z-index: 10; }
.rect.selected {
  border-color: var(--sel);
  box-shadow: 0 0 0 2px rgba(0,224,198,.25);
}

/* Inline label for each rect */
.rect-label{
  position:absolute;
  padding:2px 6px; font-size:12px; line-height:1.2;
  border-radius:6px;
  background:#0e1424cc; color:#e9edf5;
  border:1px solid #1f2a44;
  z-index:14;               /* above rect, below overlay */
  pointer-events:none;      /* don’t block drawing */
  white-space:nowrap; max-width:240px; text-overflow:ellipsis; overflow:hidden;
}

/* Resize handles */
.handle {
  position:absolute;
  width:10px; height:10px;
  background:var(--sel);
  border-radius:2px;
  border:1px solid #003f3a;
  z-index: 15;               /* visual above rect; overlay still on top for events */
  pointer-events: auto;      /* must be hit-detectable when we peek under overlay */
}
.handle:hover { transform: scale(1.05); }

.handle[data-handle="nw"], .handle[data-handle="se"] { cursor: nwse-resize; }
.handle[data-handle="ne"], .handle[data-handle="sw"] { cursor: nesw-resize; }
.handle[data-handle="n"],  .handle[data-handle="s"]  { cursor: ns-resize; }
.handle[data-handle="e"],  .handle[data-handle="w"]  { cursor: ew-resize; }

/* ===== Chips (area list) ===== */
.chip {
  display:inline-flex; align-items:center; gap:6px;
  padding:3px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  background:#0e1424;
  color:#cfe7ff;
  font-size:12px;
  margin:2px;
  cursor:pointer;
}
.chip.active { outline:2px solid #00bfa5; }

/* Delete button inside chip: SVG trash icon */
.chip .x {
  display:inline-flex; align-items:center; justify-content:center;
  padding:0; margin-left:4px; background:transparent; border:0;
  color: var(--warn); cursor:pointer; line-height:0;
}
.chip .x:hover { filter: brightness(1.1); }
.chip .x svg { width:14px; height:14px; stroke: currentColor; fill: none; stroke-width: 2; }

.namebar { display:flex; gap:8px; align-items:center; margin-top:6px; }

.folderbar {
  display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-top:8px;
}

.flag {
  padding:2px 6px;
  border-radius:6px;
  border:1px solid var(--border);
  background:#0e1424;
}

/* ===== Responsive niceties ===== */
@media (max-width: 720px) {
  .header-buttons { width:100%; justify-content:flex-start; }
  main { padding-top:140px; } /* more space if header wraps */
}

/* Optional: hide the size pill next to "Page N" */
.page h3 .pill { display: none !important; }

/* Spacing for file info line */
#fileInfo:not(:empty) { margin-top: 10px; }
