/* CantoAI — site styles
   Quietly authoritative: designed grid, careful type scale, almost no ornament.
   One accent colour, used only where the reader should act. */

:root {
  --bg: #f7f6f2;
  --bg-raised: #ffffff;
  --fg: #202321;
  --fg-muted: #5f6460;
  --line: #dad7cf;
  --line-strong: #b9b5ab;
  --accent: #b8432e;        /* 5.0:1 on --bg, white text on it 5.4:1 (WCAG AA) */
  --accent-ink: #ffffff;
  --tag-model: #3a7d6b;
  --tag-paper: #6b5fa5;
  --code-bg: #efede7;

  --font-sans: "Source Sans 3", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  --measure: 70ch;
  --container: 72rem;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1d1c;
    --bg-raised: #232625;
    --fg: #ece9e1;
    --fg-muted: #a5a9a3;
    --line: #343836;
    --line-strong: #4a4f4c;
    --accent: #e67560;
    --accent-ink: #1b1d1c;
    --tag-model: #6fb8a3;
    --tag-paper: #a99de0;
    --code-bg: #2a2d2c;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1d1c;
  --bg-raised: #232625;
  --fg: #ece9e1;
  --fg-muted: #a5a9a3;
  --line: #343836;
  --line-strong: #4a4f4c;
  --accent: #e67560;
  --accent-ink: #1b1d1c;
  --tag-model: #6fb8a3;
  --tag-paper: #a99de0;
  --code-bg: #2a2d2c;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light dark; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  font-feature-settings: "kern", "liga", "tnum";
}
html:lang(zh) body { line-height: 1.7; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 var(--s3); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 2.25rem; }
h2 { font-size: 1.5rem; margin-top: var(--s7); }
h3 { font-size: 1.125rem; }
p  { margin: 0 0 var(--s4); max-width: var(--measure); }
a  { color: var(--accent); text-decoration: none; text-underline-offset: 0.15em; }
a:hover, a:focus-visible { text-decoration: underline; }
/* links inside running text are underlined, so colour is not the only cue (WCAG 1.4.1) */
p a, li a, .small a, .prose a, .doc a { text-decoration: underline; text-decoration-thickness: 1px; }
.btn, .chip, .tag, .site-nav a, .wordmark, .thread-title, .card h3 a, .card .card-title a { text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
code, pre, .mono { font-family: var(--font-mono); font-size: 0.9em; }
pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4);
  overflow-x: auto;
  max-width: 100%;
  line-height: 1.5;
}
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s7) 0; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--fg-muted); font-size: 0.875rem; white-space: nowrap; }
.table-wrap { overflow-x: auto; margin: var(--s4) 0; }

.container { max-width: var(--container); margin: 0 auto; padding: 0 var(--s5); }
.muted { color: var(--fg-muted); }
.small { font-size: 0.875rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* The release filter toggles the `hidden` attribute; elements with an explicit
   display (e.g. .card is flex) would otherwise override the browser default. */
[hidden] { display: none !important; }

/* ---------- header ---------- */
/* keep anchor targets (#files, #cite) clear of the sticky header */
html { scroll-padding-top: 76px; }
.skip-link {
  position: absolute; left: var(--s3); top: -100px; z-index: 20;
  background: var(--bg-raised); color: var(--fg); padding: var(--s2) var(--s3);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.skip-link:focus { top: var(--s2); }
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.site-header .container {
  display: flex; align-items: center; gap: var(--s5);
  min-height: 60px;
}
.wordmark {
  color: var(--fg); font-weight: 600; font-size: 1.125rem; letter-spacing: -0.01em;
  text-decoration: none; white-space: nowrap;
}
.wordmark:hover { text-decoration: none; }
.wordmark { display: inline-flex; align-items: center; gap: var(--s2); }
.wordmark .mark { width: 28px; height: 28px; border-radius: 50%; }
.mascot { display: block; margin-bottom: var(--s4); width: 160px; height: auto; }
.wordmark span { font-weight: 400; }
.site-nav { display: flex; gap: var(--s5); margin-left: var(--s3); }
.site-nav a {
  color: var(--fg-muted); font-weight: 500; padding: var(--s2) 0;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--fg); text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); }
.header-tools { margin-left: auto; display: flex; align-items: center; gap: var(--s3); }
.lang-toggle {
  background: none; border: 1px solid var(--line-strong); color: var(--fg);
  font: inherit; font-size: 0.875rem; font-weight: 600;
  padding: 4px 10px; border-radius: var(--radius); cursor: pointer; line-height: 1.4;
}
.lang-toggle:hover { border-color: var(--fg); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: 10px 18px; border-radius: var(--radius);
  font: inherit; font-weight: 600; line-height: 1.2; cursor: pointer;
  border: 1px solid var(--accent); text-decoration: none;
  transition: background-color .12s, color .12s, border-color .12s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(0.93); text-decoration: none; }
