* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Body', Georgia, 'Times New Roman', serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--paper);
}
.muted { color: var(--chalk); }
.hidden { display: none !important; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 8px 14px;
  background: var(--mat);
  color: var(--paper);
  position: sticky;
  top: 0;
  z-index: 10;
}
.bar-left span { margin-left: 8px; }
.pager { display: flex; align-items: center; gap: 10px; }
.bar-left, .bar-right, .pager { flex-wrap: wrap; }
.bar-left .book-estimate { font-size: 13px; }
#jobLabel, .bar-left .book-estimate { color: var(--chalk-light); }
@media (max-width: 720px) {
  .bar-left #jobLabel, .bar-left .book-estimate { display: none; }
}
.inspector .fuzzy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
}
.inspector .fuzzy input[type="range"] { width: 100%; }
.inspector .fuzzy #gapBridgeValue {
  color: #b23;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.bar-right { display: flex; align-items: center; gap: 8px; }
.auth-strip { display: flex; align-items: center; gap: 8px; margin-left: 10px; font-size: 13px; }

button, .btn {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid #3a3b45;
  border-radius: 6px;
  background: #34353f;
  color: #fff;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { background: #40414d; }
button.primary { background: #2873d6; border-color: #2873d6; }
button.danger { background: #b23; border-color: #b23; width: 100%; }
button.active { outline: 2px solid #ffd24d; }
.btn.ghost { background: #fff; color: #2873d6; border-color: #2873d6; }
.btn.ghost:hover { background: #eef5ff; }
/* brand.css's outlined nav button, same as the landing/homepage header — restates it
   here since it loads after brand.css and the generic `.btn` rule above would
   otherwise win the cascade and flatten it to this toolbar's plain grey chrome. */
.btn-ghost-light { background: transparent; color: var(--paper); border: 2px solid var(--paper); }
.btn-ghost-light:hover { background: var(--paper); color: var(--mat); }

main {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 14px;
  padding: 14px;
  align-items: start;
}
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; padding: 10px; }
}
.stage {
  position: relative;
  line-height: 0;
  background:
    repeating-conic-gradient(#e8e8ec 0% 25%, #fff 0% 50%) 50% / 20px 20px;
  border: 1px solid #ddd;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.stage img { width: 100%; display: block; user-select: none; }
#silhouettes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.boxes { position: absolute; inset: 0; }

.region {
  --piece-tint: #2873d6;
  --tint: var(--piece-tint);
  position: absolute;
  border: 2px solid var(--tint);
  background: color-mix(in srgb, var(--tint) 22%, transparent);
  cursor: move;
}
.region .label {
  position: absolute;
  top: -20px;
  left: -2px;
  font-size: 11px;
  line-height: 16px;
  padding: 0 5px;
  white-space: nowrap;
  background: color-mix(in srgb, var(--tint), black 62%); /* white text stays >= 4.5:1 on light tints */
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,.45);
  border-radius: 3px 3px 0 0;
}
.region .label { cursor: pointer; }
.region .label:hover {
  background: #ffb100;
  color: #222;
  text-shadow: none;
}
/* Unnamed pieces: the chip is the call to action — make it read as a button. */
.region .label.unnamed {
  background: #ffb100;
  color: #222;
  text-shadow: none;
  font-weight: 600;
  border: 1px dashed #7a5200;
}
.region.selected { outline: 2px solid #ffb100; outline-offset: 1px; z-index: 2; }
.region.selected .label { background: #ffb100; color: #222; }
.region.wrong { --tint: #d33; border-style: dashed; }
.region.preview-only { border-style: dotted; }
.region.correct { --tint: #1a9e4b; }
.region.gap { --tint: #888; border-style: dotted; }
.region.negative {
  --tint: #d33;
  border-style: dashed;
  background: repeating-linear-gradient(
    45deg,
    color-mix(in srgb, var(--tint) 26%, transparent) 0,
    color-mix(in srgb, var(--tint) 26%, transparent) 6px,
    color-mix(in srgb, var(--tint) 12%, transparent) 6px,
    color-mix(in srgb, var(--tint) 12%, transparent) 12px
  );
}
.region.negative .label::before { content: "✕ "; }
.region.hole { --tint: #2c6fbb; border-style: dashed; background: color-mix(in srgb, var(--tint) 10%, transparent); }
.region.hole .label::before { content: "◯ "; }

/* First-use tool popovers (+ Add box / + Negative) */
.tool-popover {
  position: fixed;
  z-index: 50;
  max-width: 300px;
  background: #fff;
  border: 1px solid #c9c9d0;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  padding: 12px;
  font-size: 13px;
  line-height: 1.45;
}
.tool-popover .pop-ok { display: block; margin-top: 10px; }
.hint-chip {
  background: #ffb100;
  color: #222;
  border-radius: 3px;
  padding: 0 4px;
  font-size: 11px;
  white-space: nowrap;
}

/* Negative-region inspector: hide piece-editing controls, show the negative badge */
.inspector .negative-badge { display: none; margin: 0 0 6px; font-weight: 600; color: #b3261e; }
.inspector.negative .negative-badge { display: block; }
.inspector.negative .piece-only { display: none; }
.inspector .hole-badge { display: none; margin: 0 0 6px; font-weight: 600; color: #2c6fbb; }
.inspector.hole .hole-badge { display: block; }
.inspector.hole .piece-only { display: none; }

.handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid #ffb100;
  border-radius: 50%;
}
.handle.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.handle.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.handle.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.handle.se { right: -7px; bottom: -7px; cursor: nwse-resize; }

.stage.adding { cursor: crosshair; }

.inline-editor {
  position: absolute;
  z-index: 20;
  display: flex;
  gap: 5px;
  padding: 5px;
  background: #fff;
  border: 1px solid #ffb100;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
  line-height: normal;
}
.inline-editor input, .inline-editor select {
  font: 13px system-ui, sans-serif;
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.inline-editor .ie-name { width: 150px; }

.panel {
  position: sticky;
  top: 62px;
  background: #fff;
  border: 1px solid #e2e2e6;
  border-radius: 8px;
  padding: 12px;
}
.inspector label { display: block; margin-bottom: 10px; }
.inspector input {
  width: 100%;
  padding: 6px 8px;
  font: inherit;
  border: 1px solid #ccc;
  border-radius: 5px;
  margin-top: 3px;
}
.inspector select,
.inspector textarea {
  display: block;
  width: 100%;
  padding: 6px 8px;
  font: inherit;
  border: 1px solid #ccc;
  border-radius: 5px;
  margin-top: 3px;
  background: #fff;
}
.inspector textarea { resize: vertical; min-height: 2.6em; }
/* "Preview only": a normal checkbox beside its label, not a full-width text field. */
.inspector label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.inspector label.check input[type="checkbox"] {
  width: 16px; height: 16px; margin: 0; padding: 0; flex: none; accent-color: var(--thread, #e2536a);
}
.inspector .note-count { float: right; font-size: 11px; }
.tags { display: flex; gap: 6px; margin-bottom: 10px; }
.tags button { flex: 1; }
#recolorAll { width: 100%; margin-bottom: 10px; font-size: 12px; }
.status { min-height: 18px; }
.status.ok { color: #168640; }
.status.err { color: #b3261e; }
.hint { margin-top: 12px; font-size: 12px; }

/* busy overlay while a re-cut is running (single long request, no % available) */
.busy {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 25, 0.55);
}
.busy-box {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  color: #222;
  padding: 18px 24px;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  font-size: 15px;
  max-width: 80vw;
}
.spinner { width: 26px; height: 26px; }
button:disabled, .btn.disabled { opacity: 0.55; cursor: default; pointer-events: none; }

/* The Jobs button looks the same as on the homepage header (brand.css .btn-thread) on
   every screen; restated because this toolbar's generic button rule loads later. */
.bar-right .btn-thread {
  font-family: 'Heading', sans-serif; font-stretch: 80%; font-size: 13px; letter-spacing: 0.06em;
  text-transform: uppercase; background: var(--thread); color: var(--paper);
  border: 1px solid var(--thread);
}
.bar-right .btn-thread:hover { background: var(--thread-deep); border-color: var(--thread-deep); }

/* Join pages dialog */
dialog#join-dialog { border: none; border-radius: 10px; padding: 0; width: min(1000px, 96vw); max-height: 94vh; color: #1a1a1a; }
dialog#join-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.join-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; max-height: 94vh; box-sizing: border-box; }
.join-body h3 { margin: 0; }
.join-body p { margin: 0; line-height: 1.45; }
.join-pages { display: flex; flex-wrap: wrap; gap: 8px; }
.join-pages label { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; cursor: pointer; border: 2px solid transparent; border-radius: 6px; padding: 3px; }
.join-pages label.on { border-color: #2c6fbb; }
.join-pages img { height: 70px; border: 1px solid #ccc; background: #fff; }
.join-pages .order { font-weight: 700; color: #2c6fbb; min-height: 1em; }
.join-controls { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; font-size: 14px; }
.join-stage { overflow: auto; border: 1px solid #ccc; background: #eee; min-height: 200px; max-height: 58vh; }
.join-stage canvas { display: block; cursor: grab; }
.join-stage canvas:focus-visible { outline: 3px solid #2c6fbb; }
.join-actions { display: flex; justify-content: flex-end; gap: 8px; }
