:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --sunken: #efe9e1;
  --text: #1f1c18;
  --muted: #7a7268;
  --line: #e6dfd5;
  --accent: #c4552b;
  --accent-soft: #fbe9df;
  --on-accent: #ffffff;
  --mine: #2c2925;
  --on-mine: #ffffff;
  --theirs: #ffffff;
  --claude: #fdf0e8;
  --claude-line: #f3d6c4;
  --error: #b3261e;
  --ok: #1e7a45;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 4px 14px rgba(60, 40, 20, 0.05);
  --c0: #d9785a; --c1: #5f8fd9; --c2: #58a888; --c3: #b07ad0; --c4: #d6a23e; --c5: #5aa9bd;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #211f1c;
    --sunken: #2b2925;
    --text: #efeae2;
    --muted: #a39b90;
    --line: #34312c;
    --accent: #ee8a61;
    --accent-soft: #3b2a21;
    --on-accent: #1d120c;
    --mine: #ee8a61;
    --on-mine: #1d120c;
    --theirs: #262420;
    --claude: #33261e;
    --claude-line: #4a372b;
    --error: #ff8a80;
    --ok: #7fd6a2;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;
}

[hidden] { display: none !important; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 0.95rem; font-weight: 700; margin-top: 8px; }

.muted { color: var(--muted); font-size: 0.92rem; }
.small { font-size: 0.82rem; }
.error { color: var(--error); font-size: 0.9rem; min-height: 1.3em; }
.ok { color: var(--ok); font-size: 0.9rem; min-height: 1.3em; }
.error:empty, .ok:empty { display: none; }

.icon { display: inline-flex; width: 24px; height: 24px; }
.icon svg { width: 100%; height: 100%; }

/* ---------- 입력 / 버튼 ---------- */

form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.86rem; font-weight: 600; color: var(--muted); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--sunken);
  border: 1.5px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  width: 100%;
  min-width: 0;
}

input:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button, .button {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  background: none;
  color: inherit;
}

.primary { background: var(--accent); color: var(--on-accent); }
.secondary { background: var(--sunken); color: var(--text); }
.primary:disabled { opacity: 0.45; cursor: default; }
.chip { background: var(--sunken); color: var(--text); font-size: 0.8rem; font-weight: 600; padding: 7px 12px; border-radius: 999px; white-space: nowrap; }
.text-danger { color: var(--error); font-weight: 600; padding: 12px; }
.badge { align-self: center; background: var(--accent-soft); color: var(--accent); font-size: 0.82rem; font-weight: 700; padding: 5px 14px; border-radius: 999px; }

/* ---------- 로그인 ---------- */

.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }

.auth { width: 100%; max-width: 360px; }
.auth .logo { align-self: center; border-radius: 22px; box-shadow: var(--shadow); }
.auth h1 { text-align: center; font-size: 1.7rem; margin-top: 4px; }
.auth #auth-desc { text-align: center; margin-bottom: 10px; }
.auth .primary { margin-top: 4px; }

/* ---------- 앱 레이아웃 ---------- */

#view-app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

@media (min-width: 760px) {
  body { background: var(--sunken); }
  #view-app { border-inline: 1px solid var(--line); }
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 10px;
}

.conn { font-size: 0.78rem; color: var(--muted); background: var(--sunken); padding: 3px 10px; border-radius: 999px; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tab { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }

#tabs {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}

#tabs button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  border-radius: 12px;
}

#tabs button.active { color: var(--accent); }
#tabs button.active .icon svg { stroke-width: 2.3; }

/* ---------- 채팅 ---------- */

#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 14px 10px;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
}

.older { align-self: center; font-size: 0.82rem; font-weight: 600; color: var(--muted); background: var(--sunken); padding: 7px 14px; border-radius: 999px; margin: 6px 0; }

.day { display: flex; justify-content: center; margin: 14px 0 6px; }
.day span { font-size: 0.75rem; color: var(--muted); background: var(--sunken); border-radius: 999px; padding: 3px 12px; }

