@font-face { font-family: "Dancing Script"; src: url("fonts/dancing-script.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Caveat"; src: url("fonts/caveat.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --fg: #1b2430;
  --muted: #5d6877;
  --line: #d5dbe3;
  --accent: #1f5fae;
  --accent-fg: #ffffff;
  --accent-soft: rgba(31, 95, 174, 0.12);
  --todo: #f2b705;
  --todo-soft: rgba(242, 183, 5, 0.22);
  --done: #2e8b57;
  --done-soft: rgba(46, 139, 87, 0.12);
  --danger: #b3261e;
  --ink: #142878;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.12), 0 1px 2px rgba(16, 24, 40, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12161c;
    --surface: #1c222b;
    --fg: #e6ebf2;
    --muted: #9aa5b4;
    --line: #333c48;
    --accent: #6aa3ec;
    --accent-fg: #0b1626;
    --accent-soft: rgba(106, 163, 236, 0.16);
    --danger: #f2867d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* ---- Top bar --------------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.bar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bar-title img { flex: none; }
.doc-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.doc-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.bar-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.progress { font-size: 13px; color: var(--muted); white-space: nowrap; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 8px 14px; min-height: 38px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .link:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; font-weight: 600; }

/* ---- Status screens -------------------------------------------------------- */
.screen {
  max-width: 460px; margin: 18vh auto 0; padding: 0 16px; text-align: center;
}
.screen h1 { font-size: 22px; margin: 14px 0 6px; }
.screen p { color: var(--muted); margin: 0; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Document -------------------------------------------------------------- */
#docView { padding: 16px 16px 80px; }
.intro {
  max-width: 900px; margin: 0 auto 16px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.intro p { margin: 0 0 6px; }
.intro p:last-child { margin: 0; }
.intro blockquote {
  margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 6px 6px 0; white-space: pre-wrap;
}
.muted { color: var(--muted); font-size: 13.5px; }

#pages { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.page {
  position: relative; background: #fff; box-shadow: var(--shadow); max-width: 100%;
}
.page canvas { display: block; width: 100%; height: 100%; }
.page-num { position: absolute; right: 8px; bottom: -20px; font-size: 12px; color: var(--muted); }

/* Field overlays: sized in % of the page so they track any zoom. */
.f {
  position: absolute; display: flex; align-items: center; justify-content: center;
  border: 2px dashed #c99700; background: var(--todo-soft); border-radius: 3px;
  color: #5c4500; font: 600 12px/1.1 "Segoe UI", system-ui, sans-serif; padding: 0;
  cursor: pointer; overflow: hidden;
}
.f.done { border: 1.5px solid var(--done); background: var(--done-soft); }
.f.active { box-shadow: 0 0 0 3px var(--accent); }
.f img { max-width: 100%; max-height: 100%; pointer-events: none; }
.f .f-label { pointer-events: none; text-align: center; padding: 0 2px; white-space: nowrap; }
.f .req { color: var(--danger); margin-left: 1px; }
.f input {
  width: 100%; height: 100%; border: 0; background: transparent; padding: 0 3px;
  color: var(--ink); font: inherit; font-family: Helvetica, Arial, sans-serif; font-weight: 400; outline: none;
}
.f input::placeholder { color: #7a6420; opacity: 1; }
.f.static { cursor: default; color: var(--ink); justify-content: flex-start; padding-left: 3px; font-family: Helvetica, Arial, sans-serif; font-weight: 400; }

/* ---- Dialogs --------------------------------------------------------------- */
.dialog {
  border: 0; padding: 0; border-radius: 12px; width: min(560px, calc(100vw - 24px));
  background: var(--surface); color: var(--fg); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.dialog.small { width: min(440px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(10, 16, 24, 0.55); }
.dialog-body { padding: 18px 18px 16px; }
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.dialog p { margin: 0 0 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button {
  background: none; border: 0; padding: 8px 12px; cursor: pointer; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.pad-wrap { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 8px; height: 190px; touch-action: none; }
.pad { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.pad-line { position: absolute; left: 6%; right: 6%; bottom: 26%; border-bottom: 1px solid #b9c1cc; pointer-events: none; }
.pad-hint { position: absolute; left: 0; right: 0; bottom: 8%; text-align: center; color: #8a94a3; font-size: 12.5px; pointer-events: none; }

.field-label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 6px; color: var(--muted); }
.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--fg); font: inherit;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.input { resize: vertical; }

.font-choices { display: grid; gap: 8px; margin-top: 10px; }
.font-choice {
  display: flex; align-items: center; justify-content: center; height: 76px; padding: 0 12px;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  font-size: 34px; white-space: nowrap; overflow: hidden;
}
.font-choice[aria-pressed="true"] { border: 2px solid var(--accent); }

.upload-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 160px; padding: 16px; text-align: center; color: var(--muted); cursor: pointer;
  border: 2px dashed var(--line); border-radius: 8px; background: var(--bg);
}
.upload-drop img { max-width: 100%; max-height: 120px; background: #fff; border-radius: 4px; }

.error { color: var(--danger); font-size: 13.5px; }

.noscript { text-align: center; margin-top: 30vh; }

/* ---- Phones ---------------------------------------------------------------- */
@media (max-width: 640px) {
  .bar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .bar-title { flex: 1 1 100%; }
  .doc-title, .doc-sub { max-width: calc(100vw - 60px); }
  .bar-actions { flex: 1 1 100%; justify-content: flex-end; }
  .progress { margin-right: auto; }
  .btn { padding: 7px 12px; }
  #docView { padding: 12px 8px 80px; }
  .dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 14px 14px 0 0; }
  .dialog.small { width: 100vw; }
  .pad-wrap { height: 170px; }
}
