:root {
  --bg: #0b1020;
  --bg-soft: #131a30;
  --bg-lift: #1b2440;
  --line: #2a3557;
  --ink: #eef2ff;
  --ink-dim: #97a3c7;
  --ink-faint: #6b779c;
  --yue: #f5a524;
  --vi: #38bdf8;
  --danger: #f4526a;
  --ok: #34d399;
  --radius: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', 'PingFang HK',
    'Microsoft JhengHei', 'Noto Sans TC', sans-serif;
}

* {
  box-sizing: border-box;
}

/* Nhiều khối bên dưới đặt display:grid/flex, thứ đó đè luôn quy tắc mặc định
   của trình duyệt cho [hidden]. Không có dòng này thì màn hình gọi vẫn hiện
   ngay dưới sảnh chờ. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.zh {
  font-family: 'PingFang HK', 'Microsoft JhengHei', 'Noto Sans TC', var(--font);
}

/* ------------------------------------------------------------- Sảnh chờ -- */

.lobby {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
  overflow-y: auto;
  background: radial-gradient(1100px 600px at 50% -10%, #1c2a53 0%, var(--bg) 60%);
}

.lobby-card {
  width: min(440px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px 28px 24px;
  box-shadow: 0 24px 60px rgb(0 0 0 / 45%);
}

.lobby-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.lobby-card h1 .zh {
  display: block;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-dim);
  margin-top: 4px;
}

.sub {
  margin: 0 0 22px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-dim);
}

.field {
  display: block;
  border: 0;
  padding: 0;
  margin: 0 0 18px;
}

.field > span,
.field legend {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-dim);
  margin-bottom: 8px;
  padding: 0;
}

.field em {
  font-style: normal;
  color: var(--ink-faint);
  font-weight: 500;
}

input[type='text'] {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}

input[type='text']:focus {
  border-color: var(--vi);
  box-shadow: 0 0 0 3px rgb(56 189 248 / 18%);
}

