/* Built-in blog: the list, the post page and the layouts the editor makes (spec §5.3, §5.5).
   Colours come from app.css tokens plus the post palette below; the palette's dark values are
   switched with the same selectors as app.css. Keep the two dark blocks identical. */
:root {
  --pc-red: #c62828;
  --pc-orange: #b26a00;
  --pc-green: #1f6b45;
  --pc-blue: #1f5f8b;
  --pc-purple: #b0177a;
  --pc-gray: #53667a;
  --ps-small: 0.875em;
  --ps-large: 1.25em;
  --ps-xl: 1.5em;
  --ps-huge: 2em;
  --ph-yellow: #fff1a8;
  --ph-green: #c9efd6;
  --ph-blue: #cfe6f7;
  --ph-pink: #f9d3e8;
  --ph-gray: #dde3e9;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pc-red: #ff8a8a;
    --pc-orange: #f2b33d;
    --pc-green: #6fd1a0;
    --pc-blue: #6bb0de;
    --pc-purple: #f07ac0;
    --pc-gray: #9db0c2;
    --ph-yellow: #5c4b00;
    --ph-green: #1f5a3a;
    --ph-blue: #1f4d70;
    --ph-pink: #6e2a52;
    --ph-gray: #3a4a5a;
  }
}
:root[data-theme="dark"] {
  --pc-red: #ff8a8a;
  --pc-orange: #f2b33d;
  --pc-green: #6fd1a0;
  --pc-blue: #6bb0de;
  --pc-purple: #f07ac0;
  --pc-gray: #9db0c2;
  --ph-yellow: #5c4b00;
  --ph-green: #1f5a3a;
  --ph-blue: #1f4d70;
  --ph-pink: #6e2a52;
  --ph-gray: #3a4a5a;
}

