* { box-sizing: border-box; }

:root {
  --bg: #f6efe4;
  --panel: #fff8ee;
  --panel-2: #fffdf8;
  --line: rgba(61, 41, 24, 0.14);
  --text: #3d2918;
  --muted: #8a684c;
  --accent: #d4522a;
  --accent-2: #b56a14;
  --ok: #5d7340;
  --danger: #c0392b;
  --on-accent: #fff8ee;
  --hover: rgba(212, 82, 42, 0.12);
  --input: #fff8ee;
  --topbar: #fff8ee;
  --shadow: rgba(61, 41, 24, 0.16);
  --mask: rgba(61, 41, 24, 0.35);
  --radius: 12px;
  --radius-input: 8px;
  --topbar-edge: 1px solid rgba(61, 41, 24, 0.14);
  --btn-pad-y: 2px;
  --btn-pad-x: 8px;
  --btn-font: 12px;
  --switch-w: 28px;
  --switch-h: 16px;
  --switch-knob: 12px;
  --person-popup-font: 12px;
  --brand-logo-h: 70px;
  --switch-off: #6e6e6e;
  --switch-thumb: #fff8ee;
  --switch-edge: rgba(0, 0, 0, 0.4);
  color-scheme: light;
}

html[data-theme="cream"] {
  --bg: #f6efe4;
  --panel: #fff8ee;
  --panel-2: #fffdf8;
  --line: rgba(61, 41, 24, 0.14);
  --text: #3d2918;
  --muted: #8a684c;
  --accent: #d4522a;
  --accent-2: #b56a14;
  --ok: #5d7340;
  --danger: #c0392b;
  --on-accent: #fff8ee;
  --hover: rgba(212, 82, 42, 0.12);
  --input: #fff8ee;
  --topbar: #fff8ee;
  --shadow: rgba(61, 41, 24, 0.16);
  --mask: rgba(61, 41, 24, 0.35);
  --radius: 12px;
  --radius-input: 8px;
  --topbar-edge: 1px solid rgba(61, 41, 24, 0.14);
  --switch-off: #6e6e6e;
  --switch-thumb: #fff8ee;
  --switch-edge: rgba(0, 0, 0, 0.4);
  color-scheme: light;
}

html[data-theme="menu"] {
  --bg: #efe4cc;
  --panel: #f7efd8;
  --panel-2: #fff8e6;
  --line: rgba(45, 36, 22, 0.18);
  --text: #2c2416;
  --muted: #7a6a4a;
  --accent: #5d7340;
  --accent-2: #b85a1a;
  --ok: #5d7340;
  --danger: #c0392b;
  --on-accent: #f7efd8;
  --hover: rgba(93, 115, 64, 0.14);
  --input: #f7efd8;
  --topbar: #f7efd8;
  --shadow: rgba(45, 36, 22, 0.14);
  --mask: rgba(45, 36, 22, 0.35);
  --radius: 8px;
  --radius-input: 6px;
  --topbar-edge: 1px solid rgba(45, 36, 22, 0.22);
  --switch-off: #6e6e6e;
  --switch-thumb: #fff8e6;
  --switch-edge: rgba(0, 0, 0, 0.4);
  color-scheme: light;
}

html[data-theme="jam"] {
  --bg: #fde8ee;
  --panel: #fff5f7;
  --panel-2: #fffafb;
  --line: rgba(200, 30, 74, 0.16);
  --text: #3d1824;
  --muted: #a05670;
  --accent: #c81e4a;
  --accent-2: #d97706;
  --ok: #5d7340;
  --danger: #c81e4a;
  --on-accent: #fff5f7;
  --hover: rgba(200, 30, 74, 0.12);
  --input: #fff5f7;
  --topbar: #fff5f7;
  --shadow: rgba(80, 16, 32, 0.14);
  --mask: rgba(80, 16, 32, 0.35);
  --radius: 16px;
  --radius-input: 10px;
  --topbar-edge: 1px solid rgba(200, 30, 74, 0.2);
  --switch-off: #6e6e6e;
  --switch-thumb: #fffafb;
  --switch-edge: rgba(0, 0, 0, 0.4);
  color-scheme: light;
}

