/* =====================================================================
 * style.css - Giao dien UltraRemote Mobile
 * ---------------------------------------------------------------------
 * Mobile first, tong mau giong UltraViewer. Tu doi sang/toi theo he
 * dieu hanh. Ho tro safe-area cua iPhone.
 * ===================================================================== */

/* ---------------- Bien mau (mac dinh: sang) ---------------- */
:root {
  --nen: #F5F7FA;
  --nen-the: #FFFFFF;
  --nen-nhap: #EEF1F6;
  --chu: #1E2128;
  --chu-mo: #6B7280;
  --vien: #E2E7EF;
  --accent: #2D7FF9;
  --accent-toi: #1E6AE0;
  --xanh-online: #22C55E;
  --xam-offline: #9CA3AF;
  --do-loi: #EF4444;
  --bong: 0 2px 8px rgba(30, 33, 40, 0.08), 0 1px 2px rgba(30, 33, 40, 0.06);
  --bong-noi: 0 6px 20px rgba(45, 127, 249, 0.28);
  --bo-goc: 12px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --nen: #1E2128;
    --nen-the: #282C34;
    --nen-nhap: #31363F;
    --chu: #E8EAED;
    --chu-mo: #9AA0AA;
    --vien: #3A3F4A;
    --accent: #3B8CFF;
    --accent-toi: #2D7FF9;
    --bong: 0 2px 10px rgba(0, 0, 0, 0.4);
    --bong-noi: 0 6px 22px rgba(45, 127, 249, 0.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--nen);
  color: var(--chu);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.man-hinh { display: none; width: 100%; height: 100%; }
.man-hinh.active { display: block; }

/* ============================ DANG NHAP ============================= */
.dang-nhap-cuon {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--sat) + 24px) calc(var(--sar) + 20px) calc(var(--sab) + 24px) calc(var(--sal) + 20px);
  max-width: 480px;
  margin: 0 auto;
}

.logo-khu { text-align: center; margin: 12px 0 24px; }
.logo { display: inline-flex; filter: drop-shadow(var(--bong)); }
.ten-app { font-size: 26px; font-weight: 700; margin: 12px 0 4px; letter-spacing: -0.3px; }
.phu-de { color: var(--chu-mo); font-size: 14px; margin: 0; }

.the {
  background: var(--nen-the);
  border-radius: var(--bo-goc);
  box-shadow: var(--bong);
  padding: 20px;
  margin-bottom: 22px;
}

.nhan { display: block; font-size: 13px; font-weight: 600; color: var(--chu-mo); margin-bottom: 8px; }

.o-id {
  width: 100%;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 3px;
  text-align: center;
  padding: 14px 12px;
  border: 2px solid var(--vien);
  border-radius: var(--bo-goc);
  background: var(--nen-nhap);
  color: var(--chu);
  outline: none;
  transition: border-color .15s;
}
.o-id:focus { border-color: var(--accent); }

.o-mat-khau {
  width: 100%;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 12px;
  text-indent: 12px;          /* bu cho khoang cach chu cuoi, de van can giua */
  text-align: center;
  padding: 12px;
  border: 2px solid var(--vien);
  border-radius: var(--bo-goc);
  background: var(--nen-nhap);
  color: var(--chu);
  outline: none;
  transition: border-color .15s;
}
.o-mat-khau:focus { border-color: var(--accent); }
.o-mat-khau::placeholder { color: var(--chu-mo); font-weight: 600; }

