:root {
  color-scheme: light;
  --bg: #efeae2;
  --paper: #fffdf8;
  --ink: #1d2430;
  --muted: #667083;
  --line: #e3dbd0;
  --green: #0d6b56;
  --green-ink: #f4fbf8;
  --warn: #8a4b12;
  --warn-bg: #fff1df;
  --danger: #8d2f2f;
  --shadow: 0 10px 30px rgba(40, 32, 22, 0.06);
  --vvh: 100dvh;
  font-family: "PingFang SC", "Noto Sans SC", "WenQuanYi Micro Hei", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { min-height: var(--vvh); }

.auth {
  min-height: var(--vvh);
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.card {
  width: min(440px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px 18px 18px;
}
.brand { margin: 0 0 4px; font-size: 22px; letter-spacing: 0.01em; }
.sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.seg { display: flex; gap: 6px; margin-bottom: 14px; }
.seg button, .tabbar button, .rail button, .btn, .btn-ghost {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  min-height: 40px;
  padding: 0 12px;
}
.seg button.active, .tabbar button.active, .rail button.active, .btn {
  background: var(--green);
  color: var(--green-ink);
  border-color: var(--green);
}
.btn-ghost { background: transparent; }
.btn-danger { background: #fff; color: var(--danger); border-color: #efc7c7; }
.stack { display: grid; gap: 10px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  font-size: 16px;
}
textarea { min-height: 96px; resize: vertical; }
.alert, .note, .sim, .empty {
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.45;
  font-size: 14px;
}
.alert { background: #fdecec; color: var(--danger); }
.note, .empty { background: #f6f3ee; color: var(--muted); }
.sim { background: var(--warn-bg); color: var(--warn); font-weight: 650; }
.shell { height: var(--vvh); display: flex; flex-direction: column; }
.main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.banners { padding: 10px 12px 0; display: grid; gap: 6px; }
.banner {
  margin: 0;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.4;
}
.content { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pad { padding: 12px; display: grid; gap: 10px; align-content: start; overflow: auto; }
.content > .pad, .chat-layout > .pad { flex: 1; min-height: 0; }
.tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.tabbar button { border-radius: 12px; min-height: 44px; padding: 0 4px; }
.rail { display: none; }
.list-item, .bubble, .entry {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.list-item, .entry { padding: 12px; display: grid; gap: 4px; text-align: left; width: 100%; }
.list-item strong, .entry strong { font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chat-layout, .thread, .log { min-height: 0; }
.chat-layout { flex: 1; display: flex; flex-direction: column; }
.thread { flex: 1; display: flex; flex-direction: column; background: #f7f4ef; }
.log { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 10px; box-shadow: none; }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; font-size: 15px; }
.bubble.self { margin-left: auto; background: var(--green); color: var(--green-ink); border-color: var(--green); }
.bubble .meta { margin-top: 4px; font-size: 11px; opacity: 0.75; }
.composer {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.composer input { flex: 1; }
#message-count, #raw-count { display: block; padding: 0 12px 8px; }
.topbar { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 12px; }
h2, h3 { margin: 0; font-size: 18px; }
.raw { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 18px; letter-spacing: 0.08em; }

@media (min-width: 960px) {
  body { background: #e7e1d8; }
  .shell {
    flex-direction: row;
    width: min(1120px, calc(100% - 32px));
    margin: 16px auto;
    height: calc(var(--vvh) - 32px);
    background: transparent;
  }
  .rail {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 180px;
    padding: 16px 12px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 18px 0 0 18px;
  }
  .main {
    background: var(--bg);
    border: 1px solid var(--line);
    border-left: 0;
    border-radius: 0 18px 18px 0;
  }
  .tabbar { display: none; }
  .chat-layout { display: grid; grid-template-columns: 300px 1fr; }
  .chat-layout .pad { border-right: 1px solid var(--line); }
}