html[data-theme="citrus"] {
  --bg: #f3f0b8;
  --panel: #fbfae0;
  --panel-2: #fffee8;
  --line: rgba(80, 60, 8, 0.16);
  --text: #3a2e10;
  --muted: #8a7040;
  --accent: #e07a00;
  --accent-2: #4f8a22;
  --ok: #4f8a22;
  --danger: #c0392b;
  --on-accent: #fff8e0;
  --hover: rgba(224, 122, 0, 0.14);
  --input: #fbfae0;
  --topbar: #fbfae0;
  --shadow: rgba(80, 60, 8, 0.14);
  --mask: rgba(80, 60, 8, 0.35);
  --radius: 12px;
  --radius-input: 8px;
  --topbar-edge: 1px solid rgba(80, 60, 8, 0.18);
  --switch-off: #6e6e6e;
  --switch-thumb: #fffee8;
  --switch-edge: rgba(0, 0, 0, 0.4);
  color-scheme: light;
}

html[data-theme="night"] {
  --bg: #1c1612;
  --panel: #2a221c;
  --panel-2: #332a22;
  --line: rgba(232, 165, 75, 0.16);
  --text: #f3e6d4;
  --muted: #a89078;
  --accent: #e8a54b;
  --accent-2: #d4c4a8;
  --ok: #7e9a6a;
  --danger: #c0392b;
  --on-accent: #1c1612;
  --hover: rgba(232, 165, 75, 0.14);
  --input: #221c18;
  --topbar: #2a221c;
  --shadow: rgba(0, 0, 0, 0.45);
  --mask: rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --radius-input: 8px;
  --topbar-edge: 1px solid rgba(232, 165, 75, 0.2);
  --switch-off: #8a8a8a;
  --switch-thumb: #f3e6d4;
  --switch-edge: rgba(255, 255, 255, 0.35);
  color-scheme: dark;
}

html[data-theme="ink"] {
  --bg: #f4ead6;
  --panel: #fbf6ea;
  --panel-2: #fffdf6;
  --line: rgba(139, 90, 43, 0.18);
  --text: #2a1810;
  --muted: #8b5a2b;
  --accent: #c41e3a;
  --accent-2: #8b5a2b;
  --ok: #5d7340;
  --danger: #c0392b;
  --on-accent: #fbf6ea;
  --hover: rgba(196, 30, 58, 0.1);
  --input: #fbf6ea;
  --topbar: #fbf6ea;
  --shadow: rgba(42, 24, 16, 0.14);
  --mask: rgba(42, 24, 16, 0.35);
  --radius: 6px;
  --radius-input: 4px;
  --topbar-edge: 4px solid #c41e3a;
  --switch-off: #6e6e6e;
  --switch-thumb: #fffdf6;
  --switch-edge: rgba(0, 0, 0, 0.4);
  color-scheme: light;
}

html[data-theme="matcha"] {
  --bg: #e7f0d8;
  --panel: #f3f8ea;
  --panel-2: #f9fcef;
  --line: rgba(90, 138, 56, 0.18);
  --text: #243318;
  --muted: #6a7d52;
  --accent: #5a8a38;
  --accent-2: #b8862a;
  --ok: #5a8a38;
  --danger: #c0392b;
  --on-accent: #f3f8ea;
  --hover: rgba(90, 138, 56, 0.12);
  --input: #f3f8ea;
  --topbar: #f3f8ea;
  --shadow: rgba(36, 51, 24, 0.12);
  --mask: rgba(36, 51, 24, 0.35);
  --radius: 12px;
  --radius-input: 8px;
  --topbar-edge: 1px solid rgba(90, 138, 56, 0.22);
  --switch-off: #6e6e6e;
  --switch-thumb: #f9fcef;
  --switch-edge: rgba(0, 0, 0, 0.4);
  color-scheme: light;
}

html[data-theme="cocoa"] {
  --bg: #efe3d4;
  --panel: #f7efe4;
  --panel-2: #fbf6ef;
  --line: rgba(122, 74, 40, 0.16);
  --text: #3a2418;
  --muted: #8a6a50;
  --accent: #7a4a28;
  --accent-2: #c48a3a;
  --ok: #5d7340;
  --danger: #c0392b;
  --on-accent: #f7efe4;
  --hover: rgba(122, 74, 40, 0.12);
  --input: #f7efe4;
  --topbar: #f7efe4;
  --shadow: rgba(58, 36, 24, 0.14);
  --mask: rgba(58, 36, 24, 0.35);
  --radius: 10px;
  --radius-input: 7px;
  --topbar-edge: 1px solid rgba(122, 74, 40, 0.2);
  --switch-off: #6e6e6e;
  --switch-thumb: #fbf6ef;
  --switch-edge: rgba(0, 0, 0, 0.4);
  color-scheme: light;
}

