/* =========================================================
   아바타 AI 비서 — 모바일 우선 다크 UI
   ========================================================= */

:root {
  --bg-0: #070a12;
  --bg-1: #0d1220;
  --bg-2: #141c30;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text-0: #f2f6ff;
  --text-1: #a9b6d0;
  --text-2: #6b7897;
  --accent: #5b8fd6;
  --accent-2: #7ce0c3;
  --accent-3: #b98cf0;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --dock-h: 74px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-2) 0%, var(--bg-1) 42%, var(--bg-0) 100%);
  color: var(--text-0);
  font: 400 16px/1.5 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  position: fixed;
  inset: 0;
  touch-action: manipulation;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font-family: inherit; }

/* ── 공용 글래스 버튼 ── */
.glass-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text-0);
  font-size: 16px;
  transition: transform .16s, background .16s, border-color .16s;
}
.glass-btn:active { transform: scale(.92); background: rgba(255, 255, 255, 0.14); }
.glass-btn.on {
  background: linear-gradient(135deg, rgba(124, 224, 195, .28), rgba(91, 143, 214, .28));
  border-color: rgba(124, 224, 195, .5);
  color: #dffbee;
}

/* ═══════════ 부팅 ═══════════ */
.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 22px;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  z-index: 90;
}
.boot-orb {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent-3), var(--accent));
  filter: blur(.5px);
  animation: orbSpin 2.4s linear infinite, orbPulse 2.4s ease-in-out infinite;
  box-shadow: 0 0 70px rgba(124, 224, 195, .35), 0 0 130px rgba(91, 143, 214, .28);
}
@keyframes orbSpin { to { transform: rotate(360deg); } }
@keyframes orbPulse { 50% { scale: 1.09; } }
.boot-text { color: var(--text-1); font-size: 14px; letter-spacing: .3px; margin: 0; }

/* ═══════════ 잠금 (PIN) ═══════════ */
.lock {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(90% 60% at 50% 12%, #1b2740 0%, var(--bg-0) 70%);
}
.lock-card { width: min(360px, 100%); text-align: center; }
.lock-avatar-mini {
  width: 96px; height: 96px; margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(145deg, #24314f, #131b2e);
  border: 1px solid var(--line-strong);
  display: grid; place-items: center;
  font-size: 40px;
  color: #8fb4e6;
  box-shadow: 0 0 46px rgba(91, 143, 214, .3);
}
.lock-title { margin: 0 0 4px; font-size: 24px; font-weight: 900; letter-spacing: -.4px; }
.lock-sub { margin: 0 0 22px; color: var(--text-1); font-size: 14px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin-bottom: 26px; height: 14px; }
.pin-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 1.6px solid var(--line-strong);
  transition: background .18s, transform .18s, border-color .18s;
}
.pin-dot.filled { background: var(--accent-2); border-color: var(--accent-2); transform: scale(1.14); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-key {
  height: 62px; border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  font-size: 22px; font-weight: 700;
  display: grid; place-items: center;
  transition: transform .12s, background .12s;
}
.pin-key:active { transform: scale(.94); background: rgba(255, 255, 255, 0.13); }
.pin-key.ghost { background: transparent; border-color: transparent; font-size: 15px; color: var(--text-2); }
.lock-error { margin: 16px 0 0; min-height: 20px; color: var(--danger); font-size: 13px; }
.lock.shake .pin-dots { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-9px); }
  75% { transform: translateX(9px); }
}

/* ═══════════ 앱 셸 ═══════════ */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
}

/* ── 무대(아바타) ── */
.stage {
  position: relative;
  flex: 0 0 44vh;
  min-height: 240px;
  overflow: hidden;
  isolation: isolate;
}
.stage-glow {
  position: absolute;
  left: 50%; top: 46%;
  width: 122%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle at 50% 45%, rgba(124, 224, 195, .16), transparent 55%),
    radial-gradient(circle at 30% 70%, rgba(91, 143, 214, .2), transparent 60%),
    radial-gradient(circle at 72% 34%, rgba(185, 140, 240, .16), transparent 58%);
  filter: blur(24px);
  animation: glowDrift 14s ease-in-out infinite alternate;
  z-index: 0;
  transition: opacity .5s;
}
@keyframes glowDrift {
  0% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  100% { transform: translate(-50%, -52%) scale(1.12) rotate(8deg); }
}
.stage[data-emotion="happy"] .stage-glow { opacity: 1; filter: blur(20px) saturate(1.35); }
.stage[data-emotion="sad"] .stage-glow { opacity: .55; filter: blur(30px) saturate(.6); }
.stage[data-emotion="angry"] .stage-glow {
  background: radial-gradient(circle at 50% 45%, rgba(255, 107, 107, .28), transparent 55%);
}
.stage[data-emotion="love"] .stage-glow { background: radial-gradient(circle at 50% 45%, rgba(255, 138, 190, .26), transparent 58%); }

