/* Colours: plain light values first (every browser), then light-dark() pairs where the browser supports them
   (Chrome 123, Safari 17.5, Firefox 120). Light is the default; the system preference is ignored. Dark only when the reader chose it with the toggle
   (html[data-theme="dark"], set in header.html before first paint). Browsers without light-dark() simply stay light. */
:root {
  color-scheme: light;
  /* Light = Ocean Blue: #E5F2FA #B9DDF0 #79B8D9 #347FA8 #17445F. Dark = the same hue on deep blue-ink, never pure black.
     Text uses ink/muted/primary (>=4.5:1 on --bg and --surface in both themes);
     --accent and --soft are for lines, rings and fills, never body text. */
  --bg: #fbfdff;
  --ink: #0e2a3d;
  --muted: #456479;
  --primary: #17445f;
  --accent: #347fa8;
  --soft: #79b8d9;
  --line: #d3e9f6;
  --line-strong: #b9ddf0;
  --surface: #e5f2fa;
  --serif: "Bai Jamjuree", "Noto Sans Thai", system-ui, sans-serif;
  --sans: "Bai Jamjuree", "Noto Sans Thai", system-ui, sans-serif;
  /* Images are drawn for a light page: the line icons are black, the banner and sketches sit on white paper. */
  --icon-filter: none;
  --photo-filter: none;
  --banner-filter: none;
  --icon-blend: normal;
  accent-color: var(--accent);
  scrollbar-color: var(--soft) transparent;
}
@supports (color: light-dark(#000, #fff)) {
  :root {
    color-scheme: light;
    --bg: light-dark(#fbfdff, #0b1a25);
    --ink: light-dark(#0e2a3d, #e4eff7);
    --muted: light-dark(#456479, #9fb8c9);
    --primary: light-dark(#17445f, #8ecbe8);
    --accent: light-dark(#347fa8, #5ba6d0);
    --soft: light-dark(#79b8d9, #3f7b9a);
    --line: light-dark(#d3e9f6, #1b3446);
    --line-strong: light-dark(#b9ddf0, #2a4b61);
    --surface: light-dark(#e5f2fa, #12293a);
  }
  :root[data-theme="dark"] { color-scheme: dark; }
  :root[data-theme="dark"] { --icon-filter: invert(1); --icon-blend: screen; --photo-filter: brightness(.88); --banner-filter: brightness(.82) saturate(.92); }
}

::selection { background: var(--line-strong); color: var(--ink); }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
}

a { color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.skip {
  position: absolute;
  left: 12px;
  top: -64px;
  z-index: 20;
  padding: 10px 16px;
  background: var(--bg);
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 4px;
  font-size: 15px;
}
.skip:focus { top: 12px; }

.wrap {
  max-width: 1048px;
  margin: 0 auto;
  padding: 0 28px;
}

/* masthead */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 34px 0 26px;
  border-bottom: 1px solid var(--line);
}
.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 14px;
  text-decoration: none;
  font-weight: 600;
}
.masthead .note { font-size: 14px; color: var(--muted); }

/* banner: the painting has a white top; crop it so the scene sits close to the masthead */
.banner {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2048 / 600;
  object-fit: cover;
  object-position: center 88%;
  margin-top: 8px;
  filter: var(--banner-filter);
  border-radius: 4px;
}

/* hero */
.hero {
  padding: 32px 0 34px 260px;
}
/* the page title must not outrank the entry titles below it (32px) */
.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.4;
}
.hero .tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 16px;
}

/* two-column layout */
.layout {
  display: grid;
  grid-template-columns: 200px minmax(0, 640px);
  column-gap: 60px;
  padding-top: 42px;
}
.layout:has(> .content[data-view="page"]) { padding-top: 78px; }

/* where scrollIntoView() lands after following a link */
#content { scroll-margin-top: 24px; }

/* htmx: loading bar and view transitions */
#loading {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
}
#loading.htmx-request { animation: loading-bar 8s cubic-bezier(.1, .6, .3, 1) forwards; }
@keyframes loading-bar { to { transform: scaleX(.92); } }
@media (prefers-reduced-motion: reduce) {
  #loading.htmx-request { animation: none; transform: scaleX(1); }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* sidebar */
.side { font-size: 14px; }
.side-title {
  margin: 0 0 12px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

/* archive: a rail of years (the year on screen is marked) and, under it, the months of that year */
#archive { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.side .year {
  order: 1;
  flex: 0 0 calc((100% - 42px) / 4);
  padding: 2px 0;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  text-underline-offset: 5px;
  text-decoration-thickness: 2px;
}
.side .year:hover { text-decoration: underline; text-decoration-color: var(--soft); }
.side .year[aria-current="page"] { color: var(--primary); font-weight: 700; text-decoration: underline; text-decoration-color: var(--accent); }
.month { order: 2; flex: 0 0 100%; margin: 0; }
.month:first-of-type { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.month summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.month summary::-webkit-details-marker { display: none; }
.month summary::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .18s cubic-bezier(.2, .7, .2, 1);
}
.month[open] summary::before { transform: rotate(45deg); }
.month summary:hover { color: var(--primary); }
.month ul { list-style: none; margin: 0 0 10px; padding: 0 0 0 16px; }
.month li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 4px 0;
  line-height: 1.5;
}
.month .day { flex: none; width: 1.6em; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.month a { text-decoration: none; }
.month a:hover { text-decoration: underline; text-underline-offset: 3px; }
.month a[aria-current="page"] { color: var(--primary); font-weight: 700; }
.side .about {
  margin: 36px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

/* entry */
.entry-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 26px;
}
.entry-when { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.lock { flex: none; width: 16px; height: 16px; margin-left: 8px; vertical-align: -3px; filter: var(--icon-filter); mix-blend-mode: var(--icon-blend); }
.cats .lock { margin-left: 0; vertical-align: middle; }
.entry-meta .cats .lock { width: 20px; height: 20px; }
.entry-edit { color: var(--primary); font-size: 13px; text-decoration: none; }
.entry-edit:hover, .entry-edit:focus-visible { text-decoration: underline; text-underline-offset: 3px; }
.entry-title {
  margin: 0 0 26px;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  line-height: 1.4;
  text-wrap: balance;
  overflow-wrap: break-word;
}
.prose {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.75;
  /* Thai has no spaces: let the browser's dictionary break lines, avoid one-word last lines, never overflow on long unbroken strings */
  text-wrap: pretty;
  overflow-wrap: break-word;
}
.prose p { margin: 0 0 1.1em; }
.prose h2, .prose h3 { font-family: var(--serif); line-height: 1.3; margin: 1.8em 0 .6em; }
.prose a { color: var(--primary); text-underline-offset: 3px; }
.prose img { max-width: 100%; height: auto; border-radius: 4px; filter: var(--photo-filter); }
.prose blockquote {
  margin: 1.4em 0;
  padding-left: 1.2em;
  border-left: 1px solid var(--line-strong);
  color: var(--muted);
}
.prose code {
  background: var(--surface);
  padding: .1em .35em;
  border-radius: 3px;
  font-size: .9em;
}
.prose pre {
  background: var(--surface);
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.5;
}
.prose pre code { background: none; padding: 0; }
.prose .remember {
  margin: 2em 0 0;
  padding: 20px 24px;
  background: var(--surface);
  border-radius: 6px;
}
.prose .remember h3 {
  margin: 0 0 8px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--primary);
}
.prose .remember p { margin: 0; }
.empty { color: var(--muted); }
.empty a { color: var(--primary); text-underline-offset: 3px; }

/* footer */
.foot {
  margin-top: 96px;
  padding: 28px 0 48px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

/* small screens */
@media (min-width: 861px) {
  .side-menu > summary { display: none; }
}
@media (max-width: 860px) {
  .wrap { padding: 0 20px; }
  .hero { padding: 28px 0 8px; }
  .hero h1 { font-size: 28px; }
  .layout, .layout:has(> .content[data-view="page"]) { grid-template-columns: minmax(0, 1fr); padding-top: 16px; }
  .side { margin: 0 0 28px; }
  .content { max-width: 640px; }
  /* categories and archive sit behind one disclosure at the top instead of at the end of the page */
  .side-menu > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 16px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    color: var(--primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
  }
  .side-menu > summary::-webkit-details-marker { display: none; }
  .side-menu > summary::before {
    content: "";
    flex: none;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--primary);
    border-bottom: 1.5px solid var(--primary);
    transform: rotate(-45deg);
    transition: transform .18s cubic-bezier(.2, .7, .2, 1);
  }
  .side-menu[open] > summary::before { transform: rotate(45deg); }
  .side-menu[open] > summary { margin-bottom: 24px; }
  .entry-meta { font-size: 14px; }
  .entry-edit { font-size: 14px; }
  .entry-nav { grid-template-columns: minmax(0, 1fr); gap: 4px; font-size: 15px; }
  .entry-nav .prev, .entry-nav .next { grid-column: 1; justify-self: start; }
  .entry-nav .ttl { white-space: normal; overflow: visible; }
  .pager { font-size: 15px; }
}
/* touch: 44px targets in the sidebar and entry navigation */
@media (pointer: coarse) {
  .side .cats a { padding: 12px 0; }
  .side .year { padding: 10px 0; }
  .month summary { padding: 12px 0; }
  .month li { padding: 10px 0; }
  .entry-nav a { padding: 10px 0; }
  .pager .loadmore { padding: 12px 22px; }
  .skip { padding: 12px 18px; }
}

.prose figure.sketch { margin: 0 0 1.6em; }
.prose figure.sketch img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
  background: var(--surface);
}
.prose figure.sketch figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

/* CKEditor 5 image output: block "centered" style is a bare figure.image with no
   class, so the editor's own CSS centred it but the front end did not. */
.prose figure.image { display: table; clear: both; margin: 1.6em auto; text-align: center; max-width: 100%; }
.prose figure.image > img { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.prose figure.image > figcaption { display: table-caption; caption-side: bottom; margin-top: 8px; color: var(--muted); font-size: 13px; }
.prose figure.image.image_resized { display: block; box-sizing: border-box; }
.prose figure.image.image_resized > img { width: 100%; }
.prose figure.image-style-align-left,
.prose figure.image-style-block-align-left { margin-left: 0; margin-right: auto; }
.prose figure.image-style-align-right,
.prose figure.image-style-block-align-right { margin-left: auto; margin-right: 0; }
.prose figure.image-style-side { float: right; max-width: 50%; margin: .4em 0 1em 1.5em; }
.prose figure.image-style-align-left:not(.image-style-block-align-left) { float: left; margin: .4em 1.5em 1em 0; }
.prose figure.image-style-align-right:not(.image-style-block-align-right) { float: right; margin: .4em 0 1em 1.5em; }
.prose img.image-style-align-left { float: left; margin: .4em 1.5em 1em 0; }
.prose img.image-style-align-right { float: right; margin: .4em 0 1em 1.5em; }
.prose img.image-style-align-center { display: block; margin-left: auto; margin-right: auto; }

/* ---- ExpressionEngine additions ---- */
.entry + .entry { margin-top: 72px; padding-top: 48px; border-top: 1px solid var(--line); }
.entry-title a { text-decoration: none; }
.entry-title a:hover { text-decoration: underline; text-underline-offset: 4px; }
.entry-meta .cats { display: inline-flex; gap: 6px; align-items: center; }
.cat-icon { width: 20px; height: 20px; vertical-align: middle; filter: var(--icon-filter); mix-blend-mode: var(--icon-blend); }
.entry-meta .cat-icon { width: 22px; height: 22px; }
.more { margin: 1em 0 0; font-size: 15px; }
.more a { color: var(--primary); text-decoration: none; }
.more a:hover { text-decoration: underline; text-underline-offset: 3px; }
/* end of an entry: a small mark, then the same day in other years */
.end-mark {
  height: 6px;
  margin: 48px auto 0;
  background: radial-gradient(circle, var(--soft) 2.5px, transparent 3px) center / 22px 6px repeat-x;
  width: 66px;
}
.sameday { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--line); }
.sameday h2 { margin: 0 0 8px; font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--muted); }
.sameday p { display: flex; flex-wrap: wrap; gap: 0 14px; align-items: baseline; margin: 0; padding: 4px 0; }
.sameday time { flex: none; color: var(--muted); font-size: 14px; }
.sameday a { color: var(--primary); text-underline-offset: 3px; }
.sameday a:hover { text-decoration-thickness: 2px; }
.entry-nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.entry-nav a {
  display: flex;
  gap: 10px;
  align-items: baseline;
  min-width: 0;
  max-width: 100%;
  color: var(--primary);
  text-decoration: none;
}
.entry-nav .prev { grid-column: 1; justify-self: start; }
.entry-nav .next { grid-column: 2; justify-self: end; }
.entry-nav .ttl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-nav .arrow { flex: none; }
.entry-nav a:hover .ttl { text-decoration: underline; text-underline-offset: 3px; }
.pager { margin-top: 56px; font-size: 14px; color: var(--muted); }
.pager a { margin: 0 4px; color: var(--primary); }
#batch { display: contents; }
.pager .loadmore {
  display: inline-block;
  margin: 0 0 0 12px;
  padding: 8px 20px;
  border: 1px solid var(--primary);
  border-radius: 2px;
  color: var(--primary);
  font-size: 15px;
  text-decoration: none;
}
.pager .loadmore:hover { background: var(--surface); border-color: var(--accent); }
.pager .loadmore.htmx-request { opacity: .5; }
.loading-note { margin: 0 0 32px; font-size: 13px; color: var(--muted); }
.pager strong { margin: 0 4px; color: var(--ink); }
.side .cats { margin: 0 0 34px; padding: 0; list-style: none; font-size: 14px; }
.side .cats li { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.side .cats a { flex: 1; padding: 5px 0; text-decoration: none; }
.side .cats li:has(.lock) a { flex: 0 1 auto; }
.side .cats a:hover { color: var(--primary); }
.side .cats a[aria-current="page"] { color: var(--primary); font-weight: 700; }
.side .whoami { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.masthead .note { text-align: right; }

/* Imported WordPress posts: embedded video/audio, galleries, comments */
.prose .video { position: relative; aspect-ratio: 16 / 9; margin: 0 0 1.1em; }
.prose .video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 4px; }
.prose .audio audio { width: 100%; margin: 0 0 1.1em; }
.prose .gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 0 0 1.1em; }
.prose .gallery figure { margin: 0; }
.comments { margin-top: 3em; padding-top: 1.2em; border-top: 1px solid var(--line); }
.comments h2 { font-family: var(--serif); font-size: 1.17em; margin: 0 0 1em; }
.comment-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.comment { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px 16px 4px; }
.comment-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding-bottom: 8px; margin-bottom: 10px; border-bottom: 1px dashed var(--line); font-size: 14px; color: var(--muted); }
.comment-list { counter-reset: comment; }
.comment-no { font-size: 12px; }
.comment-no::before { counter-increment: comment; content: "#" counter(comment); }
.comment-author { color: var(--ink); font-size: 15px; }
.comment-author a { color: var(--primary); text-underline-offset: 3px; }
.comment-head time { margin-left: auto; font-size: 13px; }
.comment-body { overflow-wrap: anywhere; line-height: 1.7; }
.comment-body p { margin: 0 0 .8em; }

/* year page */
.year-list .year-meta { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.year-list .year-month {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 2.4em 0 .5em;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--primary);
}
.year-list .year-month::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.year-list .year-meta + .year-month { margin-top: 1.2em; }
.year-list .month-items { list-style: none; margin: 0; padding: 0; }
.year-list .month-items li {
  display: grid;
  grid-template-columns: 2.4em minmax(0, 1fr) auto;
  gap: 0 14px;
  align-items: baseline;
  padding: 9px 0;
}
.year-list .day { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; }
.year-list .month-items a { font-family: var(--serif); font-size: 18px; line-height: 1.5; text-decoration: none; }
.year-list .month-items a:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 4px; }
.year-list .cats { display: inline-flex; gap: 6px; }
.year-list .cat-icon { width: 18px; height: 18px; }

/* theme toggle: shows the mode it switches to (moon on a light page, sun on a dark one); 44px hit area, 20px drawing */
.masthead-end { display: flex; align-items: center; gap: 6px; }
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -10px -12px -10px 0;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--primary); background: var(--surface); }
.theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle[aria-pressed="true"] .moon, .theme-toggle[aria-pressed="false"] .sun { display: none; }

/* on this day: owner only (the template renders it for logged-in members), front page, above the entries */
.onthisday { margin: 0 0 56px; padding: 0 0 28px; border-bottom: 1px solid var(--line); }
.onthisday h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  margin: 0 0 10px;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--primary);
}
.onthisday h2 .when { font-size: 15px; font-weight: 400; color: var(--muted); }
.onthisday h2 .lock { align-self: center; margin-left: 0; }
.onthisday ul { list-style: none; margin: 0; padding: 0; }
.onthisday li {
  display: grid;
  grid-template-columns: 3.2em minmax(0, 1fr) auto;
  gap: 0 14px;
  align-items: baseline;
  padding: 7px 0;
}
.onthisday .yr { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.onthisday .t { min-width: 0; }
.onthisday li a { font-family: var(--serif); font-size: 18px; line-height: 1.5; text-decoration: none; overflow-wrap: break-word; }
.onthisday li a:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 4px; }
.onthisday .ago { color: var(--muted); font-size: 13px; white-space: nowrap; }
@media (max-width: 860px) {
  .onthisday li { grid-template-columns: 3.2em minmax(0, 1fr); }
  .onthisday .ago { grid-column: 2; }
}
@media (pointer: coarse) { .onthisday li { padding: 10px 0; } }