.nut-ket-noi {
  width: 100%;
  margin-top: 20px;
  padding: 16px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  box-shadow: var(--bong-noi);
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.nut-ket-noi:active { transform: scale(0.98); background: var(--accent-toi); }
.nut-ket-noi:disabled { opacity: .6; box-shadow: none; }

.loi {
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.12);
  color: var(--do-loi);
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

/* --------------- May da luu --------------- */
.may-da-luu-tieu-de { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.may-da-luu-tieu-de h2 { font-size: 16px; margin: 0; }
.nut-nho {
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: transparent; border: none; cursor: pointer; padding: 6px 8px;
}

.ds-may { list-style: none; margin: 0; padding: 0; }
.may {
  display: flex; align-items: center; gap: 12px;
  background: var(--nen-the);
  border-radius: var(--bo-goc);
  box-shadow: var(--bong);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform .1s;
}
.may:active { transform: scale(0.99); }
.cham { width: 10px; height: 10px; border-radius: 50%; background: var(--xam-offline); flex: none; }
.cham.online { background: var(--xanh-online); box-shadow: 0 0 6px var(--xanh-online); }
.may-thongtin { flex: 1; min-width: 0; }
.may-ten { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.may-id { font-size: 13px; color: var(--chu-mo); letter-spacing: 1px; }
.may-xoa { background: transparent; border: none; color: var(--chu-mo); font-size: 18px; cursor: pointer; padding: 6px; }
.chua-co { color: var(--chu-mo); font-size: 14px; text-align: center; padding: 10px; }

/* ============================ DIEU KHIEN =========================== */
.khung-video {
  position: absolute; inset: 0;
  background: #000;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.canvas-video {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  display: block;
  image-rendering: auto;
  will-change: transform;
}

.lop-phu {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  background: rgba(20, 22, 28, 0.92);
  color: #fff;
  z-index: 30;
  padding: 20px;
  text-align: center;
}
.lop-phu[hidden] { display: none; }
.vong-xoay {
  width: 44px; height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: xoay 0.9s linear infinite;
}
@keyframes xoay { to { transform: rotate(360deg); } }
#text-trang-thai { font-size: 16px; margin: 0; }
.tien-do-khu { width: 80%; max-width: 320px; }
.thanh-tien-do { height: 6px; background: rgba(255,255,255,0.2); border-radius: 3px; overflow: hidden; }
.thanh-tien-do-trong { height: 100%; width: 0; background: var(--accent); transition: width .1s; }
.tien-do-nhan { display: block; font-size: 12px; color: #cbd2dc; margin-top: 8px; }

/* --------------- Thanh trang thai --------------- */
.thanh-trang-thai {
  position: absolute;
  top: calc(var(--sat) + 8px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: rgba(20, 22, 28, 0.6);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: #fff; font-size: 12px;
  padding: 6px 14px; border-radius: 999px;
  z-index: 20; pointer-events: none;
  max-width: calc(100% - 24px);
  white-space: nowrap; overflow: hidden;
}
.tt-ten { font-weight: 700; }
.tt-item b { font-weight: 700; color: var(--accent); }

/* --------------- Preset --------------- */
.hang-preset {
  position: absolute;
  right: calc(var(--sar) + 10px);
  top: calc(var(--sat) + 44px);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 20;
}
.preset {
  font-size: 12px; font-weight: 600;
  padding: 7px 12px; border-radius: 8px;
  background: rgba(20, 22, 28, 0.6);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  color: #fff; border: 1px solid transparent; cursor: pointer;
}
.preset.active { background: var(--accent); border-color: var(--accent); }

/* --------------- Thanh cong cu --------------- */
.thanh-cong-cu {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around; align-items: center;
  background: rgba(20, 22, 28, 0.82);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 8px calc(var(--sar) + 8px) calc(var(--sab) + 8px) calc(var(--sal) + 8px);
  z-index: 25;
}
.cong-cu {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: none; color: #E8EAED;
  font-size: 11px; cursor: pointer; padding: 6px 10px; border-radius: 10px;
  min-width: 56px;
}
.cong-cu:active { background: rgba(255,255,255,0.12); }
.cong-cu .icon { font-size: 20px; line-height: 1; }
.cong-cu.ngat { color: #FF6B6B; }
.nhan-cc { font-size: 10px; }

/* --------------- Ban phim ao --------------- */
.ban-phim-ao {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--sab) + 64px);
  background: var(--nen-the);
  border-top: 1px solid var(--vien);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
  padding: 8px calc(var(--sar) + 8px) 10px calc(var(--sal) + 8px);
  z-index: 26;
}
.ban-phim-ao[hidden] { display: none; }
.hang-phim-dac-biet {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}
.hang-phim-dac-biet::-webkit-scrollbar { height: 0; }
.phim-dac-biet, .phim-mod {
  flex: none;
  font-size: 13px; font-weight: 600;
  padding: 9px 12px; border-radius: 8px;
  background: var(--nen-nhap); color: var(--chu);
  border: 1px solid var(--vien); cursor: pointer;
  white-space: nowrap;
}
.phim-mod.bat { background: var(--accent); color: #fff; border-color: var(--accent); }
.phim-dac-biet:active { background: var(--vien); }
.hang-go { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.input-an {
  flex: 1; font-size: 15px; padding: 10px 12px;
  border: 2px solid var(--vien); border-radius: var(--bo-goc);
  background: var(--nen-nhap); color: var(--chu); outline: none;
}
.input-an:focus { border-color: var(--accent); }

/* --------------- Bang cai dat --------------- */
.bang-cai-dat {
  position: absolute; inset: 0;
  background: rgba(20, 22, 28, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 40;
}
.bang-cai-dat[hidden] { display: none; }
.bang-cai-dat-noi-dung {
  background: var(--nen-the);
  border-radius: 16px 16px 0 0;
  width: 100%; max-width: 480px;
  padding: 20px calc(var(--sar) + 20px) calc(var(--sab) + 20px) calc(var(--sal) + 20px);
  box-shadow: 0 -8px 30px rgba(0,0,0,0.3);
}
.bang-cai-dat-noi-dung h2 { margin: 0 0 16px; font-size: 18px; }
.dong-cai-dat {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--vien); font-size: 15px;
}
.dong-cai-dat input[type=range] { width: 50%; accent-color: var(--accent); }
.dong-cai-dat input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }

/* ============================ XOAY NGANG =========================== */
@media (orientation: landscape) and (max-height: 500px) {
  /* Xoay ngang: canvas full, thu gon UI */
  .thanh-cong-cu { padding-top: 4px; padding-bottom: calc(var(--sab) + 4px); }
  .cong-cu .nhan-cc { display: none; }
  .cong-cu { min-width: 44px; padding: 8px; }
  .thanh-trang-thai { top: calc(var(--sat) + 4px); font-size: 11px; }
  .hang-preset { flex-direction: row; top: auto; bottom: calc(var(--sab) + 60px); right: 50%; transform: translateX(50%); }
  .ban-phim-ao { bottom: calc(var(--sab) + 52px); }
}

/* Che do an het UI (khi khong cham mot luc) - dat qua class .an-ui */
.man-hinh.an-ui .thanh-cong-cu,
.man-hinh.an-ui .thanh-trang-thai,
.man-hinh.an-ui .hang-preset {
  opacity: 0; pointer-events: none; transition: opacity .4s;
}
.thanh-cong-cu, .thanh-trang-thai, .hang-preset { transition: opacity .4s; }
