@font-face {
  font-family: 'Be Vietnam Pro';
  src: url('/fonts/BeVietnamPro-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --nen: #f6f5f1;
  --the: #ffffff;
  --o: #faf9f6;
  --o-dam: #efede7;
  --vien: #e4e1d8;
  --vien-dam: #cdc9be;
  --chu: #1c1b19;
  --chu-phu: #5f5c55;
  /* Màu nhấn: chữ trắng trên nền này đạt tương phản 5:1. */
  --nhan: #d81f43;
  --nhan-dam: #b5163a;
  --nhan-nhat: #fde9ed;
  --nhan-chu: #b5163a;
  --xanh: #0e7c5f;
  --xanh-nhat: #e2f3ec;
  --vang: #8a5700;
  --vang-nhat: #fdf3dc;
  --do: #c0262d;
  --bong: 0 1px 2px rgb(0 0 0 / 4%), 0 4px 18px rgb(0 0 0 / 5%);
  --bo: 16px;
  --bo-nho: 12px;
  --chu-dam: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --nen: #121211;
    --the: #1c1b19;
    --o: #232220;
    --o-dam: #2c2b28;
    --vien: #35332e;
    --vien-dam: #4b4840;
    --chu: #f1efe8;
    --chu-phu: #aaa69b;
    --nhan-nhat: #3b1820;
    --nhan-chu: #ff8fa3;
    --xanh: #4fd1a5;
    --xanh-nhat: #12302a;
    --vang: #f0b44c;
    --vang-nhat: #33280f;
    --do: #ff7a7f;
    --bong: none;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--nen);
  color: var(--chu);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1,
h2,
h3 {
  line-height: 1.25;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button,
summary,
label {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--nhan);
  outline-offset: 2px;
}

/* ---------- Biểu tượng ---------- */

.kho-bieu-tuong {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.bt {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Đầu trang ---------- */

.dau-trang {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--vien);
  background: var(--the);
}

.thuong-hieu {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.thuong-hieu h1 {
  font: 700 19px/1.2 var(--chu-dam);
}

.thuong-hieu p {
  display: none;
  margin-top: 2px;
  color: var(--chu-phu);
  font-size: 14px;
}

.logo {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  background: var(--nhan) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M12 9l11 7-11 7z' fill='white'/%3E%3C/svg%3E") center / 64% no-repeat;
}

.hang-dau {
  display: flex;
  gap: 8px;
}

.dem-nho {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--nhan);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

/* ---------- Bố cục ---------- */

.bo-cuc {
  display: grid;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 16px 112px;
}

.cac-buoc {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}

.the {
  padding: 16px;
  border: 1px solid var(--vien);
  border-radius: var(--bo);
  background: var(--the);
  box-shadow: var(--bong);
}

/* ---------- Các bước (gập, mở) ---------- */

.buoc {
  border: 1px solid var(--vien);
  border-radius: var(--bo);
  background: var(--the);
  box-shadow: var(--bong);
  scroll-margin-top: 12px;
}

.buoc.mo {
  border-color: var(--vien-dam);
}

.dau-buoc-ngoai {
  font: inherit;
}

.dau-buoc {
  display: flex;
  gap: 14px;
  align-items: center;
  width: 100%;
  min-height: 72px;
  padding: 14px 16px;
  border: 0;
  border-radius: var(--bo);
  background: none;
  text-align: left;
  cursor: pointer;
}

.dau-buoc:hover {
  background: var(--o);
}

.dau-buoc:focus-visible {
  outline-offset: -3px;
}

.so-buoc {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  background: var(--o-dam);
  color: var(--chu-phu);
  font: 700 16px/1 var(--chu-dam);
}

.so-buoc .bt {
  display: none;
  width: 18px;
  height: 18px;
  stroke-width: 3;
}

.buoc.mo .so-buoc {
  background: var(--nhan);
  color: #fff;
}

.buoc.xong .so-buoc {
  background: var(--xanh-nhat);
  color: var(--xanh);
}

.buoc.xong .so-buoc > span {
  display: none;
}

.buoc.xong .so-buoc .bt {
  display: block;
}

.tieu-de-buoc {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
}

.ten-buoc {
  font: 700 17px/1.3 var(--chu-dam);
}

.tom-tat {
  overflow: hidden;
  color: var(--chu-phu);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tom-tat:empty,
.buoc.mo .tom-tat {
  display: none;
}

.mui-ten {
  color: var(--chu-phu);
  transition: transform 0.2s;
}

.buoc.mo .dau-buoc .mui-ten {
  transform: rotate(180deg);
}

.than-buoc {
  padding: 4px 16px 16px;
}

.chan-buoc {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--vien);
}

/* ---------- Chữ phụ, gợi ý ---------- */

.goi-y {
  color: var(--chu-phu);
  font-size: 14px;
}

.than-buoc > .goi-y {
  margin-top: 12px;
}

.nhan-o {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.tieu-de-nho {
  margin: 28px 0 10px;
  font: 700 15px/1.3 var(--chu-dam);
}

.than-buoc > .tieu-de-nho:first-child {
  margin-top: 8px;
}

.meo {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--bo-nho);
  background: var(--o);
  color: var(--chu-phu);
  font-size: 14px;
}

.meo .bt {
  margin-top: 1px;
  color: var(--xanh);
}

/* Số câu nằm một dòng riêng và luôn giữ chỗ, kể cả khi chưa có chữ:
   chia câu xong (có khi ngay lúc đang nhấn chuột) không đẩy nút bên dưới đi. */
.dong-phu {
  display: grid;
  gap: 4px;
  margin: 8px 0 14px;
}

.dem {
  min-height: 1lh;
  color: var(--chu-phu);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.lien-ket {
  padding: 0;
  border: 0;
  background: none;
  color: var(--nhan-chu);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.bao {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: var(--bo-nho);
  background: var(--vang-nhat);
  color: var(--chu);
  font-size: 14px;
}

.bao code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgb(0 0 0 / 7%);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.bao a {
  color: var(--nhan-chu);
  font-weight: 600;
}

/* ---------- Nút ---------- */

.nut {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--bo-nho);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.nut:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.nut-chinh {
  background: var(--nhan);
  color: #fff;
}

.nut-chinh:hover:not(:disabled) {
  background: var(--nhan-dam);
}

.nut-phu {
  border-color: var(--vien-dam);
  background: var(--the);
  color: var(--chu);
}

.nut-phu:hover:not(:disabled) {
  background: var(--o-dam);
}

.nut-chu {
  background: none;
  color: var(--chu-phu);
}

.nut-chu:hover:not(:disabled) {
  background: var(--o-dam);
  color: var(--chu);
}

.nut-lon {
  width: 100%;
  min-height: 52px;
  font-size: 17px;
}

.nut.dang-thu {
  border-color: var(--do);
  color: var(--do);
}

.nut.dang-thu .bt {
  animation: nhay 1s infinite;
}

@keyframes nhay {
  50% {
    opacity: 0.2;
  }
}

.nut-bieu-tuong {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 1px solid var(--vien);
  border-radius: var(--bo-nho);
  background: var(--the);
  color: var(--chu-phu);
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.nut-bieu-tuong:hover:not(:disabled) {
  background: var(--o-dam);
  color: var(--chu);
}

.nut-bieu-tuong:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.hang-nut {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-top: 14px;
}

.hang-nut.giua {
  justify-content: center;
  margin-top: 0;
}

.hang-nho {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hang-nho select {
  flex: 1;
  min-width: 0;
}

/* ---------- Ô nhập ---------- */

input:not([type='checkbox'], [type='radio'], [type='range'], [type='color'], [type='file']),
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--vien-dam);
  border-radius: var(--bo-nho);
  background-color: var(--o);
  font-size: 16px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--nhan);
  outline-offset: 0;
}

input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

select {
  padding-right: 38px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23878379' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 16px;
  cursor: pointer;
}

textarea {
  display: block;
  line-height: 1.6;
  resize: vertical;
}

#kich-ban {
  min-height: 160px;
}

.luoi-o {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px 16px;
  align-items: end;
}

.luoi-o label {
  display: grid;
  gap: 6px;
  color: var(--chu-phu);
  font-size: 14px;
  font-weight: 600;
}

.luoi-o .rong {
  grid-column: 1 / -1;
}

.luoi-o label.o-mau {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

input[type='range'] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--nhan);
  cursor: pointer;
}

.truot {
  display: flex;
  gap: 12px;
  align-items: center;
}

.truot output {
  min-width: 48px;
  color: var(--chu);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.truot-nhan {
  display: grid;
  gap: 2px;
  margin-top: 12px;
  color: var(--chu-phu);
  font-size: 14px;
  font-weight: 600;
}

input[type='color'] {
  width: 56px;
  height: 44px;
  padding: 4px;
  border: 1px solid var(--vien-dam);
  border-radius: var(--bo-nho);
  background: var(--o);
  cursor: pointer;
}

input[type='checkbox'],
input[type='radio'] {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--nhan);
}

.luoi-o label.hop-chon,
.hop-chon {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  color: var(--chu);
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
}

/* Công tắc bật tắt */
.cong-tac {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
}

.cong-tac input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.cong-tac .ray {
  position: relative;
  width: 44px;
  height: 26px;
  flex: none;
  border-radius: 999px;
  background: var(--vien-dam);
  transition: background-color 0.15s;
}

.cong-tac .ray::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
  transition: transform 0.15s;
}

.cong-tac input:checked + .ray {
  background: var(--nhan);
}

.cong-tac input:checked + .ray::after {
  transform: translateX(18px);
}

.cong-tac input:focus-visible + .ray {
  outline: 2px solid var(--nhan);
  outline-offset: 2px;
}

.cong-tac.nho {
  color: var(--chu-phu);
  font-size: 14px;
}

/* Nút chọn hai lựa chọn (Tự thu / Giọng AI) */
.chon-nhom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 14px;
  padding: 4px;
  border-radius: 14px;
  background: var(--o-dam);
}

