/* Better Translation, Console Dark house theme. */

:root {
  --bg: #0B0F14;
  --panel: #131A22;
  --line: #1B2733;
  --edge: #2A3F55;
  --ink: #E6EEF7;
  --muted: #8FA3B8;
  --accent: #22D3EE;
  --accent2: #0E7490;
  --warn: #F59E0B;
  --ok: #34D399;
  --bad: #EF4444;
  --unknown: #64748B;
  --mic-level: 0;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', Roboto, system-ui, -apple-system, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.mono { font-family: Consolas, 'Cascadia Mono', monospace; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ============ screens ============ */
.screen { display: none; }
.screen.active { display: block; }
.screen.conv.active { display: flex; flex-direction: column; height: 100dvh; }
@supports not (height: 100dvh) { .screen.conv.active { height: 100vh; } }

.shell { max-width: 640px; margin: 0 auto; padding: 18px 14px calc(24px + env(safe-area-inset-bottom)); }
.shell.narrow { max-width: 480px; }

/* ============ brand ============ */
.brand { display: flex; align-items: center; gap: 14px; padding: 8px 2px 16px; }
.logo { font-size: 42px; line-height: 1; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: 0.3px; }
.tagline { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* ============ cards / fields ============ */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}
.card.center { text-align: center; }
.card-title { font-weight: 600; font-size: 15px; margin-bottom: 12px; color: var(--ink); }

.intro-card { border-color: var(--edge); }
.intro-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; color: var(--muted); font-size: 14.5px; }
.intro-list li::marker { color: var(--accent); }

.field-row { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); }

.text-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  outline: none;
}
.text-input:focus { border-color: var(--accent2); }
select.text-input { appearance: auto; }

.input-row { display: flex; gap: 8px; align-items: center; }
.input-row .text-input { flex: 1; }
.clear-x {
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  border-radius: 10px; width: 44px; height: 44px; font-size: 15px; cursor: pointer;
}
.clear-x:active { color: var(--ink); }

.code-input { text-transform: uppercase; letter-spacing: 4px; font-family: Consolas, monospace; font-size: 18px; }

.range-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; margin: 12px 0; }
.range-row .field-label { grid-column: 1 / -1; }
.range-row input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ============ buttons ============ */
.btn {
  background: var(--panel);
  border: 1px solid var(--edge);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s, transform 0.05s;
}
.btn:active { transform: scale(0.985); }
.btn.primary { background: var(--accent2); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.15); }
.btn.quiet { background: var(--bg); border-color: var(--line); color: var(--muted); }
.btn.quiet:hover { color: var(--ink); }
.btn.danger { background: #3a1420; border-color: var(--bad); color: #ffb4b4; }
.btn.big { padding: 16px 22px; font-size: 17px; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.btn.full { width: 100%; }
.btn-row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  border-radius: 10px; width: 40px; height: 40px; font-size: 17px; cursor: pointer;
}
.icon-btn.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

.divider {
  display: flex; align-items: center; gap: 12px; color: var(--muted);
  font-size: 13px; margin: 14px 0;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ============ language pack cards ============ */
.pack-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.pack-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; user-select: none;
}
.pack-card .flag { font-size: 26px; }
.pack-card .pack-name { font-weight: 600; }
.pack-card .pack-native { color: var(--muted); font-size: 13px; }
.pack-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pack-card.selected .pack-check { color: var(--accent); }
.pack-check { margin-left: auto; color: transparent; font-size: 18px; }

/* ============ meter ============ */
.meter-wrap {
  height: 14px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; margin: 12px 0 8px;
}
.meter-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 8px;
  transition: width 0.06s linear;
}
.hint { font-size: 13.5px; margin: 8px 0; line-height: 1.45; }

