:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1d1e21;
  --muted: #6b6d73;
  --line: #e4e2dc;
  --accent: #0f766e;
  --accent-soft: #d5ece8;
  --rec: #d6342c;
  --rec-soft: rgba(214, 52, 44, 0.18);
  --fresh: #fff1b8;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1f2024;
    --ink: #ececea;
    --muted: #9a9ca3;
    --line: #2e3035;
    --accent: #3fb8a9;
    --accent-soft: #1c3936;
    --rec: #f0605a;
    --rec-soft: rgba(240, 96, 90, 0.22);
    --fresh: #4a4220;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 0;
  padding-top: max(16px, env(safe-area-inset-top));
  gap: 12px;
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
h1 a { color: inherit; text-decoration: none; border-radius: 4px; }
h1 a:hover { text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 4px; }
h1 a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.status {
  flex: none;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}
body[data-phase="connecting"] .status,
body[data-phase="finishing"] .status { color: var(--accent); border-color: var(--accent); }
body[data-phase="listening"] .status { color: var(--rec); border-color: var(--rec); background: var(--rec-soft); }

.transcript {
  flex: 1;
  min-height: 40dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}
.placeholder { color: var(--muted); margin: 0; line-height: 1.7; }
.transcript.has-text .placeholder,
body:not([data-phase="idle"]) .placeholder { display: none; }
.text { margin: 0; font-size: 1.3rem; line-height: 1.85; word-break: keep-all; overflow-wrap: anywhere; }
.seg { border-radius: 4px; transition: background-color 1.2s ease; }
.seg.fresh { background: var(--fresh); }

.cursor { display: none; gap: 4px; padding-left: 4px; vertical-align: middle; }
body[data-phase="listening"] .cursor,
body[data-phase="finishing"] .cursor { display: inline-flex; }
.cursor i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}
.cursor i:nth-child(2) { animation-delay: 0.2s; }
.cursor i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.toast {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
  background: var(--rec-soft);
  color: var(--ink);
  border: 1px solid var(--rec);
}
.toast.info { background: var(--accent-soft); border-color: var(--accent); }

.extras { display: grid; gap: 8px; }
details { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
summary { cursor: pointer; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
fieldset { border: 0; padding: 12px 0 4px; margin: 0; display: grid; gap: 14px; }
fieldset:disabled { opacity: 0.55; }
label { display: grid; gap: 6px; font-size: 0.9rem; }
label.check { display: flex; align-items: center; gap: 8px; }
small { color: var(--muted); font-size: 0.78rem; }
select, input[type="number"], fieldset input[type="text"], fieldset input[type="password"] {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  max-width: 220px;
}
pre {
  margin: 10px 0 0;
  max-height: 260px;
  overflow: auto;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--muted);
}

.dock {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to bottom, transparent, var(--bg) 24px);
  padding: 24px 0 max(16px, env(safe-area-inset-bottom));
  display: grid;
  gap: 10px;
  justify-items: center;
}
.meter { width: min(320px, 100%); height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--accent); transition: width 80ms linear; }
body[data-phase="listening"] .meter div { background: var(--rec); }

.controls { display: flex; align-items: center; gap: 28px; }
button { font: inherit; cursor: pointer; }
.ghost {
  min-width: 64px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
}
.ghost:hover { border-color: var(--muted); }

.mic {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
  transition: transform 120ms ease, background-color 160ms ease;
}
.mic:active { transform: scale(0.95); }
.mic:disabled { opacity: 0.6; cursor: progress; }
.mic svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.mic .icon-stop { display: none; fill: currentColor; stroke: none; }
body[data-phase="listening"] .mic,
body[data-phase="finishing"] .mic { background: var(--rec); animation: pulse 1.6s infinite; }
body[data-phase="listening"] .mic .icon-mic,
body[data-phase="finishing"] .mic .icon-mic { display: none; }
body[data-phase="listening"] .mic .icon-stop,
body[data-phase="finishing"] .mic .icon-stop { display: block; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--rec-soft); }
  70% { box-shadow: 0 0 0 18px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.mic:focus-visible, .ghost:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.elapsed { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; }

@media (prefers-reduced-motion: reduce) {
  .mic, .cursor i { animation: none !important; }
}

/* ---------- page switch ---------- */
.modes {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.modes a {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
}
.modes a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.modes a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- YouTube page ---------- */
.app.wide { max-width: 960px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }

.yt-form { display: flex; gap: 8px; }
.yt-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}
.yt-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.player {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: #0d0d0f;
}
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: none; }
.player.loaded iframe { display: block; }
.player-empty {
  position: absolute; inset: 0; margin: 0;
  display: grid; place-items: center;
  color: #9a9ca3; font-size: 0.95rem; padding: 16px; text-align: center;
}
.player.loaded .player-empty { display: none; }

