/* Public pages and the chat: front page, about, sign-in and sign-up, chat app.
   A jewellery house's look: pearl and midnight grounds, sapphire ink, champagne gold;
   serif display headings over IBM Plex text; hallmark stamps mark every source. */

@font-face { font-family: "Plex"; src: url("fonts/plex-sans-latin-400.woff2") format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0000-024F, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex"; src: url("fonts/plex-sans-latin-500.woff2") format("woff2"); font-weight: 500; font-display: swap; unicode-range: U+0000-024F, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex"; src: url("fonts/plex-sans-latin-600.woff2") format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0000-024F, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex"; src: url("fonts/plex-sans-thai-400.woff2") format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex"; src: url("fonts/plex-sans-thai-500.woff2") format("woff2"); font-weight: 500; font-display: swap; unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex"; src: url("fonts/plex-sans-thai-600.woff2") format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Mono"; src: url("fonts/plex-mono-latin-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/plex-mono-latin-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
/* Display: Cormorant Garamond for Latin, Noto Serif Thai for Thai (both variable). */
@font-face { font-family: "Gem Display"; src: url("fonts/cormorant-garamond-latin.woff2") format("woff2"); font-weight: 300 700; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Gem Display"; src: url("fonts/noto-serif-thai.woff2") format("woff2"); font-weight: 300 700; font-display: swap; unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }

:root {
  --paper: #f7f5f0;        /* pearl */
  --paper-2: #efebe2;
  --card: #fffefb;
  --ink: #121a2b;          /* midnight sapphire text */
  --ink-soft: #5b6273;
  --line: #e4ded2;
  --sapphire: #1c4876;
  --sapphire-ink: #ffffff;
  --sapphire-tint: #e8eef6;
  --primary: #1c4876;      /* main buttons */
  --on-primary: #ffffff;
  --gold: #8a6406;         /* assay gold, for text and stamps */
  --gold-line: #c6a052;
  --gold-tint: #f6eedb;
  --champagne-1: #e6c886;  /* gold buttons */
  --champagne-2: #c99c48;
  --on-gold: #1d1606;
  --glow: rgba(28, 72, 118, 0.10);
  --shadow: rgba(18, 26, 43, 0.45);
  --danger: #a3261f;
  --focus: #8a6406;
  --radius: 14px;
  --sans: "Plex", "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  --mono: "Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --display: "Gem Display", "Cormorant Garamond", "Noto Serif Thai", Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0b0f1a;      /* midnight velvet */
    --paper-2: #10162a;
    --card: #131a2b;
    --ink: #efeae0;        /* pearl text */
    --ink-soft: #a6abb8;
    --line: #252d42;
    --sapphire: #9fc2ea;
    --sapphire-ink: #0b0f1a;
    --sapphire-tint: #1b2740;
    --primary: #ece6d8;    /* pearl buttons on midnight */
    --on-primary: #0b0f1a;
    --gold: #e3bd62;
    --gold-line: #a8843a;
    --gold-tint: #2a2414;
    --champagne-1: #edd394;
    --champagne-2: #c9a04e;
    --on-gold: #1a1305;
    --glow: rgba(90, 140, 210, 0.16);
    --shadow: rgba(0, 0, 0, 0.7);
    --danger: #ff8f87;
    --focus: #e3bd62;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
}
a { color: var(--sapphire); text-underline-offset: 0.18em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.inline { display: inline; }
h1, h2, h3 { text-wrap: balance; }
:lang(th) { line-height: 1.75; }

/* Serif display headings; Thai needs more room for its tone marks. */
.display { font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; line-height: 1.05; }
:lang(th) .display, .display:lang(th) { font-weight: 500; letter-spacing: 0; line-height: 1.4; }

/* --- shared pieces -------------------------------------------------------------------- */

.mark { width: 28px; height: 28px; flex: none; }
.mark-body { fill: var(--sapphire); }
.mark-cut { fill: none; stroke: var(--gold-line); stroke-width: 1.4; stroke-linejoin: round; }

.wordmark {
  display: inline-flex; align-items: center; gap: 0.6rem; min-width: 0;
  color: var(--ink); text-decoration: none; font-weight: 600; letter-spacing: -0.01em;
}
.wordmark span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 2.6rem; padding: 0 1.15rem; border: 1px solid var(--primary);
  border-radius: 999px; background: var(--primary); color: var(--on-primary);
  font: 500 0.95rem/1 var(--sans); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.button:hover { filter: brightness(1.08); }
.button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.button-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.button-quiet:hover { border-color: var(--gold-line); filter: none; }
.button-gold {
  border-color: transparent; color: var(--on-gold);
  background: linear-gradient(160deg, var(--champagne-1), var(--champagne-2));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 8px 20px -12px var(--champagne-2);
}
.button-link {
  padding: 0; border: 0; background: none; color: var(--sapphire);
  font: inherit; font-size: 0.85rem; cursor: pointer; text-decoration: underline;
  text-underline-offset: 0.18em;
}
.button-link.danger { color: var(--danger); }
.icon-button {
  display: inline-grid; place-items: center; width: 2.4rem; height: 2.4rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  color: var(--ink); font-size: 1.3rem; cursor: pointer;
}
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.aside, .note { color: var(--ink-soft); font-size: 0.875rem; }
.error { color: var(--danger); }
.notice {
  margin: 0 0 1rem; padding: 0.7rem 1rem; border-radius: 10px;
  background: var(--sapphire-tint); color: var(--ink);
}

/* English / ไทย */
.lang-switch {
  display: inline-flex; flex: none; padding: 2px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--card);
}
.lang-switch a {
  padding: 0.22rem 0.6rem; border-radius: 999px; color: var(--ink-soft);
  font: 500 0.78rem/1.3 var(--sans); text-decoration: none;
}
.lang-switch a:hover { color: var(--ink); }
.lang-switch a[aria-current] { background: var(--ink); color: var(--paper); }

/* The hallmark: a struck assay stamp, used for every source. */
.hallmark {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.45em; height: 1.45em; margin: 0 0.1em 0 0.2em; padding: 0 0.3em;
  border: 1.5px solid var(--gold-line); background: var(--gold-tint); color: var(--gold);
  font: 500 0.78em/1 var(--mono); letter-spacing: 0.02em; vertical-align: 0.12em;
  clip-path: polygon(0.32em 0, calc(100% - 0.32em) 0, 100% 0.32em, 100% calc(100% - 0.32em),
                     calc(100% - 0.32em) 100%, 0.32em 100%, 0 calc(100% - 0.32em), 0 0.32em);
  text-decoration: none;
}
a.cite { text-decoration: none; }
a.cite .hallmark, a.cite.hallmark { cursor: pointer; }
a.cite:hover .hallmark, a.cite.hallmark:hover { background: var(--gold-line); color: var(--card); }

/* --- top bar of the public pages -------------------------------------------------------- */

.site-top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  width: min(72rem, 100% - 2rem); margin: 0 auto; padding: 0.9rem 0;
}
.site-nav { display: flex; align-items: center; gap: 0.6rem; }
.nav-link { padding: 0.3rem 0.4rem; color: var(--ink-soft); font-size: 0.92rem; text-decoration: none; }
.nav-link:hover { color: var(--ink); }

/* --- about page --------------------------------------------------------------------------- */

.landing {
  min-height: 100vh; display: flex; flex-direction: column;
  background:
    radial-gradient(60rem 32rem at 85% -10%, var(--glow), transparent 70%),
    var(--paper);
}
.landing-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem;
  width: min(72rem, 100% - 2rem); margin: auto auto 0; padding: 1.25rem 0;
  border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 0.875rem;
}
.landing-main { width: min(72rem, 100% - 2rem); margin: 0 auto; }

.hero {
  display: grid; grid-template-columns: 1.05fr 1fr; gap: clamp(2rem, 5vw, 4.5rem);
  align-items: center; padding: clamp(2rem, 7vw, 5rem) 0 clamp(2.5rem, 6vw, 4.5rem);
}
.eyebrow {
  margin: 0 0 1rem; color: var(--gold); font: 500 0.76rem/1.4 var(--mono);
  letter-spacing: 0.14em; text-transform: uppercase;
}
:lang(th) .eyebrow { font-family: var(--sans); font-size: 0.85rem; letter-spacing: 0.02em; }
.hero h1 { margin: 0 0 1.25rem; font-size: clamp(2.6rem, 5.6vw, 4.4rem); }
:lang(th) .hero h1 { font-size: clamp(2rem, 4.2vw, 3.2rem); }
.lede { margin: 0 0 2rem; max-width: 36rem; color: var(--ink-soft); font-size: 1.08rem; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem; }
.hero-aside { margin: 0.9rem 0 0; }

.specimen {
  margin: 0; padding: 1.25rem; border: 1px solid var(--line); border-radius: 20px;
  background: var(--card); box-shadow: 0 40px 70px -50px var(--shadow);
  position: relative;
}
.specimen::before {
  content: ""; position: absolute; inset: -1px -1px auto; height: 3px; border-radius: 20px 20px 0 0;
  background: linear-gradient(90deg, transparent, var(--champagne-2), transparent);
}
.specimen-q {
  margin-left: auto; max-width: 85%; padding: 0.75rem 1rem; border-radius: 16px 16px 4px 16px;
  background: var(--sapphire-tint); font-weight: 500;
}
.specimen-a { padding: 1rem 0.25rem 0.25rem; }
.specimen-a p { margin: 0 0 1rem; }
.specimen figcaption { padding-top: 0.75rem; border-top: 1px dashed var(--line); color: var(--ink-soft); font-size: 0.8rem; }
.hallmarks { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 0.75rem; padding: 0; list-style: none; }
.hallmarks li {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.3rem 0.65rem 0.3rem 0.35rem;
  border: 1px solid var(--line); border-radius: 999px; font-size: 0.82rem; color: var(--ink-soft);
}
.hallmarks .hallmark { margin: 0; vertical-align: 0; }

.facets {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 0 0 5rem;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line);
}
.facet { padding: 1.6rem; background: var(--card); }
.facet-mark {
  display: inline-grid; place-items: center; width: 2.1rem; height: 2.1rem; margin: 0 0 1rem;
  border: 1.5px solid var(--gold-line); border-radius: 50%; color: var(--gold);
  font: 600 1.05rem/1 var(--display);
}
.facet-mark.hallmark { border-radius: 0; font: 500 0.9rem/1 var(--mono); }
.facet h2 { margin: 0 0 0.5rem; font-size: 1.05rem; font-weight: 600; }
.facet p { margin: 0; color: var(--ink-soft); font-size: 0.95rem; }