/* The list */
.blog-list h1, .blog-post h1 { font-size: var(--t-2xl); line-height: 1.2; margin: 0 0 var(--sp-1); }
.blog-items { list-style: none; margin: 24px 0; padding: 0; display: grid; gap: 24px; }
.blog-item { display: grid; grid-template-columns: 160px 1fr; gap: 16px; align-items: start; }
.blog-item:not(:has(.blog-item__cover)) { grid-template-columns: 1fr; }
.blog-item__cover img { width: 100%; height: auto; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 6px; display: block; }
.blog-item h2 { font-size: var(--t-lg); margin: 0; line-height: 1.3; }
.blog-item p { margin: 4px 0 0; }
.blog-pager { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; margin: 24px 0; }
.blog-pager a { min-height: 44px; display: inline-flex; align-items: center; gap: 8px; }
.blog-pager__lbl { flex: none; white-space: nowrap; }
.blog-pager--post { border-top: 1px solid var(--line); padding-top: 16px; }
.blog-pager--post { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }
.blog-pager--post a { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; padding: 4px 0; }
.blog-pager--post .blog-pager__older { grid-column: 2; align-items: flex-end; text-align: right; }
.blog-pager--post .blog-pager__newer { grid-column: 1; }
.blog-pager__t { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.blog-back { margin: 16px 0 32px; }
.blog-back a { display: inline-flex; align-items: center; min-height: 44px; }
.blog-back--top { margin: 0 0 var(--sp-1, 4px); }
@media (max-width: 600px) {
  .blog-item { grid-template-columns: 96px 1fr; gap: 12px; }
}

/* The post */
.blog-post { max-width: 40rem; margin: 0 auto; }
.blog-post__head { margin: 8px 0 16px; }
.blog-hero { margin: 0 0 24px; }
.blog-hero img { width: 100%; height: auto; border-radius: 6px; display: block; }
.blog-preview { max-width: 40rem; margin-left: auto; margin-right: auto; }
.blog-body { font-size: 18px; line-height: 1.6; color: var(--ink); overflow-wrap: anywhere; }
.blog-body::after { content: ""; display: table; clear: both; }
.blog-body h2 { font-size: var(--t-xl); line-height: 1.25; margin: 1.6em 0 0.5em; }
.blog-body h3 { font-size: var(--t-lg); line-height: 1.3; margin: 1.4em 0 0.4em; }
.blog-body h4 { font-size: var(--t-md); margin: 1.2em 0 0.4em; }
.blog-body p, .blog-body ul, .blog-body ol, .blog-body blockquote, .blog-body pre { margin: 0 0 1em; }
.blog-body li > p { margin: 0 0 0.3em; }
.blog-body a { color: var(--link); }
.blog-body blockquote { border-left: 4px solid var(--line); padding: 0 0 0 16px; color: var(--muted); }
.blog-body hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.blog-body pre { overflow-x: auto; padding: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; font-size: 0.875em; }
.blog-body code { font-size: 0.9em; }
.blog-body img { max-width: 100%; height: auto; display: block; border-radius: 4px; }
.blog-body figure { margin: 0 0 1em; }
.blog-body figcaption { font-size: var(--t-sm); color: var(--muted); line-height: 1.45; margin-top: 6px; }
.blog-body .img-center { margin-left: auto; margin-right: auto; }
.blog-body .img-full { margin-left: 0; margin-right: 0; }
.blog-body .wrap-left { float: left; width: 45%; margin: 0.3em 24px 1em 0; }
.blog-body .wrap-right { float: right; width: 45%; margin: 0.3em 0 1em 24px; }
.blog-body .grid { display: grid; gap: 12px; margin: 0 0 1em; clear: both; }
.blog-body .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.blog-body .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.blog-body .grid figure { margin: 0; }
.blog-body .cols { display: grid; gap: 24px; margin: 0 0 1em; clear: both; }
.blog-body .cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.blog-body .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.blog-body .col > :last-child { margin-bottom: 0; }
.blog-body table { border-collapse: collapse; display: block; max-width: 100%; overflow-x: auto; margin: 0 0 1em; font-size: 0.9em; }
/* The table box scrolls sideways when it must; its body fills the width, so a short table
   doesn't shrink to squeezed columns. */
.blog-body table > tbody, .blog-body table > thead { display: table; width: 100%; border-collapse: collapse; }
/* A table with set column widths (a colgroup with <col style="width: ..">) is wrapped at render
   time in .post-table-scroll (render_body; never stored, not in the feed). Inside it the table is a
   real table at its set widths, so <col> widths apply; the wrapper scrolls sideways when the
   table is wider than the text, so the page never widens. The editor's inline min-width is
   ignored here. Tables with no set widths keep the display:block box above. */
.blog-body .post-table-scroll { max-width: 100%; overflow-x: auto; margin: 0 0 1em; }
.blog-body .post-table-scroll > table { display: table; table-layout: fixed; width: max-content; min-width: 0 !important; max-width: none; margin: 0; overflow: visible; }
.blog-body .post-table-scroll > table > tbody { display: table-row-group; width: auto; }
.blog-body .post-table-scroll > table > thead { display: table-header-group; width: auto; }
.blog-body th, .blog-body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.blog-body th { background: var(--bg); font-weight: 600; }
.blog-body td > p, .blog-body th > p { margin: 0; }
.blog-tags { max-width: 40rem; margin: 16px auto 0; }
@media (max-width: 760px) {
  .blog-body .cols-2, .blog-body .cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .blog-body .wrap-left, .blog-body .wrap-right { float: none; width: auto; margin: 0 0 1em; }
  .blog-body .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Search box on /blog (plan Task 18). */
.blog-search { display: flex; gap: .5rem; margin: .25rem 0 1rem; max-width: 32rem; }
.blog-search input { flex: 1; min-width: 0; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: inherit; font: inherit; }

/* Callout boxes (spec 8.2): a tint, a left bar in the palette colour. */
.blog-body .callout { margin: 0 0 1em; padding: 12px 16px; border-left: 4px solid var(--pc-blue); border-radius: 4px; background: color-mix(in srgb, var(--pc-blue) 12%, var(--surface)); color: var(--ink); clear: both; }
.blog-body .callout-warn { border-left-color: var(--pc-orange); background: color-mix(in srgb, var(--pc-orange) 14%, var(--surface)); }
.blog-body .callout > :first-child { margin-top: 0; }
.blog-body .callout > :last-child { margin-bottom: 0; }
/* YouTube player (spec 8.5): 16:9 at full text width. */
.blog-body figure.video { clear: both; }
.blog-body figure.video iframe { display: block; width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 4px; background: var(--bg); }
/* Bluesky and X quote cards (spec 8.6): the network is named in text, nothing is loaded. */
.blog-body figure.quote-card { clear: both; padding: 12px 16px; border: 1px solid var(--line); border-left: 4px solid var(--pc-gray); border-radius: 6px; background: var(--surface); }
.blog-body figure.quote-bluesky { border-left-color: var(--pc-blue); }
.blog-body figure.quote-card blockquote { margin: 0; padding: 0; border: 0; color: var(--ink); }
.blog-body figure.quote-card blockquote > :last-child { margin-bottom: 0; }

/* Galleries (post gallery spec 5.2): even rows of whole maps, never cropped. Without the script
   the tiles wrap, each growing in proportion to its shape, so every row keeps one height; with
   it, static/js/gallery.js sets balanced row widths (no lone map in a short last row). */
.blog-body .gallery { clear: both; margin: 0 0 1em; }
.blog-body .gallery-grid { --row-h: 110px; display: flex; flex-wrap: wrap; gap: 4px; }
@media (min-width: 640px) { .blog-body .gallery-grid { --row-h: 160px; } }
/* Without the script a lone last map would grow to the full width: this filler takes the last
   row's spare room. The script's balanced rows (.is-laid) leave none, so it goes. */
.blog-body .gallery-grid::after { content: ""; flex: 1e4 1 0px; }
.blog-body .gallery-grid.is-laid::after { display: none; }
.blog-body .gallery-tile { position: relative; margin: 0; min-width: 0; flex: var(--r) 1 calc(var(--row-h) * var(--r)); }
.blog-body .gallery-tile a { display: block; border-radius: 3px; }
.blog-body .gallery-tile img { width: 100%; height: auto; border-radius: 3px; }
.blog-body .gallery-tile figcaption { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.blog-body .gallery-loop { position: absolute; left: 6px; bottom: 6px; padding: 1px 6px; border-radius: 3px; background: rgb(0 0 0 / 0.68); color: #fff; font-size: 12px; line-height: 1.5; pointer-events: none; }
.blog-body .gallery-note, .blog-body .gallery-credits { margin: 6px 0 0; font-size: var(--t-sm); line-height: 1.45; color: var(--muted); }
.blog-body .gallery-credits { margin-top: 2px; }
.blog-body a.zoom, .blog-hero a.zoom { display: block; cursor: zoom-in; }

/* The map viewer (spec 5.5): a full-screen dialog, dark in both themes so maps read the same. */
.viewer { width: 100vw; height: 100vh; height: 100dvh; overscroll-behavior: contain; max-width: none; max-height: none; margin: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); border: 0; background: #0b0f14; color: #f2f4f7; box-sizing: border-box; overflow: hidden; }
.viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.viewer::backdrop { background: rgb(0 0 0 / 0.85); }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.viewer-count { margin-right: auto; font-size: 15px; font-variant-numeric: tabular-nums; }
.viewer-count[hidden] + .viewer-zoom { margin-left: auto; }
.viewer button { min-height: 44px; min-width: 44px; padding: 0 14px; border: 1px solid rgb(255 255 255 / 0.35); border-radius: 4px; background: transparent; color: inherit; font: inherit; font-size: 15px; cursor: pointer; }
.viewer button:focus-visible { outline: 2px solid #8cc4ff; outline-offset: 2px; }
.viewer-stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; touch-action: pan-y pinch-zoom; user-select: none; }
.viewer-img { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; cursor: zoom-in; }
.viewer-stage.is-zoomed { display: block; overflow: auto; touch-action: none; }
.viewer-stage.is-zoomed .viewer-img { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-prev, .viewer-next { position: absolute; top: 50%; transform: translateY(-50%); font-size: 28px !important; background: rgb(0 0 0 / 0.5) !important; }
.viewer-prev { left: 12px; }
.viewer-next { right: 12px; }
.viewer-stage.is-zoomed .viewer-prev, .viewer-stage.is-zoomed .viewer-next { display: none; }
.viewer-caption { max-height: 30vh; max-height: 30dvh; margin: 0; padding: 10px 16px 14px; overflow-y: auto; font-size: 15px; line-height: 1.5; color: #d8dee6; }
@media (max-width: 639px) {
  .viewer-prev, .viewer-next { min-width: 44px; min-height: 44px; padding: 0 !important; font-size: 26px !important; }
  .viewer-prev { left: 6px; }
  .viewer-next { right: 6px; }
}
/* While the viewer is open the page behind does not move (gallery.js fixes the body in place). */
body.viewer-lock { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
.blog-follow a { display: inline-block; padding: 13px 0; margin: -13px 0; } /* 44 px to tap, same line height */
