/* ============================================================
   Reader — Claude-inspired readability pass (v2)
   ------------------------------------------------------------
   Warm cream page, slate ink, one terracotta accent.
   Serif for assistant prose, sans for UI + user text, mono for code.
   Separation by space + tone, not by borders.
   ============================================================ */

:root {
  /* Warm neutrals (cream family) */
  --bg-page:      hsl(48 33% 97%);          /* page body — the "cream"   */
  --bg-panel:     hsl(53 28% 94.5%);        /* user bubble, soft panels  */
  --bg-sunken:    hsl(50 20% 91%);          /* code, deeper surface      */
  --bg-raised:    hsl(0 0% 100%);           /* lifted cards when needed  */

  /* Ink (olive-warm near-black through mid-gray) */
  --ink:          hsl(60 3% 10%);
  --ink-1:        hsl(55 4% 22%);           /* body text                 */
  --ink-2:        hsl(50 4% 38%);           /* secondary                 */
  --ink-3:        hsl(48 4% 54%);           /* tertiary / metadata       */
  --ink-4:        hsl(46 5% 70%);           /* hairline / faint          */

  /* Warm quiet separators */
  --line:         hsl(45 10% 86%);
  --line-soft:    hsl(45 10% 91%);

  /* Single terracotta accent */
  --accent:       hsl(15 58% 52%);
  --accent-soft:  hsl(22 60% 92%);
  --accent-ink:   hsl(15 55% 38%);

  /* Semantic role tints — low chroma so they don't fight the page */
  --think-tint:   hsl(280 18% 95%);
  --think-ink:    hsl(280 12% 38%);

  --tool-tint:    hsl(210 22% 95.5%);
  --tool-ink:     hsl(215 18% 34%);

  --ok-tint:      hsl(150 24% 94.5%);
  --ok-ink:       hsl(155 32% 28%);

  --err-tint:     hsl(12 42% 94.5%);
  --err-ink:      hsl(8 55% 38%);

  --attach-tint:  hsl(130 22% 95%);
  --attach-ink:   hsl(140 24% 30%);

  /* Type */
  --font-serif:   "Source Serif 4", "Source Serif Pro", "Songti SC", "Noto Serif CJK SC", Georgia, "Times New Roman", serif;
  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", "SF Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;

  /* Column widths — Claude uses ~46rem for assistant prose */
  --col-read:     min(46rem, calc(100% - 48px));
  --col-wide:     min(52rem, calc(100% - 48px));

  /* Shadows — almost imperceptible, warm */
  --sh-1: 0 1px 0 hsl(45 15% 80% / 0.45);
  --sh-2: 0 2px 8px -4px hsl(40 20% 30% / 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--ink-1);
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.72;
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body { min-height: 100vh; }

::selection { background: var(--accent-soft); color: var(--accent-ink); }

/* =========================================================
   Page chrome — sticky, minimal
   ========================================================= */

.page-head {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-page) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(14px);
  -webkit-backdrop-filter: saturate(1.2) blur(14px);
}

.head-inner {
  max-width: var(--col-wide);
  margin: 0 auto;
  padding: 18px 0 14px;
  display: flex;
  gap: 32px;
  align-items: center;
  justify-content: space-between;
}

.head-left { display: flex; gap: 12px; align-items: center; min-width: 0; }

.logomark {
  display: inline-flex;
  gap: 3px;
  padding: 5px 6px;
  border-radius: 6px;
  background: var(--bg-panel);
  align-items: center;
}
.logomark .dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--ink-4);
}
.logomark .dot:first-child { background: var(--accent); }

.head-titles .kicker {
  font-family: var(--font-sans);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  line-height: 1;
  margin-bottom: 3px;
}
.head-titles h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
  line-height: 1.2;
  font-family: var(--font-sans);
}

.head-right { display: flex; gap: 16px; align-items: center; }

dl.meta {
  display: flex;
  gap: 18px;
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
}
dl.meta > div { display: flex; flex-direction: column; }
dl.meta dt {
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-4);
  font-weight: 500;
  line-height: 1;
  margin-bottom: 3px;
}
dl.meta dd {
  margin: 0;
  font-size: 12px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 1;
}