html[data-theme="wine"] {
  --bg: #1a1216;
  --panel: #2a1a20;
  --panel-2: #341f28;
  --line: rgba(196, 90, 120, 0.18);
  --text: #f3e6d4;
  --muted: #b09098;
  --accent: #c45a78;
  --accent-2: #e8b87a;
  --ok: #7e9a6a;
  --danger: #c0392b;
  --on-accent: #1a1216;
  --hover: rgba(196, 90, 120, 0.16);
  --input: #22141a;
  --topbar: #2a1a20;
  --shadow: rgba(0, 0, 0, 0.5);
  --mask: rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --radius-input: 8px;
  --topbar-edge: 1px solid rgba(196, 90, 120, 0.22);
  --switch-off: #8a8a8a;
  --switch-thumb: #f3e6d4;
  --switch-edge: rgba(255, 255, 255, 0.35);
  color-scheme: dark;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", serif;
}
html, * {
  scrollbar-width: thin;
  scrollbar-color: var(--muted) var(--panel);
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: var(--panel); }
*::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--accent); }
body {
  display: flex;
  flex-direction: column;
}
header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px 10px;
  background: var(--topbar);
  border-bottom: var(--topbar-edge);
}
.header-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--btn-font);
  line-height: 1.4;
  font-weight: 400;
  flex: 0 0 auto;
}
.theme-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--btn-font);
  color: var(--muted);
}
.theme-pick select,
.cfg-row select {
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  padding: 1px 6px;
  font: inherit;
  font-size: var(--btn-font);
}
.header-tools .nav-link,
.header-tools .auth-btn,
.header-tools button,
.header-tools .theme-pick,
.header-tools .theme-pick select {
  font-size: var(--btn-font);
  font-weight: 400;
  line-height: 1.4;
}
.nav-link[hidden],
.header-tools [hidden] {
  display: none !important;
}
.cfg-link,
.nav-link {
  color: var(--accent-2);
  font-size: var(--btn-font);
  text-decoration: none;
  font-weight: inherit;
  line-height: inherit;
}
header h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.28em;
  font-weight: 600;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}
