:root {
  --nen: #101113;
  --mat: #17191c;
  --mat-2: #202327;
  --vien: #2e3238;
  --chu: #f1eee8;
  --chu-phu: #a6a59f;
  --sang: #f4b860;
  --sang-chu: #1b1408;
  --zalo: #0068ff;
  --cong-tac-tat: #3b3f46;
  --bang-rong: 372px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--nen);
  color: var(--chu);
  font-family: 'Be Vietnam Pro', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--sang);
  outline-offset: 2px;
}

.bo-cuc {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--bang-rong);
  height: 100vh;
  height: 100dvh;
}

/* Khu vực 3D */
.san-khau {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #050505;
}
#khung3d {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#khung3d:active { cursor: grabbing; }

.dau-trang {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 18px;
  background: linear-gradient(to bottom, rgba(0,0,0,.78), rgba(0,0,0,0));
  pointer-events: none;
}
.dau-trang > * { pointer-events: auto; }

.logo {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .12em;
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0,0,0,.7);
}
.logo b { font-weight: 700; color: var(--sang); }

.ve-danh-muc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(16,17,19,.62);
  backdrop-filter: blur(6px);
  color: var(--chu);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}
.ve-danh-muc:hover { background: rgba(40,42,46,.8); }
.ten-mau {
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,.7);
  white-space: nowrap;
}
.ten-mau span { font-weight: 400; color: #d8d6d0; }

.dieu-khien-duoi {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.nhom-nut {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 10px;
  background: rgba(16,17,19,.72);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}
.nut-nho {
  min-height: 36px;
  padding: 6px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  white-space: nowrap;
}
.nut-nho:hover { background: rgba(255,255,255,.1); }
.nut-nho.dang-chon { background: var(--chu); color: #15161a; font-weight: 600; }

.goi-y {
  position: absolute;
  left: 50%;
  bottom: 66px;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(16,17,19,.55);
  color: #d8d6d0;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  animation: an-di 1s 6s forwards;
}
@keyframes an-di { to { opacity: 0; } }

.dang-tai, .loi-3d {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0b0c0e;
  color: var(--chu-phu);
  text-align: center;
}
.dang-tai[hidden], .loi-3d[hidden] { display: none; }
.loi-3d p { max-width: 42ch; }

/* Bảng chọn đèn */
.bang-den {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--mat);
  border-left: 1px solid var(--vien);
}
.nut-thu-gon { display: none; }
.cuon {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--vien) transparent;
}
h1 { margin: 0 0 16px; font-size: 19px; font-weight: 600; line-height: 1.3; }
h2 { margin: 18px 0 8px; font-size: 13px; font-weight: 500; color: var(--chu-phu); }

.kich-ban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.nut-kich-ban {
  min-height: 40px;
  padding: 6px 4px;
  border: 1px solid var(--vien);
  border-radius: 8px;
  background: var(--mat-2);
  font-size: 13px;
}
.nut-kich-ban:hover { border-color: #565b63; }
.nut-kich-ban.dang-chon {
  background: var(--sang);
  border-color: var(--sang);
  color: var(--sang-chu);
  font-weight: 600;
}
.nut-tat { color: var(--chu-phu); }

.ds-den { list-style: none; margin: 0; padding: 0; }
.he-den {
  border: 1px solid var(--vien);
  border-radius: 10px;
  background: var(--mat-2);
  margin-bottom: 6px;
  transition: border-color .2s;
}
.he-den.dang-bat { border-color: rgba(244,184,96,.55); }

.he-den-dau { display: flex; align-items: center; }
.he-den-ten {
  position: relative;
  flex: 1;
  min-width: 0;
  display: block;
  padding: 10px 28px 10px 12px;
  border: 0;
  background: none;
  text-align: left;
}
.he-den-ten strong { display: block; font-size: 14px; font-weight: 500; }
.ghi-chu { display: block; font-size: 12px; color: var(--chu-phu); }
.mui-ten {
  position: absolute;
  right: 10px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -6px;
  border-right: 1.5px solid var(--chu-phu);
  border-bottom: 1.5px solid var(--chu-phu);
  transform: rotate(45deg);
  transition: transform .15s;
}
.mo-rong .mui-ten { transform: translateY(3px) rotate(225deg); }

.cong-tac {
  flex: none;
  position: relative;
  width: 42px;
  height: 24px;
  margin: 0 12px 0 4px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--cong-tac-tat);
  transition: background .18s;
}
.cong-tac::after {
  /* vùng bấm rộng hơn trên điện thoại */
  content: '';
  position: absolute;
  inset: -10px -8px;
}
.cong-tac i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s;
}
.cong-tac[aria-checked="true"] { background: var(--sang); }
.cong-tac[aria-checked="true"] i { transform: translateX(18px); }