.toolbar { display: flex; gap: 4px; }
.tbtn {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tbtn:hover { background: var(--bg-panel); color: var(--ink); }
.tbtn[aria-pressed="false"] {
  color: var(--ink-4);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
.tbtn-ico { font-size: 13px; opacity: 0.85; }

.rule {
  max-width: var(--col-wide);
  margin: 0 auto;
  height: 1px;
  background: var(--line-soft);
}

/* =========================================================
   Thread
   ========================================================= */

.thread {
  max-width: var(--col-read);
  margin: 0 auto;
  padding: 48px 0 96px;
}

.loading {
  text-align: center;
  color: var(--ink-4);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 96px 0;
}

/* =========================================================
   Message blocks — separated by air, not lines
   ========================================================= */

.msg {
  position: relative;
  margin: 0 0 56px;
  scroll-margin-top: 120px;
}

.msg-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-family: var(--font-sans);
}

.msg-role {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-1);
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.msg-role .avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 600;
  font-family: var(--font-sans);
  letter-spacing: 0;
  flex-shrink: 0;
}

.msg.user .msg-role .avatar {
  background: var(--bg-sunken);
  color: var(--ink-2);
}
.msg.assistant .msg-role .avatar {
  background: var(--accent);
  color: white;
}

.msg-time {
  font-size: 11.5px;
  font-family: var(--font-sans);
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

.msg-index {
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--ink-4);
  margin-left: auto;
  letter-spacing: 0.04em;
  opacity: 0.6;
  transition: opacity .15s;
}
.msg:hover .msg-index { opacity: 1; }

/* User message — soft cream bubble, no border, generous padding */
.msg.user .msg-body {
  background: var(--bg-panel);
  border-radius: 12px;
  padding: 18px 22px;
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--ink-1);
}
.msg.user .msg-body p { margin: 0 0 0.7em; }
.msg.user .msg-body p:last-child { margin-bottom: 0; }

/* Assistant message — unbordered, just prose */
.msg.assistant .msg-body {
  padding: 0;
}

/* Wrap long unbreakable strings (Base64, tokens, URLs) inside message bubbles.
   <pre> blocks use white-space: pre and are unaffected. */
.msg-body { overflow-wrap: anywhere; word-break: break-word; }
.msg-body, .msg-body p, .msg-body li { min-width: 0; }

/* NSFW strike-through — vulgar terms get visually redacted */
.nsfw {
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  text-decoration-color: currentColor;
  text-decoration-skip-ink: none;
}

/* =========================================================
   Prose (assistant responses)
   ========================================================= */

.prose { color: var(--ink-1); }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child  { margin-bottom: 0; }

.prose p {
  margin: 0 0 1.15em;
  text-wrap: pretty;
}

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 1.9em 0 0.55em;
  line-height: 1.3;
}
.prose h1 { font-size: 22px; }
.prose h2 { font-size: 18px; }
.prose h3 { font-size: 16px; }
.prose h4 { font-size: 14px; color: var(--ink-2); }

.prose ul, .prose ol {
  margin: 0 0 1.15em;
  padding-left: 1.45em;
}
.prose li { margin: 0.35em 0; }
.prose li::marker { color: var(--ink-4); }

.prose strong { font-weight: 600; color: var(--ink); }
.prose em { font-style: italic; }

.prose a {
  color: var(--accent-ink);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
.prose a:hover { text-decoration-color: var(--accent); }

/* Inline code — quiet, no color shift */
.prose :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-sunken);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--ink);
  white-space: nowrap;
  font-weight: 500;
}

/* Code blocks — deeper cream, no border, no left accent, just bg shift */
.prose pre,
.tool-body pre {
  position: relative;
}
.prose pre[data-lang]:not([data-lang=""])::before,
.tool-body pre[data-lang]:not([data-lang=""])::before {
  content: attr(data-lang);
  position: absolute;
  top: 10px;
  right: 12px;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-4);
  pointer-events: none;
  user-select: none;
  z-index: 1;
}
.prose pre {
  margin: 1.3em 0 1.4em;
  padding: 16px 18px;
  background: var(--bg-sunken);
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
}
.prose pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  white-space: pre;
  font-weight: 400;
}

