:root {
  --bg: #f7f5f0;
  --panel: #ffffff;
  --text: #1c1d20;
  --muted: #6b6e76;
  --line: #e2ded5;
  --accent: #2f5d8a;
  --accent-text: #ffffff;
  --live: #2e8b57;
  --busy: #c58a1b;
  --danger: #b3261e;
  --size: 22px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1d2026;
    --text: #ecebe7;
    --muted: #8d919a;
    --line: #2c3038;
    --accent: #7fb0e0;
    --accent-text: #0e1116;
    --live: #5cc98a;
    --busy: #e2b04a;
    --danger: #f2827a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, select, input { font: inherit; color: inherit; }

button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button:disabled { opacity: .5; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
.icon-btn { padding: 6px 10px; min-width: 40px; background: transparent; }

select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 38vw;
}

/* ---- Login ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  display: grid;
  gap: 10px;
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-card input {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.error { color: var(--danger); margin: 0; min-height: 1.2em; }
.muted { color: var(--muted); }

/* ---- App layout: bar / scrolling transcript / controls ---- */
.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top);
}

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.langs { display: flex; align-items: center; gap: 6px; min-width: 0; }
.arrow { color: var(--muted); }
.status { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.credit { flex: none; color: var(--muted); font-size: 14px; white-space: nowrap; }
.credit strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--live); animation: pulse 1.6s infinite; }
.dot.busy { background: var(--busy); }
.dot.error { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

.menu {
  position: absolute;
  right: 12px;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 5;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 10px;
  min-width: 240px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
}
.check { display: flex; gap: 8px; align-items: center; }
.size-row { display: flex; align-items: center; gap: 6px; }
.size-row span { margin-right: auto; }

.scroller {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 40px;
  scroll-behavior: smooth;
}
.transcript, .live, .empty { max-width: 760px; margin-left: auto; margin-right: auto; }

/* One pair per sentence: the original, then its translation right beneath.
   The translation is what is read during the service: large and calm. */
.seg { margin: 0 0 1.1em; padding-left: 10px; border-left: 3px solid var(--line); }
.seg .src { margin: 0 0 .15em; font-size: calc(var(--size) * .72); color: var(--muted); line-height: 1.4; display: none; }
.seg .tr { margin: 0; font-size: var(--size); line-height: 1.45; }
.show-original .seg .src { display: block; }
/* While a translation is written its text grows in place, slightly dimmed. */
.seg.streaming { border-left-color: var(--busy); }
.seg.streaming .tr { opacity: .75; }
.seg.streaming .tr::after { content: " ▍"; opacity: .5; animation: pulse 1s infinite; }
/* Before the first translated word, show the original in its place so the
   flow of text never stalls on screen. */
.seg.pending { border-left-color: var(--busy); }
.seg.pending .tr { display: none; }
.seg.pending .src { display: block; font-size: var(--size); opacity: .6; }
.seg.failed .tr { font-size: 14px; color: var(--danger); }
.seg.failed .src { display: block; }
.seg.skipped .tr { font-size: 14px; color: var(--muted); font-style: italic; }
.seg.skipped .src { display: block; }

.live { margin-top: 0; font-size: var(--size); color: var(--muted); font-style: italic; min-height: 1.4em; }
.empty { color: var(--muted); text-align: center; margin-top: 30vh; font-size: 17px; }

.jump {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(92px + env(safe-area-inset-bottom));
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}

.controls {
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.controls .big { flex: 1; padding: 14px; font-size: 18px; }
.controls .big.recording { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---- Summary sheet ---- */
.sheet {
  width: min(760px, 100vw);
  max-height: 90vh;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-head, .sheet-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; }
.sheet-head { border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 18px; margin-right: auto; }
.sheet-foot { border-top: 1px solid var(--line); justify-content: flex-end; }
.summary-body { padding: 8px 16px 16px; overflow-y: auto; max-height: calc(90vh - 130px); font-size: 17px; line-height: 1.5; }
.summary-body h2, .summary-body h3 { font-size: 18px; margin: 1.1em 0 .3em; }
.summary-body ul, .summary-body ol { padding-left: 1.2em; }
