:root {
  --writing-size: 16px;
  --writing-family: var(--sans);
  --theme-button-ink: #fffdf9;
  --theme-button-fill: var(--wine);
  --theme-button-hover: var(--wine-dark);
  --theme-button-disabled: #a2878c;
  --theme-field: #faf7f0;
  --theme-hover: #eae2d7;
  --theme-quiet-hover: #2c251909;
  --theme-user: #f1ece3;
  --theme-user-line: #eae2d6;
  --theme-avatar: #e1ebe4;
  --theme-avatar-ink: #3e5e51;
  --theme-code: #eee8de;
  --theme-code-block: #f2eee6;
  --theme-input-hint: #7d7468;
  --theme-input-focus: #ac7581;
}

:root[data-appearance-font="serif"] { --writing-family: var(--serif); }
:root[data-appearance-font="mono"] { --writing-family: ui-monospace, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace; }

:root[data-appearance-background="white"] {
  --ink: #26252b;
  --muted: #605d66;
  --paper: #fff;
  --sidebar: #f3f3f6;
  --surface: #fff;
  --line: #e3e1e8;
  --line-strong: #c9c7d1;
  --theme-field: #fff;
  --theme-hover: #e8e7ef;
  --theme-user: #f5f4f8;
  --theme-user-line: #e5e3ee;
  --theme-code: #ececf2;
  --theme-code-block: #f3f3f7;
  --theme-input-hint: #6d6875;
}

:root[data-appearance-background="sage"] {
  --ink: #263229;
  --muted: #526458;
  --paper: #f2f6ef;
  --sidebar: #e5eee3;
  --surface: #fcfdf9;
  --line: #d7e1d4;
  --line-strong: #bacbbd;
  --wine: #385f49;
  --wine-dark: #294a37;
  --wine-light: #dceadc;
  --teal: #396b52;
  --theme-field: #f6faf5;
  --theme-hover: #d9e7d8;
  --theme-quiet-hover: #3f604b13;
  --theme-user: #e8f0e5;
  --theme-user-line: #dbe7d9;
  --theme-avatar: #d8eadd;
  --theme-avatar-ink: #335843;
  --theme-code: #e0ebe1;
  --theme-code-block: #eaf1e8;
  --theme-input-hint: #5c6f60;
  --theme-input-focus: #678a74;
  --theme-button-disabled: #647a6b;
}

:root[data-appearance-background="night"] {
  color-scheme: dark;
  --ink: #f5eeeb;
  --muted: #c5b9ba;
  --paper: #211f23;
  --sidebar: #2a252b;
  --surface: #302a31;
  --line: #494249;
  --line-strong: #71636d;
  --wine: #dfa1b1;
  --wine-dark: #ffc4d1;
  --wine-light: #51343e;
  --teal: #9bd5b9;
  --theme-button-ink: #312027;
  --theme-button-disabled: #ac959f;
  --theme-field: #231f24;
  --theme-hover: #3b3039;
  --theme-quiet-hover: #f6d8e019;
  --theme-user: #2e2830;
  --theme-user-line: #4b3e47;
  --theme-avatar: #344739;
  --theme-avatar-ink: #c2e3cb;
  --theme-code: #3c323c;
  --theme-code-block: #2c252d;
  --theme-input-hint: #c4b3bf;
  --theme-input-focus: #d592a6;
}

:is(.message-content, .composer textarea, .revision-dialog textarea, .appearance-preview) {
  font-family: var(--writing-family);
  font-size: var(--writing-size);
}
:root[data-appearance-font]:not([data-appearance-font="default"]) .markdown :is(h1,h2,h3,h4,h5,h6) {
  font-family: var(--writing-family);
}
.message-content.markdown table { font-size: .9em; }
.revision-dialog .dialog-content textarea { font-size: var(--writing-size); }
.primary, .send, .brand-mark { color: var(--theme-button-ink); background: var(--theme-button-fill); }
.primary:hover, .send:not(:disabled):hover { background: var(--theme-button-hover); }
.send:disabled { color: var(--theme-button-ink); background: var(--theme-button-disabled); }
.quiet:hover, button.picker-choice:hover { background: var(--theme-quiet-hover); }
.search { background: var(--theme-field); }
.history-item:hover { background: var(--theme-hover); }
.message.user { background: var(--theme-user); border-color: var(--theme-user-line); }
.user-avatar { color: var(--theme-avatar-ink); background: var(--theme-avatar); }
.markdown code, .markdown th { background: var(--theme-code); }
.markdown pre { background: var(--theme-code-block); }
.markdown pre code { background: transparent; }
.composer:focus-within { border-color: var(--theme-input-focus); }
.composer textarea::placeholder { color: var(--theme-input-hint); }
.appearance-size span { display: flex; justify-content: space-between; gap: .7rem; }
.appearance-size output { color: var(--muted); font-variant-numeric: tabular-nums; }
.dialog-content .appearance-size input[type="range"] { min-height: 2rem; padding: 0; border: 0; background: transparent; accent-color: var(--wine); }
.appearance-preview { padding: .68rem .76rem; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: .45rem; background: var(--paper); color: var(--ink); line-height: 1.58; }
.appearance-preview strong, .appearance-preview span { display: block; }
:root:not([data-appearance-font]), :root[data-appearance-font="default"] { --preview-heading-family: var(--serif); }
.appearance-preview strong { font-family: var(--preview-heading-family, var(--writing-family)); }

@media (max-width: 380px) {
  #appearance-settings .field-grid { grid-template-columns: 1fr; }
}
