* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #111;
  color: #fff;
  font-family: 'Segoe UI', 'Malgun Gothic', sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

/* 카메라 영역 */
#camera-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
}

#background-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 3;
  pointer-events: none;
  display: none;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  position: relative;
  z-index: 2;
}

#canvas {
  display: none;
}

/* 스티커 */
.sticker {
  position: absolute;
  z-index: 4;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.sticker:active {
  cursor: grabbing;
}

.sticker.selected {
  border-color: #2563eb;
  border-style: dashed;
}

.sticker img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* 스티커 컨트롤 */
#sticker-controls {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(37, 99, 235, 0.85);
  color: #fff;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  user-select: none;
}

.btn-circle:hover {
  background: rgba(29, 78, 216, 0.9);
}

.btn-circle:active {
  transform: scale(0.92);
}

.btn-circle-danger {
  background: rgba(220, 38, 38, 0.85);
}

.btn-circle-danger:hover {
  background: rgba(185, 28, 28, 0.9);
}

/* 컨트롤 버튼 */
#controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 20px;
  background: #222;
}

.btn {
  padding: 14px 28px;
  font-size: 18px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: #fff;
  background: #444;
  transition: background 0.2s, transform 0.1s;
}

.btn:hover {
  background: #555;
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-large {
  padding: 20px 36px;
  font-size: 24px;
}

.duration-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.btn-primary {
  background: #2563eb;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-recording {
  background: #dc2626;
}

.btn-recording:hover {
  background: #b91c1c;
}

.btn-back {
  background: #6b7280;
}

.btn-back:hover {
  background: #4b5563;
}

.btn-success {
  background: #16a34a;
}

.btn-success:hover {
  background: #15803d;
}

/* 카운트다운 */
#countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

#countdown-number {
  font-size: 120px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 40px rgba(0,0,0,0.8);
  animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(1.5); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

/* 녹화 표시 */
#recording-indicator {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  background: rgba(0,0,0,0.6);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 18px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rec-dot {
  width: 12px;
  height: 12px;
  background: #dc2626;
  border-radius: 50%;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* 비활동 타이머 */
#idle-timer {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(220, 38, 38, 0.85);
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 16px;
}

/* 모달 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #1e1e2e;
  border-radius: 16px;
  padding: 30px;
  text-align: center;
  max-width: 90%;
  max-height: 80%;
  overflow-y: auto;
}

.modal-content h2 {
  margin-bottom: 20px;
}

#qr-canvas {
  margin: 10px auto;
  display: block;
}

#qr-url {
  margin: 10px 0 20px;
  word-break: break-all;
  color: #94a3b8;
  font-size: 14px;
}

/* 미리보기 모달 */
.preview-content {
  max-width: 80%;
  max-height: 85%;
}

#preview-area {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#preview-image {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 8px;
}

#preview-video {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 8px;
}

/* 이미지 선택 그리드 */
.overlay-grid-container {
  min-width: 500px;
}

#overlay-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.overlay-item {
  border: 3px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: #333;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.overlay-item img {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  padding: 8px;
}

.overlay-item-label {
  font-size: 11px;
  color: #ccc;
  padding: 2px 4px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 100%;
  text-align: center;
}

.overlay-item-actions {
  display: flex;
  gap: 6px;
  padding: 6px;
  width: 100%;
  justify-content: center;
}

.overlay-item-actions button {
  padding: 6px 12px;
  font-size: 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #fff;
}

.btn-bg {
  background: #7c3aed;
}

.btn-bg:hover {
  background: #6d28d9;
}

.btn-sticker {
  background: #0891b2;
}

.btn-sticker:hover {
  background: #0e7490;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.hidden {
  display: none !important;
}
