/* Tercüman — 휴대폰 우선 화면 */
:root {
  --bg: #f4f5fb; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e3e5ef;
  --me: #4f46e5; --me-soft: #eef0ff; --partner: #0d9488; --partner-soft: #e6f6f4;
  --primary: #4f46e5; --danger: #dc2626; --warn: #b45309;
  --radius: 16px; --shadow: 0 1px 2px rgba(17, 24, 39, .06), 0 4px 14px rgba(17, 24, 39, .06);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f1220; --card: #181b2d; --text: #e7e9f3; --muted: #9aa0b4; --line: #2a2f47;
  --me: #818cf8; --me-soft: #23264a; --partner: #2dd4bf; --partner-soft: #12302d;
  --primary: #818cf8; --danger: #f87171; --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5;
  display: grid; grid-template-rows: auto 1fr auto; height: 100dvh; overflow: hidden;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }
.ic { display: inline-flex; line-height: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.between { justify-content: space-between; gap: 8px; }
.spacer { flex: 1; }
.mt { margin-top: 12px; }
.warn { color: var(--warn); }

/* 위쪽 막대 */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text); font-weight: 800; letter-spacing: -.2px; }
.brand img { border-radius: 8px; }
.brand span { font-size: 17px; }
.pair {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); font-size: 14px; font-weight: 600; max-width: 62vw; white-space: nowrap; overflow: hidden;
}
.pair .ic { color: var(--muted); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: 12px;
  border: 0; background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--bg); }