/* --- Syntax highlighting — desaturated, typeset-looking --- */
.hljs                      { color: var(--ink); background: transparent; }
.hljs-keyword,
.hljs-selector-tag,
.hljs-built_in,
.hljs-type                 { color: hsl(280 30% 38%); font-weight: 500; }
.hljs-string,
.hljs-regexp,
.hljs-attribute            { color: hsl(15 50% 40%); }
.hljs-number,
.hljs-literal              { color: hsl(30 55% 38%); }
.hljs-attr,
.hljs-variable,
.hljs-template-variable    { color: hsl(160 32% 32%); }
.hljs-title,
.hljs-title.class_,
.hljs-title.function_,
.hljs-name,
.hljs-section              { color: hsl(215 40% 38%); font-weight: 500; }
.hljs-comment,
.hljs-quote,
.hljs-meta                 { color: var(--ink-3); font-style: italic; }
.hljs-tag                  { color: hsl(215 25% 42%); }
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-punctuation          { color: var(--ink-2); }
.hljs-params               { color: var(--ink); }
.hljs-emphasis             { font-style: italic; }
.hljs-strong               { font-weight: 600; }

/* Tables */
.prose table {
  border-collapse: collapse;
  margin: 1.3em 0;
  font-size: 14.5px;
  font-family: var(--font-sans);
  width: 100%;
}
.prose th, .prose td {
  text-align: left;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.prose th {
  font-weight: 600;
  color: var(--ink-2);
  border-bottom: 1.5px solid var(--ink-4);
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.prose tbody tr:hover { background: var(--bg-panel); }

.prose hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2em 0;
}

.prose blockquote {
  margin: 1.2em 0;
  padding: 0.2em 1.1em;
  border-left: 2px solid var(--line);
  color: var(--ink-2);
  font-style: italic;
}

/* =========================================================
   Thinking block — tinted, borderless, quiet
   ========================================================= */

.thinking {
  margin: 10px 0 22px;
  background: var(--think-tint);
  border-radius: 8px;
  font-family: var(--font-sans);
  overflow: hidden;
  transition: background .2s;
}

.thinking summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 12px;
  color: var(--think-ink);
  font-weight: 500;
}
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::marker { display: none; }
.thinking summary:hover { background: color-mix(in srgb, var(--think-tint) 60%, var(--bg-panel)); }

.thinking .t-icon { font-size: 13px; opacity: 0.75; }
.thinking .t-label {
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-size: 10.5px;
}
.thinking .t-preview {
  color: var(--think-ink);
  opacity: 0.72;
  font-style: italic;
  font-family: var(--font-serif);
  font-size: 13.5px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thinking .t-chev {
  margin-left: auto;
  transition: transform .2s;
  color: var(--think-ink);
  opacity: 0.5;
  font-family: var(--font-mono);
  font-size: 12px;
}
.thinking[open] > summary .t-chev { transform: rotate(90deg); }
.thinking[open] > summary .t-preview { display: none; }

.thinking .t-actions {
  display: inline-flex;
  gap: 6px;
  margin-left: 4px;
}
.thinking .t-lang {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--think-ink);
  background: hsl(0 0% 100% / 0.6);
  border: 1px solid hsl(0 0% 100% / 0.8);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  transition: background .15s;
}
.thinking .t-lang:hover { background: white; }
.thinking .t-retrans {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--think-ink);
  background: hsl(0 0% 100% / 0.6);
  border: 1px solid hsl(0 0% 100% / 0.8);
  border-radius: 4px;
  padding: 1px 7px;
  cursor: pointer;
  line-height: 1.2;
}
.thinking .t-retrans:hover { background: white; }

.thinking .t-note {
  font-family: var(--font-sans);
  font-style: normal;
  font-size: 11.5px;
  color: var(--think-ink);
  opacity: 0.8;
  background: hsl(0 0% 100% / 0.55);
  border-radius: 4px;
  padding: 5px 9px;
  margin-bottom: 10px;
  display: inline-block;
}
.thinking .t-note[data-loading]::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: 1px;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.thinking .t-body {
  padding: 4px 18px 18px 44px;
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--think-ink);
  font-size: 15px;
  line-height: 1.7;
}
.thinking .t-body p { margin: 0.7em 0; }
.thinking .t-body p:first-child { margin-top: 0.9em; }
.thinking .t-body p:last-child { margin-bottom: 0; }
.thinking .t-body code {
  font-style: normal;
  background: hsl(0 0% 100% / 0.55);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.88em;
}

/* =========================================================
   Tool call / return — borderless, tinted
   ========================================================= */

.tool {
  margin: 8px 0 12px;
  background: var(--tool-tint);
  border-radius: 8px;
  font-family: var(--font-sans);
  overflow: hidden;
}
.tool + .tool { margin-top: -2px; }

.tool summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 12px;
  color: var(--tool-ink);
  font-weight: 500;
}
.tool summary::-webkit-details-marker { display: none; }
.tool summary:hover { background: color-mix(in srgb, var(--tool-tint) 50%, var(--bg-panel)); }

