* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #FAF8F3;
  --canvas-bg: #E8E1D1;
  --surface: #FFFFFF;
  --surface-2: #F4F1EA;
  --border: rgba(31, 27, 22, 0.10);
  --border-strong: rgba(31, 27, 22, 0.22);
  --text: #1F1B16;
  --text-2: #6B6358;
  --text-3: #9A9286;
  --accent: #5A6B3E;
  --accent-soft: rgba(90, 107, 62, 0.12);
  --primary: #B14A2A;
  --primary-hover: #9A3F22;
  --danger: #B14A2A;
  --highlight: #F7D94A;
  --radius: 6px;
  --radius-lg: 10px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --serif: 'Instrument Serif', Georgia, serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-rows: 56px 1fr 32px;
  height: 100vh;
}

/* ============ Topbar ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: 0.2px;
  line-height: 1;
  padding-right: 14px;
  border-right: 1px solid var(--border);
  height: 28px;
  display: flex;
  align-items: center;
  color: var(--text);
}
.brand .dot { color: var(--primary); }

.tool-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.tool-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s, color 0.12s;
}
.tool-btn:hover { color: var(--text); background: rgba(0,0,0,0.04); }
.tool-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.tool-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.6; }

.spacer { flex: 1; }

.btn {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.12s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.7; }

/* ============ Workspace ============ */
.workspace {
  display: grid;
  grid-template-columns: 180px 1fr;
  overflow: hidden;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 8px;
}
.sidebar-header {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  padding: 6px 8px 12px;
}
.thumb {
  position: relative;
  margin-bottom: 8px;
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  background: white;
  border: 2px solid transparent;
  transition: border-color 0.12s;
}
.thumb:hover { border-color: var(--border-strong); }
.thumb.active { border-color: var(--accent); }
.thumb.dragging { opacity: 0.4; }
.thumb.drop-target { border-color: var(--primary); border-style: dashed; }
.thumb canvas {
  display: block;
  width: 100%;
  height: auto;
}
.thumb-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(31, 27, 22, 0.78);
  color: white;
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
}
.thumb-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: none;
  gap: 2px;
}
.thumb:hover .thumb-actions { display: flex; }
.thumb-action {
  background: rgba(31, 27, 22, 0.85);
  border: none;
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb-action:hover { background: var(--primary); }
.thumb-action svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ============ Canvas area ============ */
.canvas-area {
  position: relative;
  background: var(--canvas-bg);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.07) 1px, transparent 0);
  background-size: 16px 16px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px;
}
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-2);
  padding: 60px 40px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.4);
  max-width: 460px;
}
.empty-state.dragover {
  background: rgba(90, 107, 62, 0.08);
  border-color: var(--accent);
}
.empty-state h2 {
  font-family: var(--serif);
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--text);
  font-weight: normal;
}
.empty-state p { margin-bottom: 20px; line-height: 1.6; }
.empty-state .hint {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  margin-top: 16px;
}

/* autosave restore prompt — editor empty state */
.restore-prompt {
  margin-top: 18px;
  padding: 13px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 420px;
}
.restore-text { font-size: 13px; color: var(--text-2); line-height: 1.5; }
.restore-actions { display: flex; gap: 8px; }

/* autosave restore banner — Design Studio */
.ds-restore-banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
}
.ds-restore-actions { display: flex; gap: 6px; }
.ds-restore-banner button {
  padding: 5px 11px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}
.ds-restore-banner button:hover { background: rgba(255, 255, 255, 0.22); }

.page-wrap {
  position: relative;
  box-shadow: 0 4px 24px rgba(31, 27, 22, 0.12), 0 1px 3px rgba(31, 27, 22, 0.08);
  background: white;
}
.page-wrap canvas {
  display: block;
}
#pdfCanvas { position: relative; z-index: 1; }
#overlayCanvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  cursor: crosshair;
}
#overlayCanvas.select-mode { cursor: default; }
#overlayCanvas.text-mode { cursor: text; }