.he-den-chi-tiet { display: none; padding: 0 12px 12px; }
.mo-rong .he-den-chi-tiet { display: block; }
.nhan { margin: 10px 0 5px; font-size: 12px; color: var(--chu-phu); }
.nhom-chon { display: flex; flex-wrap: wrap; gap: 5px; }
.chon-mau, .mau-sang {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid var(--vien);
  border-radius: 7px;
  background: var(--mat);
  font-size: 13px;
}
.mau-sang i { width: 11px; height: 11px; border-radius: 50%; }
.chon-mau.dang-chon, .mau-sang.dang-chon {
  border-color: var(--sang);
  box-shadow: inset 0 0 0 1px var(--sang);
}
.do-sang { display: flex; align-items: center; gap: 10px; }
.do-sang input { flex: 1; min-width: 0; height: 28px; accent-color: var(--sang); }
.do-sang output { width: 40px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }

.luu-y { margin: 12px 0 0; font-size: 12px; color: var(--chu-phu); }

.chan-bang {
  flex: none;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--vien);
  background: var(--mat);
}
.tong-ket {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 9px;
  font-size: 13px;
  color: var(--chu-phu);
}
.tong-ket strong { color: var(--chu); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.nut-zalo {
  display: block;
  padding: 12px;
  border-radius: 10px;
  background: var(--zalo);
  color: #fff;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.nut-zalo:hover { background: #0058d8; }

.thong-bao {
  position: fixed;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 32px));
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--chu);
  color: #15161a;
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
  z-index: 10;
}
.thong-bao[hidden] { display: none; }

/* Điện thoại và máy dọc: phòng 3D ở trên, bảng chọn ở dưới */
@media (max-width: 860px), (max-aspect-ratio: 1/1) {
  .bo-cuc {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 46%);
  }
  .bo-cuc:has(.thu-gon) { grid-template-rows: minmax(0, 1fr) auto; }
  .bang-den { border-left: 0; border-top: 1px solid var(--vien); }
  .nut-thu-gon {
    display: block;
    flex: none;
    width: 100%;
    min-height: 34px;
    border: 0;
    border-bottom: 1px solid var(--vien);
    background: var(--mat-2);
    color: var(--chu-phu);
    font-size: 12px;
  }
  .thu-gon .cuon { display: none; }
  h1 { font-size: 16px; margin-bottom: 8px; }
  h2 { margin-top: 12px; }
  .cuon { padding: 12px 16px; }
  .chan-bang { display: flex; align-items: center; gap: 12px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
  .tong-ket { flex: 1; min-width: 0; display: block; margin: 0; }
  .tong-ket span { display: block; font-size: 12px; }
  .nut-zalo { flex: none; padding: 10px 14px; }
  .dau-trang { flex-direction: column; align-items: flex-start; gap: 6px; padding: 10px 16px; }
  .ve-danh-muc { min-height: 32px; padding: 4px 9px; font-size: 13px; }
  .ten-mau { font-size: 14px; }
  .dieu-khien-duoi { left: 8px; right: 8px; bottom: 8px; gap: 5px; }
  .nut-nho { min-height: 32px; padding: 4px 8px; font-size: 12px; }
  .goi-y { bottom: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .goi-y { animation: none; display: none; }
}
