/* ScreenBuddy — Phòng chung (scene-view.js) + hộp thoại căn khuôn mặt (image-tools.js). */

.sbs-stage {
  position: relative;
  overflow: hidden;
}

.sbs-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-size: cover;
  background-position: center;
  transition: background 0.4s ease;
}
.sbs-bg.photo {
  background-color: #1f2233;
}
.sbs-bg.loading {
  animation: sbs-shimmer 1.4s ease-in-out infinite;
}

.sbs-items {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* ---------- Món đồ ---------- */
.sbs-item {
  position: absolute;
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.sbs-editing .sbs-item,
.sbs-focus-note .sbs-item.kind-note {
  pointer-events: auto;
  cursor: grab;
}
.sbs-editing .sbs-item:active,
.sbs-focus-note .sbs-item.kind-note:active {
  cursor: grabbing;
}
.sbs-editing .sbs-item.selected,
.sbs-focus-note .sbs-item.kind-note.selected {
  outline: 2px dashed rgba(99, 102, 241, 0.95);
  outline-offset: 4px;
}

.sbs-pic {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: #e9e9f2;
}
.sbs-pic img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.sbs-pic.loading {
  animation: sbs-shimmer 1.4s ease-in-out infinite;
}
.sbs-pic.missing::after {
  content: "🖼";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 30cqw;
  opacity: 0.4;
}

.frame-polaroid .sbs-frame {
  padding: 5cqw 5cqw 0;
  background: #fffdf8;
  border-radius: 1.5cqw;
  box-shadow: 0 1.5cqw 5cqw rgba(0, 0, 0, 0.3);
}
.sbs-caption {
  min-height: 15cqw;
  padding: 2.5cqw 1cqw 3cqw;
  font: 600 7.5cqw/1.2 "Segoe Print", "Comic Sans MS", "Segoe UI", cursive;
  color: #3b3346;
  text-align: center;
  overflow-wrap: anywhere;
}
.frame-round .sbs-pic {
  border-radius: 50%;
  border: 3.5cqw solid #ffffff;
  box-shadow: 0 1.5cqw 5cqw rgba(0, 0, 0, 0.3);
}
.frame-heart .sbs-pic {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50 92C22 72 4 55 4 33 4 18 16 6 30 6c9 0 16 5 20 12C54 11 61 6 70 6c14 0 26 12 26 27 0 22-18 39-46 59z'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50 92C22 72 4 55 4 33 4 18 16 6 30 6c9 0 16 5 20 12C54 11 61 6 70 6c14 0 26 12 26 27 0 22-18 39-46 59z'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
.frame-heart {
  filter: drop-shadow(0 1.5cqw 3cqw rgba(0, 0, 0, 0.3));
}
.frame-plain .sbs-pic {
  border-radius: 3cqw;
  border: 1.5cqw solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1.5cqw 5cqw rgba(0, 0, 0, 0.3);
}

.sbs-sticker {
  font: 80cqw/1.1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  text-align: center;
  filter: drop-shadow(0 1.5cqw 2cqw rgba(0, 0, 0, 0.25));
}
.sbs-text {
  font: 800 11cqw/1.15 "Segoe UI", system-ui, -apple-system, sans-serif;
  text-align: center;
  overflow-wrap: anywhere;
  text-shadow: 0 0.6cqw 0 rgba(0, 0, 0, 0.35), 0 0 3cqw rgba(0, 0, 0, 0.35);
}

/* ---------- Tay nắm khi đang chọn ---------- */
.sbs-h {
  position: absolute;
  z-index: 3;
  display: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #1f2233;
  font: 700 12px/24px "Segoe UI", sans-serif;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.sbs-item.selected .sbs-h {
  display: block;
}
.sbs-h-del { top: -14px; left: -14px; background: #ef4444; color: #fff; }
.sbs-h-front { top: -14px; left: calc(50% - 12px); }
.sbs-h-rot { top: -14px; right: -14px; cursor: alias; touch-action: none; }
.sbs-h-frame,
.sbs-h-color { bottom: -14px; left: calc(50% - 12px); }

/* ---------- Thanh công cụ + menu ---------- */
.sbs-toolbar {
  position: absolute;
  z-index: 50;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 5px;
  max-width: calc(100% - 20px);
  overflow-x: auto;
  border-radius: 14px;
  background: rgba(22, 24, 38, 0.82);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.sbs-toolbar[hidden] {
  display: none;
}
.sbs-tool {
  flex: none;
  padding: 7px 11px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #ffffff;
  font: 600 13px/1 "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
}
.sbs-tool:hover { background: rgba(255, 255, 255, 0.14); }
.sbs-tool.primary { background: #6366f1; }
.sbs-tool.primary:hover { background: #5458e8; }
.sbs-tool.danger:hover { background: rgba(239, 68, 68, 0.4); }

.sbs-pop {
  position: absolute;
  z-index: 60;
  padding: 10px;
  border-radius: 14px;
  background: #ffffff;
  color: #1f2233;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  font: 13px/1.4 "Segoe UI", system-ui, sans-serif;
}
.sbs-ask {
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
}
.sbs-pop-title {
  margin: 0 0 8px;
  font-weight: 700;
}
.sbs-row {
  display: flex;
  gap: 6px;
}
.sbs-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid #d5d7e5;
  border-radius: 9px;
  font: inherit;
  color: inherit;
  background: #fff;
}
.sbs-btn {
  padding: 7px 12px;
  border: 0;
  border-radius: 9px;
  background: #6366f1;
  color: #ffffff;
  font: 600 13px/1.2 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}
.sbs-btn.ghost { background: #eef0f7; color: #1f2233; }
.sbs-btn.block { display: block; width: 100%; margin-top: 8px; }

.sbs-bg-grid {
  display: grid;
  grid-template-columns: repeat(3, 92px);
  gap: 6px;
}
.sbs-bg-swatch {
  position: relative;
  height: 56px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  background-size: cover;
  cursor: pointer;
  overflow: hidden;
}
.sbs-bg-swatch:hover { border-color: #6366f1; }
.sbs-bg-swatch.none { background: repeating-conic-gradient(#e8e9f2 0 25%, #f7f7fb 0 50%) 0 0 / 14px 14px; }
.sbs-bg-swatch span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 4px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 11px;
}
.sbs-sticker-grid {
  display: grid;
  grid-template-columns: repeat(6, 38px);
  gap: 2px;
}
.sbs-sticker-btn {
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font: 22px/1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  cursor: pointer;
}
.sbs-sticker-btn:hover { background: #eef0f7; }

@keyframes sbs-shimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* =====================================================================
 * Hộp thoại căn khuôn mặt
 * ===================================================================== */
.sbc-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(10, 10, 20, 0.6);
}
.sbc-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 2px 0 10px;
  font-size: 12.5px;
  color: #4b4f66;
  cursor: pointer;
}
.sbc-dialog {
  width: 340px;
  max-width: calc(100vw - 24px);
  padding: 18px 20px 16px;
  border-radius: 18px;
  background: #ffffff;
  color: #1f2233;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  font: 13px/1.45 "Segoe UI", system-ui, sans-serif;
  text-align: center;
}
.sbc-title {
  margin: 0 0 4px;
  font-size: 16px;
}
.sbc-hint {
  margin: 0 0 12px;
  color: #6b7085;
}
.sbc-canvas {
  display: block;
  margin: 0 auto;
  border-radius: 12px;
  cursor: grab;
  touch-action: none;
}
.sbc-canvas:active {
  cursor: grabbing;
}
.sbc-zoom {
  width: 300px;
  max-width: 100%;
  margin: 12px 0 4px;
  accent-color: #6366f1;
}
.sbc-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.sbc-btn {
  padding: 9px 16px;
  border: 0;
  border-radius: 10px;
  background: #6366f1;
  color: #fff;
  font: 600 13px/1.2 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}
.sbc-btn.ghost {
  background: #eef0f7;
  color: #1f2233;
}

/* ---------- Giấy nhớ ---------- */
.sbs-note {
  position: relative;
  min-height: 70cqw;
  padding: 14cqw 9cqw 9cqw;
  color: #3b3346;
  font: 600 9.5cqw/1.3 "Segoe Print", "Comic Sans MS", "Segoe UI", cursive;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 2cqw 6cqw rgba(0, 0, 0, 0.28);
  border-radius: 1cqw 1cqw 3cqw 1cqw;
}
.sbs-note::before {
  content: "";
  position: absolute;
  top: -4cqw;
  left: 50%;
  width: 34cqw;
  height: 10cqw;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0.5cqw 1.5cqw rgba(0, 0, 0, 0.15);
}

/* ---------- Thẻ đếm ngày ---------- */
.sbs-counter {
  padding: 8cqw 6cqw 7cqw;
  border-radius: 8cqw;
  background: linear-gradient(160deg, #ffffff, #ffe4ec);
  color: #3b3346;
  text-align: center;
  box-shadow: 0 2cqw 7cqw rgba(0, 0, 0, 0.3);
  font-family: "Segoe UI", system-ui, sans-serif;
}
.sbs-counter.mode-until {
  background: linear-gradient(160deg, #ffffff, #dff1ff);
}
.sbs-counter-label {
  font-weight: 700;
  font-size: 11cqw;
  overflow-wrap: anywhere;
}
.sbs-counter-big {
  margin: 2cqw 0;
  font-weight: 800;
  font-size: 34cqw;
  line-height: 1;
  color: #ff4d6d;
}
.mode-until .sbs-counter-big {
  color: #2f7bd8;
}
.sbs-counter-unit {
  font-size: 10cqw;
  font-weight: 600;
}
.sbs-counter-date {
  margin-top: 3cqw;
  font-size: 8.5cqw;
  opacity: 0.6;
}

/* ---------- Hộp nhập nhiều trường ---------- */
.sbs-form {
  width: min(440px, calc(100% - 24px));
}
.sbs-field {
  display: block;
  margin-bottom: 8px;
}
.sbs-field-label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: #6b7085;
}
.sbs-form .sbs-input {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
}
.sbs-row-end {
  justify-content: flex-end;
}
.sbs-swatches {
  display: flex;
  gap: 6px;
}
.sbs-swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  cursor: pointer;
}
.sbs-swatch.selected {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px #fff inset;
}