.lang-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.lang-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.lang-body {
  display: block;
  padding: 13px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.lang-body b {
  display: block;
  font-size: 15px;
}

.lang-body small {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.lang-option input:focus-visible + .lang-body {
  outline: 2px solid var(--vi);
  outline-offset: 2px;
}

.lang-option input[value='yue']:checked + .lang-body {
  border-color: var(--yue);
  background: rgb(245 165 36 / 12%);
}

.lang-option input[value='vi']:checked + .lang-body {
  border-color: var(--vi);
  background: rgb(56 189 248 / 12%);
}

button {
  font-family: inherit;
  cursor: pointer;
}

.primary {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  color: #04122a;
  background: linear-gradient(180deg, #6ee0ff, var(--vi));
  border: 0;
  border-radius: 12px;
}

.primary:disabled {
  opacity: 0.55;
  cursor: progress;
}

.hint {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-faint);
  text-align: center;
}

.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  color: #ffd9e0;
  background: rgb(244 82 106 / 15%);
  border: 1px solid rgb(244 82 106 / 40%);
  border-radius: 10px;
}

/* ------------------------------------------------------------ Cuộc gọi -- */

.call {
  display: grid;
  grid-template-columns: minmax(320px, 38%) 1fr;
  height: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-title strong {
  display: block;
  font-size: 14px;
}

.panel-title .zh {
  font-size: 12px;
  color: var(--ink-faint);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: none;
}

.dot.ready {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgb(52 211 153 / 18%);
}

.dot.connecting,
.dot.reconnecting {
  background: var(--yue);
  animation: pulse 1.1s ease-in-out infinite;
}

.dot.error,
.dot.fatal {
  background: var(--danger);
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.transcript .empty {
  margin: auto 0;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-faint);
}

.bubble {
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 12px;
  padding: 11px 14px;
  background: var(--bg-lift);
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.bubble.lang-yue {
  border-left-color: var(--yue);
}

.bubble.lang-vi {
  border-left-color: var(--vi);
}

.bubble.self {
  background: transparent;
}

.bubble.pending {
  border-style: dashed;
}

.bubble .who {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.bubble.lang-yue .who b {
  color: var(--yue);
}

.bubble.lang-vi .who b {
  color: var(--vi);
}

/* Dòng to = thứ tiếng người đang đọc hiểu được. */
.bubble .main {
  font-size: 18px;
  line-height: 1.5;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Dòng nhỏ = nguyên văn, để đối chiếu. */
.bubble .alt {
  margin-top: 5px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-dim);
  overflow-wrap: anywhere;
}

.bubble .main:empty::after {
  content: '…';
  color: var(--ink-faint);
}

.live-hint {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-dim);
}

/* Thông báo lỗi dài phải xuống dòng được, không đẩy tràn cột. */
.live-hint span:last-child {
  min-width: 0;
}

.live-hint.bad {
  color: #ffd9e0;
  background: rgb(244 82 106 / 12%);
}

.wave[hidden] {
  display: none;
}

.wave {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.wave i {
  width: 3px;
  border-radius: 2px;
  background: var(--ok);
  animation: bar 0.9s ease-in-out infinite;
}

.wave i:nth-child(1) { height: 5px; animation-delay: 0s; }
.wave i:nth-child(2) { height: 12px; animation-delay: 0.12s; }
.wave i:nth-child(3) { height: 8px; animation-delay: 0.24s; }
.wave i:nth-child(4) { height: 13px; animation-delay: 0.36s; }

@keyframes bar {
  50% {
    transform: scaleY(0.35);
  }
}

/* ---------------------------------------------------------------- Video -- */

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px;
  gap: 12px;
}

.stage-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.room-chip {
  font-size: 12px;
  color: var(--ink-dim);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 6px 11px;
  border-radius: 999px;
}

.room-chip b {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.status {
  font-size: 12px;
  color: var(--ink-faint);
  margin-right: auto;
}

.status.live {
  color: var(--ok);
}

.status.bad {
  color: var(--danger);
}

.ghost {
  font-size: 12px;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
}

.ghost:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}

.videos {
  position: relative;
  flex: 1;
  min-height: 0;
}

.video-box {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #05070f;
  border: 1px solid var(--line);
}

.video-box.remote {
  height: 100%;
}

.video-box.local {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: clamp(120px, 22%, 230px);
  aspect-ratio: 4 / 3;
  box-shadow: 0 10px 30px rgb(0 0 0 / 55%);
}

.video-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-box.local video {
  transform: scaleX(-1); /* xem mình như soi gương */
}

.badge {
  position: absolute;
  left: 10px;
  bottom: 10px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgb(5 7 15 / 72%);
  backdrop-filter: blur(6px);
  border: 1px solid rgb(255 255 255 / 10%);
  /* Khung camera nhỏ chỉ rộng hơn trăm pixel — nhãn dài phải cắt, không được tràn. */
  max-width: calc(100% - 20px);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.video-box.local .badge {
  left: 6px;
  bottom: 6px;
  font-size: 10px;
  padding: 3px 7px;
  max-width: calc(100% - 12px);
}

.waiting {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-dim);
  background: var(--bg-soft);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--line);
  border-top-color: var(--vi);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.ctrl {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg-lift);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.ctrl .ic {
  font-size: 15px;
  line-height: 1;
}

.ctrl[aria-pressed='false'] {
  color: var(--danger);
  border-color: rgb(244 82 106 / 45%);
  background: rgb(244 82 106 / 12%);
}

.ctrl.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(560px, calc(100vw - 40px));
  padding: 10px 16px;
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
  background: var(--bg-lift);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 30px rgb(0 0 0 / 50%);
}

/* --------------------------------------------------------------- Mobile -- */

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .call {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(240px, 42vh) 1fr;
    height: 100dvh;
  }

  .panel {
    order: 2;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .stage {
    order: 1;
    padding: 10px;
  }

  .bubble .main {
    font-size: 17px;
  }

  .ctrl .lbl {
    display: none;
  }

  .ctrl {
    padding: 11px 15px;
  }

  /* Màn hình hẹp: giữ mọi thứ trên một hàng, câu trạng thái dài thì cắt bằng
     dấu ba chấm thay vì đẩy nút xuống dòng và ăn mất chỗ của video. */
  .stage-head {
    flex-wrap: nowrap;
  }

  .room-chip,
  .stage-head .ghost {
    flex: none;
    white-space: nowrap;
  }

  .status {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .video-box.local {
    right: 10px;
    bottom: 10px;
    width: clamp(104px, 32%, 160px);
  }
}
