:root {
  --bg: #f4f1ec;
  --panel: #ffffff;
  --ink: #2b2b2b;
  --muted: #8a857d;
  --accent: #e8853d;
  --accent-soft: #fdeede;
  --bubble-me: #ffe3c7;
  --bubble-bot: #ffffff;
  --line: #e8e2d8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.app {
  max-width: 720px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: transparent;
}

.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions .ghost-btn { display: inline-flex; align-items: center; gap: 5px; }

.theme-panel {
  position: fixed;
  top: 58px;
  right: max(14px, calc(50% - 346px));
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(60, 40, 20, .12);
  padding: 14px 16px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.theme-panel.hidden { display: none; }

.tp-section { display: flex; flex-direction: column; gap: 8px; }
.tp-label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .5px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,.08);
  cursor: pointer;
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.custom-color {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.custom-color input[type="color"] {
  width: 34px; height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  padding: 1px;
  cursor: pointer;
}

.patterns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pattern-thumb {
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--line);
  cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 3px;
  transition: border-color .12s, transform .12s;
}
.pattern-thumb:hover { transform: translateY(-1px); }
.pattern-thumb.active { border-color: var(--accent); }
.pattern-thumb span {
  font-size: 10px; color: var(--muted);
  background: rgba(255,255,255,.75);
  padding: 0 5px; border-radius: 4px;
}

.ghost-btn.small { align-self: flex-end; font-size: 12px; padding: 4px 10px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s;
}
.ghost-btn:hover { color: var(--accent); border-color: var(--accent); }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 10px; max-width: 85%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  flex: 0 0 34px;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  user-select: none;
}
.msg.bot .avatar { background: var(--accent); }
.msg.me .avatar { background: #b9b2a6; }

.bubble {
  padding: 11px 15px;
  border-radius: 18px;
  line-height: 1.65;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.msg.bot .bubble { background: var(--bubble-bot); border: 1px solid var(--line); border-top-left-radius: 6px; }
.msg.me .bubble { background: var(--bubble-me); border-top-right-radius: 6px; }

.msg.typing .bubble { color: var(--muted); letter-spacing: 2px; }

.inputbar {
  display: flex;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  outline: none;
  background: #faf8f5;
  transition: border-color .15s;
}
#input:focus { border-color: var(--accent); }

.send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  padding: 0 20px;
  border-radius: 14px;
  cursor: pointer;
  transition: opacity .15s, transform .05s;
}
.send-btn:active { transform: scale(.96); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 480px) {
  .msg { max-width: 92%; }
  .bubble { font-size: 15px; }
}