.section-head { max-width: 40rem; margin: 0 0 2rem; }
.section-head h2, .library h2 { margin: 0 0 0.75rem; font-size: clamp(2rem, 4vw, 2.8rem); }
.section-head > p:last-child { margin: 0; color: var(--ink-soft); }

.models-intro { margin: 0 0 3rem; }
.kinds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.kind {
  padding: 1.4rem 1.5rem; border: 1px solid var(--line); border-top: 3px solid var(--gold-line);
  border-radius: 6px 6px var(--radius) var(--radius); background: var(--card);
}
.kind h3 { margin: 0 0 0.4rem; font: 600 1.6rem/1.15 var(--display); }
:lang(th) .kind h3 { font-weight: 500; font-size: 1.35rem; line-height: 1.5; }
.kind p { margin: 0; color: var(--ink-soft); font-size: 0.95rem; }

.ways {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 0 0 5rem;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line);
}
.way { padding: 1.5rem 1.6rem; background: var(--paper-2); }
.way h3 { margin: 0 0 0.35rem; font-size: 1.05rem; font-weight: 600; }
.way p { margin: 0 0 0.75rem; color: var(--ink-soft); font-size: 0.95rem; }
.way a { font-weight: 500; text-decoration: none; }

.library { margin: 0 0 5rem; }
.library > p { margin: 0 0 1.25rem; color: var(--ink-soft); }
.publishers { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0; padding: 0; list-style: none; }
.publishers li {
  padding: 0.45rem 0.85rem; border: 1px solid var(--gold-line); border-radius: 6px;
  background: var(--card); font: 500 0.82rem/1.3 var(--mono); color: var(--ink);
}

