/* 도랏이 — Simple is Best. 모드별 색만 바뀌는 깔끔한 채팅 UI */
:root{
  --bg:#f7f5f2;
  --panel:#ffffff;
  --text:#22201d;
  --text-dim:#8b857e;
  --line:#eae4dc;
  --bot:#f1eee9;
  --user:#ff8a3d;
  --user-text:#3a1e08;
  --accent:#ff8a3d;
  --accent-soft:#ffe8d8;
  --shadow:0 2px 10px rgba(60,40,20,.06);
  --radius:18px;
}
body[data-mode="clean"]{
  --bg:#f3f8f6; --panel:#ffffff; --line:#e2ece7; --bot:#e9f2ee;
  --user:#3e9e7a; --user-text:#0d2a20;
  --accent:#3e9e7a; --accent-soft:#dff0e8;
}
body[data-mode="normal"]{
  --bg:#f7f5f2; --line:#eae4dc; --bot:#f1eee9;
  --user:#ff8a3d; --user-text:#3a1e08;
  --accent:#ff8a3d; --accent-soft:#ffe8d8;
}
body[data-mode="dorat"]{
  --bg:#f6f2fb; --line:#e8dff4; --bot:#efe6fa;
  --user:#7b3fe4; --user-text:#ffffff;
  --accent:#7b3fe4; --accent-soft:#e8ddfb;
}
body[data-mode="smart"]{
  --bg:#f4f6fb; --line:#e2e8f5; --bot:#e9eef9;
  --user:#3a6df0; --user-text:#ffffff;
  --accent:#3a6df0; --accent-soft:#e2ebff;
}