.brand-logo {
  height: var(--brand-logo-h);
  width: auto;
  display: block;
  flex: 0 0 auto;
}
.brand h1 {
  letter-spacing: 0;
  font-size: 16px;
  font-weight: 600;
}
.llm-bill {
  margin: 0;
  color: var(--muted);
  font-size: var(--btn-font);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.35;
  white-space: normal;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  min-width: 0;
  overflow: hidden;
}
.llm-bill-line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
header p a { color: var(--accent-2); text-decoration: none; }
main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}
.col {
  min-width: 140px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px 16px;
  overflow: visible;
}
#col-senses { flex: 0 0 26%; overflow: visible; }
#face {
  flex: 0 0 auto;
  width: var(--face-px);
  height: var(--face-px);
  object-fit: cover;
  display: block;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.self-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 12px;
  overflow: visible;
  position: relative;
  z-index: 6;
}
.laws {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  overflow: visible;
}
.law {
  position: relative;
  margin: 0 0 8px;
  cursor: default;
}
.law-title { color: var(--accent-2); }
.law-bubble {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  z-index: 40;
  width: max(220px, 100%);
  max-width: 360px;
  padding: 8px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px var(--shadow);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.law:hover .law-bubble,
.law:focus-within .law-bubble { display: block; }
#col-mid { flex: 0 0 42%; }
#col-chat { flex: 1 1 auto; }
.gutter {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--line);
}
.gutter:hover, .gutter.dragging { background: var(--accent); }
h2 {
  margin: 0 0 10px;
  font-size: 14px;
  letter-spacing: 0.16em;
  color: var(--accent);
  font-weight: 600;
}
h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.sense-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sense-card {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 12px;
  border-radius: var(--radius);
}
.sense-card h3 { margin: 0 0 6px; color: var(--accent); }
.sense-intro { margin: 0; color: var(--text); font-size: 13px; line-height: 1.5; }
.spark-panel {
  flex: 0 0 auto;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 11px;
}
.spark-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 4px;
}
.spark-head h2 { margin: 0; }
.spark-hint-btn {
  align-self: center;
  flex: 0 0 auto;
  position: relative;
  z-index: 5;
  min-width: 22px;
  padding: 0 6px;
  font-size: 11px;
  line-height: 1.4;
}
.spark-panel dl {
  display: grid;
  grid-template-columns: 2.6em minmax(0, 1fr);
  gap: 1px 6px;
  margin: 0;
}
.spark-panel dt { color: var(--muted); }
.spark-panel dd { margin: 0; min-width: 0; word-break: break-word; }
.ledger-split {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 8px;
}
.ledger-col {
  flex: 1 1 33%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.ledger-col + .ledger-col {
  border-left: 1px solid var(--line);
  padding-left: 8px;
}
.auto-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin: 0 0 12px;
}
.switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-ui {
  width: var(--switch-w);
  height: var(--switch-h);
  background: var(--switch-off);
  box-shadow: inset 0 0 0 1px var(--switch-edge);
  border-radius: 999px;
  position: relative;
  flex: 0 0 var(--switch-w);
}
.switch-ui::after {
  content: "";
  position: absolute;
  width: var(--switch-knob);
  height: var(--switch-knob);
  border-radius: 50%;
  background: var(--switch-thumb);
  box-shadow: 0 0 0 1px var(--switch-edge);
  top: calc((var(--switch-h) - var(--switch-knob)) / 2);
  left: calc((var(--switch-h) - var(--switch-knob)) / 2);
  transition: transform 0.15s ease;
}
.switch input:checked + .switch-ui {
  background: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.switch input:checked + .switch-ui::after {
  transform: translateX(calc(var(--switch-w) - var(--switch-h)));
}
#col-mid .pane {
  flex: 1 1 50%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#pane-thought {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.stream {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
.stream li {
  margin: 0 0 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}
.stream .ts {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}
.chat li.human { border-color: var(--ok); }
.chat li.baby { border-color: var(--accent); }
.chat li.teacher,
.chat li.mrh { border-color: var(--ok); }
.chat {
  display: flex;
  flex-direction: column;
}
.chat > li.placeholder {
  background: transparent;
  border: 0;
  padding: 4px 0 12px;
}
.chat > li.baby,
.chat > li.human,
.chat > li.teacher,
.chat > li.mrh {
  display: flex;
  align-items: flex-start;
  gap: var(--chat-bubble-gap);
  width: 100%;
  margin: 0 0 10px;
  padding: 0;
  background: transparent;
  border: 0;
  white-space: normal;
}
.chat > li.baby { justify-content: flex-start; }
.chat > li.human,
.chat > li.teacher,
.chat > li.mrh { justify-content: flex-end; }
.chat-avatar {
  width: var(--chat-face-px);
  height: var(--chat-face-px);
  border-radius: 6px;
  object-fit: cover;
  flex: 0 0 var(--chat-face-px);
  border: 1px solid var(--line);
  background: var(--input);
}
.chat-human-mark,
.chat-who,
.chat-teacher-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: var(--input);
}
.chat .bubble {
  position: relative;
  flex: 0 1 auto;
  width: fit-content;
  min-width: 0;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat li.baby .bubble {
  max-width: calc(100% - var(--chat-face-px) - var(--chat-bubble-gap) - var(--chat-face-px) - var(--chat-bubble-gap) - var(--chat-bubble-far));
}
.chat li.human .bubble,
.chat li.teacher .bubble,
.chat li.mrh .bubble {
  max-width: calc(100% - var(--chat-face-px) - var(--chat-bubble-gap) - var(--chat-bubble-far));
}
.chat li.human .bubble,
.chat li.teacher .bubble,
.chat li.mrh .bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.chat li.human .bubble .ts,
.chat li.teacher .bubble .ts,
.chat li.mrh .bubble .ts { color: inherit; opacity: 0.8; }
.chat .bubble.has-ask { padding-bottom: 26px; }
.chat .bubble.answering { outline: 2px solid var(--accent); }
.chat-answer {
  position: absolute;
  right: 6px;
  bottom: 4px;
  align-self: auto;
  font-size: 11px;
  line-height: 1.2;
  padding: 2px 7px;
}
.placeholder { color: var(--muted); font-size: 13px; padding: 4px 0 12px; }
form {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}
button {
  align-self: flex-end;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: var(--radius-input);
  padding: var(--btn-pad-y) var(--btn-pad-x);
  font: inherit;
  font-size: var(--btn-font);
  line-height: 1.4;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button:disabled {
  opacity: 0.35;
  cursor: default;
  background: var(--muted);
  color: var(--panel);
  filter: none;
}
#btn-act:not(:disabled) {
  background: var(--accent);
  color: var(--on-accent);
  opacity: 1;
}
.auto-row button { align-self: center; }
.err { margin: 8px 0 0; color: var(--danger); font-size: 13px; }
body.dragging { cursor: col-resize; user-select: none; }
.empty { color: var(--muted); font-size: 14px; line-height: 1.7; }
.popup {
  position: fixed;
  z-index: 80;
  min-width: 240px;
  max-width: min(640px, 92vw);
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px var(--shadow);
}
.popup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  cursor: move;
  background: var(--hover);
  border-radius: var(--radius) var(--radius) 0 0;
}
.popup-title {
  font-size: var(--btn-font);
  letter-spacing: 0.04em;
  color: var(--accent);
  font-weight: 400;
}
.popup-close {
  align-self: center;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  padding: 0 6px;
}
.popup-body { padding: 10px; white-space: pre-wrap; }
.popup-person {
  min-width: 180px;
  font-size: var(--person-popup-font);
}
.popup-person .popup-title {
  font-size: var(--person-popup-font);
  letter-spacing: 0.04em;
}
.popup-person .popup-body {
  font-size: var(--person-popup-font);
  line-height: 1.45;
}
.popup-person .popup-close {
  font-size: calc(var(--person-popup-font) + 4px);
}
.popup-body img { display: block; max-width: 100%; max-height: 60vh; }
.popup .tool-code {
  max-height: 70vh;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}
