/* EasyPen - mobile-first, RTL */

:root {
  --primary: #2f4fc4;
  --primary-dark: #243a9e;
  --secondary: #1e1b6b;
  --primary-soft: #e8ecfb;
  --bg: #f4f5fa;
  --surface: #ffffff;
  --text: #1c2033;
  --muted: #5d6378;
  --border: #dfe3f0;
  --danger: #d6385a;
  --success: #177a52;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(30, 27, 107, 0.12);
  --bar-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans Hebrew", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

h1, h2 {
  margin: 0 0 .25em;
  line-height: 1.25;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

img { max-width: 100%; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--secondary);
  outline-offset: 2px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 44px;
  padding: .6rem 1.1rem;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s, transform .1s, box-shadow .15s;
}

.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: 0 4px 14px rgba(47, 79, 196, .35);
}

.btn-secondary {
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.btn-ghost {
  color: var(--primary-dark);
  background: transparent;
}

.btn-danger {
  color: #fff;
  background: var(--danger);
}

.danger-text { color: var(--danger); }

.btn-sm { min-height: 44px; padding: .35rem .8rem; font-size: .9rem; }
.btn-xl { min-height: 64px; padding: 1rem 1.5rem; font-size: 1.25rem; border-radius: 16px; }
.btn-block { display: flex; width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 .5rem;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.icon-btn:active { background: rgba(0, 0, 0, .06); }

/* ---------- Header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 56px;
  padding: .5rem 1rem;
  padding-top: calc(.5rem + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary-dark);
}

/* Header buttons: install + language */
.header-actions { display: flex; align-items: center; gap: .25rem; }

/* The language button: only a globe; a see-through native <select> covers it, so a tap
   opens the phone's own list of the three languages */
.lang-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: var(--primary-dark);
}
.lang-picker:active { background: rgba(0, 0, 0, .06); }
.lang-picker:focus-within { outline: 3px solid var(--primary); outline-offset: 2px; }
.lang-picker svg { pointer-events: none; }
.lang-picker select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
}

/* ---------- Home ---------- */

.home-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem 1rem 0;
}

.upload-card,
.signatures-section {
  padding: 1.25rem;
  margin-bottom: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.upload-card { text-align: center; }
.upload-card p { margin: 0 0 1rem; }

.upload-btn {
  position: relative;
  width: 100%;
  margin-bottom: .5rem;
}

.upload-btn.is-busy { opacity: .6; pointer-events: none; }
.upload-status:empty { display: none; }

.upload-btn:focus-within {
  outline: 3px solid var(--secondary);
  outline-offset: 3px;
}

.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  margin: .75rem 0 0 !important;
  font-size: .85rem;
  color: var(--success);
}

.form-error {
  min-height: 1.5em;
  margin: .25rem 0;
  color: var(--danger);
  font-weight: 600;
}

.form-error:empty { min-height: 0; margin: 0; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: .75rem;
}