.btn-secondary { background: transparent; color: var(--accent); }
.btn-secondary:hover { background: var(--accent); color: var(--accent-ink); text-decoration: none; }
.btn-small { padding: 6px 12px; font-size: 0.875rem; }
.btn-ghost { border-color: var(--line-strong); color: var(--fg); background: transparent; }
.btn-ghost:hover { border-color: var(--fg); text-decoration: none; }
.ext::after { content: "\2197"; font-size: 0.85em; margin-left: 2px; }

/* ---------- hero ---------- */
.hero { padding: var(--s8) 0 var(--s7); border-bottom: 1px solid var(--line); }
.kicker { color: var(--accent); font-weight: 600; font-size: 0.875rem; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: var(--s3); }
html:lang(zh) .kicker { letter-spacing: 0.15em; }
.hero h1 { font-size: clamp(2.25rem, 5vw, 3.25rem); margin-bottom: var(--s4); }
.hero .tagline { font-size: 1.25rem; color: var(--fg-muted); max-width: 60ch; margin-bottom: var(--s5); }
.hero .actions { display: flex; flex-wrap: wrap; gap: var(--s3); margin-bottom: var(--s6); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s4); max-width: 44rem; }
.stat { border-top: 2px solid var(--line-strong); padding-top: var(--s2); }
.stat .value { font-size: 1.75rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--fg-muted); font-size: 0.875rem; }

/* ---------- sections ---------- */
.section { padding: var(--s7) 0; }
.section + .section { border-top: 1px solid var(--line); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s4); }
.section-head h2 { margin: 0; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s4); }
.card {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s5); display: flex; flex-direction: column; gap: var(--s3);
}
.card h3, .card .card-title { margin: 0; font-size: 1.125rem; }
.card p { margin: 0; color: var(--fg-muted); }
.card .meta { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.card .foot { margin-top: auto; padding-top: var(--s2); }
.tag {
  display: inline-block; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--fg-muted);
  text-transform: uppercase;
}
html:lang(zh) .tag { letter-spacing: 0.08em; }
.tag-dataset { border-color: var(--accent); color: var(--accent); }
.status { font-size: 0.8125rem; color: var(--fg-muted); }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); margin-right: 6px; vertical-align: middle; }
.status-live::before { background: var(--accent); }

/* status panel (home, pre-release) */
.panel { background: var(--bg-raised); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: var(--s5); max-width: var(--measure); }
.panel .meta { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-bottom: var(--s3); }
.panel h3 { margin-bottom: var(--s2); }
.panel p:last-child { margin-bottom: 0; }

/* steps */
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s5); counter-reset: step; margin-bottom: var(--s4); }
.step { border-top: 1px solid var(--line-strong); padding-top: var(--s3); }
.step::before { counter-increment: step; content: counter(step, decimal-leading-zero); font-family: var(--font-mono); color: var(--accent); font-size: 0.8125rem; display: block; margin-bottom: var(--s2); }
.step h3 { margin-bottom: var(--s1); }
.step p { color: var(--fg-muted); margin: 0; font-size: 0.9375rem; }

/* latest */
.latest { list-style: none; margin: 0; padding: 0; max-width: var(--measure); }
.latest li { display: grid; grid-template-columns: 7ch 1fr; gap: var(--s4); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.latest time { color: var(--fg-muted); font-variant-numeric: tabular-nums; }

/* timeline (public contribution record) */
.timeline { list-style: none; margin: var(--s6) 0 var(--s5); padding: 0; max-width: 60rem; }
.timeline li { display: grid; grid-template-columns: 11ch 1fr; gap: var(--s5); padding: var(--s4) 0; border-bottom: 1px solid var(--line); }
.timeline time { color: var(--fg-muted); font-variant-numeric: tabular-nums; padding-top: 2px; white-space: nowrap; }
.timeline a { color: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 0.2em; }
.timeline a:hover { text-decoration-color: var(--accent); }
.timeline .meta { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-bottom: var(--s1); }
.timeline .who { font-size: 0.875rem; color: var(--fg-muted); }
@media (max-width: 720px) { .timeline li { grid-template-columns: 1fr; gap: var(--s1); } }

/* cite block */
.cite-box { position: relative; }
.cite-box .btn { position: absolute; top: var(--s3); right: var(--s3); }
.cite-box .reference { margin: 0 0 var(--s3); padding: var(--s4) 10rem var(--s4) var(--s4); background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--radius); font-size: 0.9375rem; line-height: 1.6; max-width: none; word-break: break-all; }