/* --- sign-in and sign-up -------------------------------------------------------------------- */

.entry { position: relative; background: radial-gradient(50rem 30rem at 50% -10%, var(--glow), transparent 70%), var(--paper); }
.entry-top { position: absolute; top: 1rem; right: 1rem; }
.entry-main {
  display: flex; flex-direction: column; align-items: center; gap: 1.5rem;
  min-height: 100vh; padding: 11vh 1rem 3rem;
}
.entry-card {
  width: min(25rem, 100%); padding: 2rem; border: 1px solid var(--line);
  border-radius: 20px; background: var(--card); box-shadow: 0 30px 60px -45px var(--shadow);
}
.entry-card h1 { margin: 0 0 0.5rem; font: 600 2rem/1.1 var(--display); }
:lang(th) .entry-card h1 { font-weight: 500; font-size: 1.6rem; line-height: 1.45; }
.entry-lede { margin: 0 0 1.25rem; color: var(--ink-soft); font-size: 0.92rem; }
.entry-card form { margin-top: 1.25rem; }
.entry-card label { display: block; margin-bottom: 1rem; font-size: 0.9rem; color: var(--ink-soft); }
.entry-card input {
  display: block; width: 100%; margin-top: 0.35rem; padding: 0.65rem 0.8rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--paper);
  color: var(--ink); font: inherit;
}
.entry-card input:focus { border-color: var(--sapphire); outline: none; }
.hint { display: block; margin-top: 0.3rem; font-size: 0.78rem; }
.entry-card .button { width: 100%; margin-top: 0.5rem; }
.entry-card .aside { margin: 1.25rem 0 0; }
.entry-back { color: var(--ink-soft); font-size: 0.875rem; }