.sig-list {
  display: grid;
  gap: .75rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.sig-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.sig-card img {
  width: 55%;
  height: 64px;
  object-fit: contain;
}

.sig-card-actions {
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.empty-state {
  margin: 0 0 1rem;
  text-align: center;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  inset-inline: 1rem;
  bottom: calc(var(--bar-h) + 1rem + var(--safe-bottom));
  z-index: 100;
  max-width: 480px;
  margin: 0 auto;
  padding: .75rem 1rem;
  border-radius: 12px;
  background: #1f2440;
  color: #fff;
  text-align: center;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: var(--pin-bottom,) translateY(12px);
  transform-origin: 50% calc(100% + var(--bar-h) + 1rem + var(--safe-bottom));
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.home .toast { bottom: calc(1rem + var(--safe-bottom)); }
.draw-mode .toast {
  bottom: calc(var(--tray-h) + 1rem + var(--safe-bottom));
  transform-origin: 50% calc(100% + var(--tray-h) + 1rem + var(--safe-bottom));
}
.toast.show { opacity: 1; transform: var(--pin-bottom,); }
.toast[data-type="error"] { background: var(--danger); }
.toast[data-type="success"] { background: var(--success); }

/* ---------- Modals (native <dialog>) ---------- */

.modal {
  width: min(100% - 1.5rem, 520px);
  max-height: calc(100% - 1.5rem);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(15, 18, 50, .3);
}

.modal::backdrop { background: rgba(17, 20, 45, .55); }

/* Bottom sheet style on phones */
.modal.sheet {
  margin-bottom: 0;
  width: 100%;
  max-width: 560px;
  border-radius: 18px 18px 0 0;
  padding-bottom: var(--safe-bottom);
}

.modal-card { padding: 1rem 1.1rem 1.1rem; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}

.modal-header h2 { margin: 0; }
.modal-hint { margin: 0 0 .5rem; font-size: .9rem; color: var(--muted); }

.modal-actions {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
}

.modal-actions .btn { flex: 1; }

/* File name before saving */
.name-field {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}
.name-field:focus-within { outline: 2px solid var(--primary); outline-offset: 1px; }
.name-field input {
  flex: 1;
  min-width: 0;
  padding: .7rem .8rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* no zoom-in on iPhone */
  outline: none;
}
.name-ext { padding-inline-end: .8rem; color: var(--muted); }
/* "Add a link to EasyPen" under the file name */
.check-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 44px;
  margin-top: .4rem;
  font-size: .95rem;
  cursor: pointer;
}
.check-row input { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); flex-shrink: 0; }

/* Home: "tell a friend" */
.share-app { text-align: center; }
.share-app p { margin: 0 0 .3rem; }
.share-app-btn { gap: .45rem; }
.field-error { margin: .4rem 0 0; min-height: 1.2em; color: var(--danger); font-size: .9rem; font-weight: 700; }
.field-error:empty { min-height: 0; }
#password-dialog .modal-hint:last-of-type { margin-top: .6rem; }

/* Signature drawing */
.sig-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  max-height: 45vh;
  border: 2px dashed #c3cbef;
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.sig-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.sig-baseline {
  position: absolute;
  inset-inline: 8%;
  bottom: 25%;
  border-bottom: 1px solid #d6dcf2;
  pointer-events: none;
}

.sig-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .25rem .5rem;
  margin-top: .5rem;
}

.sample-btn { display: inline-flex; align-items: center; gap: .3rem; }

.ink-colors { display: flex; gap: .75rem; }

.ink {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-height: 44px;
  cursor: pointer;
}

.ink input { position: absolute; opacity: 0; }

.ink-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px var(--border);
}

