@font-face { font-family: 'DancingScript'; src: url(/fonts/DancingScript.ttf); font-display: swap; }
@font-face { font-family: 'GreatVibes'; src: url(/fonts/GreatVibes.ttf); font-display: swap; }
@font-face { font-family: 'Caveat'; src: url(/fonts/Caveat.ttf); font-display: swap; }
@font-face { font-family: 'Pacifico'; src: url(/fonts/Pacifico.ttf); font-display: swap; }
@font-face { font-family: 'Allura'; src: url(/fonts/Allura.ttf); font-display: swap; }
@font-face { font-family: 'Roboto'; src: url(/fonts/Roboto.ttf); font-display: swap; }

:root {
  --ink: #1d2b4f;
  --ink-soft: #3c4f80;
  --paper: #f3f1ec;
  --line: #d9d5cc;
  --text: #22252b;
  --danger: #b3261e;
  --sel: #2f6fed;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text); background: var(--paper);
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--ink); color: #fff;
}
.brand { font-weight: 700; letter-spacing: .2px; font-size: 17px; }
.brand em { font-family: 'DancingScript', cursive; font-style: normal; font-weight: 400; font-size: 21px; margin-left: 4px; color: #e9e2c9; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.toolbar select, .toolbar input[type=number] {
  font: inherit; font-size: 16px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 0 6px;
}
.toolbar select { max-width: 170px; }
.toolbar input[type=number] { width: 52px; text-align: center; }
.toolbar input[type=color] { width: 38px; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; }
.size, .zoom, .pager { display: inline-flex; align-items: center; gap: 4px; }
.zoom span, .pager span { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; font-size: 14px; }
.sep { flex: 1; }

.btn {
  font: inherit; font-size: 15px; height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.mini { width: 34px; padding: 0; font-size: 18px; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.topbar .btn.primary { background: #fff; color: var(--ink); border-color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.toggle.on { background: #e7ecfa; border-color: var(--ink-soft); color: var(--ink); font-weight: 600; }

.viewer { flex: 1; overflow: auto; padding: 16px 8px 24px; -webkit-overflow-scrolling: touch; }
.empty { max-width: 420px; margin: 12vh auto 0; text-align: center; color: #666; }
.empty .big { font-size: 20px; color: var(--ink); font-weight: 600; }

.page {
  position: relative; margin: 0 auto 16px; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 6px 18px rgba(0,0,0,.06);
}
.page canvas { display: block; width: 100%; height: 100%; }
.layer { position: absolute; inset: 0; }
.layer.adding { cursor: text; }

.anno {
  position: absolute; white-space: pre; line-height: 1.25; padding: 0; margin: 0;
  outline: 1px dashed transparent; min-width: 8px;
}
.anno .txt { outline: none; display: block; min-width: 1ch; }
.anno:hover, .anno.sel { outline-color: rgba(47,111,237,.6); }
.anno .grip, .anno .x {
  position: absolute; top: -26px; width: 24px; height: 24px; border-radius: 6px;
  display: none; align-items: center; justify-content: center; font: 14px/1 -apple-system, sans-serif;
  background: var(--sel); color: #fff; user-select: none; -webkit-user-select: none; touch-action: none;
}
.anno .grip { left: -1px; cursor: grab; }
.anno .x { left: 26px; background: var(--danger); cursor: pointer; }
.anno.sel .grip, .anno.sel .x { display: flex; }

.actions {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: #fff; border-top: 1px solid var(--line);
}
.status { flex: 1; font-size: 13px; color: #555; overflow: hidden; text-overflow: ellipsis; }
.status.err { color: var(--danger); }
.status.ok { color: #1e7b34; }

dialog { border: none; border-radius: 14px; padding: 0; width: min(440px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,25,40,.45); }
dialog form { padding: 18px; display: grid; gap: 10px; }
dialog h2 { margin: 0 0 4px; font-size: 18px; color: var(--ink); }
dialog label { display: grid; gap: 4px; font-size: 13px; color: #555; }
dialog input, dialog textarea { font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
dialog .hint { margin: 0; font-size: 12px; color: #777; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (max-width: 600px) {
  .toolbar { gap: 6px; padding: 6px 8px; }
  .toolbar select { max-width: 130px; }
  .sep { display: none; }
}
