:root {
  color-scheme: light;
  --bg: #f3efe7;
  --ink: #1e1b17;
  --muted: #6e665c;
  --line: #e2d8cb;
  --user: #1e1b17;
  --user-ink: #f6f1e8;
  --paper: #f7f4ee;
  --danger: #8d3d32;
  --ok: #1e6b4a;
  --warn: #8a5a12;
  --focus: #1d4e89;
  --code: #f6f1e8;
  --shadow: 0 1px 0 rgba(30, 27, 23, 0.04);
  font-family: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12110f;
    --ink: #f3efe6;
    --muted: #b4ab9f;
    --line: #2e2b27;
    --user: #efe7da;
    --user-ink: #1c1916;
    --paper: #181715;
    --danger: #e39b92;
    --ok: #8dccb0;
    --warn: #e2c07a;
    --focus: #9ec0ea;
    --code: #221f1c;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 64px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.brand { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.mark {
  margin: 0;
  font-family: "Iowan Old Style", Palatino, "Songti SC", "Noto Serif SC", serif;
  font-size: 1.7rem;
  letter-spacing: 0.08em;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--danger);
}
.status.online .dot { background: var(--ok); }
.status.starting .dot, .status.busy .dot { background: var(--warn); }
.bar-actions { display: flex; gap: 8px; }
.bar-actions button.active { background: var(--ink); color: var(--paper); }
.result-image { width: min(512px, 100%); height: auto; border-radius: 12px; background: var(--code); }
.bar-actions button, .quiet, .composer button, .gate button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  min-height: 40px;
  padding: 0 14px;
}
.bar-actions button[disabled], .composer button[disabled] { color: var(--muted); cursor: default; }

#stage { flex: 1; min-height: 0; display: flex; }
.gate {
  width: min(24rem, calc(100% - 40px));
  margin: auto;
  padding: 8px 0 48px;
}
.gate h1 {
  margin: 0 0 10px;
  font-family: "Iowan Old Style", Palatino, "Songti SC", "Noto Serif SC", serif;
  font-size: 3.2rem;
  font-weight: 560;
  letter-spacing: 0.12em;
}
.gate p { margin: 0 0 22px; color: var(--muted); line-height: 1.6; }
.gate label { display: block; margin-bottom: 8px; }
.gate input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
}
.gate button { width: 100%; margin-top: 14px; background: var(--ink); color: var(--paper); border-color: var(--ink); }
.note { min-height: 1.4em; color: var(--danger); }

.shell {
  width: min(42rem, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.thread {
  flex: 1;
  overflow: auto;
  padding: 28px 20px 12px;
}
.banner {
  margin: 0 0 18px;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  border-radius: 12px;
  color: var(--danger);
  line-height: 1.5;
}
.kicker {
  margin: 0 0 6px;
  color: var(--danger);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}
.empty { padding: 12vh 0 0; }
.empty-title {
  margin: 0 0 8px;
  font-family: "Iowan Old Style", Palatino, "Songti SC", serif;
  font-size: 1.8rem;
}
.empty p { margin: 0; color: var(--muted); line-height: 1.6; max-width: 28rem; }

.msg { margin: 0 0 22px; max-width: 100%; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user p, .msg.system p, .msg.pending p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
}
.msg.user p {
  max-width: min(34rem, 88%);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--user);
  color: var(--user-ink);
}
.msg.system p, .msg.pending p { color: var(--muted); }
.msg.assistant .copy { margin-top: 8px; }
.md { line-height: 1.7; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 {
  font-family: "Iowan Old Style", Palatino, "Songti SC", serif;
  font-weight: 560;
  line-height: 1.3;
  margin: 1.1em 0 0.4em;
}
.md p, .md ul, .md ol, .md blockquote { margin: 0.6em 0; }
.md a { color: inherit; }
.md blockquote {
  margin-left: 0;
  padding-left: 12px;
  border-left: 2px solid var(--line);
  color: var(--muted);
}
.md code {
  font-family: "IBM Plex Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.md :not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: var(--code);
}
.codeblock, .table-wrap { max-width: 100%; margin: 0.8em 0; }
.codebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 0 2px 6px;
}
.codeblock pre, .table-wrap {
  overflow-x: auto;
  max-width: 100%;
}
.codeblock pre {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--code);
  box-shadow: var(--shadow);
}
.codeblock code { white-space: pre; }
.md table { border-collapse: collapse; min-width: 100%; }
.md th, .md td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 8px 10px;
  white-space: nowrap;
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 8px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.hint, .fine { margin: 0; color: var(--muted); font-size: 0.86rem; line-height: 1.45; }
.hint { min-height: 1.4em; padding-bottom: 8px; }
.entry { display: flex; align-items: flex-end; gap: 8px; }
.entry textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 1rem;
  line-height: 1.5;
  min-height: 48px;
}
.entry button {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  min-width: 72px;
  min-height: 48px;
}
.fine { padding-top: 8px; }

@media (max-width: 640px) {
  .bar { padding: 10px 14px; }
  .mark { font-size: 1.45rem; }
  .thread { padding: 18px 14px 8px; }
  .composer { padding: 8px 14px calc(12px + env(safe-area-inset-bottom)); }
  .gate h1 { font-size: 2.6rem; }
  .msg.user p { max-width: 92%; }
}