/* ============ server status ============ */
.server-status { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.status-dot.warn { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.status-dot.bad { background: var(--bad); }
.status-dot.grey { background: var(--unknown); }

/* ============ waiting room ============ */
.code-display {
  font-family: Consolas, 'Cascadia Mono', monospace;
  font-size: 44px; letter-spacing: 10px; font-weight: 700;
  color: var(--accent); margin: 10px 0 16px; user-select: all;
}
.qr-card { background: #FFFFFF; border-radius: 14px; padding: 10px; display: inline-block; margin: 4px 0 10px; }
.qr-card img { display: block; width: 230px; height: 230px; }
.url-line { font-size: 13px; color: var(--muted); word-break: break-all; margin: 6px 0 10px; user-select: all; }
.wait-pulse { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); margin: 16px 0; font-size: 14px; }
.pulse-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* ============ conversation ============ */
.conv-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  flex: none; gap: 10px;
}
.conv-peer { display: flex; align-items: center; gap: 10px; font-size: 14.5px; min-width: 0; }
.conv-peer span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-actions { display: flex; gap: 8px; flex: none; }

.col-headers {
  display: flex; justify-content: space-between; padding: 6px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  flex: none; font-size: 12.5px; color: var(--muted);
}
.col-label.left { color: var(--accent); }
.col-label.right { color: var(--ink); }

.timeline { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.timeline-inner { display: flex; flex-direction: column; padding: 14px 12px 20px; max-width: 900px; margin: 0 auto; width: 100%; }
.timeline-inner .bubble { margin-top: 10px; }
.route-note { color: var(--warn); font-size: 12.5px; }

.bubble {
  max-width: 82%;
  border-radius: 14px;
  padding: 10px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bubble.mine { align-self: flex-start; border-left: 3px solid var(--accent); border-top-left-radius: 6px; }
.bubble.theirs { align-self: flex-end; border-right: 3px solid var(--edge); border-top-right-radius: 6px; background: #16202B; }
.bubble.interim { opacity: 0.75; border-style: dashed; }
.bubble.interim .bubble-text { font-style: italic; color: var(--muted); }
.bubble.speaking { border-color: var(--accent); box-shadow: 0 0 10px rgba(34, 211, 238, 0.25); }
.bubble.error { border-color: var(--bad); }

.bubble-text { font-size: 16.5px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.bubble-secondary {
  display: none; margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 14px; color: var(--muted); line-height: 1.4; white-space: pre-wrap; word-break: break-word;
}
.bubble.expanded .bubble-secondary { display: block; }
.bubble-secondary .sec-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--accent2); margin-bottom: 3px; }
.bubble-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.bubble-meta .spin { display: inline-block; animation: rotate 1.1s linear infinite; }
@keyframes rotate { to { transform: rotate(360deg); } }
.retry-link { color: var(--warn); cursor: pointer; text-decoration: underline; }
.live-tag { color: var(--accent); font-size: 11px; }

.jump-chip {
  position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%);
  background: var(--accent2); color: var(--ink); border: 1px solid var(--accent);
  border-radius: 999px; padding: 8px 16px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; z-index: 30; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

/* ============ chat bar ============ */
.chat-bar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 4px; background: var(--panel); border-top: 1px solid var(--line);
  max-width: 900px; margin: 0 auto; width: 100%;
}
.chat-input { flex: 1; padding: 10px 12px; font-size: 15px; }
.chat-send { padding: 10px 16px; flex: none; }
.chat-bar .icon-btn { flex: none; }
.chat-img { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; }

/* ============ bottom bar ============ */
.bottom-bar {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 26px;
  padding: 10px 16px 4px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.mic-status { flex: none; text-align: center; font-size: 12px; padding: 2px 0 calc(8px + env(safe-area-inset-bottom)); background: var(--panel); min-height: 22px; }

.mic-btn {
  width: 72px; height: 72px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--bg); color: var(--muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.mic-btn.listening {
  border-color: var(--accent); color: var(--accent);
  box-shadow: 0 0 calc(6px + 26px * var(--mic-level)) rgba(34, 211, 238, calc(0.2 + 0.55 * var(--mic-level)));
}
.mic-btn.blocked, .mic-btn.nomic { border-color: var(--bad); color: var(--bad); }
.mic-btn.waiting { border-color: var(--warn); color: var(--warn); }

.side-btn {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font-size: 20px; cursor: pointer;
}
.side-btn.on { border-color: var(--ok); }
.side-btn.off { opacity: 0.45; filter: grayscale(1); }

/* ============ overlay ============ */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(11, 15, 20, 0.92);
  display: flex; align-items: center; justify-content: center;
}
.overlay-card { text-align: center; padding: 24px; max-width: 380px; }
.overlay-emoji { font-size: 54px; margin-bottom: 14px; }

/* ============ modals ============ */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 70; }
.modal {
  position: fixed; z-index: 71; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(94vw, 460px); max-height: 86dvh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 16px;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600;
  position: sticky; top: 0; background: var(--panel);
}
.modal-body { padding: 14px 16px 20px; }

.toggle-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; cursor: pointer; font-size: 14.5px; user-select: none;
}
.toggle-row input { display: none; }
.switch {
  flex: none; width: 42px; height: 24px; border-radius: 999px;
  background: var(--line); position: relative; transition: background 0.15s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--muted); transition: left 0.15s, background 0.15s;
}
.toggle-row input:checked + .switch { background: var(--accent2); }
.toggle-row input:checked + .switch::after { left: 21px; background: var(--accent); }