.text-input-floater {
  position: absolute;
  z-index: 5;
  background: white;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 16px;
  font-family: var(--sans);
  color: var(--text);
  outline: none;
  min-width: 140px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ============ Statusbar ============ */
.statusbar {
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
}
.status-item { display: inline-flex; align-items: center; gap: 6px; }
.status-item .label { color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }
.nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.nav-btn svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ============ Toast ============ */
.toast-container {
  position: fixed;
  bottom: 48px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text);
  color: white;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  animation: slidein 0.2s ease-out;
  max-width: 320px;
}
.toast.error { background: #8B2E1A; }
.toast.success { background: var(--accent); }
@keyframes slidein {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.28); }

.divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}

/* Color picker for highlight */
.color-picker {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: var(--text); }

.font-picker {
  padding: 6px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
  max-width: 210px;
}
.font-picker:hover { background: var(--surface-2); }
.font-picker:focus { outline: none; border-color: var(--accent); }

/* ============ Views / routing ============ */
.view { display: none; }
.view.active { display: block; }
#view-home.active,
#view-task.active { height: 100vh; overflow-y: auto; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.7; }

a.btn { text-decoration: none; }

/* ============ Home screen ============ */
.home-scroll {
  max-width: 1080px;
  margin: 0 auto;
  padding: 44px 32px 88px;
}
.home-hero { margin-bottom: 14px; }
.home-hero .brand {
  font-family: var(--serif);
  font-size: 22px;
  border: none;
  padding: 0;
  height: auto;
  margin-bottom: 22px;
}
.home-hero h1 {
  font-family: var(--serif);
  font-size: 46px;
  font-weight: normal;
  line-height: 1.1;
  letter-spacing: 0.3px;
  margin-bottom: 10px;
}
.home-hero p {
  color: var(--text-2);
  font-size: 15px;
  max-width: 560px;
}
.tool-section { margin-top: 38px; }
.tool-section h2 {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-3);
  margin-bottom: 14px;
}
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}
.tool-tile {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.14s, box-shadow 0.14s, transform 0.14s;
}
.tool-tile:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 20px rgba(31, 27, 22, 0.09);
  transform: translateY(-2px);
}
.tool-tile-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool-tile-icon svg {
  width: 21px;
  height: 21px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool-tile-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tool-tile-name { font-weight: 600; font-size: 14.5px; }
.tool-tile-desc { color: var(--text-2); font-size: 12.5px; line-height: 1.5; }
.upcoming-list { display: flex; flex-wrap: wrap; gap: 8px; }
.upcoming-chip {
  padding: 6px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-3);
  font-size: 12px;
}

/* ============ Task panel ============ */
.task-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.task-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.task-back:hover { background: var(--surface-2); color: var(--text); }
.task-back svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }
.task-heading { display: flex; flex-direction: column; }
.task-title { font-family: var(--serif); font-size: 19px; line-height: 1.15; }
.task-blurb { font-size: 12px; color: var(--text-3); }
.task-scroll { padding: 32px 24px 80px; }

.task-card {
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
}
.task-card.task-split {
  max-width: 940px;
  display: flex;
  gap: 28px;
}
.task-split .task-form { flex: 0 0 322px; }
.task-split .task-preview { flex: 1; min-width: 0; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 56px 24px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: center;
  transition: background 0.12s, border-color 0.12s;
}
.dropzone:hover,
.dropzone.dragover {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.dropzone-icon {
  width: 38px; height: 38px;
  stroke: var(--text-3); fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
.dropzone-text { color: var(--text-2); font-size: 14px; }

.task-fileinfo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.task-fileinfo svg { width: 18px; height: 18px; stroke: var(--text-2); fill: none; stroke-width: 1.6; flex-shrink: 0; }
.task-filename { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.task-filemeta { color: var(--text-3); font-size: 12px; white-space: nowrap; }
.task-change {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--sans);
  flex-shrink: 0;
}
.task-change:hover { background: var(--surface); color: var(--text); }

.task-filelist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.task-filerow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius);
}
.task-filerow-n {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  min-width: 14px;
}
.task-filebtn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  width: 24px;
  height: 24px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}
