/* ==========================================================================
   CaptionDeD — site stylesheet
   Replaces Bootstrap 3, Bootstrap theme, Font Awesome 4 and rrssb.
   Hand written, no framework, no build step.
   ========================================================================== */

/* --- Prompt, self hosted ------------------------------------------------
   unicode-range means a Thai reader downloads only the ~13KB Thai subset per
   weight and never touches the Latin file, and vice versa.
   ------------------------------------------------------------------------ */
@font-face{font-family:Prompt;font-style:normal;font-weight:400;font-display:swap;src:url("../fonts/prompt-thai-400.woff2") format("woff2");unicode-range:U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC}
@font-face{font-family:Prompt;font-style:normal;font-weight:400;font-display:swap;src:url("../fonts/prompt-latin-400.woff2") format("woff2");unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD}
@font-face{font-family:Prompt;font-style:normal;font-weight:600;font-display:swap;src:url("../fonts/prompt-thai-600.woff2") format("woff2");unicode-range:U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC}
@font-face{font-family:Prompt;font-style:normal;font-weight:600;font-display:swap;src:url("../fonts/prompt-latin-600.woff2") format("woff2");unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD}
@font-face{font-family:Prompt;font-style:normal;font-weight:700;font-display:swap;src:url("../fonts/prompt-thai-700.woff2") format("woff2");unicode-range:U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC}
@font-face{font-family:Prompt;font-style:normal;font-weight:700;font-display:swap;src:url("../fonts/prompt-latin-700.woff2") format("woff2");unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD}

/* --- Tokens -------------------------------------------------------------
   Light is the bare :root so the un-stamped "system" state always resolves.
   Dark is redefined twice: once for prefers-color-scheme (guarded so an
   explicit light choice still wins) and once for the manual toggle.
   Only tokens are redefined; no component rule lives inside a theme block.
   ------------------------------------------------------------------------ */
:root {
  --accent:        #DB1F45;   /* 4.89:1 on white - passes AA for body text  */
  --accent-hover:  #B81C3C;
  --accent-ink:    #FFFFFF;   /* text on accent fills, 4.89:1               */
  --accent-wash:   #FEF5F7;   /* chip ground; keeps accent text at 4.6:1    */

  --ground:        #FAF8F7;
  --surface:       #FFFFFF;
  --surface-2:     #F2EDEE;
  --ink:           #1A1618;
  --ink-soft:      #5F5559;
  --ink-faint:     #8B8085;
  --rule:          #E8E1E3;

  --good:          #1B7F5A;
  --shadow-sm:     0 1px 2px rgba(26,22,24,.05);
  --shadow-md:     0 2px 4px rgba(26,22,24,.05), 0 8px 20px -12px rgba(26,22,24,.18);

  --radius:        14px;
  --radius-sm:     9px;
  --radius-pill:   999px;

  --step--1: .8125rem;
  --step-0:  1rem;
  --step-1:  1.15rem;
  --step-2:  1.4rem;
  --step-3:  1.75rem;
  --step-4:  2.15rem;

  --sans: Prompt, -apple-system, BlinkMacSystemFont, "Segoe UI", "Leelawadee UI", Roboto, sans-serif;

  --wrap: 1140px;
  --gap:  1.25rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent:       #fe2c55;  /* the original brand red - 5.04:1 on dark    */
    --accent-hover: #ff5c7a;
    --accent-ink:   #16100F;
    --accent-wash:  #2C1419;

    --ground:       #121011;
    --surface:      #1B1819;
    --surface-2:    #262122;
    --ink:          #EDE8E9;
    --ink-soft:     #A79DA0;
    --ink-faint:    #7E7478;
    --rule:         #2C2729;

    --good:         #4FC48E;
    --shadow-sm:    0 1px 2px rgba(0,0,0,.4);
    --shadow-md:    0 2px 4px rgba(0,0,0,.3), 0 8px 20px -12px rgba(0,0,0,.7);
  }
}