/* ---------- releases ---------- */
.filters { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s4) 0 var(--s5); }
.chip {
  font: inherit; font-size: 0.875rem; font-weight: 500; cursor: pointer;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: transparent; color: var(--fg);
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.empty { color: var(--fg-muted); padding: var(--s6) 0; border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; }

/* ---------- release detail ---------- */
.page-head { padding: var(--s7) 0 var(--s5); border-bottom: 1px solid var(--line); }
.page-head .meta { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; margin-bottom: var(--s3); }
.page-head h1 { margin-bottom: var(--s3); }
.page-head .lead { font-size: 1.125rem; color: var(--fg-muted); max-width: 60ch; }
.page-head .contact-line { margin: var(--s3) 0 0; }
.page-head .contact-line a { color: var(--fg); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 0.2em; }
.layout { display: grid; grid-template-columns: 1fr; gap: var(--s6); padding-top: var(--s6); }
@media (min-width: 900px) { .layout { grid-template-columns: 200px minmax(0, 1fr); } }
.toc { position: sticky; top: 76px; align-self: start; font-size: 0.875rem; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc a { display: block; padding: 4px 0 4px var(--s3); color: var(--fg-muted); border-left: 2px solid transparent; margin-left: -1px; }
.toc a:hover { color: var(--fg); text-decoration: none; }
.toc a.active { color: var(--fg); border-left-color: var(--accent); }
.doc .steps { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s4); }
.doc h2 { font-size: 1.25rem; margin-top: var(--s6); padding-top: var(--s5); border-top: 1px solid var(--line); }
.doc h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.notice { margin-bottom: var(--s4); border: 1px solid var(--line-strong); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: var(--s3) var(--s4); max-width: var(--measure); }
.licence-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s4); }
.licence-grid .card p { color: var(--fg); }

/* ---------- prose pages ---------- */
.prose h2 { margin-top: var(--s6); }
.prose ul { padding-left: 1.2em; max-width: var(--measure); }
.themes { display: grid; gap: var(--s4); counter-reset: theme; }
.theme { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s5); background: var(--bg-raised); }
.theme::before { counter-increment: theme; content: counter(theme); font-family: var(--font-mono); color: var(--accent); font-size: 0.8125rem; }
.theme h3 { margin: var(--s1) 0 var(--s2); }
.theme p { margin: 0; color: var(--fg-muted); }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s5); max-width: var(--measure); }
.dl dt { color: var(--fg-muted); }
.dl dd { margin: 0; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); margin-top: var(--s8); padding: var(--s6) 0; color: var(--fg-muted); font-size: 0.875rem; }
.site-footer .container { display: flex; flex-wrap: wrap; gap: var(--s4) var(--s6); justify-content: space-between; }
.site-footer a { color: inherit; }
.site-footer a:hover { color: var(--fg); }

/* ---------- responsive ---------- */
/* Below 900px the navigation moves to its own line and wraps rather than
   scrolling sideways, so every item (Upload, Sign in, the language toggle)
   stays on screen. */
@media (max-width: 900px) {
  html { scroll-padding-top: 116px; }
  .site-header .container { flex-wrap: wrap; row-gap: 0; padding-top: var(--s2); padding-bottom: var(--s2); }
  .site-nav { order: 3; width: 100%; margin-left: 0; flex-wrap: wrap; gap: 0 var(--s4); padding-bottom: var(--s1); }
  .header-tools { margin-left: auto; }
}
@media (max-width: 720px) {
  /* on phones the header scrolls away instead of taking a sixth of the screen */
  .site-header { position: static; }
  html { scroll-padding-top: var(--s3); }
  .site-nav a[href="/"] { display: none; }   /* the wordmark already links home */
  .hero { padding: var(--s7) 0 var(--s6); }
  h2 { margin-top: var(--s6); }
  .cite-box .btn { position: static; margin-bottom: var(--s3); }
  .cite-box .reference { padding-right: var(--s4); word-break: normal; overflow-wrap: anywhere; }
}
@media print {
  .site-header, .site-footer, .lang-toggle, .btn { display: none !important; }
  body { background: #fff; color: #000; }
}

/* ---------- platform app (forms, uploads, account) ---------- */
.tag-model { border-color: var(--tag-model); color: var(--tag-model); }
.tag-paper { border-color: var(--tag-paper); color: var(--tag-paper); }
.user-link { font-size: 0.875rem; font-weight: 600; text-decoration: none; color: var(--fg); padding: 4px 6px; }
.user-link[aria-current="page"] { text-decoration: underline; text-underline-offset: 4px; }
.flash { border-left: 3px solid var(--accent); background: var(--bg-raised); padding: var(--s2) var(--s4); margin: var(--s4) 0; border-radius: var(--radius); }
.form { max-width: var(--measure); margin-bottom: var(--s7); }
.form.narrow { max-width: 28rem; }
.field { margin-bottom: var(--s4); }
.field label { display: block; font-weight: 600; margin-bottom: var(--s1); }
.field .req { color: var(--accent); }
.field input:not([type=checkbox]), .field select, .field textarea {
  width: 100%; box-sizing: border-box; font: inherit; color: var(--fg); background: var(--bg-raised);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 8px 10px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.field .help { margin-top: var(--s1); }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--accent); }