.chon-nhom label {
  position: relative;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--chu-phu);
  font-weight: 600;
  cursor: pointer;
}

.chon-nhom input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chon-nhom label:has(input:checked) {
  background: var(--the);
  color: var(--chu);
  box-shadow: 0 1px 3px rgb(0 0 0 / 12%);
}

.chon-nhom label:has(input:focus-visible) {
  outline: 2px solid var(--nhan);
  outline-offset: 1px;
}

/* ---------- Bước 1: video mẫu ---------- */

.luoi-mau {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 12px;
}

.mau {
  position: relative;
}

.chon-mau {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 4px 4px 8px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--o);
  text-align: left;
  cursor: pointer;
}

.chon-mau:hover {
  border-color: var(--vien-dam);
}

.mau.dang-chon .chon-mau {
  border-color: var(--nhan);
  background: var(--nhan-nhat);
}

.chon-mau img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  border-radius: 10px;
  background: #000;
  object-fit: cover;
}

.chon-mau .ten {
  overflow: hidden;
  padding: 0 4px;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chon-mau .phu {
  padding: 0 4px;
  color: var(--chu-phu);
  font-size: 13px;
}

.dau-chon {
  position: absolute;
  top: 10px;
  left: 10px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--nhan);
  color: #fff;
  pointer-events: none;
}