.task-filebtn:hover { background: var(--surface); color: var(--text); }
.task-addmore {
  display: inline-block;
  padding: 7px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 20px;
}
.task-addmore:hover { background: var(--surface-2); color: var(--text); }

.task-fields { display: flex; flex-direction: column; gap: 16px; }
.task-field { display: flex; flex-direction: column; gap: 6px; }
.task-field[hidden] { display: none; }
.task-field-label { font-size: 13px; font-weight: 500; color: var(--text); }
.task-field-hint { font-size: 11.5px; color: var(--text-3); }
.task-fieldgroup {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.task-file {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  max-width: 100%;
}
.task-file-btn {
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 12px;
  white-space: nowrap;
}
.task-file:hover .task-file-btn { background: var(--surface); }
.task-file-name {
  font-size: 12px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-field input[type="text"],
.task-field input[type="password"],
.task-field input[type="number"],
.task-field select,
.task-field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
}
.task-field textarea { resize: vertical; min-height: 64px; }
.task-field input:focus,
.task-field select:focus,
.task-field textarea:focus { outline: none; border-color: var(--accent); }
.task-field input[type="color"] {
  width: 48px; height: 32px;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
}
.task-range { display: flex; align-items: center; gap: 12px; }
.task-range input[type="range"] { flex: 1; accent-color: var(--accent); }
.task-range output {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
  min-width: 52px;
  text-align: right;
}
.task-check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 13px; }
.task-check input { margin-top: 2px; accent-color: var(--accent); }

.task-run { width: 100%; justify-content: center; margin-top: 22px; padding: 10px; }
.task-note { color: var(--text-3); font-size: 13px; }
.task-error {
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(177, 74, 42, 0.10);
  border: 1px solid rgba(177, 74, 42, 0.30);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 13px;
}

