:root {
  --paper: #f5f3ee;
  --surface: #ffffff;
  --ink: #1c2024;
  --muted: #5b6168;
  --line: #e2ded5;
  --line-strong: #cfcabe;
  --accent: #1e5b4e;
  --accent-ink: #ffffff;
  --accent-soft: #e3eee9;
  --accent-line: #b9d3c9;
  --warn: #9a3412;
  --warn-soft: #fdf0e8;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", "Pretendard", sans-serif;
  --col: 46rem;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.6 var(--font);
  word-break: keep-all;
  overflow-wrap: anywhere;
  caret-color: var(--accent);
}
::selection { background: var(--accent-soft); color: var(--ink); }
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  -webkit-backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.bar-in { max-width: var(--col); margin: 0 auto; padding: 8px 12px 8px 18px; display: flex; align-items: center; gap: 8px; }
.brand { font-size: 1.12rem; font-weight: 700; letter-spacing: -0.01em; margin: 0; flex: 1; }
.bar-actions { display: flex; gap: 2px; }
.ghost {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink); font-size: 0.95rem; font-weight: 600;
}
.ghost:hover { background: #ebe8e1; }
.ghost svg { width: 20px; height: 20px; color: var(--accent); }
.icon { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); }
.icon:hover { background: #efece6; color: var(--ink); }

/* Past chats */
.history { position: fixed; inset: 0; z-index: 20; background: rgba(28, 32, 36, 0.28); display: flex; justify-content: flex-end; }
.history-in {
  width: min(26rem, 100%); height: 100%; background: var(--surface); box-shadow: -8px 0 32px rgba(28, 32, 36, 0.12);
  display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  animation: slide-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0.6; } }
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 6px 20px; }
.history-head h2 { margin: 0; font-size: 1.1rem; }
.history ul { list-style: none; margin: 0; padding: 4px 8px 16px; overflow-y: auto; }
.history li button {
  width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 12px; border: 0; border-radius: 12px; background: transparent;
}
.history li button:hover { background: #f3f1ec; }
.history li button[aria-current="true"] { background: var(--accent-soft); }
.history .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.history .d { font-size: 0.85rem; color: var(--muted); }
.history-empty { padding: 4px 20px; color: var(--muted); }

/* Conversation */
.log { flex: 1; width: 100%; max-width: var(--col); margin: 0 auto; padding: 20px 14px 12px; }
.welcome { padding: 10vh 6px 8px; }
.welcome h2 { font-size: 1.45rem; line-height: 1.35; margin: 0 0 8px; letter-spacing: -0.02em; }
.welcome p { margin: 0 0 22px; color: var(--muted); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.examples button {
  min-height: 44px; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface);
  font-size: 0.95rem; color: var(--ink);
}
.examples button:hover { border-color: var(--accent); color: var(--accent); }

#messages { display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 8px; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.bot, .msg.error, .msg.work { align-self: flex-start; }
.bubble { padding: 11px 15px; border-radius: var(--radius); white-space: pre-wrap; }
.me .bubble { background: var(--accent-soft); border: 1px solid var(--accent-line); border-bottom-right-radius: 6px; }
.bot .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.error .bubble { background: var(--warn-soft); border: 1px solid #f1cdb8; color: var(--warn); border-bottom-left-radius: 6px; }
.when { font-size: 0.8rem; color: var(--muted); padding: 0 4px; }

/* Files: one tap downloads */
.files { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.file {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 60px; width: min(24rem, 100%);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; text-decoration: none; color: var(--ink);
  box-shadow: 0 1px 2px rgba(28, 32, 36, 0.05);
}
a.file:hover { border-color: var(--accent); }
.me .file { box-shadow: none; }
.doc { width: 34px; height: 40px; flex: none; position: relative; border-radius: 5px; background: var(--k, #6b7280); color: #fff; display: grid; place-items: end center; padding-bottom: 5px; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.02em; }
.k-w { --k: #2b579a; } .k-x { --k: #1d6f42; } .k-p { --k: #c4441c; } .k-f { --k: #b3261e; } .k-h { --k: #2a7ab8; } .k-i { --k: #6d5a99; } .k-o { --k: #6b7280; }
.doc::after { content: ""; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 10px 10px 0; border-color: transparent var(--paper) rgba(255,255,255,0.45) transparent; }
.file .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file .name { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .size { font-size: 0.82rem; color: var(--muted); }
.get { display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 0.9rem; font-weight: 600; flex: none; }
.get svg { width: 18px; height: 18px; }

/* Waiting */
.work .bubble { white-space: normal; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; min-width: min(20rem, 80vw); }
.stage { font-weight: 600; }
.elapsed { color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.track { height: 4px; border-radius: 4px; background: #ece9e2; overflow: hidden; margin: 10px 0 8px; }
.track i { display: block; height: 100%; width: 34%; border-radius: 4px; background: var(--accent); animation: travel 1.6s cubic-bezier(0.45, 0, 0.25, 1) infinite; }
@keyframes travel { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
.note { font-size: 0.86rem; color: var(--muted); margin: 0; }

/* Composer */
.composer-wrap {
  position: sticky; bottom: 0; z-index: 4;
  background: linear-gradient(to top, var(--paper) 70%, color-mix(in srgb, var(--paper) 0%, transparent));
  padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
}
.composer { max-width: var(--col); margin: 0 auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 18px; box-shadow: 0 4px 18px rgba(28, 32, 36, 0.07); padding: 6px; }
.composer:focus-within { border-color: var(--accent); }
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
textarea {
  flex: 1; min-height: 44px; max-height: 40vh; resize: none; border: 0; outline: none; background: transparent;
  padding: 10px 4px; font-size: 17px; line-height: 1.5;
}
textarea::placeholder { color: #7a8087; }
.send { width: 44px; height: 44px; border: 0; border-radius: 13px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.send:disabled { background: #c9cfcc; cursor: default; }
.send svg { stroke-width: 2.2; }
.pending { list-style: none; margin: 0; padding: 0 2px; display: flex; flex-direction: column; gap: 6px; }
.pending:not(:empty) { padding: 4px 2px 6px; }
.pending li { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 10px; border-radius: 10px; background: #f5f3ee; }
.pending .meta { flex: 1; min-width: 0; }
.pending .name { font-size: 0.92rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.pending .size { font-size: 0.8rem; color: var(--muted); }
.pending .bar2 { height: 3px; background: #e4e0d8; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.pending .bar2 i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 200ms linear; }
.pending .doc { width: 26px; height: 32px; font-size: 0.5rem; padding-bottom: 3px; }
.pending .k-w { --k: #2b579a; } .k-x { --k: #1d6f42; } .k-p { --k: #c4441c; } .k-f { --k: #b3261e; } .k-h { --k: #2a7ab8; } .k-i { --k: #6d5a99; } .k-o { --k: #6b7280; }
.doc::after { border-color: transparent #f5f3ee rgba(255,255,255,0.45) transparent; border-width: 0 8px 8px 0; }
.pending .icon { width: 36px; height: 36px; }
.toast { max-width: var(--col); margin: 0 auto 8px; padding: 10px 14px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); border: 1px solid #f1cdb8; font-size: 0.95rem; }

/* Drop overlay (PC) */
.drop { position: fixed; inset: 12px; z-index: 30; border: 2px dashed var(--accent); border-radius: 20px; background: rgba(227, 238, 233, 0.92); display: grid; place-items: center; pointer-events: none; }
.drop p { font-size: 1.3rem; font-weight: 700; color: var(--accent); }

@media (min-width: 900px) {
  /* A PC screen at 100% is read from further away than a phone: everything a step larger. */
  html { font-size: 17px; }
  body { font-size: 18px; }
  .composer textarea { font-size: 18px; }
  .log { padding-top: 32px; }
  .welcome { padding-top: 14vh; }
  .msg { max-width: 78%; }
}
@media (max-width: 380px) {
  .ghost span { font-size: 0.9rem; }
  .ghost { padding: 0 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .track i { animation: none; width: 100%; opacity: 0.35; }
  .history-in { animation: none; }
}

/* Sign-in pages */
.gate { justify-content: center; align-items: center; padding: 24px 18px; }
.gate-card { width: min(26rem, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px 24px 26px; box-shadow: 0 6px 24px rgba(28, 32, 36, 0.06); }
.gate-card img { display: block; border-radius: 14px; margin-bottom: 14px; }
.gate-card h1 { font-size: 1.35rem; margin: 0 0 10px; letter-spacing: -0.01em; }
.gate-card p { margin: 0 0 18px; }
.gate-card .small { font-size: 0.92rem; color: var(--muted); }
.primary { width: 100%; min-height: 52px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-size: 1.05rem; font-weight: 700; margin-bottom: 12px; }
.primary:disabled { opacity: 0.7; }
.ghostline { width: 100%; min-height: 48px; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--surface); font-weight: 600; }
.msg-line { min-height: 1.4em; color: var(--warn); font-size: 0.95rem; margin: 8px 0 0 !important; }