.dau-chon .bt {
  width: 16px;
  height: 16px;
  stroke-width: 3;
}

.mau .xoa {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / 60%);
  color: #fff;
  cursor: pointer;
}

/* Vùng bấm 44 px cho nút xóa nhỏ */
.mau .xoa::after {
  content: '';
  position: absolute;
  inset: -5px;
}

.mau .xoa .bt {
  width: 18px;
  height: 18px;
}

@media (hover: hover) {
  .mau .xoa {
    opacity: 0;
    transition: opacity 0.15s;
  }

  .mau:hover .xoa,
  .mau .xoa:focus-visible {
    opacity: 1;
  }
}

.them-mau {
  display: grid;
  gap: 6px;
  place-items: center;
  align-content: center;
  padding: 16px 12px;
  border: 2px dashed var(--vien-dam);
  border-radius: 14px;
  background: var(--o);
  color: var(--chu-phu);
  font-size: 14px;
  text-align: center;
  cursor: pointer;
}

.them-mau b {
  color: var(--chu);
  font-size: 15px;
}

.them-mau .bt {
  width: 28px;
  height: 28px;
}

.them-mau:hover,
body.dang-keo .them-mau {
  border-color: var(--nhan);
  background: var(--nhan-nhat);
  color: var(--nhan-chu);
}