.avatar-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: block;
  transition: opacity .45s ease;
}
.clip-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .7s ease;
  pointer-events: none;
}
.clip-layer.active { opacity: 1; z-index: 3; }
.avatar-canvas.dimmed { opacity: .04; }

.stage-top {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: 0; right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
}
.stage-meta { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
.name-pill {
  font-weight: 900;
  font-size: 17px;
  letter-spacing: -.2px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .6);
  white-space: nowrap;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(8, 12, 22, .55);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
}
.status-pill i { font-size: 6px; color: var(--text-2); }
.status-pill.is-gemini i { color: var(--accent-2); }
.status-pill.is-local i { color: var(--accent-3); }
.status-pill.is-off i { color: var(--danger); }

.emotion-badge {
  position: absolute;
  left: 14px;
  bottom: 12px;
  z-index: 6;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(8, 12, 22, .5);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text-1);
}

.wake-hint {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(124, 224, 195, .13);
  border: 1px solid rgba(124, 224, 195, .35);
  color: #cdfbe9;
  font-size: 11.5px;
  font-weight: 700;
  backdrop-filter: blur(10px);
}
.wake-hint i { animation: micGlow 1.4s ease-in-out infinite; }
@keyframes micGlow { 50% { opacity: .35; } }

/* ── 대화 기록 ── */
.transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  scrollbar-width: thin;
}
.transcript::-webkit-scrollbar { width: 4px; }
.transcript::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }

.bubble {
  max-width: 84%;
  padding: 11px 15px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  animation: bubbleIn .32s cubic-bezier(.22, 1, .36, 1);
  position: relative;
}
@keyframes bubbleIn { from { opacity: 0; transform: translateY(9px) scale(.97); } }
.bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #3f6fb8, #2c4f8a);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 20px rgba(44, 79, 138, .35);
}
.bubble.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.075);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  backdrop-filter: blur(10px);
}
.bubble.assistant .bubble-emo {
  position: absolute;
  top: -7px;
  left: -7px;
  font-size: 13px;
}
.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  padding: 4px 12px;
  border: 1px dashed var(--line);
  text-align: center;
  max-width: 92%;
}
.bubble .cites { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 6px; }
.bubble .cite {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(124, 224, 195, .12);
  border: 1px solid rgba(124, 224, 195, .3);
  color: #b7f2dd;
  text-decoration: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bubble .acts { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.bubble .act {
  font-size: 11px;
  color: var(--text-1);
  display: flex; align-items: center; gap: 6px;
}
.bubble .act i { color: var(--accent-2); font-size: 10px; }
.bubble .act.fail i { color: var(--danger); }

/* ── 추천 명령 ── */
.suggest-row {
  display: flex;
  gap: 8px;
  padding: 6px 14px 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.suggest-row::-webkit-scrollbar { display: none; }
.suggest-row:empty { padding: 0; }
.suggest {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--text-1);
  white-space: nowrap;
  transition: background .15s;
}
.suggest:active { background: rgba(255, 255, 255, 0.14); }

/* ── 하단 독 ── */
.dock {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px calc(9px + var(--safe-b));
  background: linear-gradient(180deg, transparent, rgba(7, 10, 18, .85) 32%);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.mic-btn {
  position: relative;
  width: 50px; height: 50px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 19px;
  color: #06121a;
  background: linear-gradient(140deg, var(--accent-2), #4fc3f7);
  box-shadow: 0 6px 22px rgba(79, 195, 247, .38);
  transition: transform .16s, box-shadow .2s;
}
.mic-btn:active { transform: scale(.93); }
.mic-btn.rec {
  background: linear-gradient(140deg, #ff8a8a, var(--danger));
  box-shadow: 0 6px 26px rgba(255, 107, 107, .5);
}
.mic-btn.rec::after {
  content: '';
  position: absolute; inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(255, 107, 107, .55);
  animation: ring 1.3s ease-out infinite;
}
@keyframes ring {
  0% { transform: scale(.86); opacity: .9; }
  100% { transform: scale(1.35); opacity: 0; }
}
.composer {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.065);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 5px 4px 16px;
  min-width: 0;
}
.composer-input {
  flex: 1 1 auto;
  min-width: 0;
  background: none;
  border: 0;
  outline: none;
  color: var(--text-0);
  font-size: 15px;
  padding: 8px 0;
}
.composer-input::placeholder { color: var(--text-2); }
.send-btn {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #3a6fbe);
  color: #fff;
  font-size: 14px;
  transition: transform .15s;
}
.send-btn:active { transform: scale(.9); }
.wake-btn { flex: 0 0 auto; }

.thinking-bar {
  position: absolute;
  left: 50%; bottom: calc(var(--dock-h) + 10px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(8, 12, 22, .72);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  z-index: 7;
}
.thinking-bar span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-2);
  animation: dot 1.15s ease-in-out infinite;
}
.thinking-bar span:nth-child(2) { animation-delay: .16s; background: #6fd3f5; }
.thinking-bar span:nth-child(3) { animation-delay: .32s; background: var(--accent-3); }
@keyframes dot { 0%, 80%, 100% { transform: scale(.55); opacity: .45; } 40% { transform: scale(1); opacity: 1; } }

/* ═══════════ 패널 (바텀시트) ═══════════ */
.panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 70;
  height: 82vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #141c30, #0b1120);
  border-top: 1px solid var(--line-strong);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .6);
  transform: translateY(101%);
  transition: transform .34s cubic-bezier(.22, 1, .36, 1);
}
.panel.open { transform: translateY(0); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 10px;
  flex: 0 0 auto;
}
.panel-head h2 { margin: 0; font-size: 18px; font-weight: 900; }
.tabs {
  display: flex; gap: 6px;
  padding: 0 12px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 0 0 auto;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  transition: all .16s;
}
.tab.active {
  color: #dffbee;
  background: rgba(124, 224, 195, .14);
  border-color: rgba(124, 224, 195, .35);
}
.panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(28px + var(--safe-b));
}

.card {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 11px;
}
.card-title { font-size: 13px; font-weight: 800; color: var(--text-1); margin: 0 0 10px; display: flex; align-items: center; gap: 7px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-1); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line);
  color: var(--text-0);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.field .hint { font-size: 11px; color: var(--text-2); margin-top: 5px; line-height: 1.45; }