.tool-src {
  align-self: auto;
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-size: inherit;
  line-height: inherit;
}
.tool-src:hover { text-decoration: underline; filter: none; }
.popup-see {
  background: #111;
  color: #eee;
  border-color: #333;
}
.popup-see .popup-head { background: #1a1a1a; }
.popup-see .popup-title,
.popup-see .popup-close { color: #f3f3f3; }

.config-main {
  padding: 0;
  overflow: hidden;
}
.cfg-nav {
  flex: 0 0 140px;
  min-width: 120px;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cfg-cat {
  align-self: stretch;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: var(--btn-pad-y) var(--btn-pad-x);
  font-size: var(--btn-font);
  border-radius: var(--radius-input);
}
.cfg-cat:hover { background: var(--hover); }
.cfg-cat.on {
  background: var(--accent);
  color: var(--on-accent);
  opacity: 1;
}
.cfg-panel {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 12px 16px 16px;
  margin: 0;
}
.cfg-row {
  display: grid;
  grid-template-columns: 12em minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.cfg-key {
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.cfg-row input,
.cfg-row select,
.cfg-row textarea {
  width: 100%;
  min-width: 0;
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  padding: 3px 6px;
  font: inherit;
  font-size: 13px;
}
.cfg-row textarea {
  min-height: 8em;
  min-width: 12em;
  resize: both;
  line-height: 1.45;
}
.cfg-row-tall {
  align-items: start;
}
.cfg-row-tall .cfg-note {
  white-space: normal;
}
.cfg-note {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cfg-panel button[type="submit"] { margin-top: 12px; }
.cfg-panel.llm-on {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.cfg-panel.llm-on #cfg-rows {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.cfg-panel.llm-on #cfg-save { display: none; }
.llm-split {
  display: grid;
  grid-template-columns: var(--llm-side, 260px) minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}
.llm-side {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 0 8px;
}
.llm-side .llm-toolbar { padding: 0 10px 8px; }
.llm-side #llm-search {
  margin: 0 10px 8px;
  width: calc(100% - 20px);
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  padding: 4px 8px;
  font: inherit;
  font-size: var(--btn-font);
}
.llm-main {
  overflow: auto;
  padding: 16px 18px;
  min-width: 0;
}
.llm-welcome {
  margin: 48px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.llm-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px 16px;
  max-width: 640px;
  margin-bottom: 14px;
}
.llm-h { margin: 0 0 12px; color: var(--accent); font-size: var(--btn-font); font-weight: 700; }
.llm-field { margin-bottom: 10px; }
.llm-lab { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; min-height: 14px; }
.llm-hint { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.llm-hint.ok { color: var(--ok); }
.llm-hint.err { color: var(--danger); }
.llm-field input,
.llm-field select {
  width: 100%;
  min-height: 28px;
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  padding: 3px 8px;
  font: inherit;
  font-size: 13px;
}
.llm-pw { display: flex; gap: 5px; }
.llm-pw input { flex: 1; }
.llm-pw button {
  width: 28px;
  height: 28px;
  padding: 0;
  flex-shrink: 0;
  background: var(--input);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
}
.llm-balance {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  font-size: 12px;
}
.llm-toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.llm-toolbar #llm-new { flex: 1; }
.llm-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border: 0;
  background: transparent;
  max-height: none;
}
.llm-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  align-self: stretch;
  width: 100%;
  gap: 6px;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 7px 10px;
  font-size: var(--btn-font);
}
.llm-item:hover { background: var(--hover); }
.llm-item.on { background: var(--hover); box-shadow: inset 3px 0 0 var(--accent); }
.llm-mark { flex-shrink: 0; }
.llm-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; text-align: left; }
.llm-item-bal { flex-shrink: 0; color: var(--muted); font-size: 10px; }
.llm-item-prov {
  flex-shrink: 0;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--input);
  color: var(--muted);
}
.llm-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.llm-status { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.llm-status.ok { color: var(--ok); }
.llm-status.err { color: var(--danger); }
.llm-price { font-size: 12px; color: var(--muted); }
.llm-price-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.llm-price-head .llm-h { margin: 0; }
.llm-price-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.llm-price-table th, .llm-price-table td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.llm-price-table input { width: 100%; box-sizing: border-box; }
.llm-manual-hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.llm-ask-row { display: flex; gap: 6px; margin-top: 8px; }
html.is-mobile .llm-split {
  grid-template-columns: 1fr;
  grid-template-rows: minmax(180px, 32vh) 1fr;
}
html.is-mobile .llm-side { border-right: 0; border-bottom: 1px solid var(--line); }
.diary-main {
  padding: 12px 16px 16px;
  overflow: auto;
}
.diary-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 720px;
}
.diary-item {
  margin: 0 0 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.diary-item:hover { background: var(--hover); }
.diary-item .ts { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.diary-item .title { font-size: 14px; line-height: 1.5; }
.popup-body pre.tool-code,
.status-pane pre.tool-code {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}
.status-err { padding: 0 16px 12px; }
.status-group {
  margin: 10px 4px 4px;
  color: var(--muted);
  font-size: 11px;
}
.cfg-nav .placeholder { margin: 6px 4px; font-size: 12px; color: var(--muted); }
.status-doc {
  margin: 0 0 16px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.status-doc time {
  display: block;
  color: var(--muted);
  font-size: 11px;
}
.status-doc h3 {
  margin: 4px 0 8px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}
.status-body {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.65;
}
.status-pane h2 {
  margin: 18px 0 8px;
  font-size: 14px;
}
.status-pane h2:first-child { margin-top: 0; }
.status-pane .tool-code { margin-top: 8px; }
.status-pane.tools-split {
  overflow: hidden;
}
.status-tools-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--status-tools-gap);
  height: 100%;
  min-height: 0;
}
.status-tools-col {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}
.status-tools-col + .status-tools-col {
  border-left: 1px solid var(--line);
}
.status-tools-col h2 {
  margin: 0 0 8px;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  padding-bottom: 8px;
}
.status-goal-meta,
.status-goal-now {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}
.status-doc h4 {
  margin: 10px 0 6px;
  font-size: 13px;
}
.status-goal-steps {
  margin: 0;
  padding-left: 1.2em;
}
.status-goal-steps li {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.55;
}
.status-goal-steps time {
  display: inline;
  color: var(--muted);
  font-size: 11px;
}

.m-tabs,
.m-mid-tabs,
.m-nav-mask,
#m-nav-toggle { display: none; }

html.is-mobile, html.is-mobile body {
  height: 100%;
  height: 100dvh;
}
html.is-mobile body {
  padding-bottom: env(safe-area-inset-bottom);
}
html.is-mobile header {
  padding: 8px 10px;
  gap: 8px;
}
html.is-mobile header h1 {
  font-size: 16px;
  letter-spacing: 0.08em;
}
html.is-mobile .llm-bill { font-size: var(--btn-font); }
html.is-mobile .header-tools { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
html.is-mobile .gutter { display: none !important; }
html.is-mobile main {
  flex-direction: column;
  min-height: 0;
}
html.is-mobile #main .col {
  display: none;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 10px 12px 12px;
  overflow: hidden;
}
html.is-mobile #main[data-m-tab="senses"] #col-senses,
html.is-mobile #main[data-m-tab="mid"] #col-mid,
html.is-mobile #main[data-m-tab="chat"] #col-chat {
  display: flex;
}
html.is-mobile .ledger-split {
  flex-direction: column;
}
html.is-mobile .ledger-col + .ledger-col {
  border-left: 0;
  padding-left: 0;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
html.is-mobile .m-mid-tabs {
  display: flex;
  flex: 0 0 auto;
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}
html.is-mobile .m-mid-tabs button {
  flex: 1 1 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 4px;
  font-size: 13px;
  border: 0;
  border-right: 1px solid var(--line);
  min-width: 0;
}
html.is-mobile .m-mid-tabs button:last-child { border-right: 0; }
html.is-mobile .m-mid-tabs button.on {
  background: var(--accent);
  color: var(--on-accent);
  opacity: 1;
}
html.is-mobile #col-mid[data-m-mid="ledger"] #pane-thought,
html.is-mobile #col-mid[data-m-mid="teacher"] #pane-thought,
html.is-mobile #col-mid[data-m-mid="mrh"] #pane-thought {
  display: none;
}
html.is-mobile #col-mid[data-m-mid="thought"] #pane-ledger {
  display: none;
}
html.is-mobile #col-mid[data-m-mid="ledger"] #pane-ledger,
html.is-mobile #col-mid[data-m-mid="teacher"] #pane-ledger,
html.is-mobile #col-mid[data-m-mid="mrh"] #pane-ledger,
html.is-mobile #col-mid[data-m-mid="thought"] #pane-thought {
  flex: 1 1 auto;
  min-height: 0;
  border-top: 0;
  padding-top: 0;
}
html.is-mobile #col-mid[data-m-mid="ledger"] .ledger-col:not([data-m-mid-pane="ledger"]),
html.is-mobile #col-mid[data-m-mid="teacher"] .ledger-col:not([data-m-mid-pane="teacher"]),
html.is-mobile #col-mid[data-m-mid="mrh"] .ledger-col:not([data-m-mid-pane="mrh"]) {
  display: none;
}
html.is-mobile #col-mid[data-m-mid="ledger"] .ledger-col[data-m-mid-pane="ledger"],
html.is-mobile #col-mid[data-m-mid="teacher"] .ledger-col[data-m-mid-pane="teacher"],
html.is-mobile #col-mid[data-m-mid="mrh"] .ledger-col[data-m-mid-pane="mrh"] {
  flex: 1 1 auto;
  min-height: 0;
  border-left: 0;
  border-top: 0;
  padding-left: 0;
  padding-top: 0;
}