/* ── 다크 모드 (화이트 기본) ── */
body[data-theme="dark"]{
  --bg:#141519; --panel:#1b1c21; --line:#2b2d35; --bot:#23252c; --text:#ecebe7; --text-dim:#9b998f;
  --shadow:0 2px 12px rgba(0,0,0,.42);
}
body[data-theme="dark"][data-mode="clean"]{--accent:#4fc7a0; --user:#2f9d7c; --user-text:#eafff6; --accent-soft:#1b3129}
body[data-theme="dark"][data-mode="normal"]{--accent:#ff9a57; --user:#e8762c; --user-text:#1b0f04; --accent-soft:#33241a}
body[data-theme="dark"][data-mode="dorat"]{--accent:#a07bff; --user:#6b35d6; --user-text:#fff; --accent-soft:#271d3d}
body[data-theme="dark"][data-mode="smart"]{--accent:#7d9dff; --user:#3a6df0; --user-text:#fff; --accent-soft:#1c2740}
body[data-theme="dark"] .gate{background:rgba(8,9,12,.66)}
body[data-theme="dark"] .bubble pre.code{background:rgba(255,255,255,.07)}
body[data-theme="dark"] .bubble code.inline{background:rgba(255,255,255,.09)}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Apple SD Gothic Neo","Malgun Gothic","Noto Sans KR",system-ui,sans-serif;
  font-size:15px; line-height:1.45;
  display:flex; flex-direction:column;
  transition:background .36s cubic-bezier(.22,1,.36,1), color .26s cubic-bezier(.22,1,.36,1);
  overscroll-behavior-y:contain;
}

/* ── 카톡 탈출 배너 ── */
#kakao-banner[hidden]{display:none}
#kakao-banner{
  display:flex; gap:8px; align-items:center; justify-content:center;
  padding:8px 12px; background:#fee500; color:#3c1e1e; font-size:12.5px; font-weight:600;
}
#kakao-banner a{color:#3c1e1e; text-decoration:underline}

/* ── 헤더 ── */
.app-header{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding:9px 14px; padding-top:calc(9px + env(safe-area-inset-top));
  background:color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter:saturate(140%) blur(10px);
  border-bottom:1px solid var(--line);
  transition:background .34s cubic-bezier(.22,1,.36,1), border-color .34s cubic-bezier(.22,1,.36,1);
}
.brand{display:flex; align-items:center; gap:9px; min-width:0}
.mascot{width:38px; height:38px; flex:0 0 38px; transition:transform .3s}
.mascot svg{width:100%; height:100%; display:block}
body[data-mode="dorat"] .mascot{animation:wiggle 1.6s ease-in-out infinite}
@keyframes wiggle{
  0%,100%{transform:rotate(-3deg) scale(1)}
  50%{transform:rotate(3deg) scale(1.04)}
}
.brand-text{min-width:0}
.brand h1{
  margin:0; font-size:17px; font-weight:800; letter-spacing:-.02em; line-height:1.1;
}
.learned{margin:1px 0 0; font-size:11px; color:var(--text-dim); display:flex; align-items:center; gap:3px}
.learned b{color:var(--accent); font-variant-numeric:tabular-nums}
.brain{font-size:10px}

/* 화이트 / 다크 토글 (헤더) */
.theme-btn{
  appearance:none; cursor:pointer; flex:0 0 auto;
  border:1px solid var(--line); background:var(--panel); color:var(--text-dim);
  border-radius:999px; padding:5px 10px; font:inherit; font-size:11.5px; font-weight:800;
  letter-spacing:-.01em; white-space:nowrap;
  transition:color .26s cubic-bezier(.22,1,.36,1), border-color .26s cubic-bezier(.22,1,.36,1), transform .18s cubic-bezier(.22,1,.36,1);
}
.theme-btn:hover{color:var(--accent); border-color:var(--accent)}
.theme-btn:active{transform:scale(.94)}
.theme-btn[aria-pressed="true"]{color:var(--accent); border-color:color-mix(in srgb, var(--accent) 45%, var(--line))}

.modes{
  display:flex; padding:3px; gap:2px; position:relative;
  background:var(--bot); border-radius:999px; flex:0 0 auto;
  transition:background .34s cubic-bezier(.22,1,.36,1);
}
/* 선택 표시는 '미끄러지는 판' 하나가 담당한다 (iOS 세그먼트 컨트롤 느낌) */
.mode-glider{
  position:absolute; top:3px; bottom:3px; left:0; width:0;
  border-radius:999px; background:var(--panel);
  box-shadow:0 1px 4px rgba(0,0,0,.09);
  transform:translate3d(0,0,0); will-change:transform,width; pointer-events:none;
  transition:transform .46s cubic-bezier(.22,1,.36,1), width .46s cubic-bezier(.22,1,.36,1), background .34s cubic-bezier(.22,1,.36,1);
}
.mode-glider.no-anim{transition:none}
/* 모드 버튼 바로 위, 아주 작은 모델명 — 똑똑이 모드일 때만 보인다 */
.modes-wrap{display:flex; flex-direction:column; align-items:flex-end; gap:1px; flex:0 0 auto; min-width:0}
.mode-model{
  font-size:9px; line-height:1.15; letter-spacing:.01em; color:var(--text-dim);
  font-weight:600; opacity:.85; white-space:nowrap;
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
}
.mode-model[hidden]{display:none}
.mode{
  appearance:none; border:0; background:transparent; cursor:pointer; position:relative; z-index:1;
  font:inherit; font-size:12.5px; font-weight:700; color:var(--text-dim);
  padding:5px 11px; border-radius:999px;
  transition:color .26s cubic-bezier(.22,1,.36,1), transform .18s cubic-bezier(.22,1,.36,1);
  white-space:nowrap;
}
.mode:active{transform:scale(.94)}
.mode[aria-checked="true"]{color:var(--accent)}

/* ── 채팅 ── */
.chat{
  flex:1 1 auto; overflow-y:auto; -webkit-overflow-scrolling:touch;
  padding:14px 14px 8px; display:flex; flex-direction:column; gap:9px;
  scroll-behavior:smooth;
}
.row{display:flex; gap:7px; align-items:flex-end; max-width:100%}
.row.bot{justify-content:flex-start; align-items:flex-start}
.row.user{justify-content:flex-end}
.avatar{
  width:26px; height:26px; flex:0 0 26px; margin-top:3px;
}
.avatar svg{width:100%; height:100%; display:block}
.bubble{
  max-width:min(76%, 560px); padding:9px 13px; border-radius:var(--radius);
  white-space:pre-wrap; word-break:break-word; box-shadow:var(--shadow);
  transition:background .34s cubic-bezier(.22,1,.36,1);
}
/* 새로 오가는 말풍선만 iMessage처럼 살짝 튀어오른다 (복원된 옛 대화는 조용히) */
.row.in{animation:msgIn .44s cubic-bezier(.22,1,.36,1) both}
.row.user.in{animation-name:msgInRight}
@keyframes msgIn{from{opacity:0; transform:translateY(10px) scale(.96)} to{opacity:1; transform:none}}
@keyframes msgInRight{from{opacity:0; transform:translateY(8px) translateX(10px) scale(.97)} to{opacity:1; transform:none}}
.row.bot .bubble{background:var(--bot); border-bottom-left-radius:6px}
.row.user .bubble{background:var(--user); color:var(--user-text); border-bottom-right-radius:6px}
.bubble a{color:inherit}

/* 사전 카드 */
.card{padding:0; overflow:hidden; background:var(--panel); border:1px solid var(--line)}
.card-head{
  padding:9px 13px 7px; border-bottom:1px solid var(--line);
  display:flex; align-items:baseline; gap:7px; flex-wrap:wrap;
}
.card-head .w{font-weight:800; font-size:15.5px}
.card-head .pos{font-size:11px; color:var(--accent); font-weight:700}
.card-body{padding:9px 13px 11px; font-size:14px}
.card-body ol{margin:0; padding-left:17px}
.card-body li{margin:0 0 4px}
.card-body li::marker{color:var(--accent); font-weight:700}
.card-src{margin-top:6px; font-size:10.5px; color:var(--text-dim)}

/* 피드백 */
.fb{display:flex; gap:2px; margin-top:3px; padding-left:3px; opacity:.45; transition:opacity .2s}
.row.bot:hover .fb, .fb:focus-within{opacity:1}
.fb button{
  appearance:none; border:0; background:transparent; cursor:pointer;
  font-size:12px; padding:1px 4px; border-radius:8px; line-height:1.2;
  transition:transform .18s cubic-bezier(.22,1,.36,1), background .2s;
}
.fb button:active{transform:scale(.9)}
.fb button:hover{background:var(--accent-soft)}
.fb button[data-on="1"]{opacity:1; transform:scale(1.15)}
.fb .cnt{font-size:10px; color:var(--text-dim); align-self:center; min-width:8px}

/* 타이핑 */
.row.typing .bubble{transition:none}
.typing-wrap{display:inline-flex; align-items:center; gap:8px}
.typing-label{font-size:12px; color:var(--text-dim)}
.typing{display:inline-flex; gap:3px; align-items:center; height:18px}
.typing i{
  width:5px; height:5px; border-radius:50%; background:var(--text-dim);
  animation:blink 1.1s infinite ease-in-out;
}
.typing i:nth-child(2){animation-delay:.15s}
.typing i:nth-child(3){animation-delay:.3s}
@keyframes blink{0%,60%,100%{opacity:.25; transform:translateY(0)} 30%{opacity:1; transform:translateY(-2px)}}

/* 시스템 안내(모드 변경 등) */
.sys{
  align-self:center; font-size:11.5px; color:var(--text-dim);
  background:var(--accent-soft); color:var(--accent);
  padding:4px 11px; border-radius:999px; font-weight:600;
  transition:background .34s cubic-bezier(.22,1,.36,1), color .34s cubic-bezier(.22,1,.36,1);
}
.sys.in{animation:sysIn .4s cubic-bezier(.22,1,.36,1) both}
@keyframes sysIn{from{opacity:0; transform:translateY(-5px) scale(.97)} to{opacity:1; transform:none}}

/* ── 토스트 ── */
.toast{
  position:fixed; left:50%; transform:translateX(-50%);
  bottom:calc(74px + env(safe-area-inset-bottom)); z-index:30;
  background:rgba(34,32,29,.92); color:#fff; font-size:12px; font-weight:600;
  padding:7px 14px; border-radius:999px; box-shadow:0 4px 16px rgba(0,0,0,.18);
  animation:toastIn .22s ease-out;
}
@keyframes toastIn{from{opacity:0; transform:translate(-50%,8px)} to{opacity:1; transform:translate(-50%,0)}}

/* ── 입력바 ── */
.composer{
  display:flex; gap:7px; align-items:center;
  padding:8px 12px; padding-bottom:calc(8px + env(safe-area-inset-bottom));
  background:var(--panel); border-top:1px solid var(--line);
  position:sticky; bottom:0; z-index:20;
  transition:background .34s cubic-bezier(.22,1,.36,1), border-color .34s cubic-bezier(.22,1,.36,1), opacity .24s;
}
#input{
  flex:1 1 auto; min-width:0;
  border:1px solid var(--line); background:var(--bg); color:var(--text);
  border-radius:999px; padding:11px 15px; font:inherit; font-size:15px;
  outline:none; transition:border-color .22s cubic-bezier(.22,1,.36,1), box-shadow .22s cubic-bezier(.22,1,.36,1), background .34s cubic-bezier(.22,1,.36,1);
}
#input:focus{border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft)}
#input::placeholder{color:var(--text-dim)}
#send{
  flex:0 0 40px; width:40px; height:40px; border-radius:50%; border:0; cursor:pointer;
  background:var(--accent); color:#fff; display:grid; place-items:center;
  transition:transform .18s cubic-bezier(.22,1,.36,1), opacity .2s, background .34s cubic-bezier(.22,1,.36,1);
}
#send:active{transform:scale(.9)}
#send svg{fill:currentColor}