.them-mau.rong {
  grid-column: 1 / -1;
  min-height: 180px;
}

.thanh-tien-do {
  position: relative;
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--o-dam);
}

.thanh-tien-do > div {
  width: 0;
  height: 100%;
  background: var(--nhan);
  transition: width 0.3s;
}

/* Thanh tiến độ xuất: chữ nằm dưới thanh để luôn đọc được. */
.thanh-tien-do.lon {
  height: auto;
  margin-top: 4px;
  overflow: visible;
  background: none;
}

.thanh-tien-do.lon::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 10px;
  border-radius: 99px;
  background: var(--o-dam);
}

.thanh-tien-do.lon > div {
  position: relative;
  height: 10px;
  border-radius: 99px;
}

.thanh-tien-do.lon > span {
  display: block;
  margin-top: 8px;
  color: var(--chu-phu);
  font-size: 14px;
  text-align: center;
}

/* ---------- Bước 2: lời đọc ---------- */

.khung-claude {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--vien);
  border-radius: var(--bo-nho);
  background: var(--o);
}

.ds-ban {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.ds-ban:empty {
  display: none;
}

.ban {
  padding: 14px;
  border: 1px solid var(--vien);
  border-radius: var(--bo-nho);
  background: var(--the);
}

.ban h4 {
  margin-bottom: 4px;
  font-size: 15px;
}

.ban .goc-nhin {
  margin-bottom: 8px;
  color: var(--chu-phu);
  font-size: 14px;
}

.ban pre {
  margin: 0 0 10px;
  font: inherit;
  white-space: pre-wrap;
}

/* ---------- Bước 3: giọng ---------- */

.ds-cau {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: cau;
}

.ds-cau li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--vien);
  border-radius: var(--bo-nho);
  background: var(--o);
  counter-increment: cau;
}

.ds-cau li::before {
  content: counter(cau);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--o-dam);
  color: var(--chu-phu);
  font-size: 13px;
  font-weight: 700;
}

.ds-cau li.co-giong::before {
  background: var(--xanh-nhat);
  color: var(--xanh);
}

.ds-cau .chu {
  overflow-wrap: anywhere;
}

.ds-cau .tt {
  display: block;
  margin-top: 2px;
  color: var(--chu-phu);
  font-size: 13px;
}

.ds-cau .tt.loi {
  color: var(--do);
}

.ds-cau .nut-cau {
  display: flex;
  flex-wrap: wrap;
  grid-column: 2;
  gap: 8px;
}

.ds-cau .trong {
  display: block;
  padding: 20px;
  border-style: dashed;
  color: var(--chu-phu);
  text-align: center;
}

.ds-cau .trong::before {
  display: none;
}

/* ---------- Bước 4: nhạc, phụ đề, nhãn ---------- */

