@font-face {
  font-family: "Claude Serif";
  src: url("/assets/Newsreader-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Claude Serif";
  src: url("/assets/Newsreader-Bold.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: "Fusion Sans";
  src: url("/assets/NotoSansSC-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Fusion Sans";
  src: url("/assets/NotoSansSC-SemiBold.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: light;
  --page: #faf9f5;
  --sidebar: #f3f1e9;
  --surface: #ffffff;
  --surface-hover: #ebe8de;
  --line: #dedbd1;
  --line-strong: #c9c5ba;
  --text: #24231f;
  --muted: #77746d;
  --faint: #a09d95;
  --accent: #d97757;
  --accent-strong: #a64f36;
  --user: #eeece5;
  --success: #2e7550;
  --danger: #b23b32;
  --shadow: 0 10px 30px rgba(39, 36, 29, 0.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--page);
  color: var(--text);
  font-family: "Fusion Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.44; }

.pair-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px 20px;
  background: var(--page);
}

.pair-panel {
  width: min(430px, 100%);
  padding: 20px 10px;
}

.pair-logo {
  width: 52px;
  height: 52px;
  display: block;
  object-fit: contain;
}

.pair-panel h1 {
  margin: 22px 0 2px;
  font-family: "Claude Serif", "Songti SC", serif;
  font-size: 32px;
  line-height: 1.12;
}

.pair-subtitle {
  margin: 0 0 34px;
  color: var(--muted);
  font-size: 14px;
}

.pair-panel label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.pair-panel textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  line-height: 1.5;
}

.pair-panel textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.13);
}

.primary-button {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-weight: 600;
}

.primary-button:hover { background: var(--accent-strong); }
.error-text { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 13px; }

.app-view {
  position: fixed;
  inset: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
}

.sidebar {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  z-index: 20;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.sidebar-head {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
}

.sidebar-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  object-fit: contain;
}

.sidebar-brand {
  font-family: "Claude Serif", "Songti SC", serif;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.05;
}

.sidebar-caption {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.sync-button {
  min-height: 44px;
  margin: 8px 10px 12px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(39, 36, 29, 0.06);
}

.sync-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.sync-label { display: inline-flex; align-items: center; gap: 9px; }
.sync-icon { color: var(--accent-strong); font-size: 18px; line-height: 1; }
.sync-count { min-width: 14px; color: var(--accent-strong); font-size: 12px; text-align: right; }

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 7px 12px;
}

.conversation-item {
  width: 100%;
  min-height: 58px;
  padding: 9px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conversation-item:hover { background: var(--surface-hover); }
.conversation-item.active { background: var(--surface); box-shadow: 0 1px 4px rgba(39, 36, 29, 0.08); }
.conversation-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 600; }
.conversation-meta { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }

.sidebar-foot {
  padding: 13px 15px calc(13px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.server-state { color: var(--muted); font-size: 11px; }
.text-button { margin-top: 8px; padding: 0; border: 0; background: transparent; color: var(--accent-strong); font-size: 11px; }

.chat-shell {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--page);
}

.chat-header {
  position: relative;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
  border-bottom: 1px solid rgba(222, 219, 209, 0.75);
  background: var(--page);
}

.chat-identity {
  min-width: 0;
  max-width: min(480px, calc(100% - 230px));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.header-logo {
  width: 23px;
  height: 23px;
  flex: 0 0 auto;
  object-fit: contain;
}

.chat-heading { min-width: 0; }

.model-control {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-heading select {
  min-width: 0;
  max-width: 390px;
  padding: 0 17px 0 0;
  border: 0;
  outline: none;
  appearance: none;
  background: transparent;
  color: var(--text);
  font-family: "Claude Serif", "Songti SC", serif;
  font-size: 16px;
  font-weight: 700;
  text-overflow: ellipsis;
}

.model-chevron {
  margin-left: -13px;
  color: var(--muted);
  font-size: 15px;
  pointer-events: none;
}

.chat-heading h2 {
  max-width: 390px;
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-family: "Fusion Sans", sans-serif;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-state {
  position: absolute;
  right: 20px;
  max-width: 170px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-state::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-right: 6px;
  display: inline-block;
  border-radius: 50%;
  background: var(--faint);
  vertical-align: 1px;
}

.memory-state.active { color: var(--success); }
.memory-state.active::before { background: var(--success); }

.message-list {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 30px max(24px, calc((100% - 800px) / 2)) 58px;
  scrollbar-color: var(--line-strong) transparent;
}

.message-row { margin: 0 0 27px; }
.message-row.user { display: flex; justify-content: flex-end; }

.message-bubble {
  max-width: 86%;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  color: var(--text);
  font-size: 15px;
  line-height: 1.72;
}

.message-row.user .message-bubble {
  padding: 10px 14px;
  border-radius: 8px 8px 2px 8px;
  background: var(--user);
}

.message-row.assistant .message-bubble { max-width: 100%; }

.message-label {
  margin-bottom: 7px;
  color: var(--accent-strong);
  font-family: "Claude Serif", "Songti SC", serif;
  font-size: 15px;
  font-weight: 700;
}

.message-time { margin-top: 7px; color: var(--faint); font-size: 10px; line-height: 1.2; }
.typing { color: var(--muted); }

.empty-state {
  min-height: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--muted);
}

.empty-logo { width: 54px; height: 54px; object-fit: contain; }
.empty-state h3 { margin: 8px 0 0; color: var(--text); font-family: "Claude Serif", "Songti SC", serif; font-size: 25px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 12px; }

.composer-wrap {
  padding: 9px max(20px, calc((100% - 820px) / 2)) calc(10px + env(safe-area-inset-bottom));
  background: var(--page);
}

.status-line { min-height: 18px; padding: 0 5px 4px; color: var(--muted); font-size: 11px; }
.status-line.error { color: var(--danger); }

.composer {
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  align-items: end;
  gap: 8px;
  padding: 7px 7px 7px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 3px 14px rgba(39, 36, 29, 0.07);
}

.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(217, 119, 87, 0.11); }

.composer textarea {
  min-height: 38px;
  max-height: 160px;
  resize: none;
  padding: 8px 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  line-height: 1.45;
}

.composer textarea::placeholder { color: var(--muted); }

.send-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  color: var(--surface);
  font-size: 21px;
  line-height: 1;
}

.composer-note { min-height: 17px; padding-top: 5px; color: var(--faint); font-size: 9px; text-align: center; }

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 21px;
}

.icon-button:hover { background: var(--surface-hover); }
.mobile-only { display: none; }
.sidebar-backdrop { position: fixed; inset: 0; z-index: 15; background: rgba(25, 24, 21, 0.34); }

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #20211e;
    --sidebar: #272823;
    --surface: #2d2e29;
    --surface-hover: #363731;
    --line: #42433d;
    --line-strong: #55564f;
    --text: #f1efe8;
    --muted: #aaa79f;
    --faint: #817f78;
    --accent: #df7d5c;
    --accent-strong: #ef9c80;
    --user: #393a35;
    --success: #7abe92;
    --danger: #ef8178;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
  }
}

