:root {
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #1f2a44;
  --muted: #6b6f7b;
  --line: #e3dccd;
  --accent: #e4572e;
  --r: 14px;
  color-scheme: light; /* the app is light-only; keeps inputs and pdf.js controls from going dark */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overscroll-behavior: none; }
[hidden] { display: none !important; }
button, label.ghost, label.big { font: inherit; color: inherit; cursor: pointer; }
:is(button, label) > svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* buttons */
.primary, .ghost, .icon {
  border: 0; border-radius: 999px; min-height: 44px; display: inline-flex; align-items: center; gap: 6px;
  padding: 0 16px; background: transparent; white-space: nowrap; text-decoration: none;
}
.primary { background: var(--ink); color: #fff; font-weight: 600; }
.ghost { border: 1px solid var(--line); background: var(--card); }
.icon { padding: 0; width: 44px; justify-content: center; }
.primary:active, .ghost:active, .icon:active { transform: scale(.97); }
.small { font-size: 14px; color: var(--muted); }

/* home */
#home { overflow-y: auto; }
.home-inner { max-width: 560px; margin: auto; padding: 40px 20px calc(24px + env(safe-area-inset-bottom)); text-align: center; }
.logo { display: block; margin: 0 auto 8px; }
h1 { font-size: 44px; margin: 0; letter-spacing: -.02em; }
.tag { color: var(--muted); line-height: 1.5; margin: 8px 0 28px; }
.actions { display: grid; gap: 12px; }
.big {
  display: block; text-align: left; padding: 20px; border-radius: var(--r); background: var(--card);
  border: 1px solid var(--line); box-shadow: 0 1px 0 var(--line);
}
.big:hover { border-color: var(--ink); }
.big:focus-within { outline: 3px solid var(--accent); }
.big strong { display: block; font-size: 19px; }
.big span { color: var(--muted); font-size: 15px; }
.sect { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); text-align: left; margin: 22px 4px 8px; }
.new-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.new-row .ghost { justify-content: flex-start; }
.dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.home-foot a { color: inherit; }
#office-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.loading { position: absolute; inset: 60px 24px auto; text-align: center; color: var(--muted); pointer-events: none; }
.primary:disabled { opacity: .4; }
.drop-hint { color: var(--muted); font-size: 14px; }
.home-foot { margin-top: 28px; display: grid; gap: 10px; justify-items: center; }
body.dragging #home { outline: 4px dashed var(--accent); outline-offset: -12px; }

/* top bar */
.bar {
  display: flex; align-items: center; gap: 4px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); z-index: 2;
}
.bar .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; padding: 0 4px; }
.bar .name small { color: var(--muted); font-weight: 400; }

/* viewer: pdf.js needs an absolutely positioned scroll container */
#viewer-wrap { position: relative; flex: 1; background: #d9d3c6; }
#viewerContainer { position: absolute; inset: 0; overflow: auto; }
.pdfViewer .page { box-shadow: 0 1px 4px rgba(0,0,0,.2); border: 0; margin: 12px auto; }

/* edited words: a white patch with the new text, placed in % of the page so it follows zoom */
.text-edit {
  position: absolute; z-index: 1; display: flex; align-items: flex-end; padding: 0 0 0.12em; margin: 0; border: 0;
  background: #fff; color: #000; white-space: pre; line-height: 1; cursor: text; font-weight: 400;
}
#viewer:not(.edit-text) .text-edit { pointer-events: none; }
#viewer.edit-text .text-edit { outline: 1px dashed var(--accent); }
#viewer.edit-text .textLayer { cursor: text; }
#edit-input { display: block; width: 100%; margin-top: 10px; font: inherit; font-size: 17px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); }
#save-name { background: #fff; color: var(--ink); }

.stampEditor .altText { display: none !important; } /* alt text prompt makes no sense for a signature */

/* bottom tools */
.tools {
  display: flex; justify-content: space-around; background: var(--card); border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.tools button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; min-width: 46px; min-height: 52px; justify-content: center; border-radius: 12px; color: var(--muted);
}
.tools button.on { color: var(--ink); background: var(--paper); font-weight: 600; }

.swatches {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(72px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; padding: 8px; background: var(--card); border-radius: 999px; box-shadow: 0 4px 16px rgba(0,0,0,.15); z-index: 3;
}
.swatches button { width: 32px; height: 32px; border-radius: 50%; border: 2px solid #fff; background: var(--c); box-shadow: 0 0 0 1px var(--line); }
.swatches button.on { box-shadow: 0 0 0 3px var(--ink); }

/* pages */
#pages { background: var(--paper); }
.add { padding: 0 14px; }
.hint { margin: 10px 16px 0; font-size: 14px; color: var(--muted); }
.grid {
  flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px; padding: 14px 16px 24px; align-content: start;
}
.pg { background: var(--card); border: 2px solid transparent; border-radius: var(--r); padding: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.pg.sel { border-color: var(--accent); }
.pg .thumb { display: grid; place-items: center; aspect-ratio: 3/4; overflow: hidden; cursor: pointer; border: 0; background: none; width: 100%; padding: 0; }
.pg canvas { max-width: 100%; max-height: 100%; box-shadow: 0 0 0 1px var(--line); transition: transform .2s; }
.pg .meta { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.pg .meta span { font-size: 13px; color: var(--muted); padding-left: 4px; }
.pg .meta button { width: 34px; height: 34px; min-height: 0; }
.pg .meta svg { width: 18px; height: 18px; }
.pg .meta .btns { display: flex; }
.pages-foot {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}

/* dialogs */
dialog { border: 0; border-radius: 18px; padding: 20px; width: min(520px, calc(100vw - 24px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(20,24,36,.45); }
dialog h2 { margin: 0 0 4px; font-size: 20px; }
#sign-pad { width: 100%; height: auto; aspect-ratio: 5/2; background: #fff; border: 1px dashed var(--line); border-radius: 10px; touch-action: none; margin: 8px 0; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.grow { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; }
#save-name { display: block; width: 100%; margin-top: 6px; font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 10; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