.kieu-phu-de {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.the-chon {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 2px solid var(--vien);
  border-radius: 14px;
  background: var(--the);
  cursor: pointer;
}

.the-chon:hover {
  border-color: var(--vien-dam);
}

.the-chon input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.the-chon:has(input:checked) {
  border-color: var(--nhan);
  background: var(--nhan-nhat);
}

.the-chon:has(input:focus-visible) {
  outline: 2px solid var(--nhan);
  outline-offset: 2px;
}

.mau-kieu {
  display: grid;
  place-items: center;
  height: 64px;
  border-radius: 10px;
  background: linear-gradient(160deg, #3d4350, #15171c);
  color: #fff;
  font: 700 17px/1 var(--chu-dam);
  text-shadow: 0 0 2px #000, 0 2px 3px rgb(0 0 0 / 60%);
}

.mau-kieu b {
  color: #ffe14d;
}

.mau-kieu.mau-lon {
  font-size: 23px;
}

.mau-kieu.mau-tat {
  color: rgb(255 255 255 / 45%);
}

.ten-kieu {
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.nang-cao {
  margin-top: 20px;
  border: 1px solid var(--vien);
  border-radius: var(--bo-nho);
}

.nang-cao summary {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--bo-nho);
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.nang-cao summary::-webkit-details-marker {
  display: none;
}

.nang-cao summary .mui-ten {
  margin-left: auto;
}

.nang-cao[open] summary .mui-ten {
  transform: rotate(180deg);
}

.nang-cao > .luoi-o {
  padding: 4px 14px 16px;
}

/* ---------- Khung xem trước và xuất ---------- */

.xuong {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
  scroll-margin-top: 12px;
}

.the-xem {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Hộp chứa khung điện thoại: khung tự co theo cả chiều rộng lẫn chiều cao còn trống. */
.o-khung {
  display: grid;
  place-items: center;
  height: min(60vh, 520px);
  container-type: size;
}

/* Khung điện thoại: mọi kích thước tính theo khổ 1080×1920 như video xuất; phần trong viền đúng 9:16. */
.khung-dt {
  position: relative;
  box-sizing: content-box;
  width: min(100% - 12px, 290px);
  width: min(100cqw - 12px, (100cqh - 12px) * 9 / 16);
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 6px solid #111;
  border-radius: 28px;
  background: #0b0b0b;
}

.khung-dt canvas,
.khung-dt .video-nguon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Video nguồn nằm dưới canvas: trình duyệt chỉ báo khung hình của video đang hiển thị. */
.khung-dt .video-nguon {
  z-index: 0;
  object-fit: cover;
}

#xem-canvas {
  z-index: 1;
}

/* Canvas đang dựng video: phủ lên khung xem trước để thấy video đang được dựng. */
.khung-dt .canvas-dung {
  z-index: 3;
}

.xem-trong {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  gap: 10px;
  place-content: center;
  justify-items: center;
  padding: 24px;
  background: #0b0b0b;
  color: #a8a8a8;
  font-size: 14px;
  text-align: center;
}

.xem-trong .bt {
  width: 36px;
  height: 36px;
  color: #777;
}

.vung-tiktok {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.vung-tiktok .vt {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 4px;
  background: repeating-linear-gradient(45deg, rgb(255 59 92 / 22%) 0 6px, rgb(255 59 92 / 10%) 6px 12px);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  text-shadow: 0 1px 2px #000;
}

.vung-tiktok .tren {
  top: 0;
  right: 0;
  left: 0;
  height: 7.5%;
}

.vung-tiktok .phai {
  top: 42%;
  right: 0;
  width: 14%;
  height: 40%;
}

.vung-tiktok .duoi {
  right: 0;
  bottom: 0;
  left: 0;
  height: 18%;
}

.the-xuat h2 {
  font: 700 18px/1.3 var(--chu-dam);
}

.san-sang {
  display: grid;
  gap: 2px;
  margin: 10px 0 14px;
  padding: 0;
  list-style: none;
}

.san-sang li {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  min-height: 36px;
}

.san-sang span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.san-sang li.xong .bt {
  color: var(--xanh);
  stroke-width: 3;
}

.san-sang button {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  min-height: 36px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--nhan-chu);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.san-sang button:hover span {
  text-decoration: underline;
}

.san-sang button .bt {
  color: var(--vien-dam);
}

.canh-bao-nho {
  margin-top: 10px;
  color: var(--vang);
  font-size: 14px;
  font-weight: 600;
}

.canh-bao-nho:empty {
  display: none;
}

#cach-dung {
  margin-top: 10px;
  font-size: 13px;
  text-align: center;
}

.the-xuat.nhay {
  animation: nhay-vien 1.2s ease-out;
}

@keyframes nhay-vien {
  from {
    box-shadow: 0 0 0 4px rgb(216 31 67 / 45%);
  }

  to {
    box-shadow: 0 0 0 0 rgb(216 31 67 / 0%);
  }
}

/* ---------- Thanh dưới cùng (điện thoại) ---------- */

.thanh-duoi {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--vien);
  background: var(--the);
  box-shadow: 0 -6px 20px rgb(0 0 0 / 6%);
}

.thanh-duoi-chu {
  min-width: 0;
  overflow: hidden;
  color: var(--chu-phu);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Hộp thoại ---------- */

.hop-thoai {
  width: min(560px, calc(100% - 32px));
  max-width: none;
  max-height: calc(100dvh - 48px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  background: var(--the);
  color: var(--chu);
  box-shadow: 0 24px 64px rgb(0 0 0 / 30%);
}

.hop-thoai[open] {
  display: flex;
  flex-direction: column;
}

.hop-thoai::backdrop {
  background: rgb(15 15 14 / 55%);
}

.ruot-hop {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dau-hop {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 10px 20px;
  border-bottom: 1px solid var(--vien);
  background: var(--the);
}

.dau-hop h2 {
  font: 700 18px/1.3 var(--chu-dam);
}

.dau-hop .nut-bieu-tuong {
  border-color: transparent;
}

.hop-thoai section {
  padding: 16px 20px;
  scroll-margin-top: 66px;
}

.hop-thoai section + section {
  border-top: 1px solid var(--vien);
}

.hop-thoai h3 {
  margin-bottom: 8px;
  font: 700 15px/1.3 var(--chu-dam);
}

.hop-thoai section ol,
.hop-thoai section ul {
  margin: 0;
  padding-left: 20px;
}

.hop-thoai section li + li {
  margin-top: 6px;
}

.hop-thoai section p {
  margin-top: 10px;
  color: var(--chu-phu);
  font-size: 15px;
}

.hop-thoai section .nut {
  margin-top: 12px;
}

.goi-y.le {
  padding: 14px 20px 0;
}

.hop-thoai .tinh-trang {
  display: grid;
  gap: 8px;
  padding: 0;
  list-style: none;
}

.tinh-trang li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.hop-thoai .tinh-trang li + li {
  margin-top: 0;
}

.tinh-trang .bt {
  margin-top: 2px;
}

.tinh-trang .tot .bt {
  color: var(--xanh);
}

.tinh-trang .chua .bt {
  color: var(--vang);
}

/* Video vừa xuất */
.ket-qua {
  display: grid;
  gap: 16px;
  padding: 16px 20px 20px;
}

.ket-qua video {
  display: block;
  width: auto;
  max-width: 100%;
  height: min(52dvh, 520px);
  margin: 0 auto;
  aspect-ratio: 9 / 16;
  border-radius: 12px;
  background: #000;
}

.ten-xuat {
  overflow-wrap: anywhere;
  font-weight: 600;
}

.ket-qua .hang-nut .nut {
  flex: 1;
}

.ket-qua .hang-nut + .goi-y {
  margin-top: 8px;
}

.truoc-khi-dang {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--vien);
}

.truoc-khi-dang summary {
  min-height: 32px;
  font-weight: 600;
  cursor: pointer;
}

.truoc-khi-dang ul {
  margin: 6px 0 0;
  padding-left: 20px;
  font-size: 15px;
}

.truoc-khi-dang li + li {
  margin-top: 4px;
}

/* Danh sách video đã xuất */
.ds-xuat {
  display: grid;
  gap: 8px;
  padding: 12px 20px 20px;
}

.ds-xuat .trong {
  padding: 24px 0;
  color: var(--chu-phu);
  text-align: center;
}

.xuat {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--vien);
  border-radius: var(--bo-nho);
  background: var(--o);
}

.xem-xuat {
  position: relative;
  display: block;
  width: 52px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: #000;
  cursor: pointer;
}

.xem-xuat img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
}

.xem-xuat .bt {
  position: absolute;
  inset: 0;
  width: 22px;
  height: 22px;
  margin: auto;
  color: #fff;
  filter: drop-shadow(0 1px 2px rgb(0 0 0 / 60%));
}

.xuat .ten {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xuat .phu {
  color: var(--chu-phu);
  font-size: 13px;
}

.xuat .nut-cau {
  display: flex;
  gap: 6px;
}

/* ---------- Thông báo ---------- */

.thong-bao {
  position: fixed;
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 30;
  display: grid;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.thong-bao > div {
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--bo-nho);
  background: #222;
  color: #fff;
  box-shadow: 0 6px 24px rgb(0 0 0 / 25%);
  font-size: 15px;
  animation: hien 0.2s ease-out;
}

.thong-bao > div.loi {
  background: #8f1d27;
}

.thong-bao > div.tot {
  background: #0c5e48;
}

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

/* ---------- Màn hình rộng hơn ---------- */

@media (max-width: 640px) {
  /* Nút ở đầu trang chỉ còn biểu tượng; chữ vẫn để trình đọc màn hình đọc. */
  .an-khi-hep {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .hang-dau .nut,
  #nut-tai-nhac {
    position: relative;
    width: 44px;
    padding: 0;
  }

  .hang-dau .dem-nho {
    position: absolute;
    top: -6px;
    right: -6px;
  }

  .hop-thoai {
    width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
  }

  .ruot-hop {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (min-width: 641px) {
  .dau-buoc {
    padding: 16px 20px;
  }

  .than-buoc {
    padding: 4px 20px 20px;
  }

  .chon-nhom {
    display: inline-grid;
    min-width: 360px;
  }

  .ds-cau li {
    grid-template-columns: 28px minmax(0, 1fr) auto;
    align-items: center;
  }

  .ds-cau .nut-cau {
    grid-column: auto;
    flex-wrap: nowrap;
  }

  .kieu-phu-de {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  #hop-ket-qua {
    width: min(760px, calc(100% - 32px));
  }

  .ket-qua {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }

  .ket-qua video {
    height: min(68dvh, 560px);
  }
}

@media (min-width: 720px) {
  .thuong-hieu p {
    display: block;
  }
}

/* Máy tính: các bước bên trái, khung xem trước và nút xuất đứng yên bên phải. */
@media (min-width: 961px) {
  /* Đầu trang đứng yên, cao cố định 72 px để khung xuất bên dưới tính được chiều cao. */
  .dau-trang {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 72px;
    padding: 0 max(28px, calc((100% - 1240px) / 2 + 28px));
  }

  .buoc,
  .xuong {
    scroll-margin-top: 88px;
  }

  /* Lề dưới 16 px: khung xuất đứng yên (cao 100dvh − 104 px) không bị đẩy lên khi cuộn tới cuối trang. */
  .bo-cuc {
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 24px;
    padding: 24px 28px 16px;
  }

  .xuong {
    position: sticky;
    top: 88px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: calc(100vh - 104px);
    height: calc(100dvh - 104px);
    overflow-y: auto;
    align-self: start;
  }

  .the-xem {
    flex: 1 1 auto;
    min-height: 340px;
  }

  .o-khung {
    flex: 1 1 0;
    height: auto;
    min-height: 0;
  }

  .thanh-duoi {
    display: none !important;
  }

  .thong-bao {
    bottom: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
