:root {
  --bg: #0b1020; --surface: rgba(255,255,255,.055); --surface-2: rgba(255,255,255,.09); --line: rgba(255,255,255,.1);
  --text: #eef2ff; --muted: #8b93ad; --dim: #5d6584;
  --primary: #5b8cff; --primary-2: #8a5bff; --accent: #ff5e9c; --ok: #4ade80; --warn: #fbbf24; --err: #f87171;
  --grad: linear-gradient(135deg, #5b8cff, #8a5bff 60%, #c05bff);
  --grad-me: linear-gradient(135deg, #3b6cf0, #6a4cf0);
  --radius: 20px; --fab: 72px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, "SF Pro Text", "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", "Noto Sans SC", "Noto Sans JP", system-ui, sans-serif; overscroll-behavior: none; }
body { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.msg, .card-text, dialog input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; display: block; }

.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: radial-gradient(1200px 600px at 50% -10%, #182046, var(--bg) 60%); }
.glow { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .45; }
.g1 { width: 320px; height: 320px; background: #4c6fff; top: -80px; left: -100px; }
.g2 { width: 360px; height: 360px; background: #b14cff; bottom: 60px; right: -140px; opacity: .3; }

#app { display: flex; flex-direction: column; height: 100dvh; padding: calc(env(safe-area-inset-top) + 10px) 16px calc(env(safe-area-inset-bottom) + 10px); gap: 12px; }

/* 상단 */
.top { display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { width: 34px; height: 34px; border-radius: 11px; background: var(--grad); box-shadow: 0 6px 18px rgba(91,140,255,.35); }
.brand strong { display: block; font-size: 17px; letter-spacing: .2px; }
.brand small { display: block; font-size: 11px; color: var(--muted); }
.top-actions { display: flex; gap: 6px; }
.ghost { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.ghost:active { background: var(--surface-2); }
.ghost.sm { width: 34px; height: 34px; border-radius: 10px; }
.ghost.sm svg { width: 18px; height: 18px; }

/* 언어/모드 */
.langbar { display: flex; align-items: center; gap: 8px; }
.lang-pill { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; font-weight: 600; font-size: 15px; min-width: 0; }
.lang-pill.select { position: relative; background: linear-gradient(var(--bg), var(--bg)) padding-box, var(--grad) border-box; border: 1px solid transparent; }
select { color-scheme: dark; }
select option { background: #121833; color: var(--text); }
.lang-pill select { flex: 1; appearance: none; -webkit-appearance: none; background: transparent; border: 0; color: var(--text); font: inherit; font-weight: 600; padding-right: 18px; min-width: 0; }
.lang-pill.select::after { content: ''; position: absolute; right: 14px; top: 50%; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.flag { font-size: 11px; font-weight: 800; letter-spacing: .5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 3px 6px; color: var(--muted); }
.lang-pill.select .flag { background: var(--grad); color: #fff; border-color: transparent; }
.swap { color: var(--dim); }
.swap svg { width: 20px; height: 20px; }
.modes { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.modes button { flex: 0 0 auto; background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 13px; color: var(--muted); cursor: pointer; }
.modes button.on { background: var(--surface-2); color: var(--text); border-color: rgba(138,91,255,.6); }

/* 상대방 카드 */
.partner-card { background: linear-gradient(rgba(16,22,44,.9), rgba(16,22,44,.9)) padding-box, linear-gradient(135deg, rgba(91,140,255,.7), rgba(255,94,156,.5)) border-box; border: 1px solid transparent; border-radius: var(--radius); padding: 12px 14px 14px; box-shadow: 0 20px 50px rgba(0,0,0,.35); transition: transform .35s; min-height: 118px; display: flex; flex-direction: column; }
.partner-card.flipped { transform: rotate(180deg); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.card-tools { display: flex; gap: 6px; }
.badge { background: var(--grad); color: #fff; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; letter-spacing: .3px; }
.card-text { font-size: clamp(22px, 6vw, 32px); font-weight: 700; line-height: 1.3; word-break: keep-all; overflow-wrap: anywhere; max-height: 30dvh; overflow: auto; }
.card-text .placeholder { color: var(--dim); font-weight: 400; font-size: .62em; }

/* 대화 흐름 */
.stream { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 0 calc(var(--fab) + 28px); scrollbar-width: none; }
.stream::-webkit-scrollbar { display: none; }
.empty-state { margin: auto; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.6; padding: 0 12px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.45; position: relative; animation: rise .25s ease-out; }
.msg.me { align-self: flex-end; background: var(--grad-me); border-bottom-right-radius: 6px; box-shadow: 0 8px 20px rgba(59,108,240,.3); }
.msg.partner { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg .orig { color: rgba(255,255,255,.72); font-size: 13px; margin-bottom: 3px; }
.msg.partner .orig { color: var(--muted); }
.msg .trans { font-weight: 600; }
.msg .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; font-size: 11px; color: rgba(255,255,255,.55); }
.msg .meta button { background: transparent; border: 0; padding: 0; color: inherit; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.msg .meta svg { width: 14px; height: 14px; }
.msg .note { font-size: 12px; color: var(--warn); margin-top: 4px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 하단 독 + 마이크 */
.dock { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 14px); display: flex; align-items: center; gap: 8px; pointer-events: none; }
.dock > * { pointer-events: auto; }
.dock-btn { flex: 0 0 auto; white-space: nowrap; line-height: 1; height: 38px; display: flex; align-items: center; gap: 6px; background: rgba(16,22,44,.85); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 999px; padding: 9px 13px; font-size: 13px; color: var(--muted); cursor: pointer; }
.dock-btn svg { width: 17px; height: 17px; }
.dock-btn.on { color: var(--text); border-color: rgba(91,140,255,.6); }
#autoSpeak:not(.on) { opacity: .6; }
.status-chip { position: absolute; right: 0; bottom: calc(var(--fab) + 12px); max-width: 100%; background: rgba(16,22,44,.92); border: 1px solid var(--line); border-radius: 16px; padding: 8px 12px; font-size: 12px; line-height: 1.4; color: var(--muted); backdrop-filter: blur(14px); overflow-wrap: anywhere; }
.status-chip.busy { color: var(--warn); border-color: rgba(251,191,36,.5); }
.status-chip.rec { color: var(--accent); border-color: rgba(255,94,156,.6); }
.status-chip.err { color: var(--err); border-color: rgba(248,113,113,.6); }
.status-chip[hidden] { display: none; }
.fab { touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; margin-left: auto; flex: 0 0 var(--fab); width: var(--fab); height: var(--fab); min-height: var(--fab); max-height: var(--fab); aspect-ratio: 1; border-radius: 50%; border: 0; background: var(--grad); color: #fff; display: grid; place-items: center; position: relative; cursor: pointer; user-select: none; -webkit-user-select: none; box-shadow: 0 14px 34px rgba(138,91,255,.45), inset 0 1px 0 rgba(255,255,255,.3); transition: transform .12s; }
.fab > * { grid-area: 1 / 1; }
.fab:active { transform: scale(.95); }
.fab svg { width: 30px; height: 30px; }
.fab .ic-stop, .fab .wave { display: none; }
.fab .ring { width: 100%; height: 100%; border-radius: 50%; border: 2px solid rgba(255,94,156,.7); opacity: 0; }
.fab.recording { background: linear-gradient(135deg, #ff5e9c, #ff3d6e); box-shadow: 0 14px 34px rgba(255,94,156,.5); transform: scale(1.06); }
.fab.recording .ic-mic { display: none; }
.fab.recording .ring { opacity: 1; animation: ring 1.3s ease-out infinite; }
.fab.recording .wave { display: flex; gap: 3px; align-items: center; height: 26px; }
.fab.recording .wave i { width: 4px; border-radius: 2px; background: #fff; animation: bar .8s ease-in-out infinite; }
.fab.recording .wave i:nth-child(2) { animation-delay: .1s; } .fab.recording .wave i:nth-child(3) { animation-delay: .2s; } .fab.recording .wave i:nth-child(4) { animation-delay: .3s; } .fab.recording .wave i:nth-child(5) { animation-delay: .4s; }
.fab.busy { pointer-events: none; filter: saturate(.5); }
/* 핸즈프리 대기: 은은하게 숨 쉬는 테두리 */
.fab.armed { box-shadow: 0 0 0 4px rgba(74,222,128,.35), 0 14px 34px rgba(138,91,255,.45); animation: breathe 2.2s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 3px rgba(74,222,128,.25), 0 14px 34px rgba(138,91,255,.45); } 50% { box-shadow: 0 0 0 9px rgba(74,222,128,.08), 0 14px 34px rgba(138,91,255,.45); } }
#handsFree.on { color: var(--ok); border-color: rgba(74,222,128,.6); }
.fab.busy .ic-mic { animation: spin 1.1s linear infinite; opacity: .8; }
@keyframes ring { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.7); opacity: 0; } }
@keyframes bar { 0%, 100% { height: 6px; } 50% { height: 24px; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* 마주보기 모드 */
body.face-mode #app { display: none; }
.face { position: fixed; inset: 0; display: grid; grid-template-rows: 1fr auto 1fr; padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom); gap: 6px; }
.face[hidden] { display: none; }
.face-pane { position: relative; display: flex; flex-direction: column; border-radius: var(--radius); padding: 14px 16px; min-height: 0; border: 1px solid transparent; }
.face-partner { transform: rotate(180deg); background: linear-gradient(rgba(16,22,44,.92), rgba(16,22,44,.92)) padding-box, linear-gradient(135deg, rgba(255,94,156,.6), rgba(138,91,255,.6)) border-box; }
.face-me { background: linear-gradient(rgba(16,22,44,.92), rgba(16,22,44,.92)) padding-box, linear-gradient(135deg, rgba(91,140,255,.7), rgba(138,91,255,.6)) border-box; }
.face-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.face-status { flex: 1; font-size: 12px; color: var(--muted); }
.face-status.busy { color: var(--warn); } .face-status.rec { color: var(--accent); } .face-status.err { color: var(--err); }
.badge-ko { background: var(--grad-me); }
.face-text { flex: 1; overflow: auto; font-size: clamp(24px, 6.5vw, 40px); font-weight: 700; line-height: 1.3; word-break: keep-all; overflow-wrap: anywhere; padding-right: 84px; }
.face-text .placeholder { color: var(--dim); font-weight: 400; font-size: .6em; }
.face-fab { position: absolute; right: 14px; bottom: 14px; margin: 0; }
.face-divider { display: flex; justify-content: center; align-items: center; height: 36px; }
.face-divider .ghost { opacity: .7; }

/* 참가자 화면 */
body.guest-mode #app, body.guest-mode .dock { display: none; }
.guest { position: fixed; inset: 0; display: flex; flex-direction: column; padding: 5vh 6vw; gap: 3vh; }
.guest[hidden] { display: none; }
.guest-head { display: flex; align-items: center; gap: 16px; }
.guest-head .badge { font-size: clamp(14px, 1.6vw, 22px); padding: 6px 16px; }
.guest-status { font-size: clamp(14px, 1.6vw, 22px); color: var(--muted); }
.guest-status.busy { color: var(--warn); } .guest-status.rec { color: var(--accent); } .guest-status.err { color: var(--err); }
.guest-text { flex: 1; display: flex; align-items: center; font-size: clamp(32px, 5.2vw, 76px); font-weight: 700; line-height: 1.25; word-break: keep-all; overflow-wrap: anywhere; overflow: auto; }
.guest-text .placeholder { color: var(--dim); font-weight: 400; font-size: .55em; }
.guest-sub { font-size: clamp(16px, 2vw, 28px); color: var(--muted); min-height: 1.4em; }
.guest-foot { font-size: 13px; color: var(--dim); letter-spacing: .5px; }
#micSelect { display: block; width: 100%; margin-top: 5px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 15px; }
#phraseSets { margin-bottom: 8px; }

/* 시트/다이얼로그 */
dialog.sheet { border: 1px solid var(--line); border-radius: 22px 22px 0 0; background: #121833; color: var(--text); width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: 82dvh; padding: 14px 18px calc(env(safe-area-inset-bottom) + 18px); box-shadow: 0 -20px 60px rgba(0,0,0,.5); }
@media (min-width: 640px) { dialog.sheet { width: min(92vw, 520px); margin: auto; border-radius: 22px; } }
dialog::backdrop { background: rgba(5,8,20,.65); backdrop-filter: blur(4px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-foot { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.dialog-foot button { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 14px; font-size: 14px; cursor: pointer; }
.dialog-foot button.danger { color: var(--err); border-color: rgba(248,113,113,.5); }
dialog label { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }
dialog label.row { display: flex; align-items: center; gap: 8px; }
dialog input[type=url], dialog input[type=password] { display: block; width: 100%; margin-top: 5px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 15px; }
.small { font-size: 12px; color: var(--muted); margin: 4px 0 10px; }
.status { font-size: 12px; } .status.busy { color: var(--warn); } .status.ok { color: var(--ok); } .status.err { color: var(--err); }
.phrase-list { display: flex; flex-wrap: wrap; gap: 8px; }
.phrase-list button { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; font-size: 14px; cursor: pointer; }
.phrase-list button:active { background: var(--grad); }
.history-list { max-height: 55dvh; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.turn { background: var(--surface); border-radius: 14px; padding: 10px 12px; font-size: 14px; border-left: 3px solid var(--primary); }
.turn.from-partner { border-left-color: var(--accent); }
.turn .meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.turn .src { color: var(--muted); }
.turn .dst { font-weight: 600; margin-top: 2px; }
.empty { color: var(--muted); text-align: center; padding: 20px; }

/* 좁은 폰: 하단 버튼은 아이콘만, 카드·여백 축소 */
@media (max-width: 400px) {
  .dock-btn span { display: none; }
  .dock-btn { width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 50%; }
  .dock-btn svg { width: 19px; height: 19px; }
  .partner-card { min-height: 104px; padding: 10px 12px 12px; }
  .card-text { font-size: clamp(20px, 6vw, 28px); }
  .lang-pill { padding: 9px 10px; font-size: 14px; }
  .brand strong { font-size: 16px; }
}
@media (min-width: 900px) {
  #app { max-width: 1120px; margin: 0 auto; display: grid; grid-template-columns: 400px 1fr; grid-template-rows: auto auto auto 1fr; column-gap: 28px; padding-inline: 28px; }
  .top { grid-column: 1 / 3; }
  .langbar { grid-column: 1; }
  .modes { grid-column: 1; }
  .partner-card { grid-column: 1; grid-row: 4; align-self: start; position: sticky; top: 12px; padding: 18px 20px 22px; }
  .card-text { font-size: 38px; max-height: none; }
  .stream { grid-column: 2; grid-row: 2 / 5; padding-bottom: calc(var(--fab) + 20px); }
  .msg { max-width: 78%; font-size: 16px; }
  .dock { left: auto; right: max(28px, calc(50% - 560px + 28px)); width: min(1120px - 56px, 100vw - 56px); }
  .status-chip { max-width: 60%; }
}
