:root {
  --ground: #f7f6f3;
  --surface: #ffffff;
  --ink: #1d2129;
  --muted: #5d6572;
  --line: #d9d6cf;
  --accent: #0f5c5c;
  --accent-ink: #ffffff;
  --warn-ground: #fdf3e2;
  --warn-ink: #7a4a00;
  --error: #a3261f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #15181d;
    --surface: #1e232a;
    --ink: #e8eaed;
    --muted: #a3abb8;
    --line: #353c47;
    --accent: #5fc4c0;
    --accent-ink: #0d1f1f;
    --warn-ground: #3a2f1a;
    --warn-ink: #f1cf8f;
    --error: #ff8f87;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.55 system-ui, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", sans-serif;
}

a { color: var(--accent); }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 650; color: var(--ink); text-decoration: none; }

nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; }

main { max-width: 52rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.25rem;
}

.narrow { max-width: 24rem; margin: 2rem auto; }

h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.75rem 0 0.75rem; }

label { display: block; margin-bottom: 0.85rem; font-size: 0.9rem; color: var(--muted); }

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
  font: inherit;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 6px;
}

button {
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

button.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
button.link { padding: 0; color: var(--accent); background: none; font-weight: 400; text-decoration: underline; }

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

form.inline { display: inline; }
form.row { display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem; }
form.row label { flex: 1 1 11rem; margin-bottom: 0; }

.error { color: var(--error); font-weight: 600; }
.note { color: var(--muted); font-size: 0.9rem; }

.notice {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  background: var(--warn-ground);
  color: var(--warn-ink);
  border-radius: 6px;
}

code.key { display: block; overflow-wrap: anywhere; font-size: 0.95rem; }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

.ask { display: flex; flex-wrap: wrap; align-items: end; gap: 0.6rem; margin-top: 1rem; }
.ask textarea { flex: 1 1 16rem; margin-top: 0; resize: vertical; }
.ask .model-pick { flex: 1 1 100%; margin: 0; }
.ask .model-pick select { width: auto; max-width: 100%; margin-left: 0.4rem; }
.model-used { margin: 0.3rem 0 0; font-size: 0.8rem; }

.exchange {
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.question { margin: 0 0 0.6rem; font-weight: 650; }
.answer { overflow-wrap: anywhere; }
.answer.refused { color: var(--muted); font-style: italic; }
a.cite { font-size: 0.85em; text-decoration: none; font-weight: 600; }

.sources { margin: 0.9rem 0 0; padding-left: 1.6rem; font-size: 0.9rem; }
.sources li { margin-bottom: 0.45rem; }
.sources li:target { background: var(--warn-ground); color: var(--warn-ink); }
.source-title { font-weight: 600; }
.where { color: var(--muted); }
.excerpt { margin: 0.35rem 0 0; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }

.htmx-indicator { display: none; color: var(--muted); font-size: 0.9rem; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.consent { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.consent .note { margin: 0 0 0.5rem; }
.feedback { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.8rem; }

main:has(.card.wide) { max-width: 72rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.toolbar h2 { margin: 1.5rem 0 0.75rem; }
.stats { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; }
.stat { display: grid; padding: 0.5rem 0.8rem; border: 1px solid var(--line); border-radius: 6px; background: var(--ground); }
.stat b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.8rem; color: var(--muted); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 10rem; }
dd.wrap { overflow-wrap: anywhere; }
.pill { display: inline-block; padding: 0.05rem 0.55rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.pill.ok { background: var(--accent); color: var(--accent-ink); }
.pill.warn { background: var(--warn-ground); color: var(--warn-ink); }
.pill.bad { background: var(--error); color: var(--surface); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0 1rem; align-items: end; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.3rem 1rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.mono { font-family: ui-monospace, Consolas, monospace; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
input[type="file"] { padding: 0.4rem; }
.review { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 1.25rem; align-items: start; }
@media (max-width: 52rem) { .review { grid-template-columns: minmax(0, 1fr); } }
.scan { margin: 0; }
.scan img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.fields { min-width: 0; }
.fields input:not([type="checkbox"]) { width: 100%; min-width: 9rem; margin: 0; }
tr.waiting td { background: var(--warn-ground); }
label.check { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0; font-weight: normal; white-space: nowrap; }
.chart { margin: 0.75rem 0; padding: 0.5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); min-width: 0; }
.chart .plot { width: 100%; height: 22rem; }
.chart figcaption { margin-top: 0.25rem; }
.error-box { margin: 1rem 0; padding: 0.75rem 1rem; border: 1px solid var(--error); border-radius: 6px; }
.error-box > p { margin-top: 0; color: var(--error); }
.error-box table { background: transparent; }
.inline-details { display: inline-block; margin-left: 0.5rem; }
.inline-details summary { cursor: pointer; color: var(--accent); font-size: 0.85rem; }
.inline-details form.row { margin-top: 0.4rem; }
.todo { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.todo-item { display: grid; min-width: 9rem; padding: 0.55rem 0.8rem; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; color: var(--ink); background: var(--ground); }
.todo-item b { font-size: 1.2rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.todo-item span { font-size: 0.85rem; color: var(--muted); }
.bar-cell { width: 40%; min-width: 6rem; }
.week-bar { display: block; height: 0.6rem; border-radius: 3px; background: var(--accent); }
ul.plain { padding-left: 1.2rem; }
ul.plain li { margin: 0.35rem 0; }
.gap { padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.gap-head { display: flex; gap: 0.75rem; align-items: baseline; }
.gap .count { min-width: 2.5rem; text-align: right; font-weight: 700; font-size: 1.1rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.gap p.note { margin: 0.2rem 0 0 3.25rem; }
.gap details { margin-left: 3.25rem; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-bottom: 0.75rem; }
.tabs a[aria-current="page"] { font-weight: 700; text-decoration: none; color: var(--ink); }
blockquote.answer-text { margin: 0.3rem 0 1rem; padding: 0.5rem 0.9rem; border-left: 3px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
fieldset.choices { border: 1px solid var(--line); border-radius: 6px; padding: 0.5rem 0.9rem; margin: 0 0 1rem; display: grid; gap: 0.35rem; }
fieldset.choices label.check { white-space: normal; }
label.check input[type="radio"], label.check input[type="checkbox"] { width: auto; margin: 0; flex: none; }
fieldset.choices label.check { justify-content: flex-start; text-align: left; }
.guide .lead { font-size: 1.05rem; }
.guide .toc { font-size: 0.9rem; margin-bottom: 1rem; }
.guide pre { overflow-x: auto; padding: 0.75rem 1rem; background: var(--ground); border: 1px solid var(--line); border-radius: 6px; font-size: 0.85rem; line-height: 1.45; }
.guide pre.prompt code { white-space: pre-wrap; }
.guide code { font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
.guide h2 { scroll-margin-top: 1rem; }
.concept { margin: 0.5rem 0 0; }
.concept img { display: block; max-width: min(100%, 32rem); height: auto; border-radius: 8px; border: 1px solid var(--line, #ddd); }
.guidance { margin: 0.6rem 0 0; padding: 0.6rem 0.8rem; border-left: 3px solid var(--line); background: color-mix(in srgb, var(--line) 18%, transparent); border-radius: 4px; }
.guidance p { margin: 0.2rem 0; white-space: pre-line; }
.guidance-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