:root[data-theme="dark"] {
  --accent:       #fe2c55;
  --accent-hover: #ff5c7a;
  --accent-ink:   #16100F;
  --accent-wash:  #2C1419;

  --ground:       #121011;
  --surface:      #1B1819;
  --surface-2:    #262122;
  --ink:          #EDE8E9;
  --ink-soft:     #A79DA0;
  --ink-faint:    #7E7478;
  --rule:         #2C2729;

  --good:         #4FC48E;
  --shadow-sm:    0 1px 2px rgba(0,0,0,.4);
  --shadow-md:    0 2px 4px rgba(0,0,0,.3), 0 8px 20px -12px rgba(0,0,0,.7);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-0);
  /* Thai stacks vowels above and tone marks above those; 1.75 keeps two
     consecutive lines from colliding. Latin-tuned 1.5 is too tight here. */
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, svg { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
button { font: inherit; color: inherit; }

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.35;
  font-weight: 600;
  text-wrap: balance;
}
h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Layout -------------------------------------------------------------- */
.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: 1rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
  padding-block: 1.75rem 3rem;
}
@media (min-width: 62rem) {
  .layout { grid-template-columns: minmax(0, 1fr) 20.5rem; align-items: start; }
  .layout > .sidebar { position: sticky; top: 5.25rem; }
}

.stack { display: flex; flex-direction: column; gap: var(--gap); }

/* --- Header -------------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--rule);
}
@supports not (backdrop-filter: blur(1px)) {
  .site-header { background: var(--surface); }
}

.site-header__bar {
  display: flex; align-items: center; gap: 1rem;
  min-height: 4rem;
}

.brand {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: var(--step-1);
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.brand:hover { color: var(--ink); text-decoration: none; }
.brand__mark {
  display: grid; place-items: center;
  width: 2rem; height: 2rem; flex: none;
  border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink);
  font-size: .95rem;
}

.site-nav { display: flex; align-items: center; gap: .25rem; margin-inline-start: auto; }
.site-nav__link {
  padding: .45rem .7rem;
  border-radius: var(--radius-pill);
  color: var(--ink-soft); font-size: var(--step--1); font-weight: 600;
  text-decoration: none; white-space: nowrap;
}
.site-nav__link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.site-nav__link.is-active { color: var(--accent); background: var(--accent-wash); }

.icon-btn {
  display: grid; place-items: center;
  width: 2.25rem; height: 2.25rem; flex: none;
  border: 1px solid var(--rule); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--ink-soft);
  cursor: pointer; padding: 0;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

/* Mobile nav: the links collapse behind a toggle under 48rem. */
.nav-toggle { display: none; }
@media (max-width: 48rem) {
  .nav-toggle { display: grid; }
  /* Search stays visible on mobile - it is the primary way in - so the brand
     gives up its wordmark to make room rather than squeezing the input. */
  .brand { font-size: 0; gap: 0; }
  .brand__mark { font-size: .95rem; }
  .site-header__bar { gap: .5rem; }
  .site-nav {
    display: none;
    position: absolute; inset-inline: 0; top: 100%;
    flex-direction: column; align-items: stretch; gap: .15rem;
    padding: .6rem 1rem 1rem;
    background: var(--surface); border-bottom: 1px solid var(--rule);
    box-shadow: var(--shadow-md);
  }
  .site-nav.is-open { display: flex; }
  .site-nav__link { padding: .6rem .75rem; border-radius: var(--radius-sm); }
}

/* --- Search -------------------------------------------------------------- */
.search {
  display: flex; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-pill);
  padding: .35rem .35rem .35rem .9rem;
  box-shadow: var(--shadow-sm);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1 1 auto; min-width: 0;
  border: 0; background: none; color: var(--ink);
  font: inherit; padding: .35rem 0;
}
.search input::placeholder { color: var(--ink-faint); }
.search input:focus { outline: none; }
.search button {
  flex: none; display: grid; place-items: center;
  width: 2.1rem; height: 2.1rem; padding: 0;
  border: 0; border-radius: var(--radius-pill);
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
}
.search button:hover { background: var(--accent-hover); }

/* --- Live search dropdown ------------------------------------------------ */
.search-wrap { position: relative; flex: 1 1 16rem; min-width: 0; max-width: 30rem; }

