/* Markr — styles
   Split out of index.html so markup, styling, and behaviour aren't all
   crammed into one file. Sections are ordered roughly top-to-bottom as
   they appear in the page. */

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

:root {
  --black: #0a0a0a;
  --g900: #141414;
  --g800: #1c1c1c;
  --g700: #282828;
  --g600: #3a3a3a;
  --g500: #555;
  --g400: #888;
  --g300: #aaa;
  --g200: #ccc;
  --g100: #e8e8e8;
  --white: #ffffff;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --page-shadow: 0 4px 24px rgba(0, 0, 0, 0.55), 0 1px 4px rgba(0, 0, 0, 0.3);
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  background: var(--g800);
  color: var(--white);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ── Toolbar ─────────────────────────────────────────── */
#toolbar {
  height: 64px;
  background: var(--black);
  border-bottom: 1px solid var(--g700);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  flex-shrink: 0;
  user-select: none;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#toolbar::-webkit-scrollbar {
  display: none;
}

/* ── PDF toolbar ─────────────────────────────────────── */
/* A second bar, shown only once a PDF is open (js/pdf-loader.js toggles
   display). flex-wrap lets it break into as many rows as the viewport
   needs — each .tb-cluster wraps as a single atomic unit so a control
   group is never split awkwardly across a line break. */
#pdfToolbar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  /* justify-content applies per wrapped line, so this centers each row of
     clusters independently — a lone cluster on its own row sits in the
     middle rather than stuck against the left edge. */
  justify-content: center;
  gap: 10px 14px;
  background: var(--g900);
  border-bottom: 1px solid var(--g700);
  padding: 10px 16px;
  user-select: none;
}

.tb-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  background: var(--white);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--white);
  white-space: nowrap;
}

.tb-divider {
  width: 1px;
  height: 28px;
  background: var(--g700);
  flex-shrink: 0;
}

.tb-spacer {
  flex: 1;
  min-width: 8px;
}

.tb-label {
  font-size: 12.5px;
  color: var(--g400);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s, border-color 0.1s, opacity 0.1s;
  border: 1px solid transparent;
  line-height: 1;
  flex-shrink: 0;
}

/* Open PDF: secondary — outlined, not the main visual draw */
.btn-open {
  background: transparent;
  color: var(--white);
  border-color: var(--g500);
}

.btn-open:hover {
  background: var(--g700);
  border-color: var(--g300);
}

/* Save PDF: primary — filled accent colour, the obvious next action */
.btn-save {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-save:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn-save:disabled {
  background: transparent;
  color: var(--g500);
  border-color: var(--g600);
  font-weight: 500;
  cursor: default;
  opacity: 0.5;
}

.btn-secondary {
  background: transparent;
  color: var(--g400);
  border-color: var(--g600);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--g400);
  color: var(--g200);
}

.btn-secondary:disabled {
  opacity: 0.35;
  cursor: default;
}

label.btn {
  cursor: pointer;
}

label.btn input[type=file] {
  display: none;
}

/* ── Tool buttons ────────────────────────────────────── */
.tool-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--g400);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  font-family: inherit;
  flex-shrink: 0;
}

.tool-btn:hover {
  background: var(--g700);
  color: var(--g200);
  border-color: var(--g600);
}

.tool-btn.active {
  background: var(--g700);
  color: var(--white);
  border-color: var(--g600);
}

/* Info button — slightly different from tool buttons */
#infoBtn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--g600);
  background: transparent;
  color: var(--g400);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  font-family: Georgia, serif;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}

#infoBtn:hover {
  background: var(--g700);
  color: var(--white);
  border-color: var(--g500);
}

/* ── Controls ────────────────────────────────────────── */
#colorInput {
  width: 40px;
  height: 40px;
  border: 1px solid var(--g600);
  border-radius: 7px;
  padding: 3px;
  background: var(--g900);
  cursor: pointer;
  flex-shrink: 0;
}

#strokeSize,
#zoomSelect {
  height: 40px;
  border: 1px solid var(--g600);
  border-radius: 7px;
  padding: 0 8px;
  background: var(--g900);
  color: var(--white);
  font: 14px inherit;
  flex-shrink: 0;
}

#strokeSize {
  width: 58px;
  text-align: center;
}

#zoomSelect {
  width: 80px;
  cursor: pointer;
}

#zoomOutBtn,
#zoomInBtn {
  font-size: 18px;
  font-weight: 600;
}

/* ── Ad banner ───────────────────────────────────────── */
#adBanner {
  background: var(--g900);
  border-bottom: 1px solid var(--g700);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  flex-shrink: 0;
}

/* ── Viewer ──────────────────────────────────────────── */
#viewer {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--g800);
  position: relative;
  -webkit-overflow-scrolling: touch;
}

/* ── Drop zone ───────────────────────────────────────── */
#dropZone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 40px 24px 32px;
  text-align: center;
  cursor: pointer;
  width: 100%;
}