.task-preview-inner {
  background: var(--canvas-bg);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
}
.task-preview-inner canvas {
  max-width: 100%;
  height: auto;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

/* auto-redact interactive preview */
.redact-preview { display: flex; flex-direction: column; gap: 9px; width: 100%; }
.redact-nav { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.redact-navbtn {
  width: 26px; height: 26px; padding: 0;
  border: 1px solid var(--border-strong); border-radius: 5px;
  background: var(--surface); cursor: pointer; line-height: 1;
}
.redact-pageinfo { font-family: var(--mono); font-size: 11px; }
.redact-count { margin-left: auto; color: var(--text-2); }
.redact-stage { position: relative; align-self: center; line-height: 0; }
.redact-stage canvas { max-width: 100%; height: auto; box-shadow: none; }
.redact-stage .redact-base { display: block; box-shadow: 0 2px 12px rgba(31, 27, 22, 0.16); }
.redact-stage .redact-overlay { position: absolute; inset: 0; cursor: crosshair; }
.redact-hint { font-size: 11px; color: var(--text-3); text-align: center; }

/* read-aloud popover */
.ra-popover {
  position: fixed;
  z-index: 60;
  width: 256px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 8px 26px rgba(31, 27, 22, 0.20);
}
.ra-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
}
.ra-voice {
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
}
.ra-controls { display: flex; gap: 6px; }
.ra-btn {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.ra-btn:disabled { opacity: 0.45; cursor: default; }
.ra-play { background: var(--accent); color: #fff; border-color: var(--accent); }

.task-result { text-align: center; }
.task-result-icon {
  width: 46px; height: 46px;
  stroke: var(--accent); fill: none;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
  margin-bottom: 8px;
}
.task-result-title { font-family: var(--serif); font-size: 24px; }
.task-result-name {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  margin: 6px 0 20px;
  word-break: break-all;
}
.task-result-actions { display: flex; gap: 10px; justify-content: center; }

/* ============ Signature modal ============ */
.sig-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(31, 27, 22, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
.sig-modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: 560px;
  max-width: calc(100vw - 40px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.sig-head { font-family: var(--serif); font-size: 22px; margin-bottom: 14px; }
.sig-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 16px;
  width: fit-content;
}
.sig-tab {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 16px;
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-2);
}
.sig-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.sig-body { margin-bottom: 18px; }
.sig-pane[hidden] { display: none; }
.sig-pad {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: crosshair;
  touch-action: none;
}
.sig-clear {
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
}
.sig-clear:hover { background: var(--surface-2); color: var(--text); }
.sig-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-2);
  font-size: 14px;
  text-align: center;
}
.sig-upload:hover { background: var(--accent-soft); border-color: var(--accent); }
.sig-type-input {
  width: 100%;
  padding: 18px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 42px;
  text-align: center;
  color: #15233B;
  background: #fff;
  outline: none;
}
.sig-type-input:focus { border-color: var(--accent); }
.sig-fonts { display: flex; gap: 8px; margin-top: 10px; }
.sig-font {
  flex: 1;
  padding: 12px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-size: 22px;
  color: var(--text-2);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.sig-font:hover { color: var(--text); }
.sig-font.active { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.sig-foot { display: flex; justify-content: flex-end; gap: 10px; }

/* ============ Design Studio ============ */
.design-app {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}
.ds-size-pick { display: flex; align-items: center; gap: 8px; }
.ds-size-pick span {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
}
.ds-size-pick select,
.ds-field select,
.ds-field input[type="number"] {
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
}
.ds-export-wrap { position: relative; }
.ds-export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 168px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(31, 27, 22, 0.18);
  z-index: 60;
}
.ds-export-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
}
.ds-export-menu button:hover { background: var(--accent-soft); color: var(--accent); }

.design-workspace {
  display: grid;
  grid-template-columns: 250px 1fr 270px;
  overflow: hidden;
}
.design-left, .design-right {
  background: var(--surface);
  overflow-y: auto;
}
.design-left { border-right: 1px solid var(--border); }
.design-right { border-left: 1px solid var(--border); }

.design-center {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.design-canvas-area {
  flex: 1;
  min-height: 0;
  background: var(--canvas-bg);
  background-image: radial-gradient(circle at 1px 1px, rgba(0,0,0,0.07) 1px, transparent 0);
  background-size: 16px 16px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px;
}
/* multi-page navigation strip below the canvas */
.design-pagebar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.ds-page-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.ds-page-chip {
  min-width: 30px;
  height: 28px;
  padding: 0 7px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
}
.ds-page-chip.on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.ds-page-bar-actions { display: flex; gap: 4px; }
.design-stage {
  position: relative;
  line-height: 0;
  box-shadow: 0 6px 30px rgba(31, 27, 22, 0.18), 0 1px 3px rgba(31, 27, 22, 0.1);
  /* Checkerboard shows through a transparent ('none') background. */
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #dcd6c8 25%, transparent 25%, transparent 75%, #dcd6c8 75%, #dcd6c8),
    linear-gradient(45deg, #dcd6c8 25%, transparent 25%, transparent 75%, #dcd6c8 75%, #dcd6c8);
  background-size: 22px 22px;
  background-position: 0 0, 11px 11px;
}
#dsCanvas { display: block; }
.design-overlay {
  position: absolute;
  inset: 0;
  cursor: default;
}

/* selection frame + handles */
.ds-frame {
  position: absolute;
  border: 1.5px solid var(--accent);
  box-sizing: border-box;
  pointer-events: none;
}
/* multi-selection box — handle-less, dashed to signal "move only" */
.ds-frame-multi { border-style: dashed; }
.ds-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  box-sizing: border-box;
  pointer-events: auto;
}
.ds-h-tl { left: 0;    top: 0;    transform: translate(-50%,-50%); cursor: nwse-resize; }
.ds-h-tm { left: 50%;  top: 0;    transform: translate(-50%,-50%); cursor: ns-resize; }
.ds-h-tr { left: 100%; top: 0;    transform: translate(-50%,-50%); cursor: nesw-resize; }
.ds-h-ml { left: 0;    top: 50%;  transform: translate(-50%,-50%); cursor: ew-resize; }
.ds-h-mr { left: 100%; top: 50%;  transform: translate(-50%,-50%); cursor: ew-resize; }
.ds-h-bl { left: 0;    top: 100%; transform: translate(-50%,-50%); cursor: nesw-resize; }
.ds-h-bm { left: 50%;  top: 100%; transform: translate(-50%,-50%); cursor: ns-resize; }
.ds-h-br { left: 100%; top: 100%; transform: translate(-50%,-50%); cursor: nwse-resize; }
.ds-h-rot {
  left: 50%;
  top: 0;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border-color: var(--surface);
  transform: translate(-50%,-50%) translateY(-26px);
  cursor: grab;
}

.ds-textedit {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 1.5px dashed var(--accent);
  background: transparent;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

/* panels */
.ds-section { padding: 14px; border-bottom: 1px solid var(--border); }
.ds-section-title {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  margin-bottom: 10px;
}
.ds-hint { font-size: 12px; color: var(--text-3); line-height: 1.55; }

.ds-template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ds-template {
  display: flex;
  flex-direction: column;
  padding: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.12s;
}
.ds-template:hover { border-color: var(--accent); }
.ds-template canvas { width: 100%; height: auto; display: block; max-height: 130px; object-fit: cover; }
.ds-template span {
  padding: 5px 6px;
  font-size: 11px;
  color: var(--text-2);
  text-align: center;
  background: var(--surface);
}

.ds-add-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 11px;
  margin-bottom: 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
}
.ds-add-btn:hover { background: var(--surface-2); border-color: var(--accent); }
.ds-add-row { display: flex; gap: 6px; margin-bottom: 6px; }
.ds-add-mini {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.ds-add-mini:hover { background: var(--surface-2); border-color: var(--accent); }
.ds-add-btn svg, .ds-add-mini svg, .ds-icon-btn svg {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none; stroke-width: 1.7;
  flex-shrink: 0;
}
.ds-add-mini svg { width: 18px; height: 18px; }

.ds-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}
.ds-field > span { font-size: 12px; color: var(--text-2); }
.ds-field select, .ds-field input[type="number"] { width: 104px; }
.ds-field input[type="color"] {
  width: 44px; height: 28px;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
}
.ds-field input[type="range"] { width: 128px; accent-color: var(--accent); }

.ds-seg {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  overflow: hidden;
}
.ds-seg button {
  flex: 1;
  padding: 5px 8px;
  background: var(--surface);
  border: 0;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--text-2);
}
.ds-seg button:last-child { border-right: 0; }
.ds-seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ds-seg button i { font-style: italic; font-family: var(--serif); }

.ds-swatches { display: flex; flex-wrap: wrap; gap: 5px; margin: -2px 0 10px; }
.ds-swatch {
  width: 20px; height: 20px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
}
.ds-swatch:hover { transform: scale(1.12); }

.ds-prop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-family: var(--serif);
  font-size: 19px;
}
.ds-prop-actions { display: flex; gap: 5px; }
.ds-icon-btn {
  width: 30px; height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  color: var(--text-2);
}
.ds-icon-btn:hover { background: var(--surface-2); color: var(--text); }

.ds-btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.ds-flat-btn {
  flex: 1 0 auto;
  min-width: 62px;
  padding: 7px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--text-2);
}
.ds-flat-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--accent); }

.ds-layers { display: flex; flex-direction: column; gap: 3px; }
.ds-layer {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.ds-layer:hover { background: var(--surface-2); }
.ds-layer.on { background: var(--accent-soft); }
.ds-layer-glyph { width: 16px; text-align: center; color: var(--text-3); }
.ds-layer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Magic Resize chips */
.ds-resize-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ds-resize-chip {
  padding: 7px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 11.5px;
  color: var(--text-2);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ds-resize-chip:hover { background: var(--surface-2); color: var(--text); border-color: var(--accent); }

/* sub-heading inside a properties block (e.g. Background remover) */
.ds-sub-title {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  margin: 14px 0 8px;
}