.search-results {
  position: absolute; inset-inline: 0; top: calc(100% + .4rem);
  z-index: 60;
  max-height: min(70vh, 32rem); overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: .35rem;
}

.sr__group {
  padding: .5rem .65rem .3rem;
  font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint);
}

.sr__row {
  display: flex; align-items: baseline; gap: .5rem;
  padding: .5rem .65rem;
  border-radius: var(--radius-sm);
  color: var(--ink); text-decoration: none;
  font-size: var(--step--1);
}
.sr__row:hover, .sr__row.is-active {
  background: var(--accent-wash); color: var(--accent); text-decoration: none;
}
.sr__prefix { color: var(--accent); font-weight: 700; flex: none; }
.sr__text {
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sr__meta { flex: none; color: var(--ink-faint); font-size: .75rem; font-variant-numeric: tabular-nums; }
.sr__row.is-active .sr__meta { color: inherit; }

/* A caption result pairs a link with its own copy button. */
.sr__quote { display: flex; align-items: center; gap: .3rem; }
.sr__quote .sr__row { flex: 1 1 auto; min-width: 0; }
.sr__copy { flex: none; padding: .3rem .6rem; font-size: .75rem; }

.sr__all {
  justify-content: center;
  margin-top: .25rem; border-top: 1px solid var(--rule);
  color: var(--accent); font-weight: 600;
}
.sr__empty { padding: 1rem .65rem; color: var(--ink-soft); font-size: var(--step--1); text-align: center; }

/* --- Intro blurb --------------------------------------------------------- */
.intro {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: .5rem;
}
.intro h1 { font-size: var(--step-2); }
.intro p { margin: 0; color: var(--ink-soft); font-size: var(--step-0); }

/* --- Caption card -------------------------------------------------------
   The repeating unit across home, topic, author, search and tag pages.
   Built to be scanned and copied, not read as prose.
   ------------------------------------------------------------------------ */
.caption {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem 1.25rem 1rem;
  display: flex; flex-direction: column; gap: .85rem;
  transition: box-shadow .18s ease, border-color .18s ease;
}
.caption:hover { box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--accent) 28%, var(--rule)); }

.caption__meta { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .6rem;
  border-radius: var(--radius-pill);
  background: var(--accent-wash); color: var(--accent);
  font-size: var(--step--1); font-weight: 600;
  text-decoration: none; line-height: 1.6;
}
.chip:hover { background: var(--accent); color: var(--accent-ink); text-decoration: none; }
.chip--quiet { background: var(--surface-2); color: var(--ink-soft); }
.chip--quiet:hover { background: var(--ink-soft); color: var(--surface); }

.caption__text {
  margin: 0;
  font-size: var(--step-1);
  line-height: 1.85;
  color: var(--ink);
  white-space: pre-line;   /* captions carry meaningful line breaks */
  overflow-wrap: anywhere;
}
.caption__text a { color: inherit; text-decoration: none; }
.caption__text a:hover { color: var(--accent); text-decoration: none; }

.caption__img { border-radius: var(--radius-sm); overflow: hidden; }

/* Action row: copy is the primary job of this site, so it leads. */
.actions {
  display: flex; align-items: center; gap: .45rem;
  flex-wrap: wrap;
  padding-top: .2rem;
  border-top: 1px solid var(--rule);
  margin-top: .1rem;
}
.actions > .spacer { margin-inline-start: auto; }

.act {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem .8rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: var(--step--1); font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.act:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.act svg { width: 1rem; height: 1rem; flex: none; }

.act--primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.act--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }

/* Copy confirmation. Colour alone does not carry the message: the label
   text changes too, so it survives colour-blindness and greyscale. */
.act.is-done {
  background: var(--good); border-color: var(--good); color: #fff;
}
.act.is-saved { color: var(--accent); border-color: var(--accent); }
.act.is-saved svg { fill: currentColor; }

.act__count {
  font-variant-numeric: tabular-nums;
  font-size: var(--step--1);
  color: var(--ink-faint);
}

/* --- Section headings ---------------------------------------------------- */
.section-head {
  display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap;
  margin-bottom: .25rem;
}
.section-head h2 { font-size: var(--step-2); }
.section-head .count { color: var(--ink-faint); font-size: var(--step--1); font-variant-numeric: tabular-nums; }