/* ── 푸터 ── */
.app-footer{
  display:flex; justify-content:space-between; gap:10px;
  padding:4px 14px calc(4px + env(safe-area-inset-bottom)); font-size:10px; color:var(--text-dim);
  background:var(--panel); border-top:1px solid var(--line);
}
.app-footer a{color:inherit; text-decoration:underline; text-underline-offset:2px}
.app-footer .ver{flex:0 0 auto; opacity:.7}

/* 데스크톱: 가운데 좁은 기둥 */
@media (min-width:720px){
  body{align-items:center}
  .app-header, .composer, .app-footer{width:100%; max-width:680px}
  .chat{width:100%; max-width:680px}
  .app-header{border-left:1px solid var(--line); border-right:1px solid var(--line)}
  .bubble{max-width:min(70%, 460px)}
  .app-footer{border-left:1px solid var(--line); border-right:1px solid var(--line)}
}

@media (prefers-reduced-motion:reduce){
  *{animation:none !important; transition:none !important}
}

/* ── 헤더 오른쪽(모드 + 메뉴) ── */
.header-right{display:flex; align-items:center; gap:6px; flex:0 0 auto}
.menu-btn{
  appearance:none; border:0; background:transparent; cursor:pointer;
  width:28px; height:28px; border-radius:50%; color:var(--text-dim);
  font-size:18px; line-height:1; font-weight:700; padding:0;
  transition:background .2s cubic-bezier(.22,1,.36,1), color .2s, transform .18s cubic-bezier(.22,1,.36,1);
}
.menu-btn:active{transform:scale(.9)}
.menu-btn:hover{background:var(--bot); color:var(--text)}
.menu{
  position:absolute; top:calc(100% - 4px); right:14px; z-index:40;
  background:var(--panel); border:1px solid var(--line); border-radius:14px;
  box-shadow:0 10px 30px rgba(40,25,10,.14); padding:6px; min-width:186px;
}
.menu[hidden]{display:none}
.menu button{
  display:block; width:100%; text-align:left; appearance:none; border:0; background:transparent;
  font:inherit; font-size:13.5px; color:var(--text); padding:9px 11px; border-radius:9px; cursor:pointer;
}
.menu button:hover{background:var(--accent-soft); color:var(--accent)}
.nick-badge{color:var(--text-dim); font-weight:600}

