:root {
  --bg: #ffffff;
  --surface: #f6f8fc;
  --line: #e4e9f2;
  --text: #0f172a;
  --muted: #64748b;
  --blue: #2563eb;
  --blue-soft: #eaf1ff;
  --blue-dark: #1d4ed8;
  /* Handwriting fonts that ship with each OS; Android's "cursive" is Dancing Script. */
  --script: "Snell Roundhand", "Segoe Script", "Brush Script MT", "Dancing Script", cursive;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  height: 100dvh; /* tracks the phone's visible area as browser bars show and hide */
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

/* Header */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background:
    linear-gradient(90deg, var(--blue) 50%, #93b4f7 50%) top / 100% 50% no-repeat,
    linear-gradient(90deg, #93b4f7 50%, var(--blue) 50%) bottom / 100% 50% no-repeat;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Drawing toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.seg { display: flex; gap: 2px; }

.tool {
  display: flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tool:hover { color: var(--text); background: var(--surface); }
.tool.active { color: var(--blue); background: var(--blue-soft); }

.tool svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.swatches { display: flex; gap: 8px; padding-right: 6px; }

.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, .18);
  background: var(--c);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--blue); }

.slider {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 6px;
  color: var(--muted);
  font-size: 13px;
}

.slider input { accent-color: var(--blue); width: 120px; }
.slider output { width: 22px; color: var(--text); font-variant-numeric: tabular-nums; }

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.btn.ghost {
  background: var(--bg);
  border-color: var(--line);
  color: var(--text);
}
.btn.ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn.ghost:disabled { opacity: .45; cursor: default; border-color: var(--line); color: var(--text); }

.btn.primary {
  background: var(--blue);
  color: #fff;
}
.btn.primary:hover { background: var(--blue-dark); }

/* Main */
main {
  flex: 1;
  display: flex;
  padding: 24px;
  min-height: 0;
}

.drop {
  flex: 1;
  display: grid;
  place-items: center;
  border: 1.5px dashed #c8d4ea;
  border-radius: 16px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.drop-inner { text-align: center; }

.icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--bg);
  color: var(--blue);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 0 0 1px var(--line);
}

.title { margin: 0; font-weight: 600; font-size: 16px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.link {
  font: inherit;
  color: var(--blue);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  min-height: 0;
}

.toolbar { align-self: center; }

/* Takes whatever space is left; app.js sizes the canvas to fit inside it. */
.canvas-area {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.canvas-wrap {
  position: relative;
  line-height: 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line), 0 8px 30px rgba(15, 23, 42, .08);
}

canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.sel {
  position: absolute;
  border: 1.5px solid var(--blue);
  background: rgba(37, 99, 235, .08);
  pointer-events: none;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .7);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* Footer: page switcher + hint */
.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.page-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.page-btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.page-btn:disabled { opacity: .4; cursor: default; }

.hint { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }

/* Saved signatures in the toolbar */
.sigs { display: flex; align-items: center; gap: 8px; padding-right: 4px; }
.sig-list { display: flex; gap: 6px; }

.sig-thumb {
  position: relative;
  width: 76px;
  height: 34px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}
.sig-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sig-thumb.active { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-soft); }

.sig-del {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s;
}
.sig-thumb:hover .sig-del, .sig-thumb.active .sig-del { opacity: 1; }

.btn.small { font-size: 13px; padding: 6px 10px; }

/* Signature dialog */
.sheet {
  width: min(520px, calc(100vw - 32px));
  padding: 20px;
  border: 0;
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .25);
}
.sheet::backdrop { background: rgba(15, 23, 42, .35); }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 650; }

.tabs { padding: 3px; border-radius: 10px; background: var(--surface); }
.tabs .tool { padding: 6px 14px; }
.tabs .tool.active { background: var(--bg); box-shadow: 0 1px 2px rgba(15, 23, 42, .1); }

.pad {
  position: relative;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

#sigPad {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.pad-line {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 44px;
  border-bottom: 1.5px dashed #c8d4ea;
  pointer-events: none;
}
.pad-hint {
  position: absolute;
  left: 24px;
  bottom: 18px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}
.pad-clear { position: absolute; right: 14px; bottom: 14px; font-size: 13px; }

.type-pane { display: flex; flex-direction: column; padding: 14px; gap: 8px; }
.type-pane input {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.type-pane input:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.type-preview {
  flex: 1;
  display: grid;
  place-items: center;
  font-family: var(--script);
  font-size: 44px;
  line-height: 1.1;
  overflow: hidden;
  white-space: nowrap;
}

.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
  font-size: 14px;
}
.ink { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--blue); width: 16px; height: 16px; }

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.drop-overlay {
  position: fixed;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--blue);
  border-radius: 16px;
  background: rgba(234, 241, 255, .88);
  pointer-events: none;
  z-index: 10;
}
.drop-overlay div {
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .2);
}

@media (max-width: 640px) {
  /* One compact row on top, bigger tap targets below. */
  .bar { padding: 10px 16px; gap: 8px; flex-wrap: nowrap; }
  .brand-name, .wide-only { display: none; }
  .actions { gap: 6px; flex-wrap: nowrap; }
  .btn { font-size: 13px; padding: 7px 11px; }
  main { padding: 12px 16px 16px; }
  .stage { gap: 10px; }
  .toolbar { gap: 8px; row-gap: 6px; }
  .tool { padding: 9px 10px; }
  .tool span { display: none; }
  .divider { display: none; }
  .swatches { gap: 10px; padding: 0 4px; }
  .swatch { width: 28px; height: 28px; }
  .slider input { width: 140px; }
  .hint { font-size: 12px; }
  .footer { gap: 6px; }
  .page-btn { width: 38px; height: 38px; }
  .sig-thumb { width: 68px; height: 36px; }
  .sig-del { opacity: 1; }

  /* Signature dialog becomes a bottom sheet */
  .sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .pad { height: 200px; }
  .sheet-actions .btn { flex: 1; padding: 11px; }
}
