/* JotBird publish stylesheet
   Clean, friendly, and focused on readability.
*/

/* =========================
   Tokens
========================= */

:root {
  --jb-bg: #f5f5f7;
  --jb-surface: #ffffff;
  --jb-text: #111827;
  --jb-muted: #6b7280;
  --jb-border: #e5e7eb;
  --jb-accent: #2563eb;
  --jb-code-bg: #f3f4f6;
  --jb-radius: 12px;
  --jb-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --jb-font-body: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
  --jb-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

/* =========================
   Base
========================= */

html,
body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  margin: 0;
  padding: 0;
  background: var(--jb-bg);
  color: var(--jb-text);
  font-family: var(--jb-font-body);
  -webkit-font-smoothing: antialiased;
}

/* Optional safety rail if you still see rare sideways scrolling.
   Enable if needed.
*/
/*
html,
body {
  overflow-x: hidden;
}
*/

/* =========================
   Layout
========================= */

main.publish {
  max-width: 840px;
  margin: 3.5rem auto 2rem;
  padding: 2.5rem 2.75rem;
  background: var(--jb-surface);
  border-radius: var(--jb-radius);
  box-shadow: var(--jb-shadow);
  box-sizing: border-box;
}

@media (max-width: 600px) {
  main.publish {
    margin: 1.25rem auto 1.5rem;
    padding: 1.25rem 1.25rem;
  }
}

/* =========================
   Typography
========================= */

main.publish :where(h1, h2, h3, h4, h5, h6) {
  font-weight: 700;
  line-height: 1.2;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

main.publish h1 {
  font-size: 2.25rem;
  margin-top: 0;
}

main.publish h2 {
  font-size: 1.75rem;
}

main.publish h3 {
  font-size: 1.4rem;
}

main.publish h4 {
  font-size: 1.15rem;
}

main.publish h5 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

main.publish h6 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--jb-muted);
}

main.publish p {
  margin: 0.5rem 0 1rem;
  line-height: 1.7;
  font-size: 1rem;
}

main.publish strong {
  font-weight: 600;
}

main.publish em {
  font-style: italic;
}

/* =========================
   Links + long content wrapping
========================= */

main.publish a {
  color: var(--jb-accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(37, 99, 235, 0.3);

  /* Prevent long URLs from blowing up mobile layout */
  overflow-wrap: anywhere;
  word-break: break-word;
}

main.publish a:hover {
  border-bottom-color: var(--jb-accent);
}

/* Make sure footnotes and general text also wrap long tokens */
main.publish :where(p, li, .footnotes, .footnotes a) {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* =========================
   Heading permalinks
========================= */

main.publish :where(h1, h2, h3, h4, h5, h6) .header-anchor {
  border-bottom: none;
  text-decoration: none;

  margin-left: 0.3em;
  opacity: 0;
  transition: opacity 0.15s ease-in-out;
  color: var(--jb-muted, currentColor);
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

/* Hide anchor on first h1 - it's redundant at the top of the page */
main.publish > h1:first-child .header-anchor {
  display: none;
}

main.publish :where(h1, h2, h3, h4, h5, h6):hover .header-anchor,
.header-anchor:focus-visible {
  opacity: 1;
}

.header-anchor {
  font-size: 0.9em;
}

.header-anchor__icon {
  width: 1em;
  height: 1em;
  vertical-align: middle;
  stroke-width: 1.4;
}

/* =========================
   Lists
========================= */

main.publish ul,
main.publish ol {
  margin: 0.5rem 0 1.25rem;
  padding-left: 1.5rem;
}

main.publish li {
  margin: 0.25rem 0;
  line-height: 1.6;
}

main.publish :where(ul ul, ol ol, ul ol, ol ul) {
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

/* Tighter list item spacing - remove paragraph margins inside list items */
main.publish li > p {
  margin-top: 0;
  margin-bottom: 0;
}

/* Task lists (checkboxes) - hide bullets and align with other list items */
main.publish li.task-list-item {
  list-style-type: none;
  margin-left: -1.5em;
}

main.publish .task-list-item-checkbox {
  margin-right: 0.5em;
}

/* =========================
   Rules
========================= */

main.publish hr {
  border: 0;
  border-top: 1px solid var(--jb-border);
  margin: 2rem 0;
}

/* =========================
   Blockquotes
========================= */

main.publish blockquote {
  margin: 1.25rem 0;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--jb-accent);
  background: #eff6ff;
  color: #1f2933;
  border-radius: 0 10px 10px 0;
}

/* =========================
   Collapsible Sections
========================= */

main.publish details {
  margin: 1.25rem 0;
  padding: 0.75rem 1rem;
  background: var(--jb-code-bg);
  border: 1px solid var(--jb-border);
  border-radius: 8px;
}

main.publish details[open] {
  padding-bottom: 1rem;
}

main.publish summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--jb-text);
  padding: 0.25rem 0;
  list-style: none;
}

main.publish summary::-webkit-details-marker {
  display: none;
}

main.publish summary::before {
  content: "▶";
  display: inline-block;
  margin-right: 0.5rem;
  font-size: 0.75em;
  transition: transform 0.15s ease;
}

main.publish details[open] > summary::before {
  transform: rotate(90deg);
}

main.publish details > *:not(summary) {
  margin-top: 0.75rem;
}

/* =========================
   Code
========================= */

main.publish code {
  font-family: var(--jb-font-mono);
  font-size: 0.9em;
  background: var(--jb-code-bg);
  border-radius: 4px;
  padding: 0.15em 0.35em;
}

main.publish pre {
  margin: 1.2rem 0;
  padding: 0.9rem 1rem;
  background: var(--jb-code-bg);
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--jb-font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
}

main.publish pre code {
  background: transparent;
  padding: 0;
}

main.publish kbd {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  padding: 0.2em 0.45em;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff 0%, #f1f3f5 100%);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.08);
  font-family: var(--jb-font-mono);
  font-size: 0.85em;
  line-height: 1.3;
  color: #111827;
}

/* =========================
   Tables (no wrapper / no shading)
========================= */

/* Safety rail: never let content push the publish card wider */
main.publish {
  overflow-x: hidden;
}

/* Make tables self-contained horizontal scrollers */
main.publish table {
  display: block;                 /* key: lets overflow-x work reliably */
  max-width: 100%;
  width: 100%;                    /* keeps it constrained to container */
  overflow-x: auto;               /* table scrolls instead of the page */
  -webkit-overflow-scrolling: touch;

  border-collapse: collapse;
  font-size: 0.95rem;
  margin: 1.5rem 0;
}

/* Cells */
main.publish th,
main.publish td {
  border: 1px solid var(--jb-border);
  padding: 0.5rem 0.75rem;
  text-align: left;

  /* If you keep nowrap, scrolling will be needed more often */
  white-space: nowrap;
}

/* Header */
main.publish th {
  font-weight: 600;
}

/* =========================
   Images
========================= */

main.publish img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.25rem auto;
  border-radius: 8px;
}