.drop-ring {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 48px;
  border: 1.5px dashed var(--g600);
  border-radius: 14px;
  transition: border-color 0.15s, background 0.15s;
  max-width: 360px;
  width: 100%;
}

#dropZone.drag-over .drop-ring,
#dropZone:hover .drop-ring {
  border-color: var(--g400);
  background: rgba(255, 255, 255, 0.025);
}

.drop-icon {
  color: var(--g600);
}

.drop-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--g300);
}

.drop-sub {
  font-size: 12px;
  color: var(--g500);
  line-height: 1.6;
}

.drop-browse {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 7px 18px;
  border: 1px solid var(--g600);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  color: var(--g400);
  background: transparent;
  cursor: pointer;
  transition: border-color 0.1s, color 0.1s;
}

#dropZone:hover .drop-browse,
#dropZone.drag-over .drop-browse {
  border-color: var(--g400);
  color: var(--g200);
}

/* ── SEO content section ─────────────────────────────── */
/* This section is always in the DOM so search crawlers can read it.
   It hides when a PDF is opened. */
#siteContent {
  width: 100%;
  max-width: 720px;
  padding: 0 24px 48px;
}

.site-intro {
  text-align: center;
  padding: 8px 0 32px;
  border-top: 1px solid var(--g700);
  margin-top: 8px;
}

.site-intro h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--g200);
  margin-bottom: 10px;
  letter-spacing: -0.3px;
}

.site-intro p {
  font-size: 13px;
  color: var(--g400);
  line-height: 1.7;
  max-width: 480px;
  margin: 0 auto;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin: 28px 0;
}

.feature-card {
  background: var(--g900);
  border: 1px solid var(--g700);
  border-radius: 10px;
  padding: 18px 16px;
}

.feature-card .icon {
  font-size: 20px;
  margin-bottom: 8px;
  display: block;
  color: var(--g300);
}

.feature-card h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--g200);
  margin-bottom: 6px;
}

.feature-card p {
  font-size: 12px;
  color: var(--g500);
  line-height: 1.6;
}

.feature-card kbd {
  display: inline-block;
  background: var(--g700);
  border: 1px solid var(--g600);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
  color: var(--g300);
  font-family: inherit;
  margin-top: 6px;
}

.privacy-note {
  background: var(--g900);
  border: 1px solid var(--g700);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 12px;
  color: var(--g400);
  line-height: 1.6;
  text-align: center;
  margin-bottom: 16px;
}

.privacy-note strong {
  color: var(--g200);
}

.built-by {
  text-align: center;
  font-size: 12px;
  color: var(--g600);
  padding-top: 4px;
}

.built-by a {
  color: var(--g500);
  text-decoration: none;
}

.built-by a:hover {
  color: var(--g300);
}

/* ── Pages ───────────────────────────────────────────── */
#pagesContainer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 36px 24px;
  /* Opts out of #viewer's align-items:center — zoom.js positions this
     horizontally itself (via margin-left), because centering based on the
     *unscaled* layout size (what flex align-items would do) doesn't match
     where the *visually scaled* content actually needs to sit. */
  align-self: flex-start;
}

.page-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.page-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--g500);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.page-box {
  position: relative;
  line-height: 0;
  box-shadow: var(--page-shadow);
}

.page-canvas {
  display: block;
}

.anno-canvas {
  position: absolute;
  inset: 0;
  cursor: crosshair;
}

.text-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

/* ── Text boxes ──────────────────────────────────────── */
/* .textbox is the drag surface: its own padded frame background, or its
   textarea while unfocused (see textbox.js). The frame is always visible
   (not hover-gated) since hover doesn't exist on touch. */
.textbox {
  position: absolute;
  pointer-events: all;
  display: inline-flex;
  padding: 9px;
  border: 1.5px solid rgba(150, 150, 150, 0.5);
  border-radius: 6px;
  background: rgba(20, 20, 20, 0.25);
  cursor: move;
  /* Prevents the browser's own touch scroll/zoom gestures from competing
     with our Pointer Events drag/resize handling below. */
  touch-action: none;
}

/* .tb-del / .tb-resize get a counter-scale transform from textbox.js
   (1 / current PDF zoom) so their on-screen size always matches this CSS
   size, regardless of how zoomed in or out the page is — without it, these
   would shrink along with #pagesContainer's zoom transform and become too
   small to tap at mobile's typical 40-60% auto-fit zoom. */
.tb-del {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 30px;
  height: 30px;
  background: var(--g900);
  border: 1.5px solid var(--g600);
  border-radius: 50%;
  color: var(--g300);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-family: inherit;
  transition: color 0.1s;
}

.tb-del:hover {
  color: var(--white);
}

/* Resize handle — replaces the native textarea corner, which mobile
   browsers don't reliably expose to touch. */
