/* Live Translate — dark, minimal, Apple-Translate-style mobile-first CSS */

:root {
  --bg: #0a0a0f;
  --bg-soft: #14141c;
  --card: #17171f;
  --text: #f5f5f7;
  --muted: #9a9aa5;
  --accent: #4f8cff;
  --accent-dim: rgba(79, 140, 255, 0.15);
  --red: #ff3b30;
  --green: #34c759;
  --radius: 18px;
  --font-size: 100; /* percent, set from settings */
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

body {
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: contain;
}

button { font: inherit; color: inherit; }

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 12px;
}
.brand { font-size: 15px; font-weight: 700; letter-spacing: 3px; color: var(--muted); }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #3a3a44; transition: background .2s; }
.dot.live { background: var(--red); animation: pulse 1.6s infinite; }
.dot.connecting { background: #ff9f0a; animation: pulse 1s infinite; }
.dot.paused { background: #ff9f0a; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Caption area ---------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 26px;
  padding: 10px 22px 18px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.caption-block { display: flex; flex-direction: column; gap: 10px; }
.caption-block.hidden { display: none; }

.lang-label {
  font-size: calc(11px * var(--font-size) / 100);
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--muted);
}

.orig-text {
  font-size: calc(20px * var(--font-size) / 100);
  line-height: 1.45;
  color: var(--muted);
  min-height: 1.4em;
  transition: color .2s;
}
.orig-text.final { color: var(--text); }

.trans-text {
  font-size: calc(40px * var(--font-size) / 100);
  line-height: 1.25;
  font-weight: 700;
  min-height: 2em;
  overflow-wrap: break-word;
}
.trans-text .cursor::after {
  content: "▍";
  color: var(--accent);
  animation: pulse 1s infinite;
  font-weight: 400;
}
/* Live (provisional) translation: dimmed + italic while the final lands. */
.trans-text.provisional { opacity: 0.68; font-style: italic; font-weight: 500; }
#fsTrans.provisional { opacity: 0.68; font-style: italic; }

.placeholder { color: #3d3d49; }

.mic-state {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 13px; color: var(--muted); min-height: 20px;
}
.mic-state .live-indicator { color: var(--red); font-weight: 600; }

.level-bar { height: 4px; background: #22222c; border-radius: 2px; overflow: hidden; margin: 0 22px; }
.level-bar > div { height: 100%; width: 0%; background: var(--green); border-radius: 2px; transition: width 60ms linear; }

/* ---------- Controls ---------- */
.controls { padding: 0 20px calc(env(safe-area-inset-bottom, 0px) + 18px); max-width: 720px; width: 100%; margin: 0 auto; }

.btn-row { display: flex; gap: 10px; margin-top: 10px; }

.btn {
  border: none; border-radius: var(--radius); cursor: pointer;
  padding: 15px 18px; font-size: 16px; font-weight: 600;
  background: var(--card); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s, background .15s, opacity .15s;
  min-height: 54px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; }

.btn-start {
  width: 100%; font-size: 20px; padding: 20px;
  background: linear-gradient(135deg, #2b6cff, #4f8cff);
  box-shadow: 0 8px 28px rgba(79, 140, 255, .35);
}
.btn-danger { background: rgba(255, 59, 48, .14); color: #ff6b62; }
.btn-ghost { background: transparent; border: 1px solid #2a2a35; color: var(--muted); flex: 1; }
.btn.active-toggle { background: var(--accent-dim); color: var(--accent); border-color: transparent; }

/* ---------- Pause notice ---------- */
.pause-notice {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 5, 10, .92);
  display: none; align-items: center; justify-content: center;
  padding: 30px; text-align: center;
}
.pause-notice.show { display: flex; }
.pause-card { max-width: 340px; }
.pause-card h2 { margin: 0 0 12px; font-size: 24px; }
.pause-card p { color: var(--muted); line-height: 1.5; margin: 0 0 22px; }

/* ---------- Fullscreen captions ---------- */
.fs-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: #000;
  display: none; flex-direction: column;
  justify-content: center; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 30px) 30px calc(env(safe-area-inset-bottom, 0px) + 30px);
  text-align: center; cursor: pointer;
}
.fs-overlay.show { display: flex; }
.fs-orig {
  font-size: calc(22px * var(--font-size) / 100);
  color: #8a8a95; margin-bottom: 24px; max-width: 90vw; line-height: 1.4;
}
.fs-trans {
  font-size: calc(64px * var(--font-size) / 100);
  font-weight: 700; line-height: 1.2; max-width: 92vw;
  overflow-wrap: break-word;
}
.fs-controls {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  display: flex; gap: 10px; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.fs-overlay.controls-visible .fs-controls { opacity: 1; pointer-events: auto; }
.fs-controls .btn { background: rgba(40, 40, 50, .85); min-height: 50px; }

/* ---------- Settings sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.55);
  display: none; align-items: flex-end; justify-content: center;
}
.sheet-backdrop.show { display: flex; }
.sheet {
  background: var(--bg-soft); width: 100%; max-width: 560px;
  border-radius: 24px 24px 0 0;
  padding: 12px 24px calc(env(safe-area-inset-bottom, 0px) + 28px);
  max-height: 82vh; overflow-y: auto;
}
.sheet-handle { width: 44px; height: 5px; border-radius: 3px; background: #3a3a44; margin: 8px auto 18px; }
.sheet h2 { margin: 0 0 18px; font-size: 20px; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; border-bottom: 1px solid #23232d; }
.setting:last-of-type { border-bottom: none; }
.setting label { font-size: 16px; }
.setting .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }

.seg { display: flex; background: #101016; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: none; background: transparent; color: var(--muted); border-radius: 9px; padding: 9px 13px; font-size: 14px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--accent-dim); color: var(--accent); }

.toggle { position: relative; width: 52px; height: 31px; flex-shrink: 0; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track { position: absolute; inset: 0; background: #2c2c38; border-radius: 16px; transition: .2s; }
.toggle .track::after { content: ""; position: absolute; width: 25px; height: 25px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.toggle input:checked + .track { background: var(--green); }
.toggle input:checked + .track::after { transform: translateX(21px); }

input[type="range"] { width: 150px; accent-color: var(--accent); }

.provider-label { font-size: 14px; color: var(--muted); background: #101016; padding: 8px 14px; border-radius: 10px; }

/* ---------- History ---------- */
.history { max-width: 720px; width: 100%; margin: 0 auto; padding: 0 20px; }
.history-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 4px; }
.history-head h3 { font-size: 13px; letter-spacing: 2px; color: var(--muted); margin: 0; }
.history-actions { display: flex; gap: 8px; }
.chip { background: #1c1c26; border: none; border-radius: 10px; color: var(--muted); font-size: 13px; padding: 8px 12px; cursor: pointer; font-weight: 600; }
.hist-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.hist-item { background: var(--card); border-radius: 14px; padding: 13px 15px; }
.hist-item .ts { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.hist-item .ho { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.hist-item .ht { font-size: 18px; font-weight: 600; }
.hist-empty { color: #3d3d49; font-size: 14px; text-align: center; padding: 14px 0; }

/* ---------- Error toast ---------- */
.toast {
  position: fixed; left: 20px; right: 20px; bottom: calc(env(safe-area-inset-bottom, 0px) + 130px);
  z-index: 80; background: #2a1518; border: 1px solid rgba(255,59,48,.4); color: #ffb3ae;
  border-radius: 14px; padding: 13px 16px; font-size: 14px; display: none;
}
.toast.show { display: block; }

.hidden { display: none !important; }

@media (min-width: 700px) {
  .trans-text { max-width: 640px; }
}