.icon-btn.sm { width: 34px; height: 34px; border-radius: 10px; color: var(--muted); }
.icon-btn.primary { background: var(--primary); color: #fff; }
.icon-btn.on { background: var(--me-soft); color: var(--me); }
.icon-btn:disabled { opacity: .4; cursor: default; }

/* 본문 · 아래 탭 */
main { overflow-y: auto; padding: 12px 12px 16px; outline: none; -webkit-overflow-scrolling: touch; }
body[data-view="talk"] main { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.tabbar {
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 6px; text-decoration: none;
  color: var(--muted); font-size: 11.5px; font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--primary); }

/* 공통 부품 */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 12px; border: 1px solid transparent;
  padding: 11px 16px; font-weight: 700; background: var(--bg); color: var(--text);
}
.btn.block { display: flex; width: 100%; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.soft { background: var(--me-soft); color: var(--me); }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn.round { width: 64px; height: 64px; border-radius: 50%; padding: 0; background: rgba(255,255,255,.15); color: #fff; }
.btn.round.ghost { border-color: rgba(255,255,255,.3); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.chip.on { background: var(--me-soft); border-color: transparent; color: var(--me); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.link { border: 0; background: none; color: var(--primary); font-weight: 700; padding: 0; text-decoration: underline; }
.select { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.seg { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 12px; flex-wrap: wrap; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.empty { text-align: center; padding: 32px 20px; color: var(--text); }
.empty-icon { font-size: 44px; }
.empty p { margin: 8px 0; }
.page-note { margin: 2px 2px 10px; }
.page-title { font-size: 22px; margin: 4px 2px 12px; }
.group-date { font-size: 14px; color: var(--muted); margin: 16px 4px 8px; }

/* 대화 */
.toolbar { display: flex; gap: 6px; padding: 10px 12px 6px; }
.chat { flex: 1; overflow-y: auto; padding: 6px 12px 12px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.bubble {
  max-width: 88%; border-radius: 18px; padding: 10px 12px 8px; background: var(--card); box-shadow: var(--shadow);
  border: 1px solid transparent;
}
.bubble.me { align-self: flex-end; background: var(--me-soft); border-bottom-right-radius: 6px; }
.bubble.partner { align-self: flex-start; background: var(--partner-soft); border-bottom-left-radius: 6px; }
.b-orig { font-size: 13.5px; color: var(--muted); }
.b-orig em { font-style: normal; }
.b-trans { font-size: 20px; font-weight: 700; line-height: 1.4; margin-top: 3px; word-break: keep-all; overflow-wrap: anywhere; }
.bubble.me .b-trans { color: var(--me); }
.bubble.partner .b-trans { color: var(--partner); }
.b-trans.pending { color: var(--muted) !important; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.b-reading { font-size: 14px; color: var(--muted); margin-top: 2px; }
.b-error { color: var(--danger); font-size: 14px; margin-top: 4px; }
.b-actions { display: flex; align-items: center; gap: 2px; margin-top: 4px; flex-wrap: wrap; }
.b-time { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.edit-area { width: 100%; border-radius: 10px; border: 1px solid var(--line); padding: 8px; margin: 6px 0; background: var(--card); }
.dots { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.live { margin: 0 12px 8px; padding: 10px 12px; border-radius: 14px; border: 2px dashed var(--line); background: var(--card); }
.live.me { border-color: var(--me); }
.live.partner { border-color: var(--partner); }
.live-label { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.live-text { font-size: 18px; font-weight: 600; min-height: 27px; }

.typing { display: flex; align-items: center; gap: 6px; padding: 0 12px 8px; }
.type-input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; font-size: 16px; }
.chip.side.me { color: var(--me); border-color: var(--me); }
.chip.side.partner { color: var(--partner); border-color: var(--partner); }

.controls {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; padding: 10px 12px 12px;
  background: var(--card); border-top: 1px solid var(--line);
}
.mic {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 72px; border-radius: 22px;
  border: 0; color: #fff; padding: 10px 12px; text-align: left; overflow: hidden; --lvl: 0;
  transition: transform .1s ease;
}
.mic:active { transform: scale(.97); }
.mic.me { background: var(--me); }
.mic.partner { background: var(--partner); }
[data-theme="dark"] .mic { color: #0f1220; }
.mic-text { display: flex; flex-direction: column; line-height: 1.2; }
.mic-text b { font-size: 16px; white-space: nowrap; }
.mic-text small { font-size: 12px; opacity: .85; }
.mic-ring { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.mic.on .mic-ring { box-shadow: inset 0 0 0 calc(3px + var(--lvl) * 10px) rgba(255, 255, 255, .35); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { background: rgba(255, 255, 255, .12); } }
.kb { width: 48px; height: 48px; border-radius: 50%; background: var(--bg); }

/* 마주 보기 */
.f2f { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.f2f-half { flex: 1; min-height: 0; display: flex; }
.f2f-half.flip { transform: rotate(180deg); }
.f2f-half.partner { background: var(--partner-soft); }
.f2f-half.me { background: var(--me-soft); }
.f-panel { flex: 1; display: flex; flex-direction: column; padding: 12px; gap: 10px; min-height: 0; }
.f-lines { flex: 1; overflow-y: auto; display: flex; flex-direction: column; justify-content: flex-end; gap: 8px; }
.f-line { font-size: 22px; font-weight: 700; line-height: 1.35; word-break: keep-all; overflow-wrap: anywhere; }
.f-line.own { font-size: 15px; font-weight: 500; color: var(--muted); }
.f-line.live-line { color: var(--text); }
.f-hint { margin: auto; color: var(--muted); font-size: 18px; font-weight: 600; }
.mic.big { min-height: 80px; width: 100%; }
.f2f-mid { display: flex; justify-content: center; gap: 8px; padding: 6px; background: var(--card); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

/* 글 번역 */
.lang-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; margin-bottom: 10px; }
.text-area { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px; resize: vertical; min-height: 120px; font-size: 17px; background: var(--card); }
.card > .row.between { margin: 6px 0 10px; }
.result-card .result-text { font-size: 22px; font-weight: 700; line-height: 1.4; margin: 6px 0 2px; color: var(--primary); word-break: keep-all; overflow-wrap: anywhere; }
.result-card .b-actions { gap: 6px; margin-top: 10px; }

/* 표현집 */
.phrase { display: flex; align-items: center; gap: 6px; padding: 10px 8px 10px 14px; }
.phrase-main { flex: 1; text-align: left; border: 0; background: none; padding: 0; min-width: 0; }
.phrase-me { font-size: 14px; color: var(--muted); }
.phrase-say { font-size: 18px; font-weight: 700; color: var(--partner); line-height: 1.35; }
.phrase-acts { display: flex; flex-direction: column; }

/* 기록 */
.hist-orig { font-size: 14.5px; color: var(--muted); margin-top: 2px; }
.hist-trans { font-size: 17px; font-weight: 700; }

/* 설정 */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row.col { flex-direction: column; align-items: stretch; gap: 8px; }
.set-label { font-weight: 700; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.slider { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .2s; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary); outline-offset: 2px; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.voice-row { display: grid; grid-template-columns: 92px 1fr auto; gap: 6px; align-items: center; margin-top: 8px; }
.voice-lang { font-weight: 600; font-size: 14px; }

/* 언어 고르기 */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; justify-content: center; z-index: 30; }
.sheet { width: 100%; max-width: 520px; background: var(--card); border-radius: 20px 20px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-size: 17px; }
.pick-row { margin: 10px 0; }
.pick-label { font-weight: 700; font-size: 14px; margin-bottom: 6px; color: var(--muted); }

/* 크게 보기 (마이크 .mic.big 과 이름이 겹치지 않게 bigview) */
.bigview {
  position: fixed; inset: 0; z-index: 40; background: #0b0d18; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; gap: 16px;
}
.big-text { font-size: clamp(30px, 9vw, 64px); font-weight: 800; line-height: 1.25; word-break: keep-all; overflow-wrap: anywhere; }
.big-reading { font-size: 20px; opacity: .7; }
.big-actions { display: flex; gap: 16px; margin-top: 16px; }

/* 알림 */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); max-width: 92vw;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: #b91c1c; }
#toast.ok { background: #047857; }

@media (min-width: 720px) {
  main { padding: 16px 20% 20px; }
  body[data-view="talk"] main { padding: 0 12%; }
  .bubble { max-width: 70%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