.msg { display: flex; gap: 8px; margin-top: 3px; }
.msg.first { margin-top: 12px; }
.msg.mine { justify-content: flex-end; }

.avatar {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
}
.avatar-gap { flex: none; width: 38px; }
.c0 { background: var(--c0); } .c1 { background: var(--c1); } .c2 { background: var(--c2); }
.c3 { background: var(--c3); } .c4 { background: var(--c4); } .c5 { background: var(--c5); }
.claude-face { background: var(--accent); color: var(--on-accent); }
.claude-face .icon { width: 20px; height: 20px; }
.claude-face.big { width: 56px; height: 56px; border-radius: 20px; }
.claude-face.big .icon { width: 30px; height: 30px; }

.stack { display: flex; flex-direction: column; gap: 3px; min-width: 0; max-width: min(78%, 520px); }
.msg.mine .stack { align-items: flex-end; }
.msg.claude .stack { max-width: min(86%, 560px); }

.name { font-size: 0.8rem; font-weight: 600; color: var(--muted); margin-left: 2px; }
.msg.claude .name { color: var(--accent); }

.line { display: flex; align-items: flex-end; gap: 6px; min-width: 0; }
.msg.mine .line { flex-direction: row-reverse; }

.bubble {
  padding: 9px 13px;
  border-radius: 18px;
  background: var(--theirs);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-width: 0;
}

.msg.theirs.first .bubble, .msg.claude.first .bubble { border-top-left-radius: 6px; }
.msg.mine .bubble { background: var(--mine); color: var(--on-mine); box-shadow: none; }
.msg.mine.first .bubble { border-top-right-radius: 6px; }
.msg.claude .bubble { background: var(--claude); box-shadow: inset 0 0 0 1px var(--claude-line); }

.line time { flex: none; font-size: 0.68rem; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }

.dots { display: inline-flex; gap: 4px; padding: 6px 2px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0.35; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: 0.7; } }

.empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 24px; }
.empty p:first-of-type { font-weight: 700; margin-top: 10px; }

.to-bottom {
  position: absolute;
  right: 16px;
  bottom: 78px;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.to-bottom .icon { width: 20px; height: 20px; }
.to-bottom.unread { background: var(--accent); color: var(--on-accent); }

.notice {
  margin: 0 14px 8px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.88rem;
}

#composer {
  flex-direction: row;
  align-items: flex-end;
  gap: 4px;
  margin: 0 12px 10px;
  padding: 5px;
  background: var(--surface);
  border-radius: 26px;
  box-shadow: var(--shadow);
}

#composer textarea {
  flex: 1;
  resize: none;
  max-height: 132px;
  background: none;
  border: 0;
  border-radius: 0;
  padding: 9px 4px;
  line-height: 1.4;
}

#composer button {
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.spark { color: var(--accent); background: var(--accent-soft); }
.spark .icon { width: 20px; height: 20px; }
.send { background: var(--accent); color: var(--on-accent); }
.send .icon { width: 20px; height: 20px; }
.send:disabled { background: var(--sunken); color: var(--muted); cursor: default; }

/* ---------- 서비스 / 설정 ---------- */

.page { overflow-y: auto; padding: 6px 14px 20px; gap: 12px; }

.panel {
  flex: none;
  background: var(--surface);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

.service { align-items: center; text-align: center; padding: 36px 20px; gap: 10px; margin-top: 8px; }
.service-icon { width: 64px; height: 64px; border-radius: 22px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 6px; }
.service-icon .icon { width: 30px; height: 30px; }
.service .button { align-self: stretch; margin-top: 8px; }

.me, .person { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.list li { display: flex; flex-direction: column; gap: 8px; }
#user-form { border-top: 1px solid var(--line); padding-top: 14px; }
.inline { flex-direction: row; gap: 8px; }
.inline button { flex: none; }