/* Subtitle-style live caption right under the video. */
.live {
  /* Fixed height: as a sentence grows the box does not push the page down; the newest text stays at
     the bottom and older text fades out at the top. */
  position: relative;
  height: 9.5rem;
  overflow: hidden;
  border-radius: 14px;
  padding: 14px 18px;
  background: #121316;
  color: #f5f5f3;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}
.live::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2rem;
  background: linear-gradient(#121316, rgba(18, 19, 22, 0));
  pointer-events: none;
  z-index: 1;
}
.live-line { opacity: 0.55; }
.live-line.current { opacity: 1; animation: rise 0.25s ease-out; }
.live-line p { margin: 0; line-height: 1.55; word-break: keep-all; overflow-wrap: anywhere; }
.live-line .ko { font-size: 1.15rem; }
.live-line.current .ko { font-size: 1.35rem; font-weight: 600; }
.live-line .ja:empty { display: none; }

/* With translation on: Japanese is the main caption, Korean shrinks to a small line above it. */
body.translating .live { height: 13rem; }
body.translating .live-line { margin-top: 6px; }
body.translating .live-line .ko { font-size: 0.9rem; font-weight: 400; color: #b4b6bc; }
body.translating .live-line .ja { font-size: 1.15rem; }
body.translating .live-line.current .ja { font-size: 1.4rem; font-weight: 600; }

[lang="ja"] {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
}
.live-empty { margin: 0; color: #9a9ca3; font-size: 0.95rem; }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

.cc-bar { display: flex; align-items: center; gap: 14px; }
.cc-bar .meter { flex: 1; width: auto; }
.cc {
  flex: none;
  min-width: 112px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.cc:disabled { opacity: 0.6; cursor: progress; }
.cc:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
body.yt[data-phase="listening"] .cc { background: var(--rec); }

.hint { margin: 0; color: var(--muted); font-size: 0.85rem; line-height: 1.6; }
.hint.warn { color: var(--rec); }

.transcripts { display: grid; gap: 12px; }
@media (min-width: 900px) {
  body.translating .transcripts { grid-template-columns: 1fr 1fr; }
}
body:not(.translating) .translation-box { display: none; }
.transcript-box { display: grid; gap: 8px; align-content: start; }
.transcript-head { display: flex; align-items: center; gap: 8px; }
.transcript-head h2 { margin: 0 auto 0 0; font-size: 0.95rem; color: var(--muted); }
.yt .transcript { flex: none; min-height: 160px; max-height: 40dvh; }
.yt .text { font-size: 1.1rem; }

@media (prefers-reduced-motion: reduce) {
  .live-line.current { animation: none; }
}

/* ---------- publish settings and panel ---------- */
.fs-title { margin: 6px 0 0; font-size: 0.9rem; color: var(--muted); }
.publish-panel { display: flex; gap: 16px; align-items: flex-start; padding: 12px; border: 1px solid var(--accent); border-radius: 12px; background: var(--accent-soft); }
.publish-panel[hidden] { display: none; }
.listen-qr { flex: 0 0 120px; width: 120px; height: 120px; background: #fff; border-radius: 8px; padding: 4px; }
.listen-qr svg { display: block; width: 100%; height: 100%; }
.listen-info { min-width: 0; display: grid; gap: 8px; }
.listen-info h2 { margin: 0; font-size: 0.95rem; }
.listen-info a { overflow-wrap: anywhere; font-size: 0.85rem; }
.listen-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.listeners { font-size: 0.9rem; font-variant-numeric: tabular-nums; }