.row { display: flex; gap: 9px; align-items: center; }
.row > * { min-width: 0; }
.btn {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #3a6fbe);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  transition: transform .14s, opacity .14s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); color: var(--text-0); }
.btn.danger { background: linear-gradient(135deg, #e05252, #b03535); }
.btn.ok { background: linear-gradient(135deg, #2fae7a, #1f8a60); }
.btn.full { width: 100%; }
.btn:disabled { opacity: .45; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}
.item-main { flex: 1 1 auto; min-width: 0; }
.item-title { font-size: 14.5px; font-weight: 700; margin: 0 0 3px; word-break: break-word; }
.item-sub { font-size: 12px; color: var(--text-1); margin: 0; word-break: break-word; }
.item-meta { font-size: 11px; color: var(--text-2); margin: 4px 0 0; }
.icon-btn {
  width: 32px; height: 32px; flex: 0 0 auto;
  border-radius: 9px; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--text-1);
  font-size: 12px;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }
.icon-btn.danger { color: var(--danger); }

/* 의상 그리드 */
.outfit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.outfit-card {
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  padding: 9px 8px 10px;
  text-align: center;
  transition: border-color .16s, transform .16s;
}
.outfit-card:active { transform: scale(.96); }
.outfit-card.active { border-color: var(--accent-2); background: rgba(124, 224, 195, .1); }
.outfit-swatch {
  width: 100%; aspect-ratio: 1 / 1;
  border-radius: 10px;
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .1);
}
.outfit-name { font-size: 12px; font-weight: 700; }
.outfit-desc { font-size: 10.5px; color: var(--text-2); margin-top: 2px; }

.empty { text-align: center; color: var(--text-2); font-size: 13px; padding: 26px 12px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700;
  background: rgba(255, 255, 255, .07); border: 1px solid var(--line); color: var(--text-1);
}
.badge.ok { background: rgba(74, 222, 128, .14); border-color: rgba(74, 222, 128, .34); color: #b9f6ce; }
.badge.warn { background: rgba(255, 193, 94, .14); border-color: rgba(255, 193, 94, .34); color: #ffe0ab; }
.badge.bad { background: rgba(255, 107, 107, .14); border-color: rgba(255, 107, 107, .34); color: #ffc4c4; }

/* ═══════════ 토스트 ═══════════ */
.toast-wrap {
  position: fixed;
  left: 50%; bottom: calc(96px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 95;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 92vw;
}
.toast {
  padding: 10px 17px;
  border-radius: 999px;
  background: rgba(14, 20, 34, .94);
  border: 1px solid var(--line-strong);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastIn .28s cubic-bezier(.22, 1, .36, 1);
  backdrop-filter: blur(14px);
  text-align: center;
}
.toast.err { border-color: rgba(255, 107, 107, .5); color: #ffc9c9; }
.toast.ok { border-color: rgba(74, 222, 128, .45); color: #bff5d2; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }

/* ═══════════ 반응형 ═══════════ */
@media (min-width: 620px) {
  .stage { flex: 0 0 40vh; }
  .transcript { max-width: 680px; width: 100%; margin: 0 auto; }
  .dock { max-width: 680px; width: 100%; margin: 0 auto; border-radius: 22px 22px 0 0; }
  .suggest-row { max-width: 680px; margin: 0 auto; width: 100%; }
  .bubble { max-width: 74%; }
}
@media (max-height: 640px) {
  .stage { flex: 0 0 34vh; min-height: 180px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