.error { color: var(--accent); }
.notice.error { border-left-color: var(--accent); }
.form .actions { display: flex; gap: var(--s3); flex-wrap: wrap; margin-top: var(--s5); }
.form ul.errorlist, .notice ul { margin: 0; padding-left: 1.2em; }
.uploader { margin: var(--s4) 0 var(--s7); max-width: var(--measure); }
.uploader .bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin: var(--s3) 0 var(--s2); }
.uploader .fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
#files td .btn { white-space: nowrap; }
#files form { margin: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.dropzone {
  display: flex; flex-direction: column; gap: var(--s2); align-items: center; text-align: center;
  padding: var(--s6) var(--s5); border: 2px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--bg-raised); cursor: pointer; transition: border-color .12s, background-color .12s;
}
#pick:focus-visible + .dropzone { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--code-bg); }
.dropzone strong { font-size: 1.0625rem; }
.dropzone span { max-width: 60ch; }
#queue { margin-top: var(--s3); }

/* ---------- thinking (discussion) ---------- */
.threads { list-style: none; margin: var(--s4) 0 var(--s7); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-raised); }
.threads li { display: flex; gap: var(--s4); align-items: flex-start; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.threads li:last-child { border-bottom: 0; }
.threads .thread-main { flex: 1; min-width: 0; }
.threads .thread-title { font-weight: 600; color: var(--fg); margin-right: var(--s2); }
.threads .thread-meta { white-space: nowrap; padding-top: 2px; }
.threads .tag { vertical-align: middle; text-transform: none; letter-spacing: 0; }
.state-badge { display: inline-block; font-size: 0.8125rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; color: #fff; }
.state-badge.open { background: #3a7d6b; }
.state-badge.closed { background: #6b5fa5; }
.post, .comment { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4) var(--s5); margin-bottom: var(--s4); max-width: var(--measure); }
/* Posts and titles are user text: one unbroken 300-character token must not
   scroll the page. .page-head h1 carries a thread title on /thinking/<n>/. */
.post, .comment, .post-body, .threads .thread-title, .threads li, .latest li, .page-head h1 { overflow-wrap: anywhere; }
.post-body p { max-width: none; }
.post-body p:last-child { margin-bottom: 0; }
.post-actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s3); }
.post-actions form { display: inline-flex; gap: var(--s2); margin: 0; }
a.chip { text-decoration: none; }
/* .latest li is a grid, so a block-level form would take a cell of its own;
   the unpin control rides along inside the meta text instead. */
.latest .inline-form { display: inline; margin: 0; }
.inline-form { display: inline; margin: 0; }
.rules { padding-left: 1.2em; max-width: var(--measure); }
.cmdline { margin: var(--s3) 0; }
.cmdline summary { cursor: pointer; color: var(--accent); }
.cmdline pre { margin: var(--s2) 0; overflow-x: auto; }
@media (max-width: 720px) {
  /* each file on its own block: name and size, then the whole checksum */
  .files-table thead { display: none; }
  .files-table tr { display: block; padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
  .files-table td { display: block; border: 0; padding: 2px 0; }
  .files-table td.sha { word-break: break-all; }
}
.rules li { margin: var(--s1) 0; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.h-sub { font-size: 0.55em; font-weight: 400; }
.history { list-style: none; padding: 0; }
.history li { margin: var(--s1) 0; }
.history time { color: var(--fg-muted); margin-right: var(--s2); font-variant-numeric: tabular-nums; }
.earlier { margin: var(--s3) 0; }
.earlier summary { cursor: pointer; }
.pager { display: flex; gap: var(--s4); align-items: center; margin: var(--s5) 0; }
.notice .actions { margin-top: var(--s2); display: flex; gap: var(--s2); flex-wrap: wrap; }