/* =========================
   Footer (optional)
========================= */

main.publish .jb-footer {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--jb-border);
  font-size: 0.85rem;
  color: var(--jb-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* =========================
   Watermark block under the publish container
========================= */

.jb-watermark {
  margin: 3rem auto 2rem;
  text-align: center;
  opacity: 0.55;
  transition: opacity 0.2s ease;
}

.jb-watermark:hover {
  opacity: 0.8;
}

.jb-watermark img {
  width: 50px;
  height: auto;
  display: block;
  margin: 0 auto 0.6rem;
}

.jb-watermark-text {
  font-size: 0.9rem;
  color: #6b7280;
}

.jb-watermark-text a {
  color: #2563eb;
  text-decoration: none;
  border-bottom: 1px solid rgba(37, 99, 235, 0.25);
}

.jb-watermark-text a:hover {
  border-bottom-color: #2563eb;
}

/* =========================
   Print
========================= */

@media print {
  /* Give the content more usable width on the printed page */
  @page {
    margin: 10mm; /* try 8â€“12mm; default margins are often huge */
    /* size: auto; */
    /* Optional (Chrome mostly): uncomment if you want landscape for table-heavy docs */
    /* size: landscape; */
  }

  html,
  body {
    background: #ffffff;
  }

  main.publish {
    max-width: 100%;
    margin: 0;
    padding: 0;          /* key: donâ€™t waste width */
    box-shadow: none;
    border-radius: 0;
  }

  /* Tables: treat print as "fit-to-page" */
  main.publish table {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed;   /* key: enables wrapping instead of overflow */
    border-collapse: collapse;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  main.publish thead {
    display: table-header-group; /* repeat header on each page where supported */
  }

  main.publish th,
  main.publish td {
    white-space: normal !important; /* override nowrap */
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;

    /* Slightly tighter for print */
    font-size: 10pt;
    line-height: 1.25;
    padding: 6px 8px;

    vertical-align: top;
  }

  /* Prevent a single row from being split across pages when possible */
  main.publish tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* If you still see any â€œcroppingâ€, this often helps */
  main.publish table,
  main.publish th,
  main.publish td {
    box-sizing: border-box;
  }

  /* If you have a wrapper around tables, make sure it doesn't constrain */
  main.publish .jb-table-wrap {
    overflow: visible !important;
    border: none !important;
    clip-path: none !important;
  }

  /* Optional: hide watermark in print */
  .jb-watermark {
    display: none;
  }
}