/* ── 닉네임 게이트 ── */
body.gated .composer{opacity:.45; pointer-events:none}
body.gated #input{pointer-events:none}
.gate{
  position:fixed; inset:0; z-index:60; display:grid; place-items:center;
  background:rgba(28,22,16,.42); backdrop-filter:blur(6px); padding:20px;
}
.gate[hidden]{display:none}
.gate-card{
  width:100%; max-width:342px; background:var(--panel); border-radius:24px;
  padding:26px 22px 20px; text-align:center; box-shadow:0 20px 50px rgba(30,20,10,.22);
  animation:cardIn .42s cubic-bezier(.22,1,.36,1) both;
}
@keyframes cardIn{from{opacity:0; transform:translateY(12px) scale(.97)} to{opacity:1; transform:none}}
.gate-mascot{width:76px; height:76px; margin:0 auto 10px}
.gate-mascot svg{width:100%; height:100%}
.gate-card h2{margin:0 0 6px; font-size:19px; letter-spacing:-.02em}
.gate-sub{margin:0 0 16px; font-size:12.5px; color:var(--text-dim); line-height:1.5}
.gate-card form{display:flex; flex-direction:column; gap:8px}
#gate-input{
  width:100%; border:1px solid var(--line); background:var(--bg); color:var(--text);
  border-radius:12px; padding:12px 14px; font:inherit; font-size:15px; outline:none; text-align:center;
}
#gate-input:focus{border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft)}
#gate-start{
  border:0; border-radius:12px; padding:12px; font:inherit; font-size:15px; font-weight:800;
  background:var(--accent); color:#fff; cursor:pointer;
  transition:opacity .15s, transform .18s cubic-bezier(.22,1,.36,1), background .34s cubic-bezier(.22,1,.36,1);
}
#gate-start:active:not(:disabled){transform:scale(.96)}
#gate-start:disabled{opacity:.35; cursor:not-allowed}
.gate-hint{margin:8px 0 0; font-size:11.5px; color:#d0522a; min-height:14px}
.brand h1 .nick-badge{font-size:12px; font-weight:600; color:var(--text-dim); margin-left:2px}

/* 말풍선 폭: 내용에 맞게 (flex 축소로 일찍 줄바꿈되던 문제) */
.row.bot > div:not(.avatar){flex:1 1 auto; min-width:0}
.row.bot .bubble{width:fit-content; max-width:100%}

/* 똑똑이 모드: 코드·인라인 코드 */
.bubble pre.code{
  margin:7px 0 3px; padding:9px 11px; background:rgba(30,40,60,.07); border-radius:10px;
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:12px; line-height:1.5;
  white-space:pre-wrap; word-break:break-word; overflow-x:auto;
}
.row.user .bubble pre.code{background:rgba(255,255,255,.2)}
.bubble code.inline{
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:.92em;
  background:rgba(30,40,60,.07); border-radius:5px; padding:1px 5px;
}
.row.user .bubble code.inline{background:rgba(255,255,255,.2)}

/* 좁은 모바일(390px): 모드 4개가 한 줄에 깔끔하게 */
@media (max-width:430px){
  .app-header{padding-left:11px; padding-right:11px}
  .mode{padding:4px 7px; font-size:11.5px}
  .modes{gap:1px; padding:2.5px}
  .theme-btn{padding:4px 8px; font-size:11px}
  .brand h1{font-size:15.5px}
  .mascot{width:32px; height:32px; flex:0 0 32px}
  .header-right{gap:3px}
  .menu-btn{width:24px; height:24px; font-size:16px}
}

/* ── 이스터에그 (v1.9) — 미친도랏은 버튼 대신 '주문'으로만 켜진다.
   켜져 있을 때만 헤더 아래에 끄기 필이 조용히 뜬다. ── */
.egg-off{display:none}
.egg-off:not([hidden]){
  display:flex; align-items:center; justify-content:center; gap:5px;
  appearance:none; cursor:pointer; font:inherit; width:fit-content;
  margin:5px auto 0; padding:3.5px 11px;
  font-size:11px; font-weight:800; letter-spacing:-.01em;
  color:#b8174f; background:transparent;
  border:1px solid rgba(194,24,91,.32); border-radius:999px;
  opacity:.85; flex:0 0 auto;
  transition:background .26s cubic-bezier(.22,1,.36,1), border-color .26s cubic-bezier(.22,1,.36,1), transform .18s cubic-bezier(.22,1,.36,1), color .26s;
  animation:pillIn .38s cubic-bezier(.22,1,.36,1) both;
}
.egg-off:not([hidden]):active{transform:scale(.94)}
@keyframes pillIn{from{opacity:0; transform:translateY(-7px) scale(.94)} to{opacity:.85; transform:none}}
.egg-off:hover{opacity:1; background:rgba(194,24,91,.07); border-color:rgba(194,24,91,.6)}
body[data-theme="dark"] .egg-off{color:#ff8fb4; border-color:rgba(255,111,156,.35)}
body[data-theme="dark"] .egg-off:hover{background:rgba(255,111,156,.1); border-color:rgba(255,111,156,.65)}

/* 이스터에그 발동 배너 — 채팅 안에 한 번만 띄우는 띠 */
.egg-banner{
  margin:9px 0 3px; padding:9px 12px 10px; border-radius:14px;
  background:linear-gradient(100deg, rgba(194,24,91,.13), rgba(140,32,190,.12));
  border:1px solid rgba(194,24,91,.35); text-align:center;
  animation:eggIn .62s cubic-bezier(.2,.8,.3,1) 1;
}
.egg-banner .t1{
  display:block; font-size:12.5px; font-weight:900; letter-spacing:-.01em; color:#b8174f;
}
.egg-banner .t2{
  display:block; margin-top:3px; font-size:10.5px; font-weight:700; color:var(--text-dim);
  letter-spacing:-.01em;
}
body[data-theme="dark"] .egg-banner .t1{color:#ff8fb4}
body[data-theme="dark"] .egg-banner{background:linear-gradient(100deg, rgba(255,111,156,.12), rgba(160,80,240,.12))}
@keyframes eggIn{from{opacity:0; transform:translateY(-7px) scale(.985)} to{opacity:1; transform:none}}
@media (prefers-reduced-motion: reduce){.egg-banner{animation:none}}

/* 미친도랏은 도랏 기본 보라에서 좀 더 독한 색으로 */
body[data-mode="dorat"][data-flavor="crazy"]{
  --bg:#fbf1f6; --line:#f2d9e6; --bot:#f8e4ef;
  --user:#c2185b; --user-text:#ffffff; --accent:#c2185b; --accent-soft:#fad7e6;
}
body[data-theme="dark"][data-mode="dorat"][data-flavor="crazy"]{
  --accent:#ff6f9c; --user:#b8174f; --user-text:#fff; --accent-soft:#3a1324;
}

@media (max-width:430px){
  .egg-off{font-size:10.5px; padding:3px 10px; margin-top:4px}
}

/* 390px: 헤더 한 줄 유지 — 닉네임 배지는 숨긴다(대화 말풍선에는 그대로 표시) */
@media (max-width:430px){
  .brand h1 .nick-badge{display:none}
  .brand h1{white-space:nowrap}
}