html.is-mobile .m-tabs {
  display: flex;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: var(--topbar);
}
html.is-mobile .m-tabs button {
  flex: 1 1 0;
  align-self: stretch;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
}
html.is-mobile .m-tabs button.on {
  background: var(--accent);
  color: var(--on-accent);
  opacity: 1;
}
html.is-mobile #form textarea,
html.is-mobile input,
html.is-mobile select {
  font-size: 16px;
}
html.is-mobile #form textarea { min-height: 56px; }
html.is-mobile .law-bubble {
  position: static;
  display: none;
  width: auto;
  max-width: none;
  margin-top: 6px;
}
html.is-mobile .law:focus-within .law-bubble,
html.is-mobile .law:hover .law-bubble { display: block; }
html.is-mobile #m-nav-toggle {
  display: inline-flex;
  align-items: center;
  align-self: center;
  background: transparent;
  color: var(--accent-2);
  padding: 0;
  font-size: var(--btn-font);
  font-weight: 400;
  line-height: 1.4;
}
html.is-mobile .m-nav-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--mask);
  z-index: 15;
}
html.is-mobile body.m-nav-open .m-nav-mask { display: block; }
/* 配置/状况：左侧目录改为顶部横栏（对齐记录 mid-tabs） */
html.is-mobile .config-main {
  flex-direction: column;
  min-height: 0;
}
html.is-mobile .cfg-nav {
  display: flex;
  flex: 0 0 auto;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0;
  position: static;
  z-index: auto;
  top: auto;
  left: auto;
  bottom: auto;
  width: auto;
  min-width: 0;
  margin: 8px 10px 0;
  padding: 0;
  border: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  box-shadow: none;
}
html.is-mobile body.m-nav-open .cfg-nav { display: flex; }
html.is-mobile .cfg-nav .cfg-cat {
  flex: 0 0 auto;
  align-self: stretch;
  text-align: center;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  border: 0;
  border-right: 1px solid var(--line);
  white-space: nowrap;
  min-width: 0;
}
html.is-mobile .cfg-nav .cfg-cat:last-child { border-right: 0; }
html.is-mobile .cfg-nav .cfg-cat.on {
  background: var(--accent);
  color: var(--on-accent);
  opacity: 1;
}
html.is-mobile .cfg-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px 16px;
}
html.is-mobile .cfg-row {
  grid-template-columns: 1fr;
  gap: 2px 8px;
  padding: 8px 0;
}
html.is-mobile .cfg-note { white-space: normal; }
html.is-mobile .popup {
  max-width: calc(100vw - 16px);
  left: 8px !important;
}
#auth-slot {
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-btn {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.ask-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6em;
  height: 1.6em;
  color: var(--accent-2);
}
.ask-btn svg {
  width: 1.15em;
  height: 1.15em;
  display: block;
}
.ask-badge {
  position: absolute;
  top: -0.35em;
  right: -0.4em;
  min-width: 1em;
  height: 1em;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  line-height: 1em;
  text-align: center;
}
.ask-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 16em;
}
.ask-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--panel-2);
}
.ask-body {
  margin: 0 0 8px;
  white-space: pre-wrap;
}
.ask-actions {
  display: flex;
  gap: 8px;
}
.ask-actions button {
  font: inherit;
  font-size: var(--btn-font);
  font-weight: inherit;
  line-height: inherit;
  color: var(--accent-2);
  align-self: center;
}
.ask-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 8px;
}
.ask-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--btn-font);
  cursor: pointer;
}
.ask-choice input {
  margin: 0;
}
.ask-card > button {
  font: inherit;
  font-size: var(--btn-font);
}
.ask-empty {
  margin: 0;
  color: var(--muted);
}
.menu {
  position: fixed;
  z-index: 90;
  min-width: 240px;
  max-width: min(360px, 92vw);
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px var(--shadow);
  padding: 10px;
  font-size: var(--btn-font);
  line-height: 1.4;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  white-space: normal;
  font-size: var(--btn-font);
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--btn-font);
  color: var(--muted);
}
.auth-form input,
.menu input {
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  padding: 6px 8px;
  font: inherit;
  font-size: var(--btn-font);
}
.auth-form input.bad,
.menu input.bad {
  border-color: var(--danger);
}
.pwd-wrap {
  position: relative;
}
.pwd-wrap input {
  width: 100%;
  padding-left: 30px;
}
.eye-btn {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  line-height: 0;
}
.eye-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}
.eye-btn:hover { color: var(--accent); }
.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.linkish {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent-2);
  cursor: pointer;
  font: inherit;
  font-size: var(--btn-font);
}
.auth-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: var(--btn-font);
}
.auth-k { color: var(--muted); }
.auth-v { color: var(--text); }
.pencil {
  background: none;
  border: 0;
  color: var(--accent-2);
  cursor: pointer;
  font: inherit;
  font-size: var(--btn-font);
  padding: 0;
}
.auth-err { margin: 0; }