@media (max-width: 760px) {
  .app-view { display: block; }
  .mobile-only { display: grid; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    transform: translateX(-102%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }
  .chat-shell { height: 100%; }

  .chat-header {
    min-height: 68px;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) minmax(0, 82px);
    gap: 6px;
    padding: 7px 9px;
  }

  .chat-identity {
    position: static;
    max-width: 100%;
    justify-self: center;
    gap: 6px;
  }

  .header-logo { width: 21px; height: 21px; }
  .chat-heading { max-width: calc(100vw - 170px); }
  .chat-heading select { max-width: calc(100vw - 185px); font-size: 14px; }
  .chat-heading h2 { max-width: calc(100vw - 185px); font-size: 10px; }

  .memory-state {
    position: static;
    max-width: 82px;
    justify-self: end;
    font-size: 10px;
  }

  .memory-state::before { display: none; }
  .message-list { padding: 24px 16px 42px; }
  .message-bubble { max-width: 92%; font-size: 15px; }
  .message-row { margin-bottom: 25px; }
  .composer-wrap { padding: 7px 10px calc(7px + env(safe-area-inset-bottom)); }
  .composer-note { display: none; }
  .pair-panel { padding: 18px 2px; }
  .pair-panel h1 { font-size: 29px; }
}

@media (max-width: 420px) {
  .chat-heading { max-width: calc(100vw - 180px); }
  .chat-heading select,
  .chat-heading h2 { max-width: calc(100vw - 180px); }
  .message-list { padding-right: 14px; padding-left: 14px; }
}