.tb-resize {
  position: absolute;
  right: -14px;
  bottom: -14px;
  width: 30px;
  height: 30px;
  background: var(--g900);
  border: 1.5px solid var(--g600);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: nwse-resize;
  touch-action: none;
}

.tb-resize::after {
  content: '';
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--g300);
  border-bottom: 2px solid var(--g300);
  border-radius: 0 0 2px 0;
}

.textbox textarea {
  display: block;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  line-height: 1.35;
  min-width: 72px;
  min-height: 1.6em;
  padding: 2px 4px;
  font-family: Arial, Helvetica, sans-serif;
  user-select: text;
  white-space: pre;
  cursor: text;
}

/* ── Status bar ──────────────────────────────────────── */
#statusBar {
  height: 26px;
  background: var(--black);
  border-top: 1px solid var(--g700);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  flex-shrink: 0;
}

#statusBar span {
  font-size: 11px;
  color: var(--g500);
}

#statusBar .right {
  display: flex;
  align-items: center;
  gap: 16px;
}

#statusBar a {
  color: var(--g500);
  text-decoration: none;
  transition: color 0.1s;
}

#statusBar a:hover {
  color: var(--g300);
}

/* ── Info modal ──────────────────────────────────────── */
#infoModal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.8);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#infoModal.open {
  display: flex;
}

.modal-box {
  background: var(--g900);
  border: 1px solid var(--g600);
  border-radius: 14px;
  max-width: 500px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  background: var(--g700);
  border: none;
  border-radius: 50%;
  color: var(--g400);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}

.modal-close:hover {
  background: var(--g600);
  color: var(--white);
}

.modal-box h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--white);
  letter-spacing: -0.3px;
  margin-bottom: 8px;
}

.modal-box .tagline {
  font-size: 13px;
  color: var(--g400);
  line-height: 1.6;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--g700);
}

.modal-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--g500);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.shortcut-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.shortcut-table td {
  padding: 6px 0;
  font-size: 12px;
  color: var(--g300);
  border-bottom: 1px solid var(--g700);
  vertical-align: middle;
}

.shortcut-table td:first-child {
  color: var(--g400);
  width: 48%;
}

.shortcut-table tr:last-child td {
  border-bottom: none;
}

.shortcut-table kbd {
  display: inline-block;
  background: var(--g700);
  border: 1px solid var(--g600);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  color: var(--g200);
  font-family: inherit;
}

.modal-privacy {
  background: var(--g800);
  border: 1px solid var(--g700);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  color: var(--g400);
  line-height: 1.6;
  margin-bottom: 20px;
}

.modal-privacy strong {
  color: var(--g200);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  border-top: 1px solid var(--g700);
  flex-wrap: wrap;
  gap: 10px;
}

.modal-footer .credit {
  font-size: 12px;
  color: var(--g500);
}

.modal-footer .credit a {
  color: var(--g400);
  text-decoration: none;
}

.modal-footer .credit a:hover {
  color: var(--g200);
}

.bmc-modal-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: #282828;
  border: none;
  border-radius: 6px;
  color: var(--white);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.1s;
}

.bmc-modal-link:hover {
  opacity: 0.88;
}

/* ── Saving overlay ──────────────────────────────────── */
#savingOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  align-items: center;
  justify-content: center;
  z-index: 200;
  font-size: 15px;
  color: var(--g200);
  gap: 12px;
}

#savingOverlay.visible {
  display: flex;
}

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

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--g600);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes ellipsis {
  0% {
    content: '';
  }

  33% {
    content: '.';
  }

  66% {
    content: '..';
  }

  100% {
    content: '...';
  }
}

.loading::after {
  content: '';
  animation: ellipsis 1.2s steps(1, end) infinite;
}

/* ── BuyMeACoffee float position fix ─────────────────── */
.donate-fb {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ── Mobile ──────────────────────────────────────────── */
@media (max-width: 600px) {

  /* The header only holds branding + open/save now, so it comfortably
     stays one row; #pdfToolbar's own flex-wrap (see above) is what breaks
     the actual PDF controls into 2-3 rows as needed. */
  #toolbar {
    height: auto;
    min-height: 64px;
    padding: 8px 12px;
  }

  #pdfToolbar {
    padding: 8px 10px;
    gap: 8px 10px;
  }

  .tool-btn {
    width: 44px;
    height: 44px;
  }

  .btn {
    padding: 0 12px;
    font-size: 13px;
    min-height: 44px;
  }

  #colorInput {
    width: 44px;
    height: 44px;
  }

  #strokeSize,
  #zoomSelect {
    height: 44px;
  }

  #strokeSize {
    width: 50px;
  }

  #zoomSelect {
    width: 66px;
  }

  #statusBar .right span:not(#pageInfo) {
    display: none;
  }

  .feature-grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal-box {
    padding: 20px;
  }
}
