:root {
  color-scheme: dark;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: #03110f;
  color: #f4fbf8;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 85% 12%, rgba(31, 203, 144, 0.16), transparent 28rem),
    radial-gradient(circle at 8% 85%, rgba(21, 108, 88, 0.22), transparent 32rem),
    #03110f;
}

button, input, select { font: inherit; }
button { border: 0; cursor: pointer; font-weight: 750; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 30px;
}

.hero { margin-bottom: 28px; }
.eyebrow, .section-label {
  margin: 0 0 8px;
  color: #6ee7b7;
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}
h1, h2, p { margin-top: 0; }
h1 {
  max-width: 920px;
  margin-bottom: 12px;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.12;
}
.subtitle {
  max-width: 780px;
  margin-bottom: 0;
  color: #abc2ba;
  font-size: 1.05rem;
  line-height: 1.8;
}

.join-panel {
  display: grid;
  grid-template-columns: minmax(260px, .8fr) minmax(500px, 1.2fr);
  gap: 36px;
  padding: 32px;
  border: 1px solid #1b463a;
  border-radius: 28px;
  background: rgba(6, 28, 23, .92);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
}
.join-panel h2 { margin-bottom: 10px; font-size: 1.6rem; }
.join-panel p:not(.section-label) { color: #91ada4; line-height: 1.8; }
.join-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.join-fields label { display: grid; gap: 7px; color: #9eb8af; font-size: .8rem; }
.join-fields .full-width-field, .language-hint, .summary-email-field, .consent-field, .join-extras, .join-fields > .primary-button { grid-column: 1 / -1; }
.language-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid rgba(110, 231, 183, .35);
  border-radius: 12px;
  background: rgba(44, 229, 157, .1);
  color: #d7f5e8;
  font-size: .82rem;
  line-height: 1.6;
  box-shadow: 0 0 0 2px rgba(44, 229, 157, .12);
  animation: pulse-hint 2.2s ease-in-out infinite;
}
.language-hint-dismiss {
  margin-inline-start: auto;
  flex: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  opacity: .7;
}
.language-hint-dismiss:hover { opacity: 1; background: rgba(255, 255, 255, .08); }
@keyframes pulse-hint {
  50% { box-shadow: 0 0 0 5px rgba(44, 229, 157, 0); }
}
.join-fields > .primary-button { width: 100%; }
.join-extras, .advanced-panel {
  border: 1px solid #24453c;
  border-radius: 14px;
  background: rgba(4, 22, 18, .52);
}
.join-extras > summary, .advanced-panel > summary {
  padding: 13px 15px;
  color: #9eb8af;
  cursor: pointer;
  font-size: .84rem;
  font-weight: 750;
}
.join-extras-content { display: grid; gap: 12px; padding: 0 14px 14px; }
.consent-field {
  grid-template-columns: auto 1fr;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid #31554b;
  border-radius: 12px;
  background: rgba(10, 41, 34, .55);
  line-height: 1.6;
}
.consent-field input { width: 18px; min-height: 18px; margin-top: 2px; }
.room-input-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

input, select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid #31554b;
  border-radius: 12px;
  outline: none;
  background: #0a2922;
  color: #f4fbf8;
}
input:focus, select:focus { border-color: #31d698; box-shadow: 0 0 0 3px rgba(49, 214, 152, .12); }
#roomInput { direction: ltr; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }

.primary-button, .secondary-button, .danger-button, .small-button, .icon-button {
  min-height: 46px;
  border-radius: 12px;
}
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 20px;
  background: #31d698;
  color: #032019;
}
.primary-button.is-listening { background: #ff8278; color: #2b0805; }
.secondary-button, .icon-button, .small-button {
  padding: 0 16px;
  border: 1px solid #31554b;
  background: transparent;
  color: #eaf7f2;
}
.danger-button {
  padding: 0 17px;
  border: 1px solid rgba(255, 124, 114, .35);
  background: rgba(117, 29, 23, .18);
  color: #ffc5c0;
}
.small-button { min-height: 36px; font-size: .78rem; }
.icon-button { min-height: 38px; font-size: .82rem; }

.room-bar, .control-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 17px;
  border: 1px solid #183d33;
  border-radius: 19px;
  background: rgba(6, 29, 24, .78);
  backdrop-filter: blur(16px);
}
.room-bar { justify-content: space-between; margin-bottom: 10px; }
.room-identity, .presence { display: flex; align-items: center; gap: 12px; }
.participant-list {
  max-width: min(52vw, 680px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#roomCodeDisplay { direction: ltr; color: #8ff0c8; letter-spacing: .12em; }
.count-badge, .language-badge {
  padding: 7px 10px;
  border: 1px solid #2b574a;
  border-radius: 999px;
  background: #0a2922;
  color: #bce8d8;
  font-size: .82rem;
}
.presence { color: #abc2ba; font-size: .9rem; }

.simple-status-row { display: flex; margin-bottom: 10px; }
.status-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.status-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border: 1px solid #24453c;
  border-radius: 999px;
  background: rgba(8, 35, 29, .84);
  color: #cfe0da;
  font-size: .8rem;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #70857f; }
.status-pill[data-state="listening"] .status-dot {
  background: #2ce59d;
  box-shadow: 0 0 0 6px rgba(44, 229, 157, .12);
  animation: pulse 1.4s infinite;
}
.status-pill[data-state="error"] .status-dot { background: #ff7c72; }
@keyframes pulse { 50% { box-shadow: 0 0 0 11px rgba(44, 229, 157, 0); } }

/* شارة صغيرة غير تقنية بجانب حالة الاستماع: توضح أي مسار تعرّف صوتي نشِط الآن
   (صوت المتصفح مقابل المحرك المحلي) دون إغراق الواجهة بتفاصيل هندسية. */
.stt-provider-badge {
  align-self: center;
  margin-inline-start: 8px;
  padding: 4px 10px;
  border: 1px solid #24453c;
  border-radius: 999px;
  background: rgba(8, 35, 29, .5);
  color: #9fc4b8;
  font-size: .72rem;
}

.control-bar { flex-wrap: wrap; margin-bottom: 16px; }
.conversation-button { min-width: min(100%, 280px); min-height: 58px; font-size: 1.06rem; }
.camera-button { min-height: 58px; }
.language-badge { margin-inline-start: auto; }
.mic-icon { font-size: .8rem; }
.primary-button.is-listening .mic-icon { animation: pulse-mic 1s infinite alternate; }
@keyframes pulse-mic { to { transform: scale(1.45); } }

/* مؤشر VU حي: طاقة صوت حقيقية (RMS) وصلت فعلاً من الميكروفون الفيزيائي إلى
   المتصفح قبل إرسالها للسيرفر — وميض أخضر سريع فوق حالة is-listening العادية. */
.primary-button.is-live-audio { box-shadow: 0 0 0 4px rgba(44, 229, 157, .65); }

@media (prefers-reduced-motion: no-preference) {
  .primary-button.is-live-audio { animation: vu-flash .35s ease-out; }
}
@keyframes vu-flash {
  from { box-shadow: 0 0 0 8px rgba(44, 229, 157, .35); }
  to { box-shadow: 0 0 0 4px rgba(44, 229, 157, .65); }
}

.secondary-button[aria-pressed="true"] {
  border-color: #31d698;
  background: rgba(49, 214, 152, .14);
  color: #8ff0c8;
}

.media-stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, .24fr);
  gap: 15px;
  margin-bottom: 16px;
}
.media-stage[hidden] { display: none; }
.remote-video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  align-content: start;
  gap: 15px;
}
.remote-video-grid:empty::before {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 1px dashed #285c4e;
  border-radius: 23px;
  color: #78968c;
  content: "بانتظار دخول الضيوف…";
}
.remote-video-panel, .local-video-panel {
  position: relative;
  min-height: 190px;
  overflow: hidden;
  border: 1px solid #285c4e;
  border-radius: 23px;
  background: #020a09;
  box-shadow: 0 20px 55px rgba(0, 0, 0, .23);
}
.remote-video-panel { aspect-ratio: 16 / 9; }
.local-video-panel {
  position: sticky;
  top: 15px;
  align-self: start;
  aspect-ratio: 9 / 12;
}
.remote-video-panel[data-connection-state="connected"] {
  border-color: #31d698;
}
.remote-video-panel[data-connection-state="failed"] {
  border-color: #ff7c72;
}
.media-stage video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #020a09;
}
.media-stage audio { display: none; }
.remote-audio-sink {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.local-video-panel video { transform: scaleX(-1); }
.video-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #78968c;
  text-align: center;
  background: radial-gradient(circle at center, #0a2922, #020a09 72%);
}
.video-placeholder[hidden] { display: none; }
.video-label {
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  z-index: 3;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  background: rgba(2, 12, 10, .7);
  color: #dff9ef;
  font-size: .74rem;
  backdrop-filter: blur(10px);
}
.caption-overlay {
  position: absolute;
  right: 5%;
  bottom: 8%;
  left: 5%;
  z-index: 3;
  min-height: 1.5em;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .72);
  color: #fff;
  font-size: clamp(1rem, 2.1vw, 1.55rem);
  font-weight: 750;
  line-height: 1.55;
  text-align: center;
  text-shadow: 0 1px 2px #000;
  backdrop-filter: blur(8px);
}
.caption-overlay:empty { display: none; }
.play-audio-button {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  z-index: 4;
  background: rgba(3, 32, 25, .92);
}