.tool .t-icon { font-size: 12px; opacity: 0.8; }
.tool .t-label {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 10.5px;
}
.tool .t-name {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 4px;
  background: hsl(0 0% 100% / 0.7);
  color: var(--tool-ink);
  font-weight: 500;
}

.tool.ok              { background: var(--ok-tint); }
.tool.ok .t-label     { color: var(--ok-ink); }
.tool.ok .t-name      { color: var(--ok-ink); }
.tool.ok summary:hover{ background: color-mix(in srgb, var(--ok-tint) 50%, var(--bg-panel)); }

.tool.err             { background: var(--err-tint); }
.tool.err .t-label    { color: var(--err-ink); }
.tool.err .t-name     { color: var(--err-ink); }
.tool.err .t-icon     { color: var(--err-ink); opacity: 1; }
.tool.err summary:hover{background: color-mix(in srgb, var(--err-tint) 50%, var(--bg-panel));}

.tool .t-chev {
  margin-left: auto;
  transition: transform .2s;
  color: var(--tool-ink);
  opacity: 0.5;
  font-family: var(--font-mono);
  font-size: 12px;
}
.tool[open] > summary .t-chev { transform: rotate(90deg); }
.tool[open] > summary .t-tool-preview { display: none; }

.t-tool-preview {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.75;
}

.tool-body {
  padding: 0;
  background: hsl(0 0% 100% / 0.6);
}
.tool-body pre {
  margin: 0;
  padding: 12px 16px;
  background: transparent !important;
  border: none;
  border-radius: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink);
  overflow-x: auto;
  max-height: 420px;
  overflow-y: auto;
}

.tool-body pre.truncated::after {
  content: "— truncated, click to expand —";
  display: block;
  text-align: center;
  color: var(--ink-4);
  font-family: var(--font-sans);
  font-style: italic;
  font-size: 11px;
  padding-top: 10px;
}

/* =========================================================
   Attachment block
   ========================================================= */

.attach {
  margin: 10px 0 18px;
  background: var(--attach-tint);
  border-radius: 8px;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--attach-ink);
}
.attach-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--attach-ink);
}
.attach-name {
  font-family: var(--font-mono);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  padding: 2px 7px;
  background: hsl(0 0% 100% / 0.7);
  border-radius: 4px;
}
.attach-size {
  margin-left: auto;
  font-weight: 400;
  opacity: 0.7;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  font-family: var(--font-mono);
}
.attach-body {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  color: var(--ink);
  background: hsl(0 0% 100% / 0.55);
  padding: 12px 16px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

/* =========================================================
   Hidden states via toolbar
   ========================================================= */

body.hide-think .thinking { display: none; }
body.hide-tools .tool     { display: none; }

/* =========================================================
   Footer
   ========================================================= */

.page-foot {
  padding: 36px 0 56px;
  border-top: 1px solid var(--line-soft);
  margin-top: 24px;
}
.foot-inner {
  max-width: var(--col-wide);
  margin: 0 auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-4);
  display: flex;
  gap: 10px;
  align-items: center;
}
.foot-dot { opacity: 0.5; }
.foot-uuid { user-select: all; }

/* =========================================================
   Small screens
   ========================================================= */

@media (max-width: 720px) {
  html, body { font-size: 17px; line-height: 1.68; }
  .head-inner {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 20px 10px;
  }
  .head-right { align-items: flex-start; width: 100%; flex-wrap: wrap; gap: 12px; }
  dl.meta { gap: 14px; flex-wrap: wrap; }
  .toolbar { flex-wrap: wrap; }
  .thread  { padding: 32px 0 64px; }
  .msg     { margin-bottom: 44px; }
  .msg.user .msg-body { padding: 15px 17px; font-size: 15px; }
  .prose pre { font-size: 12px; padding: 12px 14px; }
  .tool-body pre { font-size: 11.5px; padding: 10px 13px; }
  .msg-index { display: none; }
  :root { --col-read: calc(100% - 32px); --col-wide: calc(100% - 32px); }
}

/* =========================================================
   Print
   ========================================================= */
@media print {
  body { background: white; }
  .page-head { position: static; background: white; }
  .toolbar, .msg-index, .t-chev { display: none; }
  body.hide-think .thinking, body.hide-tools .tool { display: block !important; }
  .thinking, .tool, .attach { break-inside: avoid; background: hsl(0 0% 97%); }
  details > *:not(summary) { display: block !important; }
}