/* ============ toasts / banners ============ */
#Toast_Container {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--panel); border: 1px solid var(--edge); color: var(--ink);
  border-radius: 12px; padding: 11px 14px; font-size: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.2s ease-out;
}
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }
.toast.warn { border-color: var(--warn); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

#Banner_Area { position: sticky; top: 0; z-index: 50; }
.banner {
  padding: 10px 14px; font-size: 13.5px; text-align: center;
  border-bottom: 1px solid var(--line);
}
.banner.warn { background: #2b2107; color: #fbd38d; border-color: var(--warn); }
.banner.bad { background: #3a1420; color: #ffb4b4; border-color: var(--bad); }

/* ============ friends ============ */
.friend-row { display: flex; flex-wrap: wrap; align-items: center; column-gap: 10px; row-gap: 3px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.friend-row:last-child { border-bottom: none; padding-bottom: 2px; }
.friend-info { display: contents; }
.friend-name { order: 0; flex: 1 1 0; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-actions { order: 1; flex: 0 0 auto; margin-left: auto; display: flex; align-items: center; gap: 8px; }
.friend-meta { order: 2; flex: 1 0 100%; display: flex; align-items: center; gap: 10px; }
.friend-sub { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--muted); }
.friend-toggle { flex: 0 0 auto; margin-left: auto; display: flex; flex-direction: row; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap; }
.friend-toggle input { display: none; }
.friend-toggle input:checked + .switch { background: var(--accent2); }
.friend-toggle input:checked + .switch::after { left: 21px; background: var(--accent); }
.friend-remove { width: auto; min-width: 40px; height: 36px; padding: 0 10px; }
.friend-nudge, .friend-talk { white-space: nowrap; }
.friend-remove.danger-arm { border-color: var(--bad); color: var(--bad); font-size: 12px; }

.foot { text-align: center; font-size: 12px; padding: 8px 0 4px; }

/* ============ desktop tweaks ============ */
@media (min-width: 700px) {
  /* Wide enough for one line: name, status, Auto connect, then the buttons. */
  .friend-row { flex-wrap: nowrap; column-gap: 12px; padding: 11px 0; }
  .friend-meta { display: contents; }
  .friend-name { flex: 0 1 auto; }
  .friend-sub { order: 1; flex: 1 1 auto; }
  .friend-toggle { order: 2; flex-direction: column; gap: 3px; font-size: 10.5px; margin-left: 0; }
  .friend-actions { order: 3; margin-left: 0; }
  .pack-grid { grid-template-columns: repeat(3, 1fr); }
  .pack-card { flex-direction: column; text-align: center; gap: 6px; padding: 16px 10px; }
  .pack-check { margin-left: 0; }
  .bubble { max-width: 62%; }
}

/* ---- nudges and room presence ---- */
@keyframes dot-pulse { 0%, 100% { box-shadow: 0 0 4px var(--ok); } 50% { box-shadow: 0 0 13px var(--ok); } }
.status-dot.pulse { animation: dot-pulse 1.6s ease-in-out infinite; }
.banner.nudge { display: flex; align-items: center; gap: 10px; background: #0e2a1e; color: #a7f3d0; border-color: var(--ok); }
.banner.nudge span:first-child { flex: 1; min-width: 0; }
.nudge-chip { margin-left: 8px; font-size: 11px; font-weight: 600; color: var(--warn); border: 1px solid var(--warn); border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.friend-row.nudged { background: rgba(245, 158, 11, 0.07); border-radius: 8px; padding-left: 8px; padding-right: 8px; }
.conv-presence { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 13px; opacity: 0.95; }
.conv-presence > span:first-child { flex: 1; min-width: 0; }
.conv-presence-actions { display: flex; gap: 8px; flex: none; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* ---- first run ---- */
.overlay.onboard { align-items: flex-start; overflow-y: auto; padding: max(24px, env(safe-area-inset-top)) 14px 24px; }
.onboard-card { width: 100%; max-width: 440px; margin: 0 auto; text-align: center; }
.onboard-card h2 { margin: 6px 0 4px; font-size: 22px; }
.onboard-card .pack-grid { text-align: left; margin: 14px 0; }
.onboard-card .btn.full { margin-top: 12px; }
.onboard-card .text-input { width: 100%; margin-top: 14px; font-size: 18px; text-align: center; }
.onboard-steps { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; }
.onboard-steps .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.onboard-steps .dot.on { background: var(--accent, #22d3ee); }
.onboard-heard { min-height: 48px; margin-top: 12px; font-size: 18px; line-height: 1.4; }
.onboard-heard.ok { color: var(--ok); }
.push-row { display: flex; align-items: center; gap: 10px; padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--line); font-size: 13px; }
.push-row span { flex: 1; }
.foot a { color: inherit; }

/* ---- per friend sheet, and the row's overflow button ---- */
.friend-more { width: 36px; min-width: 36px; height: 36px; padding: 0; font-size: 17px; line-height: 1; }
.friend-auto-chip { font-size: 11px; color: var(--accent2); }
#Friend_Modal .setting-block { margin-bottom: 14px; }
#Friend_Modal .lbl { display: block; font-size: 13px; margin-bottom: 4px; }
#Friend_Modal select { width: 100%; margin: 6px 0 8px; }
#Friend_Modal .switch-wrap { display: flex; align-items: center; gap: 10px; cursor: pointer; }
#Friend_Modal .switch-wrap input { display: none; }
#Friend_Modal .toggle-row { flex-direction: column; align-items: flex-start; gap: 6px; margin-bottom: 14px; padding: 4px 0; }
#Friend_Modal .toggle-row .hint { margin: 0; }