.live-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.transcript-card {
  overflow: hidden;
  border: 1px solid #1b463a;
  border-radius: 23px;
  background: rgba(6, 28, 23, .92);
  box-shadow: 0 20px 55px rgba(0, 0, 0, .23);
}
.outgoing-card {
  border-color: #285c4e;
  background: linear-gradient(145deg, rgba(16, 55, 45, .94), rgba(5, 28, 23, .96));
}
.outgoing-card[hidden] { display: none; }
.incoming-card {
  border-color: #385a78;
  background: linear-gradient(145deg, rgba(15, 43, 56, .96), rgba(5, 27, 28, .96));
}
.incoming-card .section-label { color: #83c7ff; }
.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 92px;
  padding: 19px 20px;
  border-bottom: 1px solid #183d33;
}
.card-heading h2 { margin-bottom: 0; font-size: 1.08rem; line-height: 1.5; }
.transcript-box {
  min-height: 330px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 26px 22px;
  outline: none;
  color: #f7fffc;
  font-size: clamp(1.18rem, 2.1vw, 1.75rem);
  font-weight: 650;
  line-height: 1.95;
  white-space: pre-wrap;
}
.transcript-box:focus-visible { box-shadow: inset 0 0 0 2px #31d698; }
.agreed-translation { color: #b9f8dc; }
.interim-transcript { color: #7f9d93; }
.interim-transcript:not(:empty)::after {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-inline-start: 5px;
  border-radius: 4px;
  background: #31d698;
  content: "";
  vertical-align: -.14em;
  animation: blink .8s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.empty-state { color: #668078; font-weight: 500; }

.metrics {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid #183d33;
  border-radius: 18px;
  background: rgba(6, 29, 24, .78);
}
.metrics > div { display: grid; gap: 5px; padding: 16px 18px; }
.metrics > div + div { border-inline-start: 1px solid #183d33; }
.metric-label { color: #78968c; font-size: .74rem; }
.metrics strong { font-variant-numeric: tabular-nums; }
.notice, .privacy-note {
  margin-top: 14px;
  border-radius: 14px;
  color: #a9c0b8;
  font-size: .84rem;
  line-height: 1.7;
}
.notice {
  grid-column: 1 / -1;
  padding: 13px 15px;
  border: 1px solid rgba(255, 124, 114, .4);
  background: rgba(117, 29, 23, .22);
  color: #ffd3ce;
}
.privacy-note { text-align: center; }

.summary-panel {
  margin-top: 16px;
  padding: 22px;
  border: 1px solid #31554b;
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(12, 48, 40, .94), rgba(5, 27, 24, .96));
}
.advanced-panel { margin-top: 16px; }
.advanced-panel[open] { padding-bottom: 16px; }
.advanced-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  padding: 4px 16px 12px;
}
.diagnostic-statuses { padding: 0 16px; }
.advanced-panel .summary-panel, .advanced-panel .metrics { margin-inline: 16px; }
.summary-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.summary-heading h2 { margin-bottom: 6px; }
.summary-heading p:not(.section-label) { margin-bottom: 0; color: #91ada4; }
.summary-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.summary-output {
  margin-top: 18px;
  padding: 20px;
  border: 1px solid #285c4e;
  border-radius: 16px;
  background: rgba(2, 18, 15, .7);
  line-height: 1.85;
}
.summary-output[hidden] { display: none; }
.summary-output h3 { margin: 16px 0 5px; color: #8ff0c8; font-size: 1rem; }
.summary-output h3:first-child { margin-top: 0; }
.summary-output p, .summary-output ul { margin-top: 0; white-space: pre-wrap; }

@media (max-width: 1100px) {
  .live-grid { grid-template-columns: 1fr 1fr; }
  .metrics { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 740px) {
  .shell { padding-top: 28px; }
  .join-panel, .join-fields { grid-template-columns: 1fr; }
  .join-panel { gap: 18px; padding: 22px; }
  .join-fields .full-width-field, .join-fields > .primary-button { grid-column: auto; }
  .room-bar { align-items: stretch; flex-direction: column; }
  .control-bar { display: grid; grid-template-columns: 1fr; align-items: stretch; }
  .conversation-button, .camera-button { width: 100%; }
  .summary-heading, .summary-actions { align-items: stretch; flex-direction: column; }
  .room-identity, .presence { flex-wrap: wrap; }
  .participant-list { max-width: 100%; white-space: normal; }
  .language-badge { margin-inline-start: 0; }
  .media-stage { grid-template-columns: 1fr; }
  .remote-video-grid { grid-template-columns: 1fr; }
  .remote-video-panel { min-height: 220px; }
  .local-video-panel {
    position: absolute;
    z-index: 5;
    width: 105px;
    min-height: 0;
    margin: 12px;
    border-radius: 16px;
    aspect-ratio: 9 / 12;
  }
  .live-grid { grid-template-columns: 1fr; }
  .transcript-box { min-height: 220px; max-height: 38vh; padding: 20px 18px; }
  .card-heading { min-height: 74px; padding: 15px 17px; }
  .advanced-controls, .diagnostic-statuses { padding-inline: 12px; }
  .advanced-panel .summary-panel, .advanced-panel .metrics { margin-inline: 12px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics > div + div { border-inline-start: 0; border-top: 1px solid #183d33; }
}
