/* ===== LỚP TRẬT TỰ ===== */
.lt-app [hidden] { display: none !important; }
.lt-app { max-width: 1200px; margin: 0 auto; }
.lt-app:fullscreen { background: var(--bg); overflow: auto; padding: 16px; max-width: none; }

.lt-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

/* ----- Đồng hồ hẹn giờ (trên cùng) ----- */
.lt-timer { padding: 16px 16px; margin: 0; transition: background .3s, border-color .3s; }
.lt-timer-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.lt-timer-title { font-weight: 700; color: var(--dark); }
.lt-timer-hint { color: var(--text-muted); font-size: .8rem; flex-basis: 100%; }
.lt-timer-hint:empty { display: none; }
.lt-timer-body { margin-top: 12px; text-align: center; }
.lt-timer-clock {
  font-size: clamp(2.6rem, 5vw, 3.6rem); font-weight: 800; line-height: 1.05;
  font-variant-numeric: tabular-nums; color: var(--dark); letter-spacing: .02em;
}
.lt-timer.running .lt-timer-clock { color: var(--primary); }
.lt-timer.warn .lt-timer-clock { color: var(--accent-dark); }
.lt-timer.done { background: #fef2f2; border-color: #fca5a5; }
.lt-timer.done .lt-timer-clock { color: #dc2626; animation: ltPulse .8s ease-in-out infinite; }
.lt-timer-bar { height: 8px; border-radius: 99px; background: var(--border); overflow: hidden; margin: 10px auto 14px; max-width: 640px; }
.lt-timer-bar i { display: block; height: 100%; width: 100%; background: var(--primary); border-radius: 99px; transition: width .25s linear, background .3s; }
.lt-timer.warn .lt-timer-bar i { background: var(--accent); }
.lt-timer.done .lt-timer-bar i { background: #ef4444; }
.lt-timer-ctrl { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.lt-timer-ctrl .btn { width: 100%; }
.lt-minutes { justify-content: center; }
.lt-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.lt-chip {
  border: 1.5px solid var(--border); background: var(--white); color: var(--text);
  border-radius: 99px; padding: 5px 13px; font-size: .85rem; font-weight: 600; cursor: pointer; font-family: inherit;
}
.lt-chip:hover { border-color: var(--primary); color: var(--primary); }
.lt-chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.lt-minutes { font-size: .88rem; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.lt-minutes input { width: 64px; padding: 6px 8px; border: 1.5px solid var(--border); border-radius: 10px; font: inherit; text-align: center; }
.lt-btn-ghost { background: var(--bg); border: 1.5px solid var(--border); color: var(--text); }
.lt-btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
@keyframes ltPulse { 50% { transform: scale(1.05); } }

/* công tắc */
.lt-switch { position: relative; display: inline-block; width: 50px; height: 28px; flex: none; }
.lt-switch input { opacity: 0; width: 0; height: 0; }
.lt-slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 99px; cursor: pointer; transition: .25s; }
.lt-slider::before { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .25s; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.lt-switch input:checked + .lt-slider { background: var(--primary); }
.lt-switch input:checked + .lt-slider::before { transform: translateX(22px); }
.lt-switch input:focus-visible + .lt-slider { outline: 3px solid rgba(37,99,235,.35); }

/* ----- Chọn chế độ ----- */
.lt-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.lt-mode {
  text-align: left; padding: 16px 18px; border-radius: 18px; border: 2px solid var(--border);
  background: var(--white); cursor: pointer; font-family: inherit; color: var(--text);
  display: flex; gap: 14px; align-items: center; transition: var(--transition);
}
.lt-mode:hover { border-color: #93c5fd; transform: translateY(-2px); }
.lt-mode.on { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 6px 20px rgba(37,99,235,.15); }
.lt-mode-ico { font-size: 2.2rem; flex: none; }
.lt-mode b { display: block; font-size: 1.02rem; color: var(--dark); }
.lt-mode span { font-size: .84rem; color: var(--text-muted); line-height: 1.45; display: block; margin-top: 2px; }

/* ----- Bố cục chính ----- */
.lt-main { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 18px; align-items: start; }
.lt-main > .lt-timer { grid-column: 1; grid-row: 1; position: sticky; top: 80px; }
.lt-main > .lt-left { grid-column: 2; grid-row: 1; }
.lt-main > .lt-side { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.lt-left { min-width: 0; }

/* ----- Sân khấu ----- */
.lt-stage {
  position: relative; border-radius: 22px; overflow: hidden; min-height: 420px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #1e2a5a 0%, #3a4a8f 60%, #5b6bb5 100%);
  transition: background .5s;
  box-shadow: var(--shadow-lg);
}
.lt-stage::before { /* sao */
  content: ''; position: absolute; inset: 0; opacity: .9; transition: opacity .5s; pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 12% 18%, #fff, transparent), radial-gradient(1.5px 1.5px at 28% 40%, #fff, transparent),
    radial-gradient(2px 2px at 44% 12%, #fff, transparent), radial-gradient(1.5px 1.5px at 63% 30%, #fff, transparent),
    radial-gradient(2px 2px at 78% 14%, #fff, transparent), radial-gradient(1.5px 1.5px at 90% 38%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 8% 56%, #fff, transparent), radial-gradient(2px 2px at 92% 62%, #fff, transparent);
}
.lt-moon { position: absolute; right: 9%; top: 9%; width: 70px; height: 70px; border-radius: 50%;
  background: #fff8d6; box-shadow: 0 0 40px 10px rgba(255,248,214,.35); transition: opacity .5s; }
.lt-moon::after { content: ''; position: absolute; width: 58px; height: 58px; border-radius: 50%; background: #3a4a8f; left: 18px; top: -6px; }
.lt-stage[data-state="wake"], .lt-stage[data-state="bark"] { background: linear-gradient(180deg, #ffb347 0%, #ff8a5c 60%, #ff6b6b 100%); }
.lt-stage[data-state="wake"]::before, .lt-stage[data-state="bark"]::before,
.lt-stage[data-state="wake"] .lt-moon, .lt-stage[data-state="bark"] .lt-moon { opacity: 0; }
.lt-stage[data-state="bark"] { animation: ltAlarm .7s ease-in-out infinite; }
@keyframes ltAlarm { 50% { filter: brightness(1.12) saturate(1.15); } }
.lt-stage.cam { background: #0b1220; min-height: 0; aspect-ratio: 16 / 9; }
.lt-stage.cam::before, .lt-stage.cam .lt-moon { display: none; }
.lt-stage.cam[data-state="bark"] { box-shadow: 0 0 0 5px #ef4444, var(--shadow-lg); animation: none; }

.lt-view1 { width: 100%; display: flex; flex-direction: column; align-items: center; padding: 20px 10px 6px; position: relative; z-index: 2; }
.lt-pet-big { width: min(430px, 88%); }
.lt-caption {
  margin-top: 6px; margin-bottom: 14px; padding: 7px 18px; border-radius: 99px; font-weight: 700; font-size: .95rem;
  background: rgba(255,255,255,.18); color: #fff; backdrop-filter: blur(4px); text-align: center;
}
.lt-view2 { position: relative; width: 100%; height: 100%; background: #000; }
.lt-view2 video, .lt-view2 canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.lt-cam-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: #cbd5e1; text-align: center; padding: 20px; }
.lt-cam-empty .big { font-size: 3.4rem; }
.lt-mascot { position: absolute; right: 12px; bottom: 12px; width: clamp(90px, 18%, 150px); z-index: 3; filter: drop-shadow(0 4px 8px rgba(0,0,0,.4)); pointer-events: none; }
.lt-banner {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 4; max-width: 90%;
  background: #ef4444; color: #fff; font-weight: 700; padding: 8px 18px; border-radius: 99px; font-size: .95rem;
  box-shadow: 0 4px 16px rgba(239,68,68,.5); animation: ltPulse .7s ease-in-out infinite; text-align: center;
}

/* ----- Nút điều khiển + đồng hồ đo ----- */
.lt-ctrl { padding: 16px 18px; margin-top: 14px; }
.lt-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.lt-status { font-size: .88rem; font-weight: 600; color: var(--text-muted); flex: 1 1 200px; }
.lt-status.on { color: #16a34a; } .lt-status.err { color: #dc2626; } .lt-status.warn { color: #d97706; }
.lt-meter-wrap { margin-top: 14px; }
.lt-meter-top { display: flex; justify-content: space-between; font-size: .85rem; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.lt-meter-top b { color: var(--dark); font-variant-numeric: tabular-nums; }
.lt-meter { position: relative; height: 22px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.lt-meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #22c55e, #eab308 60%, #ef4444); border-radius: 99px; transition: width .06s linear; }
.lt-meter-mask { position: absolute; inset: 0; }
.lt-thr-line { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--dark); border-radius: 2px; transform: translateX(-1px); }
.lt-range { width: 100%; margin-top: 10px; accent-color: var(--primary); height: 28px; }
.lt-range-lbl { display: flex; justify-content: space-between; font-size: .8rem; color: var(--text-muted); }
.lt-meter-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }

/* ----- Bảng bên ----- */
.lt-side { display: flex; flex-direction: column; gap: 14px; }
.lt-box { padding: 16px 18px; }
.lt-box h3 { font-size: .98rem; color: var(--dark); margin-bottom: 10px; }
.lt-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .9rem; margin-bottom: 10px; }
.lt-skins { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lt-skin {
  border: 2px solid var(--border); background: var(--bg); border-radius: 14px; padding: 6px 4px 4px; cursor: pointer;
  font-family: inherit; font-size: .74rem; font-weight: 600; color: var(--text); text-align: center; transition: var(--transition);
}
.lt-skin:hover { border-color: #93c5fd; }
.lt-skin.on { border-color: var(--primary); background: var(--primary-light); }
.lt-skin .pet { width: 100%; pointer-events: none; background: #cfe0ff; border-radius: 10px; margin-bottom: 3px; }
.lt-skin .pet-svg { display: block; }
.lt-skin .ph { height: 54px; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; background: #cfe0ff; border-radius: 10px; margin-bottom: 3px; }
.lt-upload { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.lt-upload small { color: var(--text-muted); line-height: 1.5; }
.lt-upload-row { display: flex; gap: 8px; flex-wrap: wrap; }
.lt-upload-row .btn { flex: 1 1 120px; padding: 8px 10px; font-size: .82rem; }
.lt-log { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; font-size: .84rem; }
.lt-log li { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; line-height: 1.4; }
.lt-log li time { color: var(--text-muted); font-variant-numeric: tabular-nums; flex: none; }
.lt-log li.loud { color: #b91c1c; font-weight: 600; }
.lt-log li.motion { color: #b45309; font-weight: 600; }
.lt-log .empty { color: var(--text-muted); border: 0; }
.lt-counts { display: flex; gap: 10px; margin-bottom: 10px; }
.lt-count { flex: 1; background: var(--bg); border-radius: 12px; padding: 8px; text-align: center; font-size: .78rem; color: var(--text-muted); }
.lt-count b { display: block; font-size: 1.5rem; color: var(--dark); }
.lt-note { font-size: .8rem; color: var(--text-muted); line-height: 1.6; }

/* ===== Thú cưng (SVG) ===== */
.pet { display: block; --fur: #f5c26b; --fur2: #d28b2c; --muzzle: #fde6b8; --nose: #3b2a20; --paw: var(--fur); }
.pet-svg { width: 100%; height: auto; overflow: visible; display: block; }
.pet .body-wrap, .pet .head, .pet .tail, .pet .mouth-open, .pet .ears { transition: transform .35s ease; }
.pet .body-wrap { transform-origin: 200px 330px; animation: petBreathe 3.4s ease-in-out infinite; }
.pet .head { transform-origin: 200px 300px; }
.pet .eyes-open, .pet .mouth-open, .pet .bubble, .pet .alert-mark, .pet .waves { display: none; }
.pet .ears-point, .pet .ears-round, .pet .whiskers, .pet .patch, .pet .eyepatch { display: none; }
.pet[data-ears="point"] .ears-floppy, .pet[data-ears="round"] .ears-floppy { display: none; }
.pet[data-ears="point"] .ears-point, .pet[data-ears="round"] .ears-round { display: inline; }
.pet[data-extra~="whiskers"] .whiskers, .pet[data-extra~="patch"] .patch, .pet[data-extra~="eyepatch"] .eyepatch { display: inline; }

.pet[data-state="sleep"] .head { transform: translateY(18px) rotate(-5deg); }
.pet[data-state="sleep"] .ears { transform: translateY(8px); }
.pet[data-state="sleep"] .tail { transform: rotate(8deg); transform-origin: 312px 285px; }
.pet[data-state="sleep"] .zzz text { animation: petZ 3s ease-in infinite; opacity: 0; }
.pet[data-state="sleep"] .zzz text:nth-child(2) { animation-delay: 1s; }
.pet[data-state="sleep"] .zzz text:nth-child(3) { animation-delay: 2s; }
.pet[data-state="sleep"] .zzz { display: inline; }
.pet:not([data-state="sleep"]) .zzz, .pet:not([data-state="sleep"]) .eyes-closed, .pet:not([data-state="sleep"]) .mouth-closed.sleepy { display: none; }
.pet[data-state="sleep"] .eyes-open { display: none; }
.pet[data-state="wake"] .eyes-open, .pet[data-state="bark"] .eyes-open { display: inline; }
.pet[data-state="wake"] .alert-mark { display: inline; animation: petBounce .5s ease-in-out infinite alternate; }
.pet[data-state="wake"] .ears, .pet[data-state="bark"] .ears { transform: translateY(-10px); }
.pet[data-state="wake"] .tail, .pet[data-state="bark"] .tail { animation: petWag .35s ease-in-out infinite alternate; transform-origin: 312px 285px; }
.pet[data-state="bark"] .mouth-closed { display: none; }
.pet[data-state="bark"] .mouth-open { display: inline; animation: petChomp .22s ease-in-out infinite alternate; transform-origin: 200px 236px; }
.pet[data-state="bark"] .bubble { display: inline; animation: petBounce .3s ease-in-out infinite alternate; }
.pet[data-state="bark"] .waves { display: inline; }
.pet[data-state="bark"] .waves path { animation: petWave .5s ease-out infinite; }
.pet[data-state="bark"] .waves path:nth-child(2) { animation-delay: .15s; }
.pet[data-state="bark"] .pet-svg { animation: petShake .18s linear infinite; }
.pet[data-state="bark"] .head { animation: petHeadUp .25s ease-in-out infinite alternate; }

@keyframes petBreathe { 50% { transform: scale(1.025, 1.04); } }
@keyframes petZ { 0% { transform: translate(0, 0); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(28px, -62px); opacity: 0; } }
@keyframes petBounce { to { transform: translateY(-8px); } }
@keyframes petWag { from { transform: rotate(-14deg); } to { transform: rotate(18deg); } }
@keyframes petChomp { from { transform: scaleY(.6); } to { transform: scaleY(1.05); } }
@keyframes petShake { 0% { transform: translate(0, 0); } 25% { transform: translate(-3px, 1px); } 75% { transform: translate(3px, -1px); } }
@keyframes petHeadUp { from { transform: translateY(0); } to { transform: translateY(-9px) rotate(2deg); } }
@keyframes petWave { 0% { opacity: .9; transform: translateX(0); } 100% { opacity: 0; transform: translateX(22px); } }

/* ảnh tuỳ chọn thay cho SVG */
.pet-img { width: 100%; height: auto; display: block; object-fit: contain; max-height: 380px; }
.pet[data-state="sleep"] .pet-img { animation: petBreathe 3.4s ease-in-out infinite; transform-origin: 50% 100%; filter: brightness(.9); }
.pet[data-state="wake"] .pet-img { animation: petBounce .5s ease-in-out infinite alternate; }
.pet[data-state="bark"] .pet-img { animation: petShake .15s linear infinite; }
.pet-imgwrap { position: relative; }
.pet-imgwrap .zz { position: absolute; right: 8%; top: 4%; font-weight: 800; color: #fff; font-size: 1.6rem; display: none; animation: petBounce 1.2s ease-in-out infinite alternate; }
.pet[data-state="sleep"] .pet-imgwrap .zz { display: block; }
.pet-imgwrap .wf { position: absolute; right: 2%; top: 2%; font-weight: 800; color: #fff; background: #ef4444; border-radius: 99px; padding: 4px 14px; font-size: 1.2rem; display: none; }
.pet[data-state="bark"] .pet-imgwrap .wf { display: block; animation: petBounce .3s ease-in-out infinite alternate; }

@media (max-width: 1000px) {
  .lt-main > .lt-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .lt-main { grid-template-columns: 1fr; }
  .lt-main > .lt-timer, .lt-main > .lt-left, .lt-main > .lt-side { grid-column: 1; grid-row: auto; position: static; }
  .lt-main > .lt-side { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .lt-modes { grid-template-columns: 1fr; }
  .lt-stage { min-height: 340px; }
  .lt-timer { padding: 12px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .pet *, .lt-stage, .lt-banner, .lt-timer-clock { animation: none !important; }
}

.lt-fs {
  position: absolute; top: 12px; right: 12px; z-index: 6; border: 0; cursor: pointer; font-family: inherit;
  background: rgba(15,23,42,.65); color: #fff; font-weight: 700; font-size: .85rem; padding: 8px 14px; border-radius: 99px; backdrop-filter: blur(4px);
}
.lt-fs:hover { background: rgba(37,99,235,.9); }
.lt-select { padding: 7px 10px; border: 1.5px solid var(--border); border-radius: 10px; font: inherit; font-size: .88rem; background: #fff; max-width: 190px; }
.lt-app:fullscreen .lt-main { grid-template-columns: 300px minmax(0, 1fr); }
.lt-app:fullscreen .lt-stage.cam { aspect-ratio: auto; height: calc(100vh - 250px); min-height: 360px; }
.lt-app:fullscreen .lt-stage:not(.cam) { min-height: calc(100vh - 250px); }
.lt-app:fullscreen .lt-timer-clock { font-size: clamp(3rem, 6vw, 4.6rem); }