/* --- chat app ------------------------------------------------------------------------------ */

.app { height: 100vh; overflow: hidden; }
.shell { display: grid; grid-template-columns: 17.5rem 1fr; height: 100vh; height: 100dvh; }

.rail {
  display: flex; flex-direction: column; gap: 1rem; min-height: 0; padding: 1rem;
  border-right: 1px solid var(--line); background: var(--paper-2);
}
.rail-head { display: flex; align-items: center; justify-content: space-between; }
.rail-close, .rail-open, .scrim { display: none; }
.new-chat { width: 100%; background: var(--card); color: var(--ink); border-color: var(--line); }
.new-chat:hover { border-color: var(--gold-line); filter: none; }
.new-chat svg { stroke: var(--gold); }
.history { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -0.5rem; }
.history-list { margin: 0; padding: 0; list-style: none; }
.history-list a {
  display: block; padding: 0.45rem 0.6rem; border-radius: 8px; color: var(--ink);
  font-size: 0.9rem; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-list a:hover { background: var(--card); }
.history-list a[aria-current="page"] { background: var(--card); box-shadow: inset 2px 0 0 var(--gold-line); font-weight: 500; }
.history-empty { padding: 0 0.6rem; color: var(--ink-soft); font-size: 0.875rem; }

.rail-foot { display: grid; gap: 0.6rem; padding-top: 0.75rem; border-top: 1px solid var(--line); font-size: 0.875rem; }
.rail-foot > a { color: var(--ink-soft); text-decoration: none; }
.rail-foot summary { cursor: pointer; color: var(--ink-soft); }
.rail-admin a { display: block; padding: 0.2rem 0 0.2rem 0.75rem; }
.rail-privacy p { margin: 0.5rem 0; color: var(--ink-soft); font-size: 0.82rem; }
.rail-privacy form { margin: 0 0 0.5rem; }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.9rem; }
.account-name { font-weight: 500; margin-right: auto; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-top {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 1.5rem;
  border-bottom: 1px solid var(--line);
}
.stage-title {
  flex: 1; margin: 0; font-size: 0.95rem; font-weight: 500; color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread { flex: 1; min-height: 0; overflow-y: auto; padding: 1.5rem 1.5rem 2rem; scroll-behavior: smooth; }
.thread > * { max-width: 46rem; margin-left: auto; margin-right: auto; }

/* An empty chat sits in the middle of the screen, as in other chat apps; the first
   question moves the box to the bottom. */
.stage:has(#welcome) .thread { flex: 0 1 auto; margin-top: auto; padding-bottom: 1rem; }
.stage:has(#welcome) .composer { margin-bottom: auto; padding-bottom: 2rem; }

.welcome { padding: 2rem 0 1rem; text-align: center; }
.welcome .mark { width: 46px; height: 46px; }
.welcome h1 { margin: 1rem 0 0.5rem; font: 600 clamp(2rem, 4.5vw, 3rem)/1.1 var(--display); letter-spacing: -0.01em; }
.welcome h1:lang(th), :lang(th) .welcome h1 { font-weight: 500; font-size: clamp(1.7rem, 3.6vw, 2.4rem); line-height: 1.45; }
.welcome > p { margin: 0 auto 2rem; max-width: 32rem; color: var(--ink-soft); }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; text-align: left; }
.suggestion {
  padding: 0.85rem 1rem; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink); font: inherit; font-size: 0.92rem; line-height: 1.5;
  text-align: left; cursor: pointer; transition: border-color 0.15s ease, transform 0.15s ease;
}
.suggestion:hover { border-color: var(--gold-line); transform: translateY(-1px); }

.exchange { margin: 0 auto 2rem; }
.turn-user { display: flex; justify-content: flex-end; margin-bottom: 1rem; }
.question {
  margin: 0; max-width: 80%; padding: 0.7rem 1rem; border-radius: 16px 16px 4px 16px;
  background: var(--sapphire-tint); white-space: pre-wrap; overflow-wrap: anywhere;
}
.turn-assistant { display: grid; grid-template-columns: 2rem 1fr; gap: 0.75rem; }
.avatar .mark { width: 26px; height: 26px; margin-top: 0.15rem; }
.reply { min-width: 0; }
.answer { overflow-wrap: anywhere; }
.answer ul { margin: 0.4rem 0 0.6rem; padding-left: 1.25rem; }
.answer li { margin: 0.2rem 0; }
.answer.refused { color: var(--ink-soft); font-style: italic; }
.provenance {
  margin: 0.6rem 0 0; padding-left: 0.7rem; border-left: 2px solid var(--line);
  color: var(--ink-soft); font-size: 0.8rem;
}
.answer a.cite { display: inline-flex; }
.answer a.cite::before { content: none; }

.guidance {
  margin: 0.9rem 0 0; padding: 0.8rem 1rem; border: 1px dashed var(--line);
  border-radius: 12px; background: var(--card);
}
.guidance p { margin: 0.2rem 0; white-space: pre-line; }
.guidance-label { font: 500 0.72rem/1.4 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }

.sources { display: grid; gap: 0.45rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.sources details { border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.sources summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.15rem 0.5rem;
  padding: 0.5rem 0.75rem; cursor: pointer; list-style: none; font-size: 0.86rem;
}
.sources summary::-webkit-details-marker { display: none; }
.sources .hallmark { margin: 0; vertical-align: 0; }
.source-title { font-weight: 500; }
.where { color: var(--ink-soft); font: 0.78rem/1.4 var(--mono); }
.excerpt {
  margin: 0; padding: 0.6rem 0.9rem 0.8rem; border-top: 1px solid var(--line);
  color: var(--ink-soft); font-size: 0.88rem; white-space: pre-line;
}

.reply-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1rem; margin-top: 0.75rem; }
.reply-meta .note { font-size: 0.8rem; }
.feedback { display: inline-flex; align-items: center; gap: 0.6rem; }
.concept { margin: 0; }
.concept img { display: block; max-width: min(100%, 30rem); height: auto; border-radius: 12px; border: 1px solid var(--line); }
.chart .plot { min-height: 18rem; }

.pending .reply { color: var(--ink-soft); }
.pending .dots::after { content: "…"; animation: blink 1.2s steps(4, end) infinite; }
@keyframes blink { 0% { opacity: 0.2; } 50% { opacity: 1; } 100% { opacity: 0.2; } }

.thread .error { padding: 0.7rem 1rem; border: 1px solid var(--danger); border-radius: 10px; }
.failed .reply { display: grid; justify-items: start; gap: 0.75rem; }
.failed .error { margin: 0; }

.composer { padding: 0 1.5rem 1rem; }
.composer-box, .composer-note { max-width: 46rem; margin: 0 auto; }
.composer-box {
  padding: 0.6rem 0.6rem 0.5rem 1rem; border: 1px solid var(--line); border-radius: 22px;
  background: var(--card); box-shadow: 0 16px 36px -28px var(--shadow);
}
.composer-box:focus-within { border-color: var(--gold-line); }
.composer textarea {
  display: block; width: 100%; max-height: 12rem; padding: 0.35rem 0; border: 0; resize: none;
  background: transparent; color: var(--ink); font: inherit; line-height: 1.5; outline: none;
}
.composer-row { position: relative; display: flex; align-items: center; gap: 0.75rem; }
.send {
  display: grid; place-items: center; width: 2.35rem; height: 2.35rem; flex: none; margin-left: auto;
  border: 0; border-radius: 50%; color: var(--on-gold); cursor: pointer;
  background: linear-gradient(160deg, var(--champagne-1), var(--champagne-2));
}
.send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.send:disabled, .send.htmx-request { opacity: 0.45; cursor: wait; }
.composer-note { margin-top: 0.5rem; color: var(--ink-soft); font-size: 0.75rem; text-align: center; }
.guest-note { font-size: 0.8rem; }
.guest-note strong { color: var(--gold); font-weight: 600; }

/* --- choosing a model --------------------------------------------------------------------- */

.model-chip {
  display: inline-flex; align-items: center; gap: 0.4rem; max-width: 17rem;
  padding: 0.35rem 0.75rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--paper); color: var(--ink); font: 500 0.82rem/1.2 var(--sans);
  text-decoration: none; cursor: pointer; list-style: none; user-select: none;
}
.model-chip::-webkit-details-marker { display: none; }
.model-chip:hover { border-color: var(--gold-line); }
.model-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-chip svg { width: 14px; height: 14px; flex: none; fill: none; stroke: var(--gold); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.model-chip .chev { stroke: var(--ink-soft); transition: transform 0.15s ease; }
.model-menu[open] .chev { transform: rotate(180deg); }

.model-panel {
  position: absolute; bottom: calc(100% + 0.9rem); left: -0.5rem; z-index: 30;
  width: min(27rem, calc(100vw - 2rem)); max-height: min(30rem, 62vh); overflow-y: auto;
  padding: 1.1rem; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); box-shadow: 0 30px 70px -30px var(--shadow);
}
.model-panel-title { margin: 0 0 0.8rem; font: 600 1.5rem/1.1 var(--display); }
:lang(th) .model-panel-title { font-weight: 500; font-size: 1.25rem; line-height: 1.5; }
.model-tabs { display: flex; gap: 0.25rem; margin: 0 0 0.9rem; padding: 0.25rem; border-radius: 999px; background: var(--paper); }
.model-tab {
  flex: 1; padding: 0.4rem 0.7rem; border: 0; border-radius: 999px; background: none;
  color: var(--ink-soft); font: 500 0.85rem/1.3 var(--sans); cursor: pointer;
}
.model-tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px -1px var(--shadow); }
.model-group { display: grid; gap: 0.5rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.model-group + .model-group { margin-top: 1rem; }
.model-group legend { margin-bottom: 0.3rem; padding: 0; font-weight: 600; font-size: 0.9rem; }
.model-panel:has(.model-tabs:not([hidden])) legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.model-panel:has(.model-tabs:not([hidden])) .model-group + .model-group { margin-top: 0; }
.model-group-note { margin: 0 0 0.25rem; color: var(--ink-soft); font-size: 0.82rem; }
.model-card {
  position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.75rem;
  padding: 0.75rem 0.9rem; border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.model-card:hover { border-color: var(--gold-line); }
.model-card input { position: absolute; opacity: 0; pointer-events: none; }
.model-card:has(input:checked) { border-color: var(--gold); background: var(--gold-tint); }
.model-card:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.model-card-body { display: grid; gap: 0.1rem; min-width: 0; }
.model-name { font-weight: 600; font-size: 0.95rem; }
.model-provider { color: var(--gold); font: 500 0.7rem/1.4 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
:lang(th) .model-provider { font-family: var(--sans); letter-spacing: 0; text-transform: none; }
.model-desc { color: var(--ink-soft); font-size: 0.82rem; }
.model-tick { width: 1.15rem; height: 1.15rem; border: 1.5px solid var(--line); border-radius: 50%; }
.model-card:has(input:checked) .model-tick {
  border-color: var(--champagne-2); background: var(--champagne-2);
  box-shadow: inset 0 0 0 3px var(--gold-tint);
}
.model-panel-foot { margin: 0.9rem 0 0; color: var(--ink-soft); font-size: 0.78rem; }

.htmx-indicator { visibility: hidden; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { visibility: visible; }

/* --- the front page for visitors ---------------------------------------------------------- */

.guest .guest-shell {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  background: radial-gradient(56rem 30rem at 50% 0%, var(--glow), transparent 70%), var(--paper);
}
.guest .stage { flex: 1; }

/* --- narrow screens ----------------------------------------------------------------------- */

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .facets, .kinds { grid-template-columns: 1fr; }
  .ways { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(19rem, 86vw);
    transform: translateX(-102%); transition: transform 0.2s ease;
  }
  .rail-open-state .rail { transform: none; }
  .rail-close, .rail-open { display: inline-grid; }
  .rail-open-state .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(12, 19, 34, 0.45); }
  .stage-top, .thread { padding-left: 1rem; padding-right: 1rem; }
  .composer { padding: 0 0.75rem 0.75rem; }
  .suggestions { grid-template-columns: 1fr; }
  .suggestion:nth-child(n+3) { display: none; }
  .question { max-width: 90%; }
  .composer-note { display: none; }
  .guest-note { display: block; }
  .wide-only { display: none; }
  .site-nav { gap: 0.4rem; }
  .site-nav .button { min-height: 2.25rem; padding: 0 0.8rem; font-size: 0.85rem; }
}

@media (max-width: 520px) {
  .site-top .wordmark { flex: none; }
  .site-top .wordmark span { display: none; }
  .nav-link { display: none; }
  .site-nav { gap: 0.3rem; }
  .site-nav .button { padding: 0 0.7rem; }
  .lang-switch a { padding: 0.2rem 0.45rem; }
  .model-chip { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .rail, .suggestion, .model-chip .chev { transition: none; }
  .pending .dots::after { animation: none; }
}