/* --- Chip cloud (topics, tags) ------------------------------------------- */
.cloud { display: flex; flex-wrap: wrap; gap: .45rem; }

/* --- Sidebar ------------------------------------------------------------- */
.sidebar { display: flex; flex-direction: column; gap: var(--gap); }
.widget {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: .8rem;
}
.widget__title {
  font-size: var(--step--1); font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint); margin: 0;
}
.widget ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.widget li a { color: var(--ink); font-size: var(--step--1); text-decoration: none; }
.widget li a:hover { color: var(--accent); }

/* --- Ads ----------------------------------------------------------------
   Wrapper is unstyled apart from spacing: AdSense must not be boxed in a way
   that could look like site chrome, and must never be clipped.
   ------------------------------------------------------------------------ */
.ad { margin: 0; overflow: hidden; }
.ad--infeed { padding: .25rem 0; }

/* --- Pagination ---------------------------------------------------------- */
.pagi { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; padding-block: 1.5rem .5rem; }
.pagi a, .pagi span {
  min-width: 2.4rem; padding: .45rem .7rem;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-soft);
  text-align: center; font-size: var(--step--1); font-weight: 600; text-decoration: none;
}
.pagi a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.pagi .active, .pagi .current {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
/* The pagination class emits Bootstrap-shaped markup; neutralise its list. */
.pagi ul { list-style: none; display: flex; flex-wrap: wrap; gap: .35rem; margin: 0; padding: 0; }

/* --- Loader / feed states ------------------------------------------------ */
.feed-status {
  padding: 1.25rem; text-align: center;
  color: var(--ink-faint); font-size: var(--step--1);
}
.spinner {
  width: 1.1rem; height: 1.1rem; display: inline-block; vertical-align: -.2em;
  border: 2px solid var(--rule); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Toast --------------------------------------------------------------- */
.toast {
  position: fixed; inset-inline: 0; bottom: 1.25rem;
  margin-inline: auto; width: max-content; max-width: calc(100% - 2rem);
  z-index: 100;
  padding: .6rem 1.1rem;
  border-radius: var(--radius-pill);
  background: var(--ink); color: var(--ground);
  font-size: var(--step--1); font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(.5rem);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

/* --- Letters (authors page) ---------------------------------------------- */
.letters { display: flex; flex-wrap: wrap; gap: .3rem; }
.letters a {
  display: grid; place-items: center;
  min-width: 2.1rem; height: 2.1rem; padding-inline: .4rem;
  border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-soft);
  font-size: var(--step--1); font-weight: 600; text-decoration: none;
}
.letters a:hover, .letters a.selected {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); text-decoration: none;
}

/* --- Grids --------------------------------------------------------------- */
.grid-cards {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}

/* --- Page content (static pages) ----------------------------------------- */
.prose {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.prose :where(p, ul, ol) { color: var(--ink-soft); }
.prose :where(h2, h3) { margin-block: 1.25rem .5rem; color: var(--ink); }
.prose img { border-radius: var(--radius-sm); }

/* --- Empty state --------------------------------------------------------- */
.empty {
  background: var(--surface); border: 1px dashed var(--rule);
  border-radius: var(--radius); padding: 2.5rem 1.5rem;
  text-align: center; color: var(--ink-soft);
  display: flex; flex-direction: column; gap: .75rem; align-items: center;
}

/* --- Footer -------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--rule);
  background: var(--surface);
  padding-block: 2rem;
  margin-top: 2rem;
}
.site-footer__inner {
  display: flex; flex-wrap: wrap; gap: 1rem 2rem;
  align-items: center; justify-content: space-between;
  color: var(--ink-soft); font-size: var(--step--1);
}
.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--accent); }
.footer-links { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }

/* --- Tables (defensive: legacy content may include them) ----------------- */
.prose table { width: 100%; border-collapse: collapse; }
.prose :where(td, th) { border-bottom: 1px solid var(--rule); padding: .5rem; text-align: start; }

/* Wide content must scroll inside itself, never the page body. */
.scroll-x { overflow-x: auto; }