.ink-black { background: #111827; }
.ink-blue { background: #1e3a8a; }
.ink-sampled .ink-dot { background: var(--c, #000); }
.ink input:checked + .ink-dot { border-color: #fff; box-shadow: 0 0 0 2px var(--primary); }
.ink input:focus-visible + .ink-dot { outline: 3px solid var(--secondary); outline-offset: 2px; }

.check {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}

.check input { width: 20px; height: 20px; accent-color: var(--primary); }

/* Signature picker */
.sig-choices {
  display: grid;
  gap: .6rem;
  margin: 0 0 .75rem;
  padding: 0;
  list-style: none;
}

.sig-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 84px;
  padding: .5rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
}

.sig-choice:active,
.sig-choice:hover { border-color: var(--primary); }
.sig-choice img { max-height: 100%; object-fit: contain; }

/* ---------- Viewer ---------- */

/* The editor zooms its pages itself (see pinch zoom in viewer.js): browser zoom would move
   the fixed bars along with the page */
html:has(> body.viewer),
.viewer {
  touch-action: pan-x pan-y;
}

.viewer {
  --tray-h: 244px;   /* height of the drawing tray */
  padding-bottom: calc(var(--bar-h) + var(--safe-bottom));
  background: #e6e9f2;
}

.viewer-header { justify-content: flex-start; }

/* The back arrow points to the start side */
[dir="ltr"] #back-btn svg,
[dir="ltr"] #draw-undo svg,
[dir="ltr"] #undo-btn svg,
[dir="ltr"] #draw-redo svg,
[dir="ltr"] #redo-btn svg { transform: scaleX(-1); }

/* Undo: at the end of the header, next to the title */
.undo-btn {
  flex-shrink: 0;
  gap: .3rem;
  margin-inline-start: auto;
}
/* Redo sits right after undo */
.redo-btn { margin-inline-start: 0; }
.sample-mode .undo-btn { visibility: hidden; }

/* Headers stay at the top of the visible screen while pinch-zoomed (see pinBars in viewer.js) */
.viewer .app-header {
  transform: var(--pin-top,);
  transform-origin: 50% 0;
}

.doc-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.doc-title #doc-name {
  overflow: hidden;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: calc(100% * var(--zoom, 1));
  padding: 12px 8px 24px;
}

.page {
  position: relative;
  width: 100%;
  max-width: calc(900px * var(--zoom, 1));
  background: #fff;
  box-shadow: 0 2px 10px rgba(20, 25, 70, .15);
}

.page.has-dragging { z-index: 2; }

.page canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.page:not(.is-rendered)::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #f1f3f9, #fbfbfe, #f1f3f9);
}

.overlay-layer {
  position: absolute;
  inset: 0;
  direction: ltr;   /* overlay coordinates are physical (left/top) */
}

.text-mode .overlay-layer {
  cursor: text;
  outline: 2px dashed rgba(47, 79, 196, .5);
  outline-offset: -2px;
}

/* Overlay items */
.ov {
  position: absolute;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.ov.is-selected { outline: 2px dashed var(--primary); outline-offset: 2px; }
.ov.is-dragging { cursor: grabbing; opacity: .9; }

.ov-sig img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ov-resize {
  position: absolute;
  bottom: -14px;
  inset-inline-end: -14px;   /* bottom-left in Hebrew */
  display: none;
  width: 28px;
  height: 28px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: nesw-resize;
}

[dir="ltr"] .ov-resize { cursor: nwse-resize; }

/* Bigger invisible touch target around the handle */
.ov-resize::after {
  content: "";
  position: absolute;
  inset: -10px;
}

.ov.is-selected .ov-resize { display: block; }

.ov-text {
  font-family: Arial, Helvetica, "Noto Sans Hebrew", sans-serif;
  font-size: calc(var(--fs, 14) * var(--pt, 1) * 1px);
  line-height: 1.3;
  color: #111827;
}

.ov-text-content {
  min-width: 1.5em;
  min-height: 1.3em;
  padding: .15em .3em;
  white-space: pre;
  outline: none;
}

.ov-text.is-editing {
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  background: rgba(47, 79, 196, .08);
}

.ov-text.is-editing .ov-text-content { user-select: text; -webkit-user-select: text; }

.ov-move {
  position: absolute;
  top: -30px;
  inset-inline-start: -4px;
  display: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  line-height: 28px;
  text-align: center;
  cursor: move;
}

.ov-text.is-selected .ov-move { display: block; }

/* Status / loading */
.status-screen {
  position: fixed;
  inset: 56px 0 calc(var(--bar-h) + var(--safe-bottom));
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
  background: var(--bg);
}

.status-screen.is-error .spinner { display: none; }
.status-screen.is-error p { color: var(--danger); font-weight: 700; }

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.busy {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(255, 255, 255, .85);
  font-weight: 700;
}

/* Contextual bars above the bottom bar */
.mode-hint,
.item-toolbar {
  position: fixed;
  inset-inline: .5rem;
  bottom: calc(var(--bar-h) + .5rem + var(--safe-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  max-width: 560px;
  margin: 0 auto;
  padding: .4rem .6rem;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: var(--pin-bottom,);
  transform-origin: 50% calc(100% + var(--bar-h) + .5rem + var(--safe-bottom));
}

.mode-hint { background: var(--primary-soft); font-weight: 600; }

.text-tools {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-inline-end: auto;
}

.font-size { min-width: 3.2em; text-align: center; font-weight: 700; }

/* Signature size slider (like the drawing width) */
.item-toolbar .sig-size { flex: 1; min-width: 0; gap: 8px; }

/* Picking a colour from the document: tap on the page, nothing else reacts */
.sample-mode .pages { cursor: crosshair; }
/* One finger picks (no scrolling); two fingers zoom and scroll (pinch zoom in viewer.js) */
.sample-mode .page { touch-action: none; }
.sample-mode .overlay-layer,
.sample-mode .overlay-layer *,
.sample-mode .page-moves { pointer-events: none; }
.sample-mode .bottom-bar { display: none; }
.sample-hint { bottom: calc(.5rem + var(--safe-bottom)); }
.sample-text { flex: 1; min-width: 0; }

.sample-swatch {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--border);
}

/* Enlarged view above the finger; the rim shows the colour under the centre ring */
.loupe {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  width: 112px;
  height: 112px;
  overflow: hidden;
  border: 6px solid var(--c, #fff);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .35), 0 6px 18px rgba(20, 25, 70, .35);
  pointer-events: none;
}

.loupe canvas { display: block; width: 100%; height: 100%; }

.loupe::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000;
  transform: translate(-50%, -50%);
}

/* The picked spot on the page */
.sample-marker {
  position: absolute;
  z-index: 4;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 1.5px #000, 0 2px 6px rgba(0, 0, 0, .35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Sticky bottom action bar */
.bottom-bar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  /* The main action gets a wider column ("Save & Share" in English) */
  grid-template-columns: repeat(3, 1fr) 1.3fr;
  gap: 6px;
  height: calc(var(--bar-h) + var(--safe-bottom));
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  transform: var(--pin-bottom,);
  transform-origin: 50% 100%;
  box-shadow: 0 -4px 16px rgba(30, 27, 107, .08);
}

.bar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 0 2px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--primary-dark);
  font: inherit;
  /* One line even with a large phone font: "שמור ושתף" wrapped and was cut off */
  font-size: min(.85rem, 3.4vw);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.bar-btn:active { background: var(--primary-soft); }
.bar-btn[aria-pressed="true"] { background: var(--primary-soft); }
.bar-btn:disabled { opacity: .45; cursor: default; }

.bar-btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.bar-btn-primary:active { background: var(--secondary); }

/* Page order arrows (documents made of images) */
.page-moves {
  position: absolute;
  top: 8px;
  inset-inline-start: 8px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: 24px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 8px rgba(20, 25, 70, .25);
}

.page-num {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 3.6em;
  min-height: 44px;
  padding: 0 8px;
  border: 1.5px solid var(--primary);
  border-radius: 22px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font: inherit;
  line-height: 1.1;
  cursor: pointer;
}
.page-num-text { font-size: .9rem; font-weight: 800; }
.page-num-move {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: .7rem;
  font-weight: 700;
}

/* "Move page to ...": a grid of places */
.move-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: .5rem;
  max-height: 50vh;
  overflow-y: auto;
  padding: 2px;
}
.move-to {
  min-height: 48px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--primary-dark);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
}
.move-to:active { background: var(--primary-soft); }
.move-to[aria-current] {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: default;
}

.page-move {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

.page-move:disabled { background: #c9cfe3; cursor: default; }
.draw-mode .page-moves,
.draw-mode .page-remove { display: none; }

/* ✕ on the page: removes the file it came from (documents combined from several files) */
.page-remove {
  position: absolute;
  top: 12px;
  inset-inline-end: 8px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(20, 25, 70, .25);
  cursor: pointer;
}
.page-remove[hidden] { display: none; }
.sample-mode .page-remove { pointer-events: none; }

/* "Add files or photos" after the last page */
.add-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  width: 100%;
  max-width: 900px;
  padding: .25rem 0 .5rem;
  text-align: center;
}
.add-pages[hidden] { display: none; }
.add-pages-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  width: 100%;
  min-height: 64px;
  padding: .8rem 1rem;
  border: 2px dashed var(--primary);
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.add-pages-btn:disabled { opacity: .6; }
.draw-mode .add-pages,
.sample-mode .add-pages { display: none; }

/* ---------- Free drawing ---------- */

.draw-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.draw-mode .draw-layer {
  pointer-events: auto;
  /* One finger draws; two fingers zoom and scroll (pinch zoom in viewer.js) */
  touch-action: none;
  cursor: crosshair;
}

/* Signatures and text stay visible but don't catch the pen */
.draw-mode .overlay-layer,
.draw-mode .overlay-layer * { pointer-events: none; }

.draw-mode .viewer-header,
.draw-mode .bottom-bar { display: none; }

.viewer.draw-mode { padding-bottom: calc(var(--tray-h) + var(--safe-bottom)); }
.viewer.tray-collapsed { --tray-h: 45px; }

.draw-title { font-weight: 700; }
.draw-done { font-weight: 800; }

.draw-tray {
  --ink: #1c2033;
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px calc(14px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(30, 27, 107, .08);
  transform: var(--pin-bottom,) translateY(var(--collapse, 0px));
  transform-origin: 50% 100%;
}

/* Tapping the handle tucks the tray down, leaving only the handle */
.tray-collapsed .draw-tray { --collapse: calc(100% - 45px - var(--safe-bottom));   /* handle + top border */ }
.draw-tray.is-sliding { transition: transform .2s ease; }

.tray-top {
  position: relative;
  margin: 0 -16px -10px;
}

.tray-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}

.draw-tools { display: flex; flex-direction: column; gap: 10px; }

.tray-handle svg { transition: transform .2s ease; }
.tray-collapsed .tray-handle svg { transform: rotate(180deg); }

/* Scroll mode: fingers scroll and zoom, nothing is drawn */
.scroll-toggle {
  position: absolute;
  inset-inline-start: 12px;
  top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}

.scroll-toggle[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

.scroll-mode .draw-layer {
  pointer-events: none;
  cursor: auto;
}
.pen-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 92px;
  overflow: hidden;
  overflow: clip;   /* hidden alone lets focus scroll the lowered pens */
  border-bottom: 1px solid var(--border);
}

.pens { display: flex; align-items: flex-end; gap: 6px; }

.pen-btn {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 52px;
  height: 84px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform: translateY(24px);
  transition: transform .15s ease;
}

.pen-btn[aria-pressed="true"] { transform: none; }
.pen-btn svg { width: 40px; height: 90px; }
.pen-tip { fill: var(--ink); }
.pen-marker .pen-tip { fill-opacity: .55; }
.pen-body { fill: #fff; stroke: #c9cede; }

.draw-tool-name {
  flex: 1;
  align-self: center;
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
}

.draw-undo {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.draw-undo:disabled { opacity: .4; cursor: default; }

.color-row { display: flex; justify-content: space-between; }

.color-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.color-btn span {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c);
}

.color-btn[aria-pressed="true"] span { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--c); }

.width-row { display: flex; align-items: center; gap: 12px; }
.width-row input { flex: 1; height: 28px; margin: 0; accent-color: var(--primary); }
.width-dot { flex-shrink: 0; border-radius: 50%; background: var(--muted); }
.width-dot-sm { width: 4px; height: 4px; }
.width-dot-lg { width: 18px; height: 18px; }

/* ---------- Home footer ---------- */

.site-footer {
  padding: 0 1rem calc(1.25rem + var(--safe-bottom));
  font-size: .95rem;
  line-height: 1.4;
  text-align: center;
}

.footer-row a {
  display: inline-block;
  padding: .4rem .15rem;
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible { color: var(--primary-dark); text-decoration: underline; }

.footer-dot { margin: 0 .4rem; color: #aab0c4; }

.footer-copy { margin: .35rem 0 0; font-size: .8rem; color: var(--muted); }

.footer-version { margin: .15rem 0 0; font-size: .75rem; color: var(--muted); }

/* ---------- Legal documents ---------- */

.legal-nav {
  position: sticky;
  top: calc(56px + env(safe-area-inset-top, 0px));
  z-index: 10;
  display: flex;
  gap: .25rem;
  padding: .5rem 1rem;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.legal-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 .9rem;
  border-radius: 999px;
  color: var(--primary-dark);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

/* Centered when the tabs fit, scrollable from the start when they don't */
.legal-nav a:first-child { margin-inline-start: auto; }
.legal-nav a:last-child { margin-inline-end: auto; }

.legal-nav a[aria-current="page"] {
  color: #fff;
  background: var(--primary);
}

.legal-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem max(1.5rem, env(safe-area-inset-right, 0px)) calc(2.5rem + var(--safe-bottom)) max(1.5rem, env(safe-area-inset-left, 0px));
  line-height: 1.75;
}

.legal-content h1 { margin-top: .5rem; font-size: 1.6rem; }
.legal-content h2 { margin-top: 1.75rem; font-size: 1.2rem; color: var(--primary-dark); }
.legal-content h3 { margin-top: 1.25rem; font-size: 1.05rem; }
.legal-content p,
.legal-content ul,
.legal-content ol { margin: .5rem 0 .9rem; }
.legal-content ul,
.legal-content ol { padding-inline-start: 1.4rem; }
.legal-content li { margin-bottom: .35rem; }
.legal-content a { color: var(--primary-dark); }
.legal-content code { padding: 0 .3em; border-radius: 4px; background: var(--primary-soft); font-size: .9em; }
.legal-content hr { margin: 2rem 0; border: 0; border-top: 1px solid var(--border); }

.table-wrap { overflow-x: auto; margin: .75rem 0 1rem; }

.legal-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
  background: var(--surface);
}

.legal-content th,
.legal-content td {
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  text-align: start;
  vertical-align: top;
}

.legal-content th { background: var(--primary-soft); }

/* Phones: each table row becomes a card, each cell shows its column name */
@media (max-width: 599px) {
  .legal-content table,
  .legal-content tbody,
  .legal-content tr,
  .legal-content td { display: block; }
  .legal-content thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .legal-content table { background: none; }
  .legal-content tr {
    margin-bottom: .75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
  }
  .legal-content td { border: 0; border-bottom: 1px solid var(--border); }
  .legal-content td:last-child { border-bottom: 0; }
  .legal-content td::before {
    content: attr(data-label);
    display: block;
    font-size: .8rem;
    font-weight: 700;
    color: var(--primary-dark);
  }
  .legal-content td:first-child { background: var(--primary-soft); font-weight: 700; }
}

.placeholder {
  padding: 0 .25em;
  border-radius: 4px;
  background: #fff1b8;
  color: #6b4e00;
  font-family: ui-monospace, Menlo, monospace;
  font-size: .85em;
}

/* ---------- Share target fallback page ---------- */

.simple-page {
  max-width: 480px;
  margin: 15vh auto 0;
  padding: 1.5rem;
  text-align: center;
}

/* ---------- Larger screens ---------- */

@media (min-width: 600px) {
  .pages { padding: 20px 16px 32px; gap: 20px; }
  .modal.sheet { margin-bottom: auto; border-radius: 18px; }
  .bottom-bar,
  .draw-tray { max-width: 640px; margin: 0 auto; border-radius: 18px 18px 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Guides (static pages for search, under guides/) ---------- */

.brand-link { color: inherit; text-decoration: none; }
.lang-switch { display: flex; gap: .25rem; }
.guide-video { margin: 1.25rem auto 1.5rem; text-align: center; }
.guide-video video {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  aspect-ratio: 9 / 16;
  margin: 0 auto .5rem;
  border-radius: 16px;
  background: #1d2f86;
  box-shadow: 0 8px 24px rgba(29, 47, 134, .25);
}
.guide-content .lead { font-size: 1.08rem; color: var(--text); }
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  font-size: .85rem;
  color: var(--muted);
}
.breadcrumbs a { color: var(--primary-dark); }
.guide-steps { counter-reset: step; list-style: none; padding-inline-start: 0 !important; }
.guide-steps li {
  position: relative;
  padding-inline-start: 2.6rem;
  margin-bottom: .9rem !important;
  counter-increment: step;
}
.guide-steps li::before {
  content: counter(step);
  position: absolute;
  inset-inline-start: 0;
  top: .1rem;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
  line-height: 1.9rem;
  text-align: center;
}
.guide-cta {
  margin: 2rem 0;
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.legal-content .guide-cta .btn { width: 100%; color: #fff; text-decoration: none; }
.guide-cta p { margin: .6rem 0 0; }
.guide-list { list-style: none; padding: 0 !important; }
.guide-list li { margin-bottom: .75rem !important; }
.guide-list a {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text) !important;
  text-decoration: none;
}
.guide-list strong { color: var(--primary-dark); font-size: 1.05rem; }
.guide-list .muted { font-size: .92rem; line-height: 1.55; }
